tor-browser

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

commit 8ef739bd5f3506e8261aeae8a0b3ab61c9378c02
parent 757847de0fcf5cd1299e81a70ac5412c4162484e
Author: Emilio Cobos Álvarez <emilio@crisal.io>
Date:   Sat, 15 Nov 2025 00:04:55 +0000

Bug 2000145 - Remove more nsView members. r=tnikkel,layout-reviewers

* Dimensions don't need to be a rect, just a size.
 * We don't need a frame, it's just the pres shells root frame.
 * mWidgetIsTopLevel is always true iff there is a widget.

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

Diffstat:
Mdom/base/nsDOMWindowUtils.cpp | 2+-
Mlayout/base/PresShell.cpp | 22+++++-----------------
Mlayout/base/PresShell.h | 7-------
Mlayout/base/nsDocumentViewer.cpp | 23++++++++++-------------
Mlayout/generic/ViewportFrame.cpp | 10+---------
Mlayout/generic/nsIFrame.cpp | 1-
Mview/nsView.cpp | 44++++++++------------------------------------
Mview/nsView.h | 48++++--------------------------------------------
Mview/nsViewManager.cpp | 22+++++++---------------
Mview/nsViewManager.h | 10+++-------
10 files changed, 39 insertions(+), 150 deletions(-)

diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp @@ -428,7 +428,7 @@ nsDOMWindowUtils::UpdateLayerTree() { if (nsView* view = vm->GetRootView()) { nsAutoScriptBlocker scriptBlocker; presShell->PaintAndRequestComposite( - view->GetFrame(), view->GetWidget()->GetWindowRenderer(), + presShell->GetRootFrame(), view->GetWidget()->GetWindowRenderer(), PaintFlags::PaintSyncDecodeImages); presShell->GetWindowRenderer()->WaitOnTransactionProcessed(); } diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp @@ -5875,7 +5875,7 @@ void PresShell::ProcessSynthMouseOrPointerMoveEvent( refpoint = aPointerInfo.mLastRefPointInRootDoc; DebugOnly<nsLayoutUtils::TransformResult> result = nsLayoutUtils::TransformPoint( - RelativeTo{rootView->GetFrame(), ViewportType::Visual}, + RelativeTo{GetRootFrame(), ViewportType::Visual}, RelativeTo{popupFrame, ViewportType::Layout}, refpoint); MOZ_ASSERT(result == nsLayoutUtils::TRANSFORM_SUCCEEDED); } @@ -7018,15 +7018,6 @@ void PresShell::nsSynthMouseMoveEvent::Revoke() { } } -nsIFrame* PresShell::GetClosestAncestorFrameForAncestorView() const { - nsViewManager* vm = GetViewManager(); - if (!vm) { - return nullptr; - } - nsView* view = vm->GetRootView(); - return view ? view->GetFrame() : nullptr; -} - static CallState FlushThrottledStyles(Document& aDocument) { PresShell* presShell = aDocument.GetPresShell(); if (presShell && presShell->IsVisible()) { @@ -7210,8 +7201,7 @@ nsresult PresShell::HandleEvent(nsIFrame* aFrameForPresShell, if (MOZ_UNLIKELY(IsDestroying())) { return NS_OK; } - nsIFrame* const newFrameForPresShell = - GetClosestAncestorFrameForAncestorView(); + nsIFrame* const newFrameForPresShell = GetRootFrame(); if (MOZ_UNLIKELY(!newFrameForPresShell)) { return NS_OK; } @@ -8184,8 +8174,7 @@ void PresShell::EventHandler::MaybeSynthesizeCompatMouseEventsForTouchEnd( if (MOZ_UNLIKELY(presShell->IsDestroying())) { break; } - nsIFrame* const frameForPresShell = - presShell->GetClosestAncestorFrameForAncestorView(); + nsIFrame* const frameForPresShell = presShell->GetRootFrame(); if (!frameForPresShell) { break; } @@ -8370,7 +8359,7 @@ nsIFrame* PresShell::EventHandler::GetFrameForHandlingEventWith( } // Otherwise, use nearest ancestor frame which includes the PresShell. - return retargetPresShell->GetClosestAncestorFrameForAncestorView(); + return retargetPresShell->GetRootFrame(); } bool PresShell::EventHandler::MaybeHandleEventWithAnotherPresShell( @@ -8581,8 +8570,7 @@ void PresShell::EventHandler::MaybeFlushThrottledStyles( // FIXME: aWeakFrameForPresShell may be target content's frame if aGUIEvent // of the caller is a touch event. So, we need to use different computation // for such cases. - aWeakFrameForPresShell = - mPresShell->GetClosestAncestorFrameForAncestorView(); + aWeakFrameForPresShell = mPresShell->GetRootFrame(); } } diff --git a/layout/base/PresShell.h b/layout/base/PresShell.h @@ -2178,13 +2178,6 @@ class PresShell final : public nsStubDocumentObserver, already_AddRefed<PresShell> GetParentPresShellForEventHandling(); /** - * Return a frame for a view which is the closest ancestor view which has - * a frame. I.e., if the closest ancestor view does not have a frame, - * this returns a frame for the next closest ancestor view. - */ - [[nodiscard]] nsIFrame* GetClosestAncestorFrameForAncestorView() const; - - /** * EventHandler is implementation of PresShell::HandleEvent(). */ class MOZ_STACK_CLASS EventHandler final { diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp @@ -1916,8 +1916,7 @@ nsDocumentViewer::SetBoundsWithFlags(const LayoutDeviceIntRect& aBounds, int32_t p2a = mPresContext->AppUnitsPerDevPixel(); const nsSize size = LayoutDeviceSize::ToAppUnits(mBounds.Size(), p2a); nsView* rootView = mViewManager->GetRootView(); - if (boundsChanged && rootView) { - nsRect viewDims = rootView->GetBounds(); + if (boundsChanged && rootView && rootView->GetSize() == size) { // If the view/frame tree and prescontext visible area already has the new // size but we did not, then it's likely that we got reflowed in response // to a call to GetContentSize. Thus there is a disconnect between the @@ -1927,16 +1926,14 @@ nsDocumentViewer::SetBoundsWithFlags(const LayoutDeviceIntRect& aBounds, // if they are the same as the new size it won't do anything, but we still // need to invalidate because what we want to draw to the screen has // changed. - if (viewDims.Size() == size) { - if (nsIFrame* f = rootView->GetFrame()) { - f->InvalidateFrame(); - - // Forcibly refresh the viewport sizes even if the view size is not - // changed since it is possible that the |mBounds| change means that - // the software keyboard appeared/disappeared. In such cases we might - // need to fire visual viewport events. - mPresShell->RefreshViewportSize(); - } + if (nsIFrame* f = mPresShell->GetRootFrame()) { + f->InvalidateFrame(); + + // Forcibly refresh the viewport sizes even if the view size is not + // changed since it is possible that the |mBounds| change means that + // the software keyboard appeared/disappeared. In such cases we might + // need to fire visual viewport events. + mPresShell->RefreshViewportSize(); } } @@ -2212,7 +2209,7 @@ void nsDocumentViewer::MakeWindow(const nsSize& aSize) { void nsDocumentViewer::DetachFromTopLevelWidget() { if (mViewManager) { nsView* oldView = mViewManager->GetRootView(); - if (oldView && oldView->IsAttachedToTopLevel()) { + if (oldView && oldView->HasWidget()) { oldView->DetachFromTopLevelWidget(); } } diff --git a/layout/generic/ViewportFrame.cpp b/layout/generic/ViewportFrame.cpp @@ -341,17 +341,10 @@ void ViewportFrame::RemoveFrame(DestroyContext& aContext, ChildListID aListID, void ViewportFrame::SetView(nsView* aView) { MOZ_ASSERT(!mView, "Should not swap views"); - if (aView) { - aView->SetFrame(this); - } mView = aView; } void ViewportFrame::Destroy(DestroyContext& aContext) { - // Prevent event dispatch during destruction. - if (mView) { - mView->SetFrame(nullptr); - } if (PresShell()->IsDestroying()) { PresShell::ClearMouseCapture(this); } @@ -510,8 +503,7 @@ void ViewportFrame::Reflow(nsPresContext* aPresContext, FinishAndStoreOverflow(&aDesiredSize); if (mView) { - mView->GetViewManager()->ResizeView( - mView, nsRect(nsPoint(), aDesiredSize.PhysicalSize())); + mView->GetViewManager()->ResizeView(mView, aDesiredSize.PhysicalSize()); } NS_FRAME_TRACE_REFLOW_OUT("ViewportFrame::Reflow", aStatus); diff --git a/layout/generic/nsIFrame.cpp b/layout/generic/nsIFrame.cpp @@ -943,7 +943,6 @@ void nsIFrame::Destroy(DestroyContext& aContext) { } if (nsView* view = GetView()) { - view->SetFrame(nullptr); view->Destroy(); } diff --git a/view/nsView.cpp b/view/nsView.cpp @@ -28,10 +28,7 @@ using namespace mozilla; using namespace mozilla::widget; nsView::nsView(nsViewManager* aViewManager) - : mViewManager(aViewManager), - mFrame(nullptr), - mWidgetIsTopLevel(false), - mForcedRepaint(false) { + : mViewManager(aViewManager), mForcedRepaint(false) { MOZ_COUNT_CTOR(nsView); // Views should be transparent by default. Not being transparent is @@ -58,8 +55,6 @@ nsView::~nsView() { // Destroy and release the widget DestroyWidget(); - - MOZ_RELEASE_ASSERT(!mFrame); } class DestroyWidgetRunnable : public Runnable { @@ -85,22 +80,7 @@ void nsView::DestroyWidget() { // widget here. However, if we're attached to somebody elses widget, we // want to leave the widget alone: don't reset the client data or call // Destroy. Just clear our event view ptr and free our reference to it. - if (mWidgetIsTopLevel) { - mWindow->SetAttachedWidgetListener(nullptr); - } else { - mWindow->SetWidgetListener(nullptr); - - nsCOMPtr<nsIRunnable> widgetDestroyer = - new DestroyWidgetRunnable(mWindow); - - // Don't leak if we happen to arrive here after the main thread - // has disappeared. - nsCOMPtr<nsIThread> mainThread = do_GetMainThread(); - if (mainThread) { - mainThread->Dispatch(widgetDestroyer.forget(), NS_DISPATCH_NORMAL); - } - } - + mWindow->SetAttachedWidgetListener(nullptr); mWindow = nullptr; } } @@ -174,8 +154,6 @@ LayoutDeviceIntRect nsView::CalcWidgetBounds( aTransparency); } -void nsView::SetDimensions(const nsRect& aRect) { mDimBounds = aRect; } - // Attach to a top level widget and start receiving mirrored events. void nsView::AttachToTopLevelWidget(nsIWidget* aWidget) { MOZ_ASSERT(aWidget, "null widget ptr"); @@ -205,12 +183,10 @@ void nsView::AttachToTopLevelWidget(nsIWidget* aWidget) { if (mWindow->GetWindowType() != WindowType::Invisible) { mWindow->AsyncEnableDragDrop(true); } - mWidgetIsTopLevel = true; } // Detach this view from an attached widget. void nsView::DetachFromTopLevelWidget() { - MOZ_ASSERT(mWidgetIsTopLevel, "Not attached currently!"); MOZ_ASSERT(mWindow, "null mWindow for DetachFromTopLevelWidget!"); mWindow->SetAttachedWidgetListener(nullptr); @@ -218,7 +194,7 @@ void nsView::DetachFromTopLevelWidget() { mWindow->GetPreviouslyAttachedWidgetListener()) { if (nsView* view = listener->GetView()) { // Ensure the listener doesn't think it's being used anymore - view->SetPreviousWidget(nullptr); + view->mPreviousWindow = nullptr; } } @@ -228,8 +204,6 @@ void nsView::DetachFromTopLevelWidget() { mPreviousWindow = mWindow; mWindow = nullptr; - - mWidgetIsTopLevel = false; } #ifdef DEBUG @@ -243,10 +217,7 @@ void nsView::List(FILE* out, int32_t aIndent) const { fprintf(out, "(widget=%p[%" PRIuPTR "] pos=%s) ", (void*)mWindow, widgetRefCnt, ToString(mWindow->GetBounds()).c_str()); } - nsRect brect = GetBounds(); - fprintf(out, "{%d,%d,%d,%d}", brect.X(), brect.Y(), brect.Width(), - brect.Height()); - fprintf(out, " frame=%p <\n", mFrame); + fprintf(out, "{%d, %d}", mSize.width, mSize.height); for (i = aIndent; --i >= 0;) fputs(" ", out); fputs(">\n", out); } @@ -283,7 +254,7 @@ bool nsView::WindowResized(nsIWidget* aWidget, int32_t aWidth, // on a non-default-dpi display (bug 829963) pc->DeviceContext()->CheckDPIChange(); int32_t p2a = pc->AppUnitsPerDevPixel(); - if (auto* frame = GetFrame()) { + if (auto* frame = ps->GetRootFrame()) { // Usually the resize would deal with this, but there are some cases (like // web-extension popups) where frames might already be correctly sized etc // due to a call to e.g. nsDocumentViewer::GetContentSize or so. @@ -452,8 +423,9 @@ void nsView::SafeAreaInsetsChanged( } bool nsView::IsPrimaryFramePaintSuppressed() const { - return StaticPrefs::layout_show_previous_page() && mFrame && - mFrame->PresShell()->IsPaintingSuppressed(); + return StaticPrefs::layout_show_previous_page() && + mViewManager->GetPresShell() && + mViewManager->GetPresShell()->IsPaintingSuppressed(); } void nsView::CallOnAllRemoteChildren( diff --git a/view/nsView.h b/view/nsView.h @@ -138,24 +138,9 @@ class nsView final : public nsIWidgetListener { void Destroy(); /** - * Called to get the dimensions and position of the view's bounds. - * The view's bounds (x,y) are relative to the origin of the parent view, but - * are in appunits of this. - * The view's bounds (x,y) might not be the same as the view's position, - * if the view has content above or to the left of its origin. - * @param aBounds out parameter for bounds + * Called to get the size of the view. */ - nsRect GetBounds() const { return mDimBounds; } - - /** - * Set the view's frame. - */ - void SetFrame(nsIFrame* aRootFrame) { mFrame = aRootFrame; } - - /** - * Retrieve the view's frame. - */ - nsIFrame* GetFrame() const { return mFrame; } + nsSize GetSize() const { return mSize; } /** * Destroys the associated widget for this view. If this method is @@ -179,12 +164,6 @@ class nsView final : public nsIWidgetListener { void DetachFromTopLevelWidget(); /** - * Returns a flag indicating whether the view owns it's widget - * or is attached to an existing top level widget. - */ - bool IsAttachedToTopLevel() const { return mWidgetIsTopLevel; } - - /** * In 4.0, the "cutout" nature of a view is queryable. * If we believe that all cutout view have a native widget, this * could be a replacement. @@ -194,14 +173,6 @@ class nsView final : public nsIWidgetListener { nsIWidget* GetWidget() const { return mWindow; } /** - * The widget which we have attached a listener to can also have a "previous" - * listener set on it. This is to keep track of the last nsView when - * navigating to a new one so that we can continue to paint that if the new - * one isn't ready yet. - */ - void SetPreviousWidget(nsIWidget* aWidget) { mPreviousWindow = aWidget; } - - /** * Returns true if the view has a widget associated with it. */ bool HasWidget() const { return mWindow != nullptr; } @@ -271,15 +242,7 @@ class nsView final : public nsIWidgetListener { bool ForcedRepaint() { return mForcedRepaint; } - void InitializeWindow(bool aEnableDragDrop, bool aResetVisibility); - - /** - * Called to indicate that the dimensions of the view have been changed. - * The x and y coordinates may be < 0, indicating that the view extends above - * or to the left of its origin position. The term 'dimensions' indicates it - * is relative to this view. - */ - void SetDimensions(const nsRect& aRect); + void SetSize(const nsSize& aSize) { mSize = aSize; } void CallOnAllRemoteChildren( const std::function<mozilla::CallState(mozilla::dom::BrowserParent*)>& @@ -288,10 +251,7 @@ class nsView final : public nsIWidgetListener { nsViewManager* mViewManager; nsCOMPtr<nsIWidget> mWindow; nsCOMPtr<nsIWidget> mPreviousWindow; - nsIFrame* mFrame; - // relative to parent, but in our appunits - nsRect mDimBounds; - bool mWidgetIsTopLevel; + nsSize mSize; bool mForcedRepaint; bool mIsDirty = false; }; diff --git a/view/nsViewManager.cpp b/view/nsViewManager.cpp @@ -71,8 +71,7 @@ nsViewManager::~nsViewManager() { } nsView* nsViewManager::CreateView(const nsSize& aSize) { auto* v = new nsView(this); - nsRect dim(nsPoint(), aSize); - v->SetDimensions(dim); + v->SetSize(aSize); return v; } @@ -92,15 +91,15 @@ nsSize nsViewManager::GetWindowDimensions() const { if (mDelayedResize != nsSize(NSCOORD_NONE, NSCOORD_NONE)) { return mDelayedResize; } - return mRootView->GetBounds().Size(); + return mRootView->GetSize(); } void nsViewManager::DoSetWindowDimensions(const nsSize& aSize) { - if (mRootView->GetBounds().Size() == aSize) { + if (mRootView->GetSize() == aSize) { return; } // Don't resize the widget. It is already being set elsewhere. - mRootView->SetDimensions(nsRect(nsPoint(), aSize)); + mRootView->SetSize(aSize); if (RefPtr<PresShell> presShell = mPresShell) { presShell->ResizeReflow(aSize); } @@ -203,9 +202,6 @@ void nsViewManager::Refresh(nsView* aView, nsAutoScriptBlocker scriptBlocker; SetPainting(true); - MOZ_ASSERT(!aView->GetFrame() || !aView->GetFrame()->GetParent(), - "Frame should be a display root"); - if (RefPtr<PresShell> presShell = mPresShell) { #ifdef MOZ_DUMP_PAINTING if (nsLayoutUtils::InvalidationDebuggingIsEnabled()) { @@ -216,7 +212,7 @@ void nsViewManager::Refresh(nsView* aView, if (!renderer->NeedsWidgetInvalidation()) { renderer->FlushRendering(wr::RenderReasons::WIDGET); } else { - presShell->SyncPaintFallback(aView->GetFrame(), renderer); + presShell->SyncPaintFallback(presShell->GetRootFrame(), renderer); } #ifdef MOZ_DUMP_PAINTING if (nsLayoutUtils::InvalidationDebuggingIsEnabled()) { @@ -363,13 +359,9 @@ void nsViewManager::MaybeUpdateLastUserEventTime(WidgetGUIEvent* aEvent) { } } -void nsViewManager::ResizeView(nsView* aView, const nsRect& aRect) { +void nsViewManager::ResizeView(nsView* aView, const nsSize& aSize) { NS_ASSERTION(aView->GetViewManager() == this, "wrong view manager"); - - nsRect oldDimensions = aView->GetBounds(); - if (!oldDimensions.IsEqualEdges(aRect)) { - aView->SetDimensions(aRect); - } + aView->SetSize(aSize); // Note that if layout resizes the view and the view has a custom clip // region set, then we expect layout to update the clip region too. Thus diff --git a/view/nsViewManager.h b/view/nsViewManager.h @@ -82,15 +82,11 @@ class nsViewManager final { void FlushDelayedResize(); /** - * Resize a view. In addition to setting the width and height, you can - * set the x and y of its bounds relative to its position. Negative x and y - * will let the view extend above and to the left of the (0,0) point in its - * coordinate system. - * The view manager generates the appropriate dirty regions. + * Resize a view. * @param aView view to move - * @param the new bounds relative to the current position + * @param aSize the new size */ - void ResizeView(nsView* aView, const nsRect& aRect); + void ResizeView(nsView* aView, const nsSize& aSize); /** * Set the presshell associated with this manager