tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 49a62d866d7931144fc1395ca5fc0222e4dcbff1
parent db1bf99e8930697acaf3fcbd109bc495df570b25
Author: Emilio Cobos Álvarez <emilio@crisal.io>
Date:   Wed, 12 Nov 2025 07:59:07 +0000

Bug 1999621 - Remove nsIFrame::GetOffsetFromView. r=tnikkel,layout-reviewers

Now that only root frames have views, we can just use the root frame directly.

This is only used to have a common reference frame for caret position (this
should probably be simpler).

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

Diffstat:
Mlayout/generic/nsFrameSelection.cpp | 7+------
Mlayout/generic/nsIFrame.cpp | 46+++++++++-------------------------------------
Mlayout/generic/nsIFrame.h | 9+++------
3 files changed, 13 insertions(+), 49 deletions(-)

diff --git a/layout/generic/nsFrameSelection.cpp b/layout/generic/nsFrameSelection.cpp @@ -516,12 +516,7 @@ nsresult nsFrameSelection::DesiredCaretPos::FetchPos( if (!caretFrame) { return NS_ERROR_FAILURE; } - nsPoint viewOffset(0, 0); - nsView* view = nullptr; - caretFrame->GetOffsetFromView(viewOffset, &view); - if (view) { - coord += viewOffset; - } + coord += caretFrame->GetOffsetToRootFrame(); aDesiredCaretPos = coord.TopLeft(); return NS_OK; } diff --git a/layout/generic/nsIFrame.cpp b/layout/generic/nsIFrame.cpp @@ -7756,6 +7756,10 @@ nsPoint nsIFrame::GetOffsetTo(const nsIFrame* aOther) const { return OffsetCalculator<&nsIFrame::GetPosition>(this, aOther); } +nsPoint nsIFrame::GetOffsetToRootFrame() const { + return GetOffsetTo(PresShell()->GetRootFrame()); +} + nsPoint nsIFrame::GetOffsetToIgnoringScrolling(const nsIFrame* aOther) const { return OffsetCalculator<&nsIFrame::GetPositionIgnoringScrolling>(this, aOther); @@ -7845,27 +7849,6 @@ nsRect nsIFrame::GetScreenRectInAppUnits() const { return nsRect(rootScreenPos + GetOffsetTo(rootFrame), GetSize()); } -// Returns the offset from this frame to the closest geometric parent that -// has a view. Also returns the containing view or null in case of error -void nsIFrame::GetOffsetFromView(nsPoint& aOffset, nsView** aView) const { - MOZ_ASSERT(aView, "null OUT parameter pointer"); - nsIFrame* frame = const_cast<nsIFrame*>(this); - - *aView = nullptr; - aOffset.MoveTo(0, 0); - while (true) { - aOffset += frame->GetPosition(); - frame = frame->GetParent(); - if (!frame) { - break; - } - if (auto* view = frame->GetView()) { - *aView = view; - break; - } - } -} - nsIWidget* nsIFrame::GetNearestWidget() const { if (!HasAnyStateBits(NS_FRAME_IN_POPUP)) { return PresContext()->GetRootWidget(); @@ -9275,9 +9258,7 @@ static nsresult GetNextPrevLineFromBlockFrame(PeekOffsetStruct* aPos, farStoppingFrame = firstFrame; } } - nsPoint offset; - nsView* view; // used for call of get offset from view - aBlockFrame->GetOffsetFromView(offset, &view); + nsPoint offset = aBlockFrame->GetOffsetToRootFrame(); nsPoint newDesiredPos = aPos->mDesiredCaretPos - offset; // get desired position into blockframe coords @@ -9338,12 +9319,7 @@ static nsresult GetNextPrevLineFromBlockFrame(PeekOffsetStruct* aPos, while (!found) { nsPoint point; nsRect tempRect = resultFrame->GetRect(); - nsPoint offset; - nsView* view; // used for call of get offset from view - resultFrame->GetOffsetFromView(offset, &view); - if (!view) { - return NS_ERROR_FAILURE; - } + nsPoint offset = resultFrame->GetOffsetToRootFrame(); if (resultFrame->GetWritingMode().IsVertical()) { point.y = aPos->mDesiredCaretPos.y; point.x = tempRect.width + offset.x; @@ -9352,10 +9328,8 @@ static nsresult GetNextPrevLineFromBlockFrame(PeekOffsetStruct* aPos, point.x = aPos->mDesiredCaretPos.x; } - if (!resultFrame->GetView()) { - nsView* view; - nsPoint offset; - resultFrame->GetOffsetFromView(offset, &view); + if (!resultFrame->IsViewportFrame()) { + nsPoint offset = resultFrame->GetOffsetToRootFrame(); nsIFrame::ContentOffsets offsets = resultFrame->GetContentOffsetsFromPoint( point - offset, nsIFrame::IGNORE_NATIVE_ANONYMOUS_SUBTREE); @@ -9396,9 +9370,7 @@ static nsresult GetNextPrevLineFromBlockFrame(PeekOffsetStruct* aPos, } while (!found) { nsPoint point = aPos->mDesiredCaretPos; - nsView* view; - nsPoint offset; - resultFrame->GetOffsetFromView(offset, &view); + nsPoint offset = resultFrame->GetOffsetToRootFrame(); nsIFrame::ContentOffsets offsets = resultFrame->GetContentOffsetsFromPoint( point - offset, nsIFrame::IGNORE_NATIVE_ANONYMOUS_SUBTREE); diff --git a/layout/generic/nsIFrame.h b/layout/generic/nsIFrame.h @@ -3359,6 +3359,9 @@ class nsIFrame : public nsQueryFrame { */ nsPoint GetOffsetTo(const nsIFrame* aOther) const; + // GetOffsetTo() to the root of this document. + nsPoint GetOffsetToRootFrame() const; + /** * Just like GetOffsetTo, but treats all scrollframes as scrolled to * their origin. @@ -3408,12 +3411,6 @@ class nsIFrame : public nsQueryFrame { nsRect GetScreenRectInAppUnits() const; /** - * Returns the offset from this frame to the closest geometric parent that - * has a view. Also returns the containing view or null in case of error - */ - void GetOffsetFromView(nsPoint& aOffset, nsView** aView) const; - - /** * Returns the nearest widget containing this frame. If this frame has a * view and the view has a widget, then this frame's widget is * returned, otherwise this frame's geometric parent is checked