summaryrefslogtreecommitdiffstats
path: root/extensions/spellcheck/src/mozSpellChecker.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /extensions/spellcheck/src/mozSpellChecker.h
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--extensions/spellcheck/src/mozSpellChecker.h180
1 files changed, 180 insertions, 0 deletions
diff --git a/extensions/spellcheck/src/mozSpellChecker.h b/extensions/spellcheck/src/mozSpellChecker.h
new file mode 100644
index 0000000000..ca2ac2f51e
--- /dev/null
+++ b/extensions/spellcheck/src/mozSpellChecker.h
@@ -0,0 +1,180 @@
+/* -*- 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<CopyableTArray<bool>, nsresult, false> CheckWordPromise;
+} // namespace mozilla
+
+class mozSpellChecker final {
+ public:
+ NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(mozSpellChecker)
+ NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(mozSpellChecker)
+
+ static already_AddRefed<mozSpellChecker> Create() {
+ RefPtr<mozSpellChecker> 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<nsString>& 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<nsString>* aSuggestions);
+
+ /**
+ * This is a flavor of CheckWord, is async version of CheckWord.
+ * @Param aWords is array of words to check
+ */
+ RefPtr<mozilla::CheckWordPromise> CheckWords(
+ const nsTArray<nsString>& aWords);
+
+ /**
+ * 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<nsString>* 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 <ISO 639 language code>-<ISO 3166 country code>.
+ * For example: en-US
+ * @param aDictionaryList is an array of nsStrings that represent the
+ * dictionaries supported by the spellchecker.
+ */
+ nsresult GetDictionaryList(nsTArray<nsCString>* aDictionaryList);
+
+ /**
+ * Returns a string representing the current dictionary.
+ * @param aDictionary will contain the name of the dictionary.
+ * This name is the same string that is in the list returned
+ * by GetDictionaryList().
+ */
+ nsresult GetCurrentDictionary(nsACString& aDictionary);
+
+ /**
+ * Tells the spellchecker to use a specific dictionary.
+ * @param aDictionary a string that is in the list returned
+ * by GetDictionaryList() or an empty string. If aDictionary is
+ * empty string, spellchecker will be disabled.
+ */
+ nsresult SetCurrentDictionary(const nsACString& aDictionary);
+
+ /**
+ * Tells the spellchecker to use a specific dictionary from list.
+ * @param aList a preferred dictionary list
+ */
+ RefPtr<mozilla::GenericPromise> SetCurrentDictionaryFromList(
+ const nsTArray<nsCString>& aList);
+
+ void DeleteRemoteEngine() { mEngine = nullptr; }
+
+ mozilla::TextServicesDocument* GetTextServicesDocument();
+
+ protected:
+ mozSpellChecker();
+ virtual ~mozSpellChecker();
+
+ nsresult Init();
+
+ RefPtr<mozEnglishWordUtils> mConverter;
+ RefPtr<mozilla::TextServicesDocument> mTextServicesDocument;
+ nsCOMPtr<mozIPersonalDictionary> mPersonalDictionary;
+
+ nsCOMPtr<mozISpellCheckingEngine> mSpellCheckingEngine;
+ bool mFromStart;
+
+ nsCString mCurrentDictionary;
+
+ MOZ_CAN_RUN_SCRIPT
+ nsresult SetupDoc(int32_t* outBlockOffset);
+
+ nsresult GetCurrentBlockIndex(
+ mozilla::TextServicesDocument* aTextServicesDocument,
+ int32_t* aOutBlockIndex);
+
+ nsresult GetEngineList(nsCOMArray<mozISpellCheckingEngine>* aDictionaryList);
+
+ mozilla::RemoteSpellcheckEngineChild* mEngine;
+
+ friend class mozilla::RemoteSpellcheckEngineChild;
+};
+#endif // mozSpellChecker_h__