Bug 1568501 - Search from the end of the line rather than the start, like this code did before bug 1566945. r=dholbert

Differential Revision: https://phabricator.services.mozilla.com/D39268

--HG--
extra : moz-landing-system : lando
This commit is contained in:
L. David Baron 2019-07-25 21:02:40 +00:00
parent 868643a218
commit 2af9d08603
3 changed files with 26 additions and 2 deletions

View File

@ -5475,8 +5475,12 @@ void nsBlockFrame::AddFrames(nsFrameList& aFrameList, nsIFrame* aPrevSibling,
frames = &overflowLines->mFrames; frames = &overflowLines->mFrames;
} }
} }
// FIXME: Should this IndexOf search from the end?
prevSiblingIndex = prevSibLine->IndexOf(aPrevSibling); nsLineList::iterator nextLine = prevSibLine.next();
nsIFrame* lastFrameInLine = nextLine == lineList->end()
? frames->LastChild()
: nextLine->mFirstChild->GetPrevSibling();
prevSiblingIndex = prevSibLine->RIndexOf(aPrevSibling, lastFrameInLine);
MOZ_ASSERT(prevSiblingIndex >= 0, MOZ_ASSERT(prevSiblingIndex >= 0,
"aPrevSibling must be in aPrevSiblingLine"); "aPrevSibling must be in aPrevSiblingLine");
} else { } else {

View File

@ -302,6 +302,20 @@ int32_t nsLineBox::IndexOf(nsIFrame* aFrame) const {
return -1; return -1;
} }
int32_t nsLineBox::RIndexOf(nsIFrame* aFrame,
nsIFrame* aLastFrameInLine) const {
nsIFrame* frame = aLastFrameInLine;
for (int32_t i = GetChildCount() - 1; i >= 0; --i) {
MOZ_ASSERT(i != 0 || frame == mFirstChild,
"caller provided incorrect last frame");
if (frame == aFrame) {
return i;
}
frame = frame->GetPrevSibling();
}
return -1;
}
bool nsLineBox::IsEmpty() const { bool nsLineBox::IsEmpty() const {
if (IsBlock()) return mFirstChild->IsEmpty(); if (IsBlock()) return mFirstChild->IsEmpty();

View File

@ -525,8 +525,14 @@ class nsLineBox final : public nsLineLink {
void AddSizeOfExcludingThis(nsWindowSizes& aSizes) const; void AddSizeOfExcludingThis(nsWindowSizes& aSizes) const;
// Find the index of aFrame within the line, starting search at the start.
int32_t IndexOf(nsIFrame* aFrame) const; int32_t IndexOf(nsIFrame* aFrame) const;
// Find the index of aFrame within the line, starting search at the end.
// (Produces the same result as IndexOf, but with different performance
// characteristics.) The caller must provide the last frame in the line.
int32_t RIndexOf(nsIFrame* aFrame, nsIFrame* aLastFrameInLine) const;
bool Contains(nsIFrame* aFrame) const { bool Contains(nsIFrame* aFrame) const {
return MOZ_UNLIKELY(mFlags.mHasHashedFrames) ? mFrames->Contains(aFrame) return MOZ_UNLIKELY(mFlags.mHasHashedFrames) ? mFrames->Contains(aFrame)
: IndexOf(aFrame) >= 0; : IndexOf(aFrame) >= 0;