Bug 1507543 - Spellchecker for contenteditable/design-mode should not run without focus; r=m_kato
authorEdgar Chen <echen@mozilla.com>
Mon, 03 Dec 2018 11:20:09 +0000
changeset 508446 5e2fad03c885961363aa136290e69df9009f4726
parent 508427 01d0813d8203d78613fc33a3e8e32627c1300b50
child 508447 147a524d090bd96e16642c53062908bc8ab039f6
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1507543
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1507543 - Spellchecker for contenteditable/design-mode should not run without focus; r=m_kato Differential Revision: https://phabricator.services.mozilla.com/D12875
editor/libeditor/tests/test_bug366682.html
editor/reftests/reftest.list
editor/reftests/spellcheck-contenteditable-nofocus-1.html
editor/reftests/spellcheck-contenteditable-nofocus-2.html
editor/reftests/spellcheck-contenteditable-nofocus.html
editor/spellchecker/EditorSpellCheck.cpp
--- a/editor/libeditor/tests/test_bug366682.html
+++ b/editor/libeditor/tests/test_bug366682.html
@@ -38,16 +38,17 @@ function getEditor() {
   var editingSession = SpecialPowers.wrap(win).docShell.editingSession;
   return editingSession.getEditorForWindow(win);
 }
 
 function runTest() {
   editDoc().body.innerHTML = "<div>errror and an other errror</div>";
   gMisspeltWords = ["errror", "errror"];
   editDoc().designMode = "on";
+  editDoc().defaultView.focus();
 
   SpecialPowers.Cu.import(
     "resource://testing-common/AsyncSpellCheckTestHelper.jsm")
                .onSpellCheck(editDoc().documentElement, evalTest);
 }
 
 function evalTest() {
   ok(isSpellingCheckOk(getEditor(), gMisspeltWords),
--- a/editor/reftests/reftest.list
+++ b/editor/reftests/reftest.list
@@ -114,17 +114,18 @@ needs-focus != 824080-4.html 824080-5.ht
 needs-focus == 824080-6.html 824080-6-ref.html
 needs-focus pref(layout.accessiblecaret.enabled,false) pref(layout.accessiblecaret.enabled_on_touch,false) == 824080-7.html 824080-7-ref.html
 needs-focus != 824080-6.html 824080-7.html
 # Bug 674927: copy spellcheck-textarea tests to contenteditable
 == spellcheck-contenteditable-attr.html spellcheck-contenteditable-nofocus-ref.html
 fails-if(Android) needs-focus != spellcheck-contenteditable-attr.html spellcheck-contenteditable-ref.html
 needs-focus == spellcheck-contenteditable-focused.html spellcheck-contenteditable-ref.html
 needs-focus == spellcheck-contenteditable-focused-reframe.html spellcheck-contenteditable-ref.html
-== spellcheck-contenteditable-nofocus.html spellcheck-contenteditable-disabled-ref.html
+== spellcheck-contenteditable-nofocus-1.html spellcheck-contenteditable-disabled-ref.html
+== spellcheck-contenteditable-nofocus-2.html spellcheck-contenteditable-disabled-ref.html
 == spellcheck-contenteditable-disabled.html spellcheck-contenteditable-disabled-ref.html
 == spellcheck-contenteditable-disabled-partial.html spellcheck-contenteditable-disabled-partial-ref.html
 == spellcheck-contenteditable-attr-inherit.html spellcheck-contenteditable-disabled-ref.html
 == spellcheck-contenteditable-attr-dynamic.html spellcheck-contenteditable-disabled-ref.html
 == spellcheck-contenteditable-attr-dynamic-inherit.html spellcheck-contenteditable-disabled-ref.html
 == spellcheck-contenteditable-property-dynamic.html spellcheck-contenteditable-disabled-ref.html
 == spellcheck-contenteditable-property-dynamic-inherit.html spellcheck-contenteditable-disabled-ref.html
 == spellcheck-contenteditable-attr-dynamic-override.html spellcheck-contenteditable-disabled-ref.html
rename from editor/reftests/spellcheck-contenteditable-nofocus.html
rename to editor/reftests/spellcheck-contenteditable-nofocus-1.html
new file mode 100644
--- /dev/null
+++ b/editor/reftests/spellcheck-contenteditable-nofocus-2.html
@@ -0,0 +1,2 @@
+<!DOCTYPE html>
+<html><body><div contenteditable>blahblahblah</div></body></html>
\ No newline at end of file
--- a/editor/spellchecker/EditorSpellCheck.cpp
+++ b/editor/spellchecker/EditorSpellCheck.cpp
@@ -641,37 +641,40 @@ EditorSpellCheck::UpdateCurrentDictionar
   nsresult rv;
 
   RefPtr<EditorSpellCheck> kungFuDeathGrip = this;
 
   // Get language with html5 algorithm
   nsCOMPtr<nsIContent> rootContent;
   HTMLEditor* htmlEditor = mEditor->AsHTMLEditor();
   if (htmlEditor) {
-    rootContent = htmlEditor->GetActiveEditingHost();
+    rootContent = htmlEditor->GetFocusedContent();
   } else {
     rootContent = mEditor->GetRoot();
   }
 
+  if (!rootContent) {
+    return NS_ERROR_FAILURE;
+  }
+
   // Try to get topmost document's document element for embedded mail editor.
   uint32_t flags = 0;
   mEditor->GetFlags(&flags);
   if (flags & nsIPlaintextEditor::eEditorMailMask) {
     nsCOMPtr<nsIDocument> ownerDoc = rootContent->OwnerDoc();
     NS_ENSURE_TRUE(ownerDoc, NS_ERROR_FAILURE);
     nsIDocument* parentDoc = ownerDoc->GetParentDocument();
     if (parentDoc) {
       rootContent = parentDoc->GetDocumentElement();
+      if (!rootContent) {
+        return NS_ERROR_FAILURE;
+      }
     }
   }
 
-  if (!rootContent) {
-    return NS_ERROR_FAILURE;
-  }
-
   RefPtr<DictionaryFetcher> fetcher =
       new DictionaryFetcher(this, aCallback, mDictionaryFetcherGroup);
   rootContent->GetLang(fetcher->mRootContentLang);
   nsCOMPtr<nsIDocument> doc = rootContent->GetComposedDoc();
   NS_ENSURE_STATE(doc);
   doc->GetContentLanguage(fetcher->mRootDocContentLang);
 
   rv = fetcher->Fetch(mEditor);