Bug 1247364 - add AllChildrenIterator::Seek, r=bz

This commit is contained in:
Alexander Surkov 2016-02-11 08:22:39 -05:00
parent e7ddbfc7cb
commit 64ca196ec5
2 changed files with 37 additions and 4 deletions

View File

@ -190,7 +190,7 @@ FlattenedChildIterator::Init(bool aIgnoreXBL)
}
}
void
bool
ExplicitChildIterator::Seek(nsIContent* aChildToFind)
{
if (aChildToFind->GetParent() == mParent &&
@ -204,14 +204,14 @@ ExplicitChildIterator::Seek(nsIContent* aChildToFind)
mShadowIterator = nullptr;
mDefaultChild = nullptr;
mIsFirst = false;
return;
return true;
}
// Can we add more fast paths here based on whether the parent of aChildToFind
// is a shadow insertion point or content insertion point?
// Slow path: just walk all our kids.
Seek(aChildToFind, nullptr);
return Seek(aChildToFind, nullptr);
}
nsIContent*
@ -311,6 +311,37 @@ ExplicitChildIterator::GetPreviousChild()
return mChild;
}
bool
AllChildrenIterator::Seek(nsIContent* aChildToFind)
{
if (mPhase == eNeedBeforeKid) {
mPhase = eNeedExplicitKids;
nsIFrame* frame = mOriginalContent->GetPrimaryFrame();
if (frame) {
nsIFrame* beforeFrame = nsLayoutUtils::GetBeforeFrame(frame);
if (beforeFrame) {
if (beforeFrame->GetContent() == aChildToFind) {
return true;
}
}
}
}
if (mPhase == eNeedExplicitKids) {
if (ExplicitChildIterator::Seek(aChildToFind)) {
return true;
}
mPhase = eNeedAnonKids;
}
nsIContent* child = nullptr;
do {
child = GetNextChild();
} while (child && child != aChildToFind);
return child == aChildToFind;
}
nsIContent*
AllChildrenIterator::GetNextChild()
{

View File

@ -64,7 +64,7 @@ public:
// found. This version can take shortcuts that the two-argument version
// can't, so can be faster (and in fact can be O(1) instead of O(N) in many
// cases).
void Seek(nsIContent* aChildToFind);
bool Seek(nsIContent* aChildToFind);
// Looks for aChildToFind respecting insertion points until aChildToFind is found.
// or aBound is found. If aBound is nullptr then the seek is unbounded. Returns
@ -199,6 +199,8 @@ public:
~AllChildrenIterator() { MOZ_ASSERT(!mMutationGuard.Mutated(0)); }
#endif
bool Seek(nsIContent* aChildToFind);
nsIContent* GetNextChild();
nsIContent* Parent() const { return mOriginalContent; }