commit ef2d17cdc52c0fe32eac4fcdba62fdff1086b6d5 parent 7555406ff90809104b0df19c1e0067976194ea75 Author: Emilio Cobos Álvarez <emilio@crisal.io> Date: Fri, 28 Nov 2025 08:57:00 +0000 Bug 2000626 - Move delayed resizes to PresShell. r=jwatt This removes the last need for frames to have a view around. Differential Revision: https://phabricator.services.mozilla.com/D272884 Diffstat:
19 files changed, 124 insertions(+), 275 deletions(-)
diff --git a/accessible/generic/LocalAccessible.cpp b/accessible/generic/LocalAccessible.cpp @@ -2153,15 +2153,11 @@ Relation LocalAccessible::RelationByType(RelationType aType) const { // ROLE_WINDOW accessible which will prevent us from going up further // (because it is system generated and has no idea about the hierarchy // above it). - nsIFrame* frame = GetFrame(); - if (frame) { - nsView* view = frame->GetView(); - if (view) { - ScrollContainerFrame* scrollContainerFrame = do_QueryFrame(frame); - if (scrollContainerFrame || view->GetWidget() || - !frame->GetParent()) { - rel.AppendTarget(LocalParent()); - } + if (nsIFrame* frame = GetFrame()) { + ScrollContainerFrame* scrollContainerFrame = do_QueryFrame(frame); + if (scrollContainerFrame || frame->GetOwnWidget() || + !frame->GetParent()) { + rel.AppendTarget(LocalParent()); } } diff --git a/accessible/ios/RootAccessibleWrap.mm b/accessible/ios/RootAccessibleWrap.mm @@ -24,15 +24,10 @@ RootAccessibleWrap::RootAccessibleWrap(dom::Document* aDocument, : RootAccessible(aDocument, aPresShell) {} void RootAccessibleWrap::GetNativeWidget(void** aOutView) { - nsIFrame* frame = GetFrame(); - if (frame) { - nsView* view = frame->GetView(); - if (view) { - nsIWidget* widget = view->GetWidget(); - if (widget) { - *aOutView = (void**)widget->GetNativeData(NS_NATIVE_WIDGET); - MOZ_DIAGNOSTIC_ASSERT(*aOutView, "Couldn't get the native UIView!"); - } + if (nsIFrame* frame = GetFrame()) { + if (nsIWidget* widget = frame->GetOwnWidget()) { + *aOutView = (void**)widget->GetNativeData(NS_NATIVE_WIDGET); + MOZ_DIAGNOSTIC_ASSERT(*aOutView, "Couldn't get the native UIView!"); } } } diff --git a/accessible/mac/RootAccessibleWrap.mm b/accessible/mac/RootAccessibleWrap.mm @@ -34,18 +34,12 @@ Class RootAccessibleWrap::GetNativeType() { } void RootAccessibleWrap::GetNativeWidget(void** aOutView) { - nsIFrame* frame = GetFrame(); - if (frame) { - nsView* view = frame->GetView(); - if (view) { - nsIWidget* widget = view->GetWidget(); - if (widget) { - *aOutView = (void**)widget->GetNativeData(NS_NATIVE_WIDGET); - MOZ_ASSERT( - *aOutView || gfxPlatform::IsHeadless(), - "Couldn't get the native NSView parent we need to connect the " - "accessibility hierarchy!"); - } + if (nsIFrame* frame = GetFrame()) { + if (nsIWidget* widget = frame->GetOwnWidget()) { + *aOutView = (void**)widget->GetNativeData(NS_NATIVE_WIDGET); + MOZ_ASSERT(*aOutView || gfxPlatform::IsHeadless(), + "Couldn't get the native NSView parent we need to connect the " + "accessibility hierarchy!"); } } } diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp @@ -1062,12 +1062,8 @@ nsRect Element::GetClientAreaRect() { if (presContext && presContext->UseOverlayScrollbars() && !doc->StyleOrLayoutObservablyDependsOnParentDocumentLayout() && doc->IsScrollingElement(this)) { - if (PresShell* presShell = doc->GetPresShell()) { - // Ensure up to date dimensions, but don't reflow - if (RefPtr<nsViewManager> viewManager = presShell->GetViewManager()) { - viewManager->FlushDelayedResize(); - } - return nsRect(nsPoint(), presContext->GetVisibleArea().Size()); + if (RefPtr ps = doc->GetPresShell()) { + return nsRect(nsPoint(), ps->MaybePendingLayoutViewportSize()); } } diff --git a/dom/base/nsGlobalWindowOuter.cpp b/dom/base/nsGlobalWindowOuter.cpp @@ -3432,24 +3432,25 @@ nsresult nsGlobalWindowOuter::GetInnerSize(CSSSize& aSize) { NS_ENSURE_STATE(mDocShell); - RefPtr<nsPresContext> presContext = mDocShell->GetPresContext(); - PresShell* presShell = mDocShell->GetPresShell(); - - if (!presContext || !presShell) { + RefPtr<PresShell> presShell = mDocShell->GetPresShell(); + if (!presShell) { aSize = {}; return NS_OK; } // Whether or not the css viewport has been overridden, we can get the // correct value by looking at the visible area of the presContext. - if (RefPtr<nsViewManager> viewManager = presShell->GetViewManager()) { - viewManager->FlushDelayedResize(); + presShell->FlushDelayedResize(); + + nsPresContext* pc = presShell->GetPresContext(); + if (NS_WARN_IF(!pc)) { + aSize = {}; + return NS_OK; } nsSize innerSize = presShell->GetInnerSize(); - if (presContext->GetDynamicToolbarState() == DynamicToolbarState::Collapsed) { - innerSize = - nsLayoutUtils::ExpandHeightForViewportUnits(presContext, innerSize); + if (pc->GetDynamicToolbarState() == DynamicToolbarState::Collapsed) { + innerSize = nsLayoutUtils::ExpandHeightForViewportUnits(pc, innerSize); } aSize = CSSPixel::FromAppUnits(innerSize); diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp @@ -1261,6 +1261,9 @@ void PresShell::Destroy() { } if (mViewManager) { + if (auto* root = mViewManager->GetRootView()) { + root->Destroy(); + } // Clear the view manager's weak pointer back to |this| in case it // was leaked. mViewManager->SetPresShell(nullptr); @@ -1799,8 +1802,44 @@ void PresShell::RefreshZoomConstraintsForScreenSizeChange() { } } +nsSize PresShell::MaybePendingLayoutViewportSize() const { + if (mPendingLayoutViewportSize) { + return *mPendingLayoutViewportSize; + } + return mPresContext ? mPresContext->GetVisibleArea().Size() : nsSize(); +} + +bool PresShell::ShouldDelayResize() const { + if (!IsVisible()) { + return true; + } + nsRefreshDriver* rd = GetRefreshDriver(); + return rd && rd->IsResizeSuppressed(); +} + +void PresShell::FlushDelayedResize() { + if (!mPendingLayoutViewportSize) { + return; + } + auto size = mPendingLayoutViewportSize.extract(); + if (!mPresContext || size == mPresContext->GetVisibleArea().Size()) { + return; + } + ResizeReflow(size); +} + +void PresShell::SetLayoutViewportSize(const nsSize& aSize, bool aDelay) { + mPendingLayoutViewportSize = Some(aSize); + if (aDelay || ShouldDelayResize()) { + SetNeedStyleFlush(); + SetNeedLayoutFlush(); + return; + } + FlushDelayedResize(); +} + void PresShell::ForceResizeReflowWithCurrentDimensions() { - ResizeReflow(mViewManager->GetWindowDimensions()); + ResizeReflow(MaybePendingLayoutViewportSize()); } void PresShell::ResizeReflow(const nsSize& aSize, @@ -4374,8 +4413,6 @@ void PresShell::DoFlushPendingNotifications(mozilla::ChangesToFlush aFlush) { return; } - // Make sure the view manager stays alive. - RefPtr<nsViewManager> viewManager = mViewManager; // We need to make sure external resource documents are flushed too (for // example, svg filters that reference a filter in an external document // need the frames in the external document to be constructed for the @@ -4395,7 +4432,7 @@ void PresShell::DoFlushPendingNotifications(mozilla::ChangesToFlush aFlush) { // Process pending restyles, since any flush of the presshell wants // up-to-date style data. if (MOZ_LIKELY(!mIsDestroying)) { - viewManager->FlushDelayedResize(); + FlushDelayedResize(); mPresContext->FlushPendingMediaFeatureValuesChanged(); } @@ -12486,7 +12523,7 @@ void PresShell::PaintSynchronously() { return; } - mViewManager->FlushDelayedResize(); + FlushDelayedResize(); mIsPainting = true; auto cleanUpPaintingBit = MakeScopeExit([&] { mIsPainting = false; }); diff --git a/layout/base/PresShell.h b/layout/base/PresShell.h @@ -366,6 +366,13 @@ class PresShell final : public nsStubDocumentObserver, MOZ_CAN_RUN_SCRIPT bool ResizeReflowIgnoreOverride( const nsSize&, ResizeReflowOptions = ResizeReflowOptions::NoOption); MOZ_CAN_RUN_SCRIPT void ForceResizeReflowWithCurrentDimensions(); + MOZ_CAN_RUN_SCRIPT void FlushDelayedResize(); + nsSize MaybePendingLayoutViewportSize() const; + bool ShouldDelayResize() const; + // FIXME: MOZ_CAN_RUN_SCRIPT_BOUNDARY because the aDelay parameter forces us + // to effectively not run script. + MOZ_CAN_RUN_SCRIPT_BOUNDARY void SetLayoutViewportSize(const nsSize&, + bool aDelay); /** Schedule a resize event if applicable. */ enum class ResizeEventKind : uint8_t { Regular, Visual }; @@ -3335,6 +3342,9 @@ class PresShell final : public nsStubDocumentObserver, // Only populated on root content documents. nsSize mVisualViewportSize; + // Layout viewport size that we still haven't committed to the layout tree. + Maybe<nsSize> mPendingLayoutViewportSize; + using Arena = nsPresArena<8192, ArenaObjectID, eArenaObjectID_COUNT>; Arena mFrameArena; diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp @@ -2673,11 +2673,7 @@ ViewportFrame* nsCSSFrameConstructor::ConstructRootFrame() { viewportFrame->AddStateBits(NS_FRAME_OWNS_ANON_BOXES); - // Bind the viewport frame to the root view - if (nsView* rootView = mPresShell->GetViewManager()->GetRootView()) { - viewportFrame->SetView(rootView); - mPresShell->SetNeedsWindowPropertiesSync(); - } + mPresShell->SetNeedsWindowPropertiesSync(); // Make it an absolute container for fixed-pos elements viewportFrame->AddStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN); diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp @@ -337,9 +337,8 @@ class nsDocumentViewer final : public nsIDocumentViewer, /** * Creates a view manager, root view, and widget for the root view, setting * mViewManager and mWindow. - * @param aSize the initial size in appunits */ - void MakeWindow(const nsSize& aSize); + void MakeWindow(); nsresult CreateDeviceContext(nsSubDocumentFrame* aContainerFrame); /** @@ -714,7 +713,6 @@ nsresult nsDocumentViewer::InitPresentationStuff(bool aDoInitialReflow) { mPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom()); const nsSize size = LayoutDevicePixel::ToAppUnits(mBounds.Size(), p2a); - mViewManager->SetWindowDimensions(size); mPresContext->SetInitialVisibleArea(nsRect(nsPoint(), size)); // We rely on the default zoom not being initialized until here. mPresContext->RecomputeBrowsingContextDependentData(); @@ -837,9 +835,7 @@ nsresult nsDocumentViewer::InitInternal( // this new document since doing that will cause us to re-enter // into nsSubDocumentFrame code through reflows caused by // FlushPendingNotifications() calls down the road... - - MakeWindow(nsSize(mPresContext->DevPixelsToAppUnits(aBounds.width), - mPresContext->DevPixelsToAppUnits(aBounds.height))); + MakeWindow(); Hide(); #ifdef NS_PRINT_PREVIEW @@ -1934,17 +1930,16 @@ 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 && rootView->GetSize() == size) { + if (boundsChanged && mPresContext->GetVisibleArea().Size() == 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 // size on the document viewer/docshell/containing widget and view - // tree/frame tree/prescontext visible area). SetWindowDimensions compares - // to the root view dimenstions to determine if it needs to do anything; - // 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. + // tree/frame tree/prescontext visible area). SetLayoutViewportSize + // compares to the pres context visible area to determine if it needs to + // do anything; 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 (nsIFrame* f = mPresShell->GetRootFrame()) { f->InvalidateFrame(); @@ -1956,8 +1951,9 @@ nsDocumentViewer::SetBoundsWithFlags(const LayoutDeviceIntRect& aBounds, } } - mViewManager->SetWindowDimensions( - size, !!(aFlags & nsIDocumentViewer::eDelayResize)); + RefPtr ps = mPresShell; + ps->SetLayoutViewportSize(size, + !!(aFlags & nsIDocumentViewer::eDelayResize)); } // If there's a previous viewer, it's the one that's actually showing, @@ -2074,8 +2070,7 @@ nsDocumentViewer::Show() { return rv; } - MakeWindow(nsSize(mPresContext->DevPixelsToAppUnits(mBounds.width), - mPresContext->DevPixelsToAppUnits(mBounds.height))); + MakeWindow(); if (mPresContext) { Hide(); @@ -2190,7 +2185,7 @@ nsDocumentViewer::ClearHistoryEntry() { //------------------------------------------------------- -void nsDocumentViewer::MakeWindow(const nsSize& aSize) { +void nsDocumentViewer::MakeWindow() { if (GetIsPrintPreview()) { return; } @@ -2198,7 +2193,7 @@ void nsDocumentViewer::MakeWindow(const nsSize& aSize) { mViewManager = new nsViewManager(); // Create a view - nsView* view = mViewManager->CreateView(aSize); + nsView* view = mViewManager->CreateView(); // Create a widget if we were given a parent widget or don't have a // container view that we can hook up to without a widget. @@ -3326,8 +3321,7 @@ NS_IMETHODIMP nsDocumentViewer::SetPrintSettingsForSubdocument( rv = mPresContext->Init(mDeviceContext); NS_ENSURE_SUCCESS(rv, rv); - MakeWindow(nsSize(mPresContext->DevPixelsToAppUnits(mBounds.width), - mPresContext->DevPixelsToAppUnits(mBounds.height))); + MakeWindow(); MOZ_TRY(InitPresentationStuff(true)); } diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp @@ -541,19 +541,16 @@ void nsPresContext::PreferenceChanged(const char* aPrefName) { // other documents, and we'd need to save the return value of the first call // for all of them. (void)mDeviceContext->CheckDPIChange(); - OwningNonNull<mozilla::PresShell> presShell(*mPresShell); - // Re-fetch the view manager's window dimensions in case there's a - // deferred resize which hasn't affected our mVisibleArea yet - RefPtr<nsViewManager> vm = presShell->GetViewManager(); - if (!vm) { - return; - } + RefPtr ps = mPresShell; + // Use the maybe-pending size from presshell in case there's a + // deferred resize which hasn't affected our visible area yet. auto oldSizeDevPixels = LayoutDeviceSize::FromAppUnits( - vm->GetWindowDimensions(), oldAppUnitsPerDevPixel); + ps->MaybePendingLayoutViewportSize(), oldAppUnitsPerDevPixel); UIResolutionChangedInternal(); - vm->SetWindowDimensions( - LayoutDeviceSize::ToAppUnits(oldSizeDevPixels, AppUnitsPerDevPixel())); + ps->SetLayoutViewportSize( + LayoutDeviceSize::ToAppUnits(oldSizeDevPixels, AppUnitsPerDevPixel()), + /* aDelay = */ false); return; } @@ -1399,19 +1396,20 @@ void nsPresContext::SetFullZoom(float aZoom) { return; } - // Re-fetch the view manager's window dimensions in case there's a deferred - // resize which hasn't affected our mVisibleArea yet + // Use the maybe-pending size from presshell in case there's a + // deferred resize which hasn't affected our visible area yet. + RefPtr ps = mPresShell; const auto oldSizeDevPixels = LayoutDeviceSize::FromAppUnits( - mPresShell->GetViewManager()->GetWindowDimensions(), - mCurAppUnitsPerDevPixel); + ps->MaybePendingLayoutViewportSize(), mCurAppUnitsPerDevPixel); mDeviceContext->SetFullZoom(aZoom); mFullZoom = aZoom; AppUnitsPerDevPixelChanged(); - mPresShell->GetViewManager()->SetWindowDimensions( - LayoutDeviceSize::ToAppUnits(oldSizeDevPixels, AppUnitsPerDevPixel())); + ps->SetLayoutViewportSize( + LayoutDeviceSize::ToAppUnits(oldSizeDevPixels, AppUnitsPerDevPixel()), + /* aDelay = */ false); } void nsPresContext::SetOverrideDPPX(float aDPPX) { diff --git a/layout/generic/ViewportFrame.cpp b/layout/generic/ViewportFrame.cpp @@ -339,11 +339,6 @@ void ViewportFrame::RemoveFrame(DestroyContext& aContext, ChildListID aListID, } #endif -void ViewportFrame::SetView(nsView* aView) { - MOZ_ASSERT(!mView, "Should not swap views"); - mView = aView; -} - void ViewportFrame::Destroy(DestroyContext& aContext) { if (PresShell()->IsDestroying()) { PresShell::ClearMouseCapture(this); @@ -502,10 +497,6 @@ void ViewportFrame::Reflow(nsPresContext* aPresContext, // so we don't need to change our overflow areas. FinishAndStoreOverflow(&aDesiredSize); - if (mView) { - mView->GetViewManager()->ResizeView(mView, aDesiredSize.PhysicalSize()); - } - NS_FRAME_TRACE_REFLOW_OUT("ViewportFrame::Reflow", aStatus); } diff --git a/layout/generic/ViewportFrame.h b/layout/generic/ViewportFrame.h @@ -94,12 +94,9 @@ class ViewportFrame : public nsContainerFrame { virtual nsresult GetFrameName(nsAString& aResult) const override; #endif - nsView* GetViewportFrameView() const { return mView; } - void SetView(nsView*); - protected: ViewportFrame(ComputedStyle* aStyle, nsPresContext* aPresContext, ClassID aID) - : nsContainerFrame(aStyle, aPresContext, aID), mView(nullptr) {} + : nsContainerFrame(aStyle, aPresContext, aID) {} private: nsDisplayWrapList* MaybeWrapTopLayerList(nsDisplayListBuilder*, @@ -108,8 +105,6 @@ class ViewportFrame : public nsContainerFrame { mozilla::FrameChildListID GetAbsoluteListID() const override { return FrameChildListID::Fixed; } - - nsView* mView; }; } // namespace mozilla diff --git a/layout/generic/nsIFrame.cpp b/layout/generic/nsIFrame.cpp @@ -950,10 +950,6 @@ void nsIFrame::Destroy(DestroyContext& aContext) { ps->ClearFrameRefs(this); } - if (nsView* view = GetView()) { - view->Destroy(); - } - // Make sure that our deleted frame can't be returned from GetPrimaryFrame() if (IsPrimaryFrame()) { mContent->SetPrimaryFrame(nullptr); @@ -7861,20 +7857,15 @@ nsIFrame* nsIFrame::GetTailContinuation() { } nsIWidget* nsIFrame::GetOwnWidget() const { - if (auto* view = GetView()) { - return view->GetWidget(); - } if (IsMenuPopupFrame()) { return static_cast<const nsMenuPopupFrame*>(this)->GetWidget(); } + if (!GetParent()) { + return PresShell()->GetOwnWidget(); + } return nullptr; } -nsView* nsIFrame::DoGetView() const { - MOZ_ASSERT(IsViewportFrame()); - return static_cast<const ViewportFrame*>(this)->GetViewportFrameView(); -} - template <nsPoint (nsIFrame::*PositionGetter)() const> static nsPoint OffsetCalculator(const nsIFrame* aThis, const nsIFrame* aOther) { MOZ_ASSERT(aOther, "Must have frame for destination coordinate system!"); @@ -8012,14 +8003,9 @@ nsIWidget* nsIFrame::GetNearestWidget(nsPoint& aOffset) const { const auto targetAPD = PresContext()->AppUnitsPerDevPixel(); auto curAPD = targetAPD; do { - if (frame->IsMenuPopupFrame()) { - return static_cast<nsMenuPopupFrame*>(frame)->GetWidget(); - } - if (auto* view = frame->GetView()) { - if (auto* widget = view->GetWidget()) { - aOffset = aOffset.ScaleToOtherAppUnits(curAPD, targetAPD); - return widget; - } + if (auto* widget = frame->GetOwnWidget()) { + aOffset = aOffset.ScaleToOtherAppUnits(curAPD, targetAPD); + return widget; } aOffset += frame->GetPosition(); nsPoint crossDocOffset; @@ -8877,11 +8863,6 @@ void nsIFrame::ListGeneric(nsACString& aTo, const char* aPrefix, const bool onlyDeterministic = aFlags.contains(ListFlag::OnlyListDeterministicInfo); aTo += ListTag(onlyDeterministic); - if (auto* view = GetView()) { - aTo += " [view"; - ListPtr(aTo, aFlags, view); - aTo += "]"; - } if (!onlyDeterministic) { if (GetParent()) { aTo += nsPrintfCString(" parent=%p", static_cast<void*>(GetParent())); diff --git a/layout/generic/nsIFrame.h b/layout/generic/nsIFrame.h @@ -3316,20 +3316,10 @@ class nsIFrame : public nsQueryFrame { return IsIntrinsicKeyword(*bSize); } - protected: - nsView* DoGetView() const; - public: // Gets the widget owned by this frame. nsIWidget* GetOwnWidget() const; - nsView* GetView() const { - if (MOZ_LIKELY(!IsViewportFrame())) { - return nullptr; - } - return DoGetView(); - } - /** * Get the offset between the coordinate systems of |this| and aOther. * Adding the return value to a point in the coordinate system of |this| diff --git a/layout/printing/nsPrintJob.cpp b/layout/printing/nsPrintJob.cpp @@ -1211,7 +1211,7 @@ nsresult nsPrintJob::SetRootView(nsPrintObject* aPO, bool aDocumentIsTopLevel, if (!aPO->mViewManager->GetRootView()) { // Create a child window of the parent that is our "root view/window" - nsView* rootView = aPO->mViewManager->CreateView(adjSize); + nsView* rootView = aPO->mViewManager->CreateView(); aPO->mViewManager->SetRootView(rootView); } diff --git a/view/nsView.cpp b/view/nsView.cpp @@ -128,7 +128,6 @@ void nsView::List(FILE* out, int32_t aIndent) const { fprintf(out, "(widget=%p[%" PRIuPTR "] pos=%s) ", (void*)mWindow, widgetRefCnt, ToString(mWindow->GetBounds()).c_str()); } - fprintf(out, "{%d, %d}", mSize.width, mSize.height); for (i = aIndent; --i >= 0;) fputs(" ", out); fputs(">\n", out); } @@ -138,7 +137,7 @@ PresShell* nsView::GetPresShell() { return GetViewManager()->GetPresShell(); } bool nsView::WindowResized(nsIWidget* aWidget, int32_t aWidth, int32_t aHeight) { - PresShell* ps = GetPresShell(); + RefPtr<PresShell> ps = GetPresShell(); if (!ps) { return false; } @@ -159,7 +158,8 @@ bool nsView::WindowResized(nsIWidget* aWidget, int32_t aWidth, frame->InvalidateFrame(); } const LayoutDeviceIntSize size(aWidth, aHeight); - mViewManager->SetWindowDimensions(LayoutDeviceIntSize::ToAppUnits(size, p2a)); + ps->SetLayoutViewportSize(LayoutDeviceIntSize::ToAppUnits(size, p2a), + /* aDelay = */ false); if (nsXULPopupManager* pm = nsXULPopupManager::GetInstance()) { pm->AdjustPopupsOnWindowChange(ps); diff --git a/view/nsView.h b/view/nsView.h @@ -137,11 +137,6 @@ class nsView final : public nsIWidgetListener { */ void Destroy(); - /** - * Called to get the size of the view. - */ - nsSize GetSize() const { return mSize; } - // Stops listening to mWidget and clears it. void DetachWidget(); @@ -214,8 +209,6 @@ class nsView final : public nsIWidgetListener { private: explicit nsView(nsViewManager* = nullptr); - void SetSize(const nsSize& aSize) { mSize = aSize; } - void CallOnAllRemoteChildren( const std::function<mozilla::CallState(mozilla::dom::BrowserParent*)>& aCallback); @@ -223,7 +216,6 @@ class nsView final : public nsIWidgetListener { nsViewManager* mViewManager; nsCOMPtr<nsIWidget> mWindow; nsCOMPtr<nsIWidget> mPreviousWindow; - nsSize mSize; }; #endif diff --git a/view/nsViewManager.cpp b/view/nsViewManager.cpp @@ -51,10 +51,7 @@ using namespace mozilla::layers; uint32_t nsViewManager::gLastUserEventTime = 0; -nsViewManager::nsViewManager() - : mPresShell(nullptr), - mDelayedResize(NSCOORD_NONE, NSCOORD_NONE), - mRootView(nullptr) {} +nsViewManager::nsViewManager() : mPresShell(nullptr), mRootView(nullptr) {} nsViewManager::~nsViewManager() { if (mRootView) { @@ -67,11 +64,8 @@ nsViewManager::~nsViewManager() { "Releasing nsViewManager without having called Destroy on " "the PresShell!"); } -nsView* nsViewManager::CreateView(const nsSize& aSize) { - auto* v = new nsView(this); - v->SetSize(aSize); - return v; -} + +nsView* nsViewManager::CreateView() { return new nsView(this); } void nsViewManager::SetRootView(nsView* aView) { MOZ_ASSERT(!aView || aView->GetViewManager() == this, @@ -82,74 +76,6 @@ void nsViewManager::SetRootView(nsView* aView) { mRootView = aView; } -nsSize nsViewManager::GetWindowDimensions() const { - if (!mRootView) { - return {}; - } - if (mDelayedResize != nsSize(NSCOORD_NONE, NSCOORD_NONE)) { - return mDelayedResize; - } - return mRootView->GetSize(); -} - -void nsViewManager::DoSetWindowDimensions(const nsSize& aSize) { - if (mRootView->GetSize() == aSize) { - return; - } - // Don't resize the widget. It is already being set elsewhere. - mRootView->SetSize(aSize); - if (RefPtr<PresShell> presShell = mPresShell) { - presShell->ResizeReflow(aSize); - } -} - -bool nsViewManager::ShouldDelayResize() const { - MOZ_ASSERT(mRootView); - if (!mPresShell || !mPresShell->IsVisible()) { - return true; - } - if (nsRefreshDriver* rd = mPresShell->GetRefreshDriver()) { - if (rd->IsResizeSuppressed()) { - return true; - } - } - return false; -} - -void nsViewManager::SetWindowDimensions(const nsSize& aSize, - bool aDelayResize) { - if (!mRootView) { - return; - } - if (!ShouldDelayResize() && !aDelayResize) { - if (mDelayedResize != nsSize(NSCOORD_NONE, NSCOORD_NONE) && - mDelayedResize != aSize) { - // We have a delayed resize; that now obsolete size may already have - // been flushed to the PresContext so we need to update the PresContext - // with the new size because if the new size is exactly the same as the - // root view's current size then DoSetWindowDimensions will not - // request a resize reflow (which would correct it). See bug 617076. - mDelayedResize = aSize; - FlushDelayedResize(); - } - mDelayedResize.SizeTo(NSCOORD_NONE, NSCOORD_NONE); - DoSetWindowDimensions(aSize); - } else { - mDelayedResize = aSize; - if (mPresShell) { - mPresShell->SetNeedStyleFlush(); - mPresShell->SetNeedLayoutFlush(); - } - } -} - -void nsViewManager::FlushDelayedResize() { - if (mDelayedResize != nsSize(NSCOORD_NONE, NSCOORD_NONE)) { - DoSetWindowDimensions(mDelayedResize); - mDelayedResize.SizeTo(NSCOORD_NONE, NSCOORD_NONE); - } -} - void nsViewManager::MaybeUpdateLastUserEventTime(WidgetGUIEvent* aEvent) { WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent(); if ((mouseEvent && @@ -164,14 +90,3 @@ void nsViewManager::MaybeUpdateLastUserEventTime(WidgetGUIEvent* aEvent) { gLastUserEventTime = PR_IntervalToMicroseconds(PR_IntervalNow()); } } - -void nsViewManager::ResizeView(nsView* aView, const nsSize& aSize) { - NS_ASSERTION(aView->GetViewManager() == this, "wrong view manager"); - 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 - // in the case where mClipRect has been optimized away to just be a null - // pointer, and this resize is implicitly changing the clip rect, it's OK - // because layout will change it back again if necessary. -} diff --git a/view/nsViewManager.h b/view/nsViewManager.h @@ -12,7 +12,6 @@ #include "nsCRT.h" #include "nsTArray.h" #include "nsTArray.h" -#include "mozilla/Attributes.h" #include "mozilla/EventForwards.h" class nsIWidget; @@ -38,12 +37,9 @@ class nsViewManager final { /** * Create an ordinary view - * @param aSize initial size for view - * XXX We should eliminate this parameter; you can set the bounds - * after CreateView * @result The new view. Never null. */ - nsView* CreateView(const nsSize& aSize); + nsView* CreateView(); /** * Get the root of the view tree. @@ -59,27 +55,6 @@ class nsViewManager final { */ void SetRootView(nsView* aView); - /** Get the dimensions of the root view. */ - nsSize GetWindowDimensions() const; - - /** - * Set the dimensions of the root window. - * Called if the root window is resized. - */ - void SetWindowDimensions(const nsSize& aSize, bool aDelayResize = false); - - /** - * Do any resizes that are pending. - */ - void FlushDelayedResize(); - - /** - * Resize a view. - * @param aView view to move - * @param aSize the new size - */ - void ResizeView(nsView* aView, const nsSize& aSize); - /** * Set the presshell associated with this manager * @param aPresShell - new presshell @@ -103,15 +78,8 @@ class nsViewManager final { private: static uint32_t gLastUserEventTime; - MOZ_CAN_RUN_SCRIPT_BOUNDARY void DoSetWindowDimensions(const nsSize&); - bool ShouldDelayResize() const; - mozilla::PresShell* mPresShell; - // The size for a resize that we delayed until the root view becomes - // visible again. - nsSize mDelayedResize; - nsView* mRootView; // from here to public should be static and locked... MMP };