From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- extensions/spellcheck/src/mozSpellChecker.h | 197 ++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 extensions/spellcheck/src/mozSpellChecker.h (limited to 'extensions/spellcheck/src/mozSpellChecker.h') diff --git a/extensions/spellcheck/src/mozSpellChecker.h b/extensions/spellcheck/src/mozSpellChecker.h new file mode 100644 index 0000000000..aec4a95d65 --- /dev/null +++ b/extensions/spellcheck/src/mozSpellChecker.h @@ -0,0 +1,197 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozSpellChecker_h__ +#define mozSpellChecker_h__ + +#include "mozilla/MozPromise.h" +#include "nsCOMPtr.h" +#include "nsCOMArray.h" +#include "nsString.h" +#include "mozIPersonalDictionary.h" +#include "mozISpellCheckingEngine.h" +#include "nsClassHashtable.h" +#include "nsTArray.h" +#include "nsCycleCollectionParticipant.h" + +class mozEnglishWordUtils; + +namespace mozilla { +class RemoteSpellcheckEngineChild; +class TextServicesDocument; +typedef MozPromise, nsresult, false> CheckWordPromise; +typedef MozPromise, nsresult, false> + SuggestionsPromise; +} // namespace mozilla + +class mozSpellChecker final { + public: + NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(mozSpellChecker) + NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(mozSpellChecker) + + static already_AddRefed Create() { + RefPtr spellChecker = new mozSpellChecker(); + nsresult rv = spellChecker->Init(); + NS_ENSURE_SUCCESS(rv, nullptr); + return spellChecker.forget(); + } + + /** + * Tells the spellchecker what document to check. + * @param aDoc is the document to check. + * @param aFromStartOfDoc If true, start check from beginning of document, + * if false, start check from current cursor position. + */ + nsresult SetDocument(mozilla::TextServicesDocument* aTextServicesDocument, + bool aFromStartofDoc); + + /** + * Selects (hilites) the next misspelled word in the document. + * @param aWord will contain the misspelled word. + * @param aSuggestions is an array of nsStrings, that represent the + * suggested replacements for the misspelled word. + */ + MOZ_CAN_RUN_SCRIPT + nsresult NextMisspelledWord(nsAString& aWord, + nsTArray& aSuggestions); + + /** + * Checks if a word is misspelled. No document is required to use this method. + * @param aWord is the word to check. + * @param aIsMisspelled will be set to true if the word is misspelled. + * @param aSuggestions is an array of nsStrings which represent the + * suggested replacements for the misspelled word. The array will be empty + * in chrome process if there aren't any suggestions. If suggestions is + * unnecessary, use CheckWords of async version. + */ + nsresult CheckWord(const nsAString& aWord, bool* aIsMisspelled, + nsTArray* aSuggestions); + + /** + * This is a flavor of CheckWord, is async version of CheckWord. + * @Param aWords is array of words to check + */ + RefPtr CheckWords( + const nsTArray& aWords); + + /* + * Checks if a word is misspelled, then get suggestion words if existed. + */ + RefPtr Suggest(const nsAString& aWord, + uint32_t aMaxCount); + + /** + * Replaces the old word with the specified new word. + * @param aOldWord is the word to be replaced. + * @param aNewWord is the word that is to replace old word. + * @param aAllOccurrences will replace all occurrences of old + * word, in the document, with new word when it is true. If + * false, it will replace the 1st occurrence only! + */ + MOZ_CAN_RUN_SCRIPT + nsresult Replace(const nsAString& aOldWord, const nsAString& aNewWord, + bool aAllOccurrences); + + /** + * Ignores all occurrences of the specified word in the document. + * @param aWord is the word to ignore. + */ + nsresult IgnoreAll(const nsAString& aWord); + + /** + * Add a word to the user's personal dictionary. + * @param aWord is the word to add. + */ + nsresult AddWordToPersonalDictionary(const nsAString& aWord); + + /** + * Remove a word from the user's personal dictionary. + * @param aWord is the word to remove. + */ + nsresult RemoveWordFromPersonalDictionary(const nsAString& aWord); + + /** + * Returns the list of words in the user's personal dictionary. + * @param aWordList is an array of nsStrings that represent the + * list of words in the user's personal dictionary. + */ + nsresult GetPersonalDictionary(nsTArray* aWordList); + + /** + * Returns the list of strings representing the dictionaries + * the spellchecker supports. It was suggested that the strings + * returned be in the RFC 1766 format. This format looks something + * like -. + * For example: en-US + * @param aDictionaryList is an array of nsStrings that represent the + * dictionaries supported by the spellchecker. + */ + nsresult GetDictionaryList(nsTArray* aDictionaryList); + + /** + * Returns a string representing the current dictionaries. + * @param aDictionaries will contain the names of the dictionaries. + * This name is the same string that is in the list returned + * by GetDictionaryList(). + */ + nsresult GetCurrentDictionaries(nsTArray& aDictionaries); + + /** + * Tells the spellchecker to use the specified dictionary. + * @param aDictionary a string that is in the list returned + * by GetDictionaryList() or an empty string . If aDictionary is + * an empty array, the spellchecker will be disabled. + */ + nsresult SetCurrentDictionary(const nsACString& aDictionary); + + /** + * Tells the spellchecker to use the specified dictionaries. + * @param aDictionaries an array of strings that is in the list returned + * by GetDictionaryList() or an empty array. If aDictionaries is + * an empty array, the spellchecker will be disabled. + */ + RefPtr SetCurrentDictionaries( + const nsTArray& aDictionaries); + + /** + * Tells the spellchecker to use a specific dictionary from list. + * @param aList a preferred dictionary list + */ + RefPtr SetCurrentDictionaryFromList( + const nsTArray& aList); + + void DeleteRemoteEngine() { mEngine = nullptr; } + + mozilla::TextServicesDocument* GetTextServicesDocument(); + + protected: + mozSpellChecker(); + virtual ~mozSpellChecker(); + + nsresult Init(); + + RefPtr mConverter; + RefPtr mTextServicesDocument; + nsCOMPtr mPersonalDictionary; + + nsCOMPtr mSpellCheckingEngine; + bool mFromStart; + + nsTArray mCurrentDictionaries; + + MOZ_CAN_RUN_SCRIPT + nsresult SetupDoc(int32_t* outBlockOffset); + + nsresult GetCurrentBlockIndex( + mozilla::TextServicesDocument* aTextServicesDocument, + int32_t* aOutBlockIndex); + + nsresult GetEngineList(nsCOMArray* aDictionaryList); + + mozilla::RemoteSpellcheckEngineChild* mEngine; + + friend class mozilla::RemoteSpellcheckEngineChild; +}; +#endif // mozSpellChecker_h__ -- cgit v1.2.3