Bug 1497480 - Part 2: Make spellchecking to work in ShadowDOM after anchor navigates away from it; r=smaug a=jcristau
authorEdgar Chen <echen@mozilla.com>
Fri, 02 Nov 2018 00:07:30 +0000
changeset 501042 ad24ecd2dd3979ec8e13ab4ba79d370c4423fbbd
parent 501041 fa8dfa3aef26a452b800502fa4e6ebf956e64c5e
child 501043 f9639e65bc99f3a2ced65aab2ec17d1f2095734a
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, jcristau
bugs1497480
milestone64.0
Bug 1497480 - Part 2: Make spellchecking to work in ShadowDOM after anchor navigates away from it; r=smaug a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D9543
extensions/spellcheck/src/mozInlineSpellChecker.cpp
--- a/extensions/spellcheck/src/mozInlineSpellChecker.cpp
+++ b/extensions/spellcheck/src/mozInlineSpellChecker.cpp
@@ -81,19 +81,16 @@ using namespace mozilla::dom;
 // be too short to a low-end machine.
 #define INLINESPELL_MINIMUM_WORDS_BEFORE_TIMEOUT 5
 
 // These notifications are broadcast when spell check starts and ends.  STARTED
 // must always be followed by ENDED.
 #define INLINESPELL_STARTED_TOPIC "inlineSpellChecker-spellCheck-started"
 #define INLINESPELL_ENDED_TOPIC "inlineSpellChecker-spellCheck-ended"
 
-static bool ContentIsDescendantOf(nsINode* aPossibleDescendant,
-                                    nsINode* aPossibleAncestor);
-
 static const char kMaxSpellCheckSelectionSize[] =
   "extensions.spellcheck.inline.max-misspellings";
 static const PRTime kMaxSpellCheckTimeInUsec =
   INLINESPELL_CHECK_TIMEOUT * PR_USEC_PER_MSEC;
 
 mozInlineSpellStatus::mozInlineSpellStatus(mozInlineSpellChecker* aSpellChecker)
     : mSpellChecker(aSpellChecker), mWordCount(0)
 {
@@ -223,17 +220,18 @@ mozInlineSpellStatus::InitForNavigation(
   if (NS_WARN_IF(!textEditor)) {
     return NS_ERROR_FAILURE;
   }
   Element* root = textEditor->GetRoot();
   if (NS_WARN_IF(!root)) {
     return NS_ERROR_FAILURE;
   }
   // the anchor node might not be in the DOM anymore, check
-  if (root && aOldAnchorNode && ! ContentIsDescendantOf(aOldAnchorNode, root)) {
+  if (root && aOldAnchorNode &&
+      !nsContentUtils::ContentIsShadowIncludingDescendantOf(aOldAnchorNode, root)) {
     *aContinue = false;
     return NS_OK;
   }
 
   mOldNavigationAnchorRange =
     PositionToCollapsedRange(aOldAnchorNode, aOldAnchorOffset);
   if (NS_WARN_IF(!mOldNavigationAnchorRange)) {
     return NS_ERROR_FAILURE;
@@ -1723,34 +1721,16 @@ mozInlineSpellChecker::SaveCurrentSelect
   }
 
   mCurrentSelectionAnchorNode = selection->GetFocusNode();
   mCurrentSelectionOffset = selection->FocusOffset();
 
   return NS_OK;
 }
 
-// This is a copy of nsContentUtils::ContentIsDescendantOf. Another crime
-// for XPCOM's rap sheet
-bool // static
-ContentIsDescendantOf(nsINode* aPossibleDescendant,
-                      nsINode* aPossibleAncestor)
-{
-  MOZ_ASSERT(aPossibleDescendant, "The possible descendant is null!");
-  MOZ_ASSERT(aPossibleAncestor, "The possible ancestor is null!");
-
-  do {
-    if (aPossibleDescendant == aPossibleAncestor)
-      return true;
-    aPossibleDescendant = aPossibleDescendant->GetParentNode();
-  } while (aPossibleDescendant);
-
-  return false;
-}
-
 // mozInlineSpellChecker::HandleNavigationEvent
 //
 //    Acts upon mouse clicks and keyboard navigation changes, spell checking
 //    the previous word if the new navigation location moves us to another
 //    word.
 //
 //    This is complicated by the fact that our mouse events are happening after
 //    selection has been changed to account for the mouse click. But keyboard