Bug 1330912 - Part 3. Don't update dictionary during onfocus when spellcheck is unnecessary. r?masayuki draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Tue, 11 Apr 2017 16:51:04 +0900
changeset 560173 78726a55b49859593e6a0beb7c8ec5c743b3b34a
parent 560172 1ff598bc449d363eb38b22ef15681849449610ba
child 560174 8f8a5e5a29ea64bf19dc9e8eb7b8e7652f14de95
push id53359
push userm_kato@ga2.so-net.ne.jp
push dateTue, 11 Apr 2017 08:08:55 +0000
reviewersmasayuki
bugs1330912
milestone55.0a1
Bug 1330912 - Part 3. Don't update dictionary during onfocus when spellcheck is unnecessary. r?masayuki Such as <input type=password>, focused element doesn't use spellchecker, we should not call UpdateCurrentDictionary. Also, when the attribute is changed, we should call UpdateCurrentDictionary if uninitialized. MozReview-Commit-ID: LSfDTAszviE
editor/libeditor/EditorBase.cpp
editor/libeditor/EditorBase.h
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -140,16 +140,17 @@ EditorBase::EditorBase()
   , mDocDirtyState(-1)
   , mSpellcheckCheckboxState(eTriUnset)
   , mShouldTxnSetSelection(true)
   , mDidPreDestroy(false)
   , mDidPostCreate(false)
   , mDispatchInputEvent(true)
   , mIsInEditAction(false)
   , mHidingCaret(false)
+  , mSpellCheckerDictionaryUpdated(true)
 {
 }
 
 EditorBase::~EditorBase()
 {
   NS_ASSERTION(!mDocWeak || mDidPreDestroy, "Why PreDestroy hasn't been called?");
 
   if (mComposition) {
@@ -1339,16 +1340,21 @@ EditorBase::SyncRealTimeSpell()
 {
   bool enable = GetDesiredSpellCheckState();
 
   // Initializes mInlineSpellChecker
   nsCOMPtr<nsIInlineSpellChecker> spellChecker;
   GetInlineSpellChecker(enable, getter_AddRefs(spellChecker));
 
   if (mInlineSpellChecker) {
+    if (!mSpellCheckerDictionaryUpdated && enable) {
+      mInlineSpellChecker->UpdateCurrentDictionary();
+      mSpellCheckerDictionaryUpdated = true;
+    }
+
     // We might have a mInlineSpellChecker even if there are no dictionaries
     // available since we don't destroy the mInlineSpellChecker when the last
     // dictionariy is removed, but in that case spellChecker is null
     mInlineSpellChecker->SetEnableRealTimeSpell(enable && spellChecker);
   }
 
   return NS_OK;
 }
@@ -5210,18 +5216,20 @@ EditorBase::IsAcceptableInputEvent(Widge
   // element of the DOM window.
   return IsActiveInDOMWindow();
 }
 
 void
 EditorBase::OnFocus(nsIDOMEventTarget* aFocusEventTarget)
 {
   InitializeSelection(aFocusEventTarget);
-  if (mInlineSpellChecker) {
+  mSpellCheckerDictionaryUpdated = false;
+  if (mInlineSpellChecker && CanEnableSpellCheck()) {
     mInlineSpellChecker->UpdateCurrentDictionary();
+    mSpellCheckerDictionaryUpdated = true;
   }
 }
 
 NS_IMETHODIMP
 EditorBase::GetSuppressDispatchingInputEvent(bool* aSuppressed)
 {
   NS_ENSURE_ARG_POINTER(aSuppressed);
   *aSuppressed = !mDispatchInputEvent;
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -1077,16 +1077,18 @@ protected:
   bool mDidPreDestroy;
   // Whether PostCreate has been called.
   bool mDidPostCreate;
   bool mDispatchInputEvent;
   // True while the instance is handling an edit action.
   bool mIsInEditAction;
   // Whether caret is hidden forcibly.
   bool mHidingCaret;
+  // Whether spellchecker dictionary is initialized after focused.
+  bool mSpellCheckerDictionaryUpdated;
 
   friend bool NSCanUnload(nsISupports* serviceMgr);
   friend class AutoRules;
   friend class AutoSelectionRestorer;
   friend class AutoTransactionsConserveSelection;
   friend class RangeUpdater;
 };