Bug 1330912 - Don't init spell checker dictionary on spellcheck=false content. r?masayuki draft
authorChris Pearce <cpearce@mozilla.com>
Thu, 12 Jan 2017 17:42:24 +0800
changeset 493835 e4f1f72a25b3ebca69c0964b4eae705093ea6861
parent 493537 eb23648534779c110f3a1f2baae1849ae4a9c570
child 547945 fd43f2324390e76435e7716a50240eb1d6948906
push id47861
push userbmo:cpearce@mozilla.com
push dateMon, 06 Mar 2017 06:32:32 +0000
reviewersmasayuki
bugs1330912
milestone54.0a1
Bug 1330912 - Don't init spell checker dictionary on spellcheck=false content. r?masayuki Initializing the spell check dictionary causes a sync IPC call to SendSetDictionary which can take up to 50ms. This was observed while profiling Google Docs, even though the node being focused on Google Docs is spellcheck=false, i.e. we're wasting time setting up the spell checker when it's not going to be used. This patch prevents us initializing the spell checker dictionary when spellcheck is disabled, avoiding the sync IPC. MozReview-Commit-ID: D8nxVsDKDGx
editor/libeditor/EditorBase.cpp
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -48,16 +48,17 @@
 #include "nsComponentManagerUtils.h"    // for do_CreateInstance
 #include "nsComputedDOMStyle.h"         // for nsComputedDOMStyle
 #include "nsContentUtils.h"             // for nsContentUtils
 #include "nsDOMString.h"                // for DOMStringIsNull
 #include "nsDebug.h"                    // for NS_ENSURE_TRUE, etc.
 #include "nsError.h"                    // for NS_OK, etc.
 #include "nsFocusManager.h"             // for nsFocusManager
 #include "nsFrameSelection.h"           // for nsFrameSelection
+#include "nsGenericHTMLElement.h"       // for nsGenericHTMLElement
 #include "nsGkAtoms.h"                  // for nsGkAtoms, nsGkAtoms::dir
 #include "nsIAbsorbingTransaction.h"    // for nsIAbsorbingTransaction
 #include "nsIAtom.h"                    // for nsIAtom
 #include "nsIContent.h"                 // for nsIContent
 #include "nsIDOMAttr.h"                 // for nsIDOMAttr
 #include "nsIDOMCharacterData.h"        // for nsIDOMCharacterData
 #include "nsIDOMDocument.h"             // for nsIDOMDocument
 #include "nsIDOMElement.h"              // for nsIDOMElement
@@ -5169,20 +5170,34 @@ EditorBase::IsAcceptableInputEvent(Widge
     return false;
   }
 
   // Otherwise, we shouldn't handle any input events when we're not an active
   // element of the DOM window.
   return IsActiveInDOMWindow();
 }
 
+// The element has a spellcheck=false attribute.
+static bool
+IsSpellCheckFalse(Element* aElement)
+{
+  return aElement &&
+         aElement->IsHTMLElement() &&
+         !static_cast<nsGenericHTMLElement*>(aElement)->Spellcheck();
+}
+
 void
 EditorBase::OnFocus(nsIDOMEventTarget* aFocusEventTarget)
 {
   InitializeSelection(aFocusEventTarget);
+  nsCOMPtr<nsIContent> content = do_QueryInterface(aFocusEventTarget);
+  Element* root = IsPlaintextEditor() ? GetExposedRoot() : GetEditorRoot();
+  if (!IsEditable(content) || IsSpellCheckFalse(root)) {
+    return;
+  }
   if (mInlineSpellChecker) {
     mInlineSpellChecker->UpdateCurrentDictionary();
   }
 }
 
 NS_IMETHODIMP
 EditorBase::GetSuppressDispatchingInputEvent(bool* aSuppressed)
 {