EditorSpellCheck.h (2809B)
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 nsTArray<nsCString> mPreferredLangs; 68 69 uint32_t mTxtSrvFilterType; 70 int32_t mSuggestedWordIndex; 71 uint32_t mDictionaryFetcherGroup; 72 73 bool mUpdateDictionaryRunning; 74 75 nsresult DeleteSuggestedWordList(); 76 77 bool BuildDictionaryList(const nsACString& aDictName, 78 const nsTArray<nsCString>& aDictList, 79 enum dictCompare aCompareType, 80 nsTArray<nsCString>& aOutList); 81 82 nsresult DictionaryFetched(DictionaryFetcher* aFetchState); 83 84 void SetDictionarySucceeded(DictionaryFetcher* aFetcher); 85 void SetFallbackDictionary(DictionaryFetcher* aFetcher); 86 87 public: 88 void BeginUpdateDictionary() { mUpdateDictionaryRunning = true; } 89 void EndUpdateDictionary() { mUpdateDictionaryRunning = false; } 90 }; 91 92 } // namespace mozilla 93 94 #endif // mozilla_EditorSpellCheck_h