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
--- 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)
{