1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef mozilla_EditorSpellCheck_h 7 #define mozilla_EditorSpellCheck_h 8 9 #include "mozilla/mozSpellChecker.h" // for mozilla::CheckWordPromise 10 #include "nsCOMPtr.h" // for nsCOMPtr 11 #include "nsCycleCollectionParticipant.h" 12 #include "nsIEditorSpellCheck.h" // for NS_DECL_NSIEDITORSPELLCHECK, etc 13 #include "nsISupportsImpl.h" 14 #include "nsString.h" // for nsString 15 #include "nsTArray.h" // for nsTArray 16 #include "nscore.h" // for nsresult 17 18 class mozSpellChecker; 19 class nsIEditor; 20 21 namespace mozilla { 22 23 class DictionaryFetcher; 24 class EditorBase; 25 26 enum dictCompare { 27 DICT_NORMAL_COMPARE, 28 DICT_COMPARE_CASE_INSENSITIVE, 29 DICT_COMPARE_DASHMATCH 30 }; 31 32 class EditorSpellCheck final : public nsIEditorSpellCheck { 33 friend class DictionaryFetcher; 34 35 public: 36 EditorSpellCheck(); 37 38 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 39 NS_DECL_CYCLE_COLLECTION_CLASS(EditorSpellCheck) 40 41 /* Declare all methods in the nsIEditorSpellCheck interface */ 42 NS_DECL_NSIEDITORSPELLCHECK 43 44 mozSpellChecker* GetSpellChecker(); 45 46 /** 47 * Like CheckCurrentWord, checks the word you give it, returning true via 48 * promise if it's misspelled. 49 * This is faster than CheckCurrentWord because it does not compute 50 * any suggestions. 51 * 52 * Watch out: this does not clear any suggestions left over from previous 53 * calls to CheckCurrentWord, so there may be suggestions, but they will be 54 * invalid. 55 */ 56 RefPtr<mozilla::CheckWordPromise> CheckCurrentWordsNoSuggest( 57 const nsTArray<nsString>& aSuggestedWords); 58 59 protected: 60 virtual ~EditorSpellCheck(); 61 62 RefPtr<mozSpellChecker> mSpellChecker; 63 RefPtr<EditorBase> mEditor; 64 65 nsTArray<nsString> mSuggestedWordList; 66 67 // these are the words in the current personal dictionary, 68 // GetPersonalDictionary must be called to load them. 69 nsTArray<nsString> mDictionaryList; 70 71 nsCString mPreferredLang; 72 73 uint32_t mTxtSrvFilterType; 74 int32_t mSuggestedWordIndex; 75 int32_t mDictionaryIndex; 76 uint32_t mDictionaryFetcherGroup; 77 78 bool mUpdateDictionaryRunning; 79 80 nsresult DeleteSuggestedWordList(); 81 82 void BuildDictionaryList(const nsACString& aDictName, 83 const nsTArray<nsCString>& aDictList, 84 enum dictCompare aCompareType, 85 nsTArray<nsCString>& aOutList); 86 87 nsresult DictionaryFetched(DictionaryFetcher* aFetchState); 88 89 void SetFallbackDictionary(DictionaryFetcher* aFetcher); 90 91 public: BeginUpdateDictionary()92 void BeginUpdateDictionary() { mUpdateDictionaryRunning = true; } EndUpdateDictionary()93 void EndUpdateDictionary() { mUpdateDictionaryRunning = false; } 94 }; 95 96 } // namespace mozilla 97 98 #endif // mozilla_EditorSpellCheck_h 99