Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 1f3059e

Browse files
Bug 1542663 - Make nsViewManager and nsView (nsIWidgetListener) use mozilla::PresShell directly rather than via nsIPresShell r=tnikkel
This patch makes `nsViewManager::GetPresShell()` and `nsIWidgetListener::GetPresShell()` (overridden by `nsView` and `nsWebShellWindow::WidgetListenerDelegate`) return `mozilla::PresShell*`. Additionally, makes `nsWebShellWindow::GetPresShell()` also return `mozilla::PresShell()`. Differential Revision: https://phabricator.services.mozilla.com/D26454 --HG-- extra : moz-landing-system : lando
1 parent d50c9e3 commit 1f3059e

16 files changed

Lines changed: 104 additions & 105 deletions

layout/base/PresShell.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5443,16 +5443,15 @@ void PresShell::ProcessSynthMouseMoveEvent(bool aFromScroll) {
54435443
// XXX set event.mModifiers ?
54445444
// XXX mnakano I think that we should get the latest information from widget.
54455445

5446-
nsCOMPtr<nsIPresShell> shell = pointVM->GetPresShell();
5447-
if (shell) {
5446+
if (RefPtr<PresShell> presShell = pointVM->GetPresShell()) {
54485447
// Since this gets run in a refresh tick there isn't an InputAPZContext on
54495448
// the stack from the nsBaseWidget. We need to simulate one with at least
54505449
// the correct target guid, so that the correct callback transform gets
54515450
// applied if this event goes to a child process. The input block id is set
54525451
// to 0 because this is a synthetic event which doesn't really belong to any
54535452
// input block. Same for the APZ response field.
54545453
InputAPZContext apzContext(mMouseEventTargetGuid, 0, nsEventStatus_eIgnore);
5455-
shell->DispatchSynthMouseMove(&event);
5454+
presShell->DispatchSynthMouseMove(&event);
54565455
}
54575456

54585457
if (!aFromScroll) {
@@ -5523,7 +5522,7 @@ void PresShell::ClearApproximateFrameVisibilityVisited(nsView* aView,
55235522
bool aClear) {
55245523
nsViewManager* vm = aView->GetViewManager();
55255524
if (aClear) {
5526-
PresShell* presShell = static_cast<PresShell*>(vm->GetPresShell());
5525+
PresShell* presShell = vm->GetPresShell();
55275526
if (!presShell->mApproximateFrameVisibilityVisited) {
55285527
presShell->ClearApproximatelyVisibleFramesList();
55295528
}

layout/generic/nsSubDocumentFrame.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ static Document* GetDocumentFromView(nsView* aView) {
5656
MOZ_ASSERT(aView, "null view");
5757

5858
nsViewManager* vm = aView->GetViewManager();
59-
nsIPresShell* ps = vm ? vm->GetPresShell() : nullptr;
60-
return ps ? ps->GetDocument() : nullptr;
59+
PresShell* presShell = vm ? vm->GetPresShell() : nullptr;
60+
return presShell ? presShell->GetDocument() : nullptr;
6161
}
6262

6363
nsSubDocumentFrame::nsSubDocumentFrame(ComputedStyle* aStyle,

view/nsView.cpp

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ nsView::nsView(nsViewManager* aViewManager, nsViewVisibility aVisibility)
5757
}
5858

5959
void nsView::DropMouseGrabbing() {
60-
nsIPresShell* presShell = mViewManager->GetPresShell();
61-
if (presShell) presShell->ClearMouseCaptureOnView(this);
60+
if (PresShell* presShell = mViewManager->GetPresShell()) {
61+
presShell->ClearMouseCaptureOnView(this);
62+
}
6263
}
6364

6465
nsView::~nsView() {
@@ -925,9 +926,7 @@ static bool IsPopupWidget(nsIWidget* aWidget) {
925926
return (aWidget->WindowType() == eWindowType_popup);
926927
}
927928

928-
nsIPresShell* nsView::GetPresShell() {
929-
return GetViewManager()->GetPresShell();
930-
}
929+
PresShell* nsView::GetPresShell() { return GetViewManager()->GetPresShell(); }
931930

932931
bool nsView::WindowMoved(nsIWidget* aWidget, int32_t x, int32_t y) {
933932
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
@@ -955,7 +954,7 @@ bool nsView::WindowResized(nsIWidget* aWidget, int32_t aWidth,
955954

956955
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
957956
if (pm) {
958-
nsIPresShell* presShell = mViewManager->GetPresShell();
957+
PresShell* presShell = mViewManager->GetPresShell();
959958
if (presShell && presShell->GetDocument()) {
960959
pm->AdjustPopupsOnWindowChange(presShell);
961960
}
@@ -1007,38 +1006,40 @@ void nsView::DidPaintWindow() {
10071006
void nsView::DidCompositeWindow(mozilla::layers::TransactionId aTransactionId,
10081007
const TimeStamp& aCompositeStart,
10091008
const TimeStamp& aCompositeEnd) {
1010-
nsIPresShell* presShell = mViewManager->GetPresShell();
1011-
if (presShell) {
1012-
nsAutoScriptBlocker scriptBlocker;
1009+
PresShell* presShell = mViewManager->GetPresShell();
1010+
if (!presShell) {
1011+
return;
1012+
}
10131013

1014-
nsPresContext* context = presShell->GetPresContext();
1015-
nsRootPresContext* rootContext = context->GetRootPresContext();
1016-
if (rootContext) {
1017-
rootContext->NotifyDidPaintForSubtree(aTransactionId, aCompositeEnd);
1018-
}
1014+
nsAutoScriptBlocker scriptBlocker;
10191015

1020-
// If the two timestamps are identical, this was likely a fake composite
1021-
// event which wouldn't be terribly useful to display.
1022-
if (aCompositeStart == aCompositeEnd) {
1023-
return;
1024-
}
1016+
nsPresContext* context = presShell->GetPresContext();
1017+
nsRootPresContext* rootContext = context->GetRootPresContext();
1018+
if (rootContext) {
1019+
rootContext->NotifyDidPaintForSubtree(aTransactionId, aCompositeEnd);
1020+
}
1021+
1022+
// If the two timestamps are identical, this was likely a fake composite
1023+
// event which wouldn't be terribly useful to display.
1024+
if (aCompositeStart == aCompositeEnd) {
1025+
return;
1026+
}
10251027

1026-
nsIDocShell* docShell = context->GetDocShell();
1027-
RefPtr<TimelineConsumers> timelines = TimelineConsumers::Get();
1028+
nsIDocShell* docShell = context->GetDocShell();
1029+
RefPtr<TimelineConsumers> timelines = TimelineConsumers::Get();
10281030

1029-
if (timelines && timelines->HasConsumer(docShell)) {
1030-
timelines->AddMarkerForDocShell(
1031-
docShell, MakeUnique<CompositeTimelineMarker>(
1032-
aCompositeStart, MarkerTracingType::START));
1033-
timelines->AddMarkerForDocShell(
1034-
docShell, MakeUnique<CompositeTimelineMarker>(
1035-
aCompositeEnd, MarkerTracingType::END));
1036-
}
1031+
if (timelines && timelines->HasConsumer(docShell)) {
1032+
timelines->AddMarkerForDocShell(
1033+
docShell, MakeUnique<CompositeTimelineMarker>(
1034+
aCompositeStart, MarkerTracingType::START));
1035+
timelines->AddMarkerForDocShell(
1036+
docShell, MakeUnique<CompositeTimelineMarker>(aCompositeEnd,
1037+
MarkerTracingType::END));
10371038
}
10381039
}
10391040

10401041
void nsView::RequestRepaint() {
1041-
nsIPresShell* presShell = mViewManager->GetPresShell();
1042+
PresShell* presShell = mViewManager->GetPresShell();
10421043
if (presShell) {
10431044
presShell->ScheduleViewManagerFlush();
10441045
}

view/nsView.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ class nsViewManager;
2222
class nsIWidget;
2323
class nsIFrame;
2424

25+
namespace mozilla {
26+
class PresShell;
27+
} // namespace mozilla
28+
2529
// Enumerated type to indicate the visibility of a layer.
2630
// hide - the layer is not shown.
2731
// show - the layer is shown irrespective of the visibility of
@@ -379,7 +383,7 @@ class nsView final : public nsIWidgetListener {
379383
}
380384

381385
// nsIWidgetListener
382-
virtual nsIPresShell* GetPresShell() override;
386+
virtual mozilla::PresShell* GetPresShell() override;
383387
virtual nsView* GetView() override { return this; }
384388
virtual bool WindowMoved(nsIWidget* aWidget, int32_t x, int32_t y) override;
385389
virtual bool WindowResized(nsIWidget* aWidget, int32_t aWidth,

view/nsViewManager.cpp

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,30 @@
33
* License, v. 2.0. If a copy of the MPL was not distributed with this
44
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
55

6-
#include "nsAutoPtr.h"
76
#include "nsViewManager.h"
7+
8+
#include "mozilla/MouseEvents.h"
9+
#include "mozilla/PresShell.h"
10+
#include "mozilla/Preferences.h"
11+
#include "mozilla/StartupTimeline.h"
12+
#include "mozilla/dom/Document.h"
13+
#include "nsAutoPtr.h"
814
#include "nsGfxCIID.h"
915
#include "nsView.h"
1016
#include "nsCOMPtr.h"
11-
#include "mozilla/MouseEvents.h"
1217
#include "nsRegion.h"
1318
#include "nsCOMArray.h"
1419
#include "nsIPluginWidget.h"
1520
#include "nsXULPopupManager.h"
16-
#include "nsIPresShell.h"
1721
#include "nsIPresShellInlines.h"
1822
#include "nsPresContext.h"
19-
#include "mozilla/StartupTimeline.h"
2023
#include "GeckoProfiler.h"
2124
#include "nsRefreshDriver.h"
22-
#include "mozilla/Preferences.h"
2325
#include "nsContentUtils.h" // for nsAutoScriptBlocker
2426
#include "nsLayoutUtils.h"
2527
#include "Layers.h"
2628
#include "gfxPlatform.h"
2729
#include "gfxPrefs.h"
28-
#include "mozilla/dom/Document.h"
2930

3031
/**
3132
XXX TODO XXX
@@ -178,9 +179,9 @@ void nsViewManager::DoSetWindowDimensions(nscoord aWidth, nscoord aHeight) {
178179
if (!oldDim.IsEqualEdges(newDim)) {
179180
// Don't resize the widget. It is already being set elsewhere.
180181
mRootView->SetDimensions(newDim, true, false);
181-
if (mPresShell)
182-
mPresShell->ResizeReflow(aWidth, aHeight, oldDim.Width(),
183-
oldDim.Height());
182+
if (RefPtr<PresShell> presShell = mPresShell) {
183+
presShell->ResizeReflow(aWidth, aHeight, oldDim.Width(), oldDim.Height());
184+
}
184185
}
185186
}
186187

@@ -363,7 +364,7 @@ void nsViewManager::ProcessPendingUpdatesForView(nsView* aView,
363364
return;
364365
}
365366

366-
nsCOMPtr<nsIPresShell> rootShell(mPresShell);
367+
RefPtr<PresShell> rootPresShell = mPresShell;
367368
AutoTArray<nsCOMPtr<nsIWidget>, 1> widgets;
368369
aView->GetViewManager()->ProcessPendingUpdatesRecurse(aView, widgets);
369370
for (uint32_t i = 0; i < widgets.Length(); ++i) {
@@ -372,8 +373,8 @@ void nsViewManager::ProcessPendingUpdatesForView(nsView* aView,
372373
if (view->mNeedsWindowPropertiesSync) {
373374
view->mNeedsWindowPropertiesSync = false;
374375
if (nsViewManager* vm = view->GetViewManager()) {
375-
if (nsIPresShell* ps = vm->GetPresShell()) {
376-
ps->SyncWindowProperties(view);
376+
if (PresShell* presShell = vm->GetPresShell()) {
377+
presShell->SyncWindowProperties(view);
377378
}
378379
}
379380
}
@@ -383,7 +384,7 @@ void nsViewManager::ProcessPendingUpdatesForView(nsView* aView,
383384
view->ResetWidgetBounds(false, true);
384385
}
385386
}
386-
if (rootShell->GetViewManager() != this) {
387+
if (rootPresShell->GetViewManager() != this) {
387388
return; // presentation might have been torn down
388389
}
389390
if (aFlushDirtyRegion) {
@@ -589,8 +590,8 @@ void nsViewManager::InvalidateWidgetArea(nsView* aWidgetView,
589590

590591
static bool ShouldIgnoreInvalidation(nsViewManager* aVM) {
591592
while (aVM) {
592-
nsIPresShell* shell = aVM->GetPresShell();
593-
if (!shell || shell->ShouldIgnoreInvalidation()) {
593+
PresShell* presShell = aVM->GetPresShell();
594+
if (!presShell || presShell->ShouldIgnoreInvalidation()) {
594595
return true;
595596
}
596597
nsView* view = aVM->GetRootView()->GetParent();
@@ -673,9 +674,8 @@ void nsViewManager::WillPaintWindow(nsIWidget* aWidget) {
673674
}
674675
}
675676

676-
nsCOMPtr<nsIPresShell> shell = mPresShell;
677-
if (shell) {
678-
shell->WillPaintWindow();
677+
if (RefPtr<PresShell> presShell = mPresShell) {
678+
presShell->WillPaintWindow();
679679
}
680680
}
681681

@@ -698,9 +698,8 @@ bool nsViewManager::PaintWindow(nsIWidget* aWidget,
698698
}
699699

700700
void nsViewManager::DidPaintWindow() {
701-
nsCOMPtr<nsIPresShell> shell = mPresShell;
702-
if (shell) {
703-
shell->DidPaintWindow();
701+
if (RefPtr<PresShell> presShell = mPresShell) {
702+
presShell->DidPaintWindow();
704703
}
705704
}
706705

@@ -750,9 +749,8 @@ void nsViewManager::DispatchEvent(WidgetGUIEvent* aEvent, nsView* aView,
750749
// Hold a refcount to the presshell. The continued existence of the
751750
// presshell will delay deletion of this view hierarchy should the event
752751
// want to cause its destruction in, say, some JavaScript event handler.
753-
nsCOMPtr<nsIPresShell> shell = view->GetViewManager()->GetPresShell();
754-
if (shell) {
755-
shell->HandleEvent(frame, aEvent, false, aStatus);
752+
if (RefPtr<PresShell> presShell = view->GetViewManager()->GetPresShell()) {
753+
presShell->HandleEvent(frame, aEvent, false, aStatus);
756754
return;
757755
}
758756
}
@@ -1049,9 +1047,8 @@ void nsViewManager::CallWillPaintOnObservers() {
10491047
if (vm->RootViewManager() == this) {
10501048
// One of our kids.
10511049
if (vm->mRootView && vm->mRootView->IsEffectivelyVisible()) {
1052-
nsCOMPtr<nsIPresShell> shell = vm->GetPresShell();
1053-
if (shell) {
1054-
shell->WillPaint();
1050+
if (RefPtr<PresShell> presShell = vm->GetPresShell()) {
1051+
presShell->WillPaint();
10551052
}
10561053
}
10571054
}

view/nsViewManager.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ class nsIWidget;
2020
struct nsRect;
2121
class nsRegion;
2222
class nsDeviceContext;
23-
class nsIPresShell;
23+
24+
namespace mozilla {
25+
class PresShell;
26+
} // namespace mozilla
2427

2528
class nsViewManager final {
2629
~nsViewManager();
@@ -223,12 +226,12 @@ class nsViewManager final {
223226
* Set the presshell associated with this manager
224227
* @param aPresShell - new presshell
225228
*/
226-
void SetPresShell(nsIPresShell* aPresShell) { mPresShell = aPresShell; }
229+
void SetPresShell(mozilla::PresShell* aPresShell) { mPresShell = aPresShell; }
227230

228231
/**
229232
* Get the pres shell associated with this manager
230233
*/
231-
nsIPresShell* GetPresShell() { return mPresShell; }
234+
mozilla::PresShell* GetPresShell() const { return mPresShell; }
232235

233236
/**
234237
* Get the device context associated with this manager
@@ -385,7 +388,7 @@ class nsViewManager final {
385388
void PostPendingUpdate();
386389

387390
RefPtr<nsDeviceContext> mContext;
388-
nsIPresShell* mPresShell;
391+
mozilla::PresShell* mPresShell;
389392

390393
// The size for a resize that we delayed until the root view becomes
391394
// visible again.

widget/cocoa/SwipeTracker.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "InputData.h"
1010
#include "mozilla/FlushType.h"
11+
#include "mozilla/PresShell.h"
1112
#include "mozilla/TimeStamp.h"
1213
#include "mozilla/TouchEvents.h"
1314
#include "mozilla/dom/SimpleGestureEventBinding.h"
@@ -27,7 +28,7 @@
2728

2829
static already_AddRefed<nsRefreshDriver> GetRefreshDriver(nsIWidget& aWidget) {
2930
nsIWidgetListener* widgetListener = aWidget.GetWidgetListener();
30-
nsIPresShell* presShell = widgetListener ? widgetListener->GetPresShell() : nullptr;
31+
PresShell* presShell = widgetListener ? widgetListener->GetPresShell() : nullptr;
3132
nsPresContext* presContext = presShell ? presShell->GetPresContext() : nullptr;
3233
RefPtr<nsRefreshDriver> refreshDriver = presContext ? presContext->RefreshDriver() : nullptr;
3334
return refreshDriver.forget();

widget/cocoa/nsChildView.mm

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "mozilla/MiscEvents.h"
1818
#include "mozilla/MouseEvents.h"
19+
#include "mozilla/PresShell.h"
1920
#include "mozilla/TextEvents.h"
2021
#include "mozilla/TouchEvents.h"
2122
#include "mozilla/WheelHandlingHelper.h" // for WheelDeltaAdjustmentStrategy
@@ -41,7 +42,6 @@
4142
#include "nsGfxCIID.h"
4243
#include "nsStyleConsts.h"
4344
#include "nsIWidgetListener.h"
44-
#include "nsIPresShell.h"
4545
#include "nsIScreen.h"
4646

4747
#include "nsDragService.h"
@@ -813,8 +813,7 @@ static void ManipulateViewWithoutNeedingDisplay(NSView* aView, void (^aCallback)
813813
mBounds = nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, newScale);
814814

815815
if (mWidgetListener && !mWidgetListener->GetXULWindow()) {
816-
nsIPresShell* presShell = mWidgetListener->GetPresShell();
817-
if (presShell) {
816+
if (PresShell* presShell = mWidgetListener->GetPresShell()) {
818817
presShell->BackingScaleFactorChanged();
819818
}
820819
}
@@ -3154,10 +3153,8 @@ - (void)scrollbarSystemMetricChanged {
31543153
[self systemMetricsChanged];
31553154

31563155
if (mGeckoChild) {
3157-
nsIWidgetListener* listener = mGeckoChild->GetWidgetListener();
3158-
if (listener) {
3159-
nsIPresShell* presShell = listener->GetPresShell();
3160-
if (presShell) {
3156+
if (nsIWidgetListener* listener = mGeckoChild->GetWidgetListener()) {
3157+
if (PresShell* presShell = listener->GetPresShell()) {
31613158
presShell->ReconstructFrames();
31623159
}
31633160
}

0 commit comments

Comments
 (0)