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
--- 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;