Bug 1455891: Use GetFlattenedTreeParent more in nsFind. r=mats draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 03 Jul 2018 09:21:58 +0200
changeset 813921 35ae348b47a2423ddd96ec34f67a1e5b8018a680
parent 813920 da8525dc3818977f0202bbd614ab9e24a8097781
child 813922 f12211aac0db2aef9c76c9fc6a316b0495dcafb3
push id115046
push userbmo:emilio@crisal.io
push dateWed, 04 Jul 2018 05:02:13 +0000
reviewersmats
bugs1455891
milestone63.0a1
Bug 1455891: Use GetFlattenedTreeParent more in nsFind. r=mats This is the right thing to use for this kind of stuff. MozReview-Commit-ID: FrgD48LjRSG
toolkit/components/find/nsFind.cpp
--- a/toolkit/components/find/nsFind.cpp
+++ b/toolkit/components/find/nsFind.cpp
@@ -192,29 +192,30 @@ SkipNode(const nsIContent* aContent)
       return true;
     }
 
     // Only climb to the nearest block node
     if (IsBlockNode(content)) {
       return false;
     }
 
-    content = content->GetParent();
+    content = content->GetFlattenedTreeParent();
   }
 
   return false;
 }
 
 static const nsIContent*
-GetBlockParent(const Text* aNode)
+GetBlockParent(const Text& aNode)
 {
   // FIXME(emilio): This should use GetFlattenedTreeParent instead to properly
   // handle Shadow DOM.
-  for (const nsIContent* current = aNode->GetParent(); current;
-       current = current->GetParent()) {
+  for (const nsIContent* current = aNode.GetFlattenedTreeParent();
+       current;
+       current = current->GetFlattenedTreeParent()) {
     if (IsBlockNode(current)) {
       return current;
     }
   }
   return nullptr;
 }
 
 struct nsFind::State final
@@ -320,17 +321,17 @@ nsFind::State::Initialize()
     return;
   }
 
   if (!current->IsText() || SkipNode(current->AsText())) {
     Advance();
     return;
   }
 
-  mLastBlockParent = GetBlockParent(current->AsText());
+  mLastBlockParent = GetBlockParent(*current->AsText());
 
   if (current != beginning) {
     return;
   }
 
   mIterOffset = mFindBackward ? mStartPoint.EndOffset()
                               : mStartPoint.StartOffset();
 }
@@ -339,17 +340,17 @@ const nsTextFragment*
 nsFind::State::GetNextNonEmptyTextFragmentInSameBlock()
 {
   while (true) {
     const Text* current = GetNextNode();
     if (!current) {
       return nullptr;
     }
 
-    const nsIContent* blockParent = GetBlockParent(current);
+    const nsIContent* blockParent = GetBlockParent(*current);
     if (!blockParent || blockParent != mLastBlockParent) {
       return nullptr;
     }
 
     const nsTextFragment& frag = current->TextFragment();
     if (frag.GetLength()) {
       return &frag;
     }
@@ -571,17 +572,17 @@ nsFind::Find(const char16_t* aPatText, n
       current = state.GetNextNode();
       if (!current) {
         return NS_OK;
       }
 
       // We have a new text content. If its block parent is different from the
       // block parent of the last text content, then we need to clear the match
       // since we don't want to find across block boundaries.
-      const nsIContent* blockParent = GetBlockParent(current);
+      const nsIContent* blockParent = GetBlockParent(*current);
       DEBUG_FIND_PRINTF("New node: old blockparent = %p, new = %p\n",
                         (void*)state.mLastBlockParent, (void*)blockParent);
       if (blockParent != state.mLastBlockParent) {
         DEBUG_FIND_PRINTF("Different block parent!\n");
         state.mLastBlockParent = blockParent;
         // End any pending match:
         matchAnchorNode = nullptr;
         matchAnchorOffset = 0;