commit 689d193e7fd01a59c7335e2bf23fba966598234a
parent 8a43b19ddf11288b8bc4ded880d1833c50bfb949
Author: Emilio Cobos Álvarez <emilio@crisal.io>
Date: Wed, 19 Nov 2025 01:27:15 +0000
Bug 2001001 - Remove some other view usage to get our widget. r=layout-reviewers,tnikkel
No behavior change but now that we introduced PresShell::GetOwnWidget() this is
nicer.
Differential Revision: https://phabricator.services.mozilla.com/D272885
Diffstat:
2 files changed, 30 insertions(+), 31 deletions(-)
diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp
@@ -5603,21 +5603,15 @@ struct PaintParams {
WindowRenderer* PresShell::GetWindowRenderer() {
NS_ASSERTION(mViewManager, "Should have view manager");
- if (nsView* rootView = mViewManager->GetRootView()) {
- if (nsIWidget* widget = rootView->GetWidget()) {
- return widget->GetWindowRenderer();
- }
+ if (nsIWidget* widget = GetOwnWidget()) {
+ return widget->GetWindowRenderer();
}
return nullptr;
}
nsIWidget* PresShell::GetNearestWidget() const {
- if (mViewManager) {
- if (auto* root = mViewManager->GetRootView()) {
- if (nsIWidget* widget = root->GetWidget()) {
- return widget;
- }
- }
+ if (auto* widget = GetOwnWidget()) {
+ return widget;
}
if (auto* embedder = GetInProcessEmbedderFrame()) {
return embedder->GetNearestWidget();
@@ -5625,13 +5619,19 @@ nsIWidget* PresShell::GetNearestWidget() const {
return GetRootWidget();
}
+nsIWidget* PresShell::GetOwnWidget() const {
+ if (!mViewManager) {
+ return nullptr;
+ }
+ if (auto* root = mViewManager->GetRootView()) {
+ return root->GetWidget();
+ }
+ return nullptr;
+}
+
bool PresShell::AsyncPanZoomEnabled() {
- NS_ASSERTION(mViewManager, "Should have view manager");
- nsView* rootView = mViewManager->GetRootView();
- if (rootView) {
- if (nsIWidget* widget = rootView->GetWidget()) {
- return widget->AsyncPanZoomEnabled();
- }
+ if (nsIWidget* widget = GetOwnWidget()) {
+ return widget->AsyncPanZoomEnabled();
}
return gfxPlatform::AsyncPanZoomEnabled();
}
@@ -5757,12 +5757,11 @@ void PresShell::ProcessSynthMouseMoveEvent(bool aFromScroll) {
mSynthMouseMoveEvent.Forget();
});
// If drag session has started, we shouldn't synthesize mousemove event.
- nsView* rootView = mViewManager ? mViewManager->GetRootView() : nullptr;
- if (!rootView || !rootView->HasWidget()) {
+ nsIWidget* widget = GetOwnWidget();
+ if (!widget) {
return;
}
- nsCOMPtr<nsIDragSession> dragSession =
- nsContentUtils::GetDragSession(rootView->GetWidget());
+ nsCOMPtr<nsIDragSession> dragSession = nsContentUtils::GetDragSession(widget);
if (dragSession) {
// Don't forget it. We need to synthesize a mouse move when the drag
// session ends.
@@ -5843,11 +5842,11 @@ void PresShell::ProcessSynthMouseOrPointerMoveEvent(
// widget we will put in the event we dispatch, in widgetAPD appunits
nsPoint refpoint(0, 0);
- nsView* const rootView = mViewManager ? mViewManager->GetRootView() : nullptr;
- if (!rootView || !rootView->HasWidget()) {
+ nsIWidget* ownWidget = GetOwnWidget();
+ if (!ownWidget) {
return;
}
- MOZ_ASSERT(!nsCOMPtr{nsContentUtils::GetDragSession(rootView->GetWidget())});
+ MOZ_ASSERT(!nsCOMPtr{nsContentUtils::GetDragSession(ownWidget)});
// We need a widget to put in the event we are going to dispatch so we look
// for a view that has a widget and the mouse location is over. We first look
@@ -5865,7 +5864,7 @@ void PresShell::ProcessSynthMouseOrPointerMoveEvent(
// We either dispatch the event to a popup, or a view.
nsMenuPopupFrame* popupFrame =
- FindPopupFrame(mPresContext, rootView->GetWidget(),
+ FindPopupFrame(mPresContext, ownWidget,
LayoutDeviceIntPoint::FromAppUnitsToNearest(
aPointerInfo.mLastRefPointInRootDoc, APD));
if (popupFrame) {
@@ -5880,7 +5879,7 @@ void PresShell::ProcessSynthMouseOrPointerMoveEvent(
MOZ_ASSERT(result == nsLayoutUtils::TRANSFORM_SUCCEEDED);
}
if (!widget) {
- widget = rootView->GetWidget();
+ widget = ownWidget;
widgetAPD = APD;
pointShell = this;
refpoint = aPointerInfo.mLastRefPointInRootDoc;
@@ -12021,12 +12020,8 @@ nsIWidget* PresShell::GetRootWidget() const {
return nullptr;
}
for (nsPresContext* pc = mPresContext; pc; pc = pc->GetParentPresContext()) {
- if (auto* vm = pc->PresShell()->GetViewManager()) {
- if (auto* view = vm->GetRootView()) {
- if (auto* widget = view->GetWidget()) {
- return widget;
- }
- }
+ if (auto* widget = pc->PresShell()->GetOwnWidget()) {
+ return widget;
}
}
return nullptr;
diff --git a/layout/base/PresShell.h b/layout/base/PresShell.h
@@ -454,6 +454,10 @@ class PresShell final : public nsStubDocumentObserver,
// popup).
nsIWidget* GetNearestWidget() const;
+ // Return the widget that we're painting into, if we're responsible to paint
+ // into a widget.
+ nsIWidget* GetOwnWidget() const;
+
// Get the current frame of our embedder, if it's in our same process.
nsSubDocumentFrame* GetInProcessEmbedderFrame() const;
void SetInProcessEmbedderFrame(nsSubDocumentFrame*);