Bug 1542663 - Make nsViewManager and nsView (nsIWidgetListener) use mozilla::PresShell directly rather than via nsIPresShell r=tnikkel
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 13 Apr 2019 01:05:21 +0000
changeset 528201 7b63cad25d9b4081eedc4a4d65004c60ac0c9277
parent 528200 a1917a9966fb544d1b4c172aa5acca7fa9bf5cae
child 528202 fd5cb917b6eb7623ee6de94d5105ac4e23c38371
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstnikkel
bugs1542663
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
layout/base/PresShell.cpp
layout/generic/nsSubDocumentFrame.cpp
view/nsView.cpp
view/nsView.h
view/nsViewManager.cpp
view/nsViewManager.h
widget/cocoa/SwipeTracker.mm
widget/cocoa/nsChildView.mm
widget/cocoa/nsCocoaWindow.mm
widget/gtk/nsWindow.cpp
widget/nsBaseWidget.cpp
widget/nsIWidgetListener.cpp
widget/nsIWidgetListener.h
widget/windows/nsWindowBase.cpp
xpfe/appshell/nsWebShellWindow.cpp
xpfe/appshell/nsWebShellWindow.h
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -5438,26 +5438,25 @@ void PresShell::ProcessSynthMouseMoveEve
   WidgetMouseEvent event(true, eMouseMove, view->GetWidget(),
                          WidgetMouseEvent::eSynthesized);
   event.mRefPoint =
       LayoutDeviceIntPoint::FromAppUnitsToNearest(refpoint, viewAPD);
   event.mTime = PR_IntervalNow();
   // XXX set event.mModifiers ?
   // XXX mnakano I think that we should get the latest information from widget.
 
-  nsCOMPtr<nsIPresShell> shell = pointVM->GetPresShell();
-  if (shell) {
+  if (RefPtr<PresShell> presShell = pointVM->GetPresShell()) {
     // Since this gets run in a refresh tick there isn't an InputAPZContext on
     // the stack from the nsBaseWidget. We need to simulate one with at least
     // the correct target guid, so that the correct callback transform gets
     // applied if this event goes to a child process. The input block id is set
     // to 0 because this is a synthetic event which doesn't really belong to any
     // input block. Same for the APZ response field.
     InputAPZContext apzContext(mMouseEventTargetGuid, 0, nsEventStatus_eIgnore);
-    shell->DispatchSynthMouseMove(&event);
+    presShell->DispatchSynthMouseMove(&event);
   }
 
   if (!aFromScroll) {
     mSynthMouseMoveEvent.Forget();
   }
 }
 
 /* static */
@@ -5518,17 +5517,17 @@ void PresShell::RebuildApproximateFrameV
   DecApproximateVisibleCount(oldApproximatelyVisibleFrames);
 }
 
 /* static */
 void PresShell::ClearApproximateFrameVisibilityVisited(nsView* aView,
                                                        bool aClear) {
   nsViewManager* vm = aView->GetViewManager();
   if (aClear) {
-    PresShell* presShell = static_cast<PresShell*>(vm->GetPresShell());
+    PresShell* presShell = vm->GetPresShell();
     if (!presShell->mApproximateFrameVisibilityVisited) {
       presShell->ClearApproximatelyVisibleFramesList();
     }
     presShell->mApproximateFrameVisibilityVisited = false;
   }
   for (nsView* v = aView->GetFirstChild(); v; v = v->GetNextSibling()) {
     ClearApproximateFrameVisibilityVisited(v, v->GetViewManager() != vm);
   }
--- a/layout/generic/nsSubDocumentFrame.cpp
+++ b/layout/generic/nsSubDocumentFrame.cpp
@@ -51,18 +51,18 @@ using mozilla::dom::Document;
 using mozilla::layout::RenderFrame;
 
 static bool sShowPreviousPage = true;
 
 static Document* GetDocumentFromView(nsView* aView) {
   MOZ_ASSERT(aView, "null view");
 
   nsViewManager* vm = aView->GetViewManager();
-  nsIPresShell* ps = vm ? vm->GetPresShell() : nullptr;
-  return ps ? ps->GetDocument() : nullptr;
+  PresShell* presShell = vm ? vm->GetPresShell() : nullptr;
+  return presShell ? presShell->GetDocument() : nullptr;
 }
 
 nsSubDocumentFrame::nsSubDocumentFrame(ComputedStyle* aStyle,
                                        nsPresContext* aPresContext)
     : nsAtomicContainerFrame(aStyle, aPresContext, kClassID),
       mOuterView(nullptr),
       mInnerView(nullptr),
       mIsInline(false),
--- a/view/nsView.cpp
+++ b/view/nsView.cpp
@@ -52,18 +52,19 @@ nsView::nsView(nsViewManager* aViewManag
   if (!sShowPreviousPageInitialized) {
     Preferences::AddBoolVarCache(&sShowPreviousPage,
                                  "layout.show_previous_page", true);
     sShowPreviousPageInitialized = true;
   }
 }
 
 void nsView::DropMouseGrabbing() {
-  nsIPresShell* presShell = mViewManager->GetPresShell();
-  if (presShell) presShell->ClearMouseCaptureOnView(this);
+  if (PresShell* presShell = mViewManager->GetPresShell()) {
+    presShell->ClearMouseCaptureOnView(this);
+  }
 }
 
 nsView::~nsView() {
   MOZ_COUNT_DTOR(nsView);
 
   while (GetFirstChild()) {
     nsView* child = GetFirstChild();
     if (child->GetViewManager() == mViewManager) {
@@ -920,19 +921,17 @@ nsPoint nsView::ConvertFromParentCoords(
   aPt -= GetPosition();
   return aPt;
 }
 
 static bool IsPopupWidget(nsIWidget* aWidget) {
   return (aWidget->WindowType() == eWindowType_popup);
 }
 
-nsIPresShell* nsView::GetPresShell() {
-  return GetViewManager()->GetPresShell();
-}
+PresShell* nsView::GetPresShell() { return GetViewManager()->GetPresShell(); }
 
 bool nsView::WindowMoved(nsIWidget* aWidget, int32_t x, int32_t y) {
   nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
   if (pm && IsPopupWidget(aWidget)) {
     pm->PopupMoved(mFrame, nsIntPoint(x, y));
     return true;
   }
 
@@ -950,17 +949,17 @@ bool nsView::WindowResized(nsIWidget* aW
     // on a non-default-dpi display (bug 829963)
     devContext->CheckDPIChange();
     int32_t p2a = devContext->AppUnitsPerDevPixel();
     mViewManager->SetWindowDimensions(NSIntPixelsToAppUnits(aWidth, p2a),
                                       NSIntPixelsToAppUnits(aHeight, p2a));
 
     nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
     if (pm) {
-      nsIPresShell* presShell = mViewManager->GetPresShell();
+      PresShell* presShell = mViewManager->GetPresShell();
       if (presShell && presShell->GetDocument()) {
         pm->AdjustPopupsOnWindowChange(presShell);
       }
     }
 
     return true;
   }
   if (IsPopupWidget(aWidget)) {
@@ -1002,48 +1001,50 @@ bool nsView::PaintWindow(nsIWidget* aWid
 void nsView::DidPaintWindow() {
   RefPtr<nsViewManager> vm = mViewManager;
   vm->DidPaintWindow();
 }
 
 void nsView::DidCompositeWindow(mozilla::layers::TransactionId aTransactionId,
                                 const TimeStamp& aCompositeStart,
                                 const TimeStamp& aCompositeEnd) {
-  nsIPresShell* presShell = mViewManager->GetPresShell();
-  if (presShell) {
-    nsAutoScriptBlocker scriptBlocker;
+  PresShell* presShell = mViewManager->GetPresShell();
+  if (!presShell) {
+    return;
+  }
 
-    nsPresContext* context = presShell->GetPresContext();
-    nsRootPresContext* rootContext = context->GetRootPresContext();
-    if (rootContext) {
-      rootContext->NotifyDidPaintForSubtree(aTransactionId, aCompositeEnd);
-    }
+  nsAutoScriptBlocker scriptBlocker;
+
+  nsPresContext* context = presShell->GetPresContext();
+  nsRootPresContext* rootContext = context->GetRootPresContext();
+  if (rootContext) {
+    rootContext->NotifyDidPaintForSubtree(aTransactionId, aCompositeEnd);
+  }
 
-    // If the two timestamps are identical, this was likely a fake composite
-    // event which wouldn't be terribly useful to display.
-    if (aCompositeStart == aCompositeEnd) {
-      return;
-    }
-
-    nsIDocShell* docShell = context->GetDocShell();
-    RefPtr<TimelineConsumers> timelines = TimelineConsumers::Get();
+  // If the two timestamps are identical, this was likely a fake composite
+  // event which wouldn't be terribly useful to display.
+  if (aCompositeStart == aCompositeEnd) {
+    return;
+  }
 
-    if (timelines && timelines->HasConsumer(docShell)) {
-      timelines->AddMarkerForDocShell(
-          docShell, MakeUnique<CompositeTimelineMarker>(
-                        aCompositeStart, MarkerTracingType::START));
-      timelines->AddMarkerForDocShell(
-          docShell, MakeUnique<CompositeTimelineMarker>(
-                        aCompositeEnd, MarkerTracingType::END));
-    }
+  nsIDocShell* docShell = context->GetDocShell();
+  RefPtr<TimelineConsumers> timelines = TimelineConsumers::Get();
+
+  if (timelines && timelines->HasConsumer(docShell)) {
+    timelines->AddMarkerForDocShell(
+        docShell, MakeUnique<CompositeTimelineMarker>(
+                      aCompositeStart, MarkerTracingType::START));
+    timelines->AddMarkerForDocShell(
+        docShell, MakeUnique<CompositeTimelineMarker>(aCompositeEnd,
+                                                      MarkerTracingType::END));
   }
 }
 
 void nsView::RequestRepaint() {
-  nsIPresShell* presShell = mViewManager->GetPresShell();
+  PresShell* presShell = mViewManager->GetPresShell();
   if (presShell) {
     presShell->ScheduleViewManagerFlush();
   }
 }
 
 bool nsView::ShouldNotBeVisible() {
   if (mFrame && mFrame->IsMenuPopupFrame()) {
     nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
--- a/view/nsView.h
+++ b/view/nsView.h
@@ -17,16 +17,20 @@
 #include "Units.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/EventForwards.h"
 
 class nsViewManager;
 class nsIWidget;
 class nsIFrame;
 
+namespace mozilla {
+class PresShell;
+}  // namespace mozilla
+
 // Enumerated type to indicate the visibility of a layer.
 // hide - the layer is not shown.
 // show - the layer is shown irrespective of the visibility of
 //        the layer's parent.
 enum nsViewVisibility {
   nsViewVisibility_kHide = 0,
   nsViewVisibility_kShow = 1
 };
@@ -374,17 +378,17 @@ class nsView final : public nsIWidgetLis
                    "Only display roots should have dirty regions");
       mDirtyRegion = new nsRegion();
       NS_ASSERTION(mDirtyRegion, "Out of memory!");
     }
     return mDirtyRegion;
   }
 
   // nsIWidgetListener
-  virtual nsIPresShell* GetPresShell() override;
+  virtual mozilla::PresShell* GetPresShell() override;
   virtual nsView* GetView() override { return this; }
   virtual bool WindowMoved(nsIWidget* aWidget, int32_t x, int32_t y) override;
   virtual bool WindowResized(nsIWidget* aWidget, int32_t aWidth,
                              int32_t aHeight) override;
   virtual bool RequestWindowClose(nsIWidget* aWidget) override;
   virtual void WillPaintWindow(nsIWidget* aWidget) override;
   virtual bool PaintWindow(nsIWidget* aWidget,
                            LayoutDeviceIntRegion aRegion) override;
--- a/view/nsViewManager.cpp
+++ b/view/nsViewManager.cpp
@@ -1,36 +1,37 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "nsViewManager.h"
+
+#include "mozilla/MouseEvents.h"
+#include "mozilla/PresShell.h"
+#include "mozilla/Preferences.h"
+#include "mozilla/StartupTimeline.h"
+#include "mozilla/dom/Document.h"
 #include "nsAutoPtr.h"
-#include "nsViewManager.h"
 #include "nsGfxCIID.h"
 #include "nsView.h"
 #include "nsCOMPtr.h"
-#include "mozilla/MouseEvents.h"
 #include "nsRegion.h"
 #include "nsCOMArray.h"
 #include "nsIPluginWidget.h"
 #include "nsXULPopupManager.h"
-#include "nsIPresShell.h"
 #include "nsIPresShellInlines.h"
 #include "nsPresContext.h"
-#include "mozilla/StartupTimeline.h"
 #include "GeckoProfiler.h"
 #include "nsRefreshDriver.h"
-#include "mozilla/Preferences.h"
 #include "nsContentUtils.h"  // for nsAutoScriptBlocker
 #include "nsLayoutUtils.h"
 #include "Layers.h"
 #include "gfxPlatform.h"
 #include "gfxPrefs.h"
-#include "mozilla/dom/Document.h"
 
 /**
    XXX TODO XXX
 
    DeCOMify newly private methods
    Optimize view storage
 */
 
@@ -173,19 +174,19 @@ void nsViewManager::GetWindowDimensions(
 
 void nsViewManager::DoSetWindowDimensions(nscoord aWidth, nscoord aHeight) {
   nsRect oldDim = mRootView->GetDimensions();
   nsRect newDim(0, 0, aWidth, aHeight);
   // We care about resizes even when one dimension is already zero.
   if (!oldDim.IsEqualEdges(newDim)) {
     // Don't resize the widget. It is already being set elsewhere.
     mRootView->SetDimensions(newDim, true, false);
-    if (mPresShell)
-      mPresShell->ResizeReflow(aWidth, aHeight, oldDim.Width(),
-                               oldDim.Height());
+    if (RefPtr<PresShell> presShell = mPresShell) {
+      presShell->ResizeReflow(aWidth, aHeight, oldDim.Width(), oldDim.Height());
+    }
   }
 }
 
 bool nsViewManager::ShouldDelayResize() const {
   MOZ_ASSERT(mRootView);
   if (!mRootView->IsEffectivelyVisible() || !mPresShell ||
       !mPresShell->IsVisible()) {
     return true;
@@ -358,37 +359,37 @@ void nsViewManager::Refresh(nsView* aVie
 
 void nsViewManager::ProcessPendingUpdatesForView(nsView* aView,
                                                  bool aFlushDirtyRegion) {
   NS_ASSERTION(IsRootVM(), "Updates will be missed");
   if (!aView) {
     return;
   }
 
-  nsCOMPtr<nsIPresShell> rootShell(mPresShell);
+  RefPtr<PresShell> rootPresShell = mPresShell;
   AutoTArray<nsCOMPtr<nsIWidget>, 1> widgets;
   aView->GetViewManager()->ProcessPendingUpdatesRecurse(aView, widgets);
   for (uint32_t i = 0; i < widgets.Length(); ++i) {
     nsView* view = nsView::GetViewFor(widgets[i]);
     if (view) {
       if (view->mNeedsWindowPropertiesSync) {
         view->mNeedsWindowPropertiesSync = false;
         if (nsViewManager* vm = view->GetViewManager()) {
-          if (nsIPresShell* ps = vm->GetPresShell()) {
-            ps->SyncWindowProperties(view);
+          if (PresShell* presShell = vm->GetPresShell()) {
+            presShell->SyncWindowProperties(view);
           }
         }
       }
     }
     view = nsView::GetViewFor(widgets[i]);
     if (view) {
       view->ResetWidgetBounds(false, true);
     }
   }
-  if (rootShell->GetViewManager() != this) {
+  if (rootPresShell->GetViewManager() != this) {
     return;  // presentation might have been torn down
   }
   if (aFlushDirtyRegion) {
     nsAutoScriptBlocker scriptBlocker;
     SetPainting(true);
     for (uint32_t i = 0; i < widgets.Length(); ++i) {
       nsIWidget* widget = widgets[i];
       nsView* view = nsView::GetViewFor(widget);
@@ -584,18 +585,18 @@ void nsViewManager::InvalidateWidgetArea
       LayoutDeviceIntRect bounds = ViewToWidget(aWidgetView, iter.Get());
       widget->Invalidate(bounds);
     }
   }
 }
 
 static bool ShouldIgnoreInvalidation(nsViewManager* aVM) {
   while (aVM) {
-    nsIPresShell* shell = aVM->GetPresShell();
-    if (!shell || shell->ShouldIgnoreInvalidation()) {
+    PresShell* presShell = aVM->GetPresShell();
+    if (!presShell || presShell->ShouldIgnoreInvalidation()) {
       return true;
     }
     nsView* view = aVM->GetRootView()->GetParent();
     aVM = view ? view->GetViewManager() : nullptr;
   }
   return false;
 }
 
@@ -668,19 +669,18 @@ void nsViewManager::WillPaintWindow(nsIW
       // destroyed it during CallWillPaintOnObservers.
       view = nsView::GetViewFor(widget);
       if (view) {
         view->SetForcedRepaint(false);
       }
     }
   }
 
-  nsCOMPtr<nsIPresShell> shell = mPresShell;
-  if (shell) {
-    shell->WillPaintWindow();
+  if (RefPtr<PresShell> presShell = mPresShell) {
+    presShell->WillPaintWindow();
   }
 }
 
 bool nsViewManager::PaintWindow(nsIWidget* aWidget,
                                 const LayoutDeviceIntRegion& aRegion) {
   if (!aWidget || !mContext) return false;
 
   NS_ASSERTION(
@@ -693,19 +693,18 @@ bool nsViewManager::PaintWindow(nsIWidge
   if (view && !aRegion.IsEmpty()) {
     Refresh(view, aRegion);
   }
 
   return true;
 }
 
 void nsViewManager::DidPaintWindow() {
-  nsCOMPtr<nsIPresShell> shell = mPresShell;
-  if (shell) {
-    shell->DidPaintWindow();
+  if (RefPtr<PresShell> presShell = mPresShell) {
+    presShell->DidPaintWindow();
   }
 }
 
 void nsViewManager::DispatchEvent(WidgetGUIEvent* aEvent, nsView* aView,
                                   nsEventStatus* aStatus) {
   AUTO_PROFILER_LABEL("nsViewManager::DispatchEvent", OTHER);
 
   WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
@@ -745,19 +744,18 @@ void nsViewManager::DispatchEvent(Widget
       frame = view->GetFrame();
     }
   }
 
   if (nullptr != frame) {
     // Hold a refcount to the presshell. The continued existence of the
     // presshell will delay deletion of this view hierarchy should the event
     // want to cause its destruction in, say, some JavaScript event handler.
-    nsCOMPtr<nsIPresShell> shell = view->GetViewManager()->GetPresShell();
-    if (shell) {
-      shell->HandleEvent(frame, aEvent, false, aStatus);
+    if (RefPtr<PresShell> presShell = view->GetViewManager()->GetPresShell()) {
+      presShell->HandleEvent(frame, aEvent, false, aStatus);
       return;
     }
   }
 
   *aStatus = nsEventStatus_eIgnore;
 }
 
 // Recursively reparent widgets if necessary
@@ -1044,19 +1042,18 @@ void nsViewManager::CallWillPaintOnObser
   }
 
   uint32_t index;
   for (index = 0; index < gViewManagers->Length(); index++) {
     nsViewManager* vm = gViewManagers->ElementAt(index);
     if (vm->RootViewManager() == this) {
       // One of our kids.
       if (vm->mRootView && vm->mRootView->IsEffectivelyVisible()) {
-        nsCOMPtr<nsIPresShell> shell = vm->GetPresShell();
-        if (shell) {
-          shell->WillPaint();
+        if (RefPtr<PresShell> presShell = vm->GetPresShell()) {
+          presShell->WillPaint();
         }
       }
     }
   }
 }
 
 void nsViewManager::GetLastUserEventTime(uint32_t& aTime) {
   aTime = gLastUserEventTime;
--- a/view/nsViewManager.h
+++ b/view/nsViewManager.h
@@ -15,17 +15,20 @@
 #include "nsTArray.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/EventForwards.h"
 
 class nsIWidget;
 struct nsRect;
 class nsRegion;
 class nsDeviceContext;
-class nsIPresShell;
+
+namespace mozilla {
+class PresShell;
+}  // namespace mozilla
 
 class nsViewManager final {
   ~nsViewManager();
 
  public:
   friend class nsView;
 
   typedef mozilla::LayoutDeviceIntRect LayoutDeviceIntRect;
@@ -218,22 +221,22 @@ class nsViewManager final {
    * views that need to be drawn in front of all other views.
    */
   void SetViewFloating(nsView* aView, bool aFloatingView);
 
   /**
    * Set the presshell associated with this manager
    * @param aPresShell - new presshell
    */
-  void SetPresShell(nsIPresShell* aPresShell) { mPresShell = aPresShell; }
+  void SetPresShell(mozilla::PresShell* aPresShell) { mPresShell = aPresShell; }
 
   /**
    * Get the pres shell associated with this manager
    */
-  nsIPresShell* GetPresShell() { return mPresShell; }
+  mozilla::PresShell* GetPresShell() const { return mPresShell; }
 
   /**
    * Get the device context associated with this manager
    */
   nsDeviceContext* GetDeviceContext() const { return mContext; }
 
   /**
    * A stack class for disallowing changes that would enter painting. For
@@ -380,17 +383,17 @@ class nsViewManager final {
   bool PaintWindow(nsIWidget* aWidget, const LayoutDeviceIntRegion& aRegion);
   void DidPaintWindow();
 
   // Call this when you need to let the viewmanager know that it now has
   // pending updates.
   void PostPendingUpdate();
 
   RefPtr<nsDeviceContext> mContext;
-  nsIPresShell* mPresShell;
+  mozilla::PresShell* mPresShell;
 
   // The size for a resize that we delayed until the root view becomes
   // visible again.
   nsSize mDelayedResize;
 
   nsView* mRootView;
   // mRootViewManager is a strong ref unless it equals |this|.  It's
   // never null (if we have no ancestors, it will be |this|).
--- a/widget/cocoa/SwipeTracker.mm
+++ b/widget/cocoa/SwipeTracker.mm
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "SwipeTracker.h"
 
 #include "InputData.h"
 #include "mozilla/FlushType.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/TouchEvents.h"
 #include "mozilla/dom/SimpleGestureEventBinding.h"
 #include "nsAlgorithm.h"
 #include "nsChildView.h"
 #include "UnitTransforms.h"
 
 // These values were tweaked to make the physics feel similar to the native swipe.
@@ -22,17 +23,17 @@ static const double kWholePagePixelSize 
 static const double kRubberBandResistanceFactor = 4.0;
 static const double kSwipeSuccessThreshold = 0.25;
 static const double kSwipeSuccessVelocityContribution = 0.3;
 
 namespace mozilla {
 
 static already_AddRefed<nsRefreshDriver> GetRefreshDriver(nsIWidget& aWidget) {
   nsIWidgetListener* widgetListener = aWidget.GetWidgetListener();
-  nsIPresShell* presShell = widgetListener ? widgetListener->GetPresShell() : nullptr;
+  PresShell* presShell = widgetListener ? widgetListener->GetPresShell() : nullptr;
   nsPresContext* presContext = presShell ? presShell->GetPresContext() : nullptr;
   RefPtr<nsRefreshDriver> refreshDriver = presContext ? presContext->RefreshDriver() : nullptr;
   return refreshDriver.forget();
 }
 
 SwipeTracker::SwipeTracker(nsChildView& aWidget, const PanGestureInput& aSwipeStartEvent,
                            uint32_t aAllowedDirections, uint32_t aSwipeDirection)
     : mWidget(aWidget),
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -11,16 +11,17 @@
 #include <unistd.h>
 #include <math.h>
 
 #include "nsChildView.h"
 #include "nsCocoaWindow.h"
 
 #include "mozilla/MiscEvents.h"
 #include "mozilla/MouseEvents.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/TouchEvents.h"
 #include "mozilla/WheelHandlingHelper.h"  // for WheelDeltaAdjustmentStrategy
 #include "mozilla/dom/DataTransfer.h"
 #include "mozilla/dom/MouseEventBinding.h"
 #include "mozilla/dom/SimpleGestureEventBinding.h"
 #include "mozilla/dom/WheelEventBinding.h"
 
@@ -36,17 +37,16 @@
 #include "nsIRollupListener.h"
 #include "nsViewManager.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIFile.h"
 #include "nsILocalFileMac.h"
 #include "nsGfxCIID.h"
 #include "nsStyleConsts.h"
 #include "nsIWidgetListener.h"
-#include "nsIPresShell.h"
 #include "nsIScreen.h"
 
 #include "nsDragService.h"
 #include "nsClipboard.h"
 #include "nsCursorManager.h"
 #include "nsWindowMap.h"
 #include "nsCocoaFeatures.h"
 #include "nsCocoaUtils.h"
@@ -808,18 +808,17 @@ void nsChildView::BackingScaleFactorChan
     return;
   }
 
   mBackingScaleFactor = newScale;
   NSRect frame = [mView frame];
   mBounds = nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, newScale);
 
   if (mWidgetListener && !mWidgetListener->GetXULWindow()) {
-    nsIPresShell* presShell = mWidgetListener->GetPresShell();
-    if (presShell) {
+    if (PresShell* presShell = mWidgetListener->GetPresShell()) {
       presShell->BackingScaleFactorChanged();
     }
   }
 }
 
 int32_t nsChildView::RoundsWidgetCoordinatesTo() {
   if (BackingScaleFactor() == 2.0) {
     return 2;
@@ -3149,20 +3148,18 @@ NSEvent* gLastDragMouseDownEvent = nil;
 - (void)systemMetricsChanged {
   if (mGeckoChild) mGeckoChild->NotifyThemeChanged();
 }
 
 - (void)scrollbarSystemMetricChanged {
   [self systemMetricsChanged];
 
   if (mGeckoChild) {
-    nsIWidgetListener* listener = mGeckoChild->GetWidgetListener();
-    if (listener) {
-      nsIPresShell* presShell = listener->GetPresShell();
-      if (presShell) {
+    if (nsIWidgetListener* listener = mGeckoChild->GetWidgetListener()) {
+      if (PresShell* presShell = listener->GetPresShell()) {
         presShell->ReconstructFrames();
       }
     }
   }
 }
 
 - (NSString*)description {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -28,26 +28,26 @@
 #include "nsMenuUtilsX.h"
 #include "nsStyleConsts.h"
 #include "nsNativeThemeColors.h"
 #include "nsNativeThemeCocoa.h"
 #include "nsChildView.h"
 #include "nsCocoaFeatures.h"
 #include "nsIScreenManager.h"
 #include "nsIWidgetListener.h"
-#include "nsIPresShell.h"
 #include "VibrancyManager.h"
 
 #include "gfxPlatform.h"
 #include "gfxPrefs.h"
 #include "qcms.h"
 
 #include "mozilla/AutoRestore.h"
 #include "mozilla/BasicEvents.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/PresShell.h"
 #include <algorithm>
 
 namespace mozilla {
 namespace layers {
 class LayerManager;
 }  // namespace layers
 }  // namespace mozilla
 using namespace mozilla::layers;
@@ -1611,18 +1611,17 @@ void nsCocoaWindow::BackingScaleFactorCh
   }
 
   mBackingScaleFactor = newScale;
 
   if (!mWidgetListener || mWidgetListener->GetXULWindow()) {
     return;
   }
 
-  nsIPresShell* presShell = mWidgetListener->GetPresShell();
-  if (presShell) {
+  if (PresShell* presShell = mWidgetListener->GetPresShell()) {
     presShell->BackingScaleFactorChanged();
   }
   mWidgetListener->UIResolutionChanged();
 }
 
 int32_t nsCocoaWindow::RoundsWidgetCoordinatesTo() {
   if (BackingScaleFactor() == 2.0) {
     return 2;
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -6,16 +6,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsWindow.h"
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/EventForwards.h"
 #include "mozilla/MiscEvents.h"
 #include "mozilla/MouseEvents.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/TouchEvents.h"
 #include "mozilla/UniquePtrExtensions.h"
 #include "mozilla/WidgetUtils.h"
 #include "mozilla/dom/WheelEventBinding.h"
 #include <algorithm>
@@ -27,17 +28,16 @@
 #include "nsIRollupListener.h"
 #include "nsINode.h"
 
 #include "nsWidgetsCID.h"
 #include "nsDragService.h"
 #include "nsIWidgetListener.h"
 #include "nsIScreenManager.h"
 #include "SystemTimeConverter.h"
-#include "nsIPresShell.h"
 #include "nsViewManager.h"
 
 #include "nsGtkKeyUtils.h"
 #include "nsGtkCursors.h"
 #include "ScreenHelperGTK.h"
 
 #include <gtk/gtk.h>
 #include <gtk/gtkx.h>
@@ -3035,32 +3035,30 @@ void nsWindow::ThemeChanged() {
     children = children->next;
   }
 
   IMContextWrapper::OnThemeChanged();
 }
 
 void nsWindow::OnDPIChanged() {
   if (mWidgetListener) {
-    nsIPresShell *presShell = mWidgetListener->GetPresShell();
-    if (presShell) {
+    if (PresShell *presShell = mWidgetListener->GetPresShell()) {
       presShell->BackingScaleFactorChanged();
       // Update menu's font size etc
       presShell->ThemeChanged();
     }
     mWidgetListener->UIResolutionChanged();
   }
 }
 
 void nsWindow::OnCheckResize() { mPendingConfigures++; }
 
 void nsWindow::OnCompositedChanged() {
   if (mWidgetListener) {
-    nsIPresShell *presShell = mWidgetListener->GetPresShell();
-    if (presShell) {
+    if (PresShell *presShell = mWidgetListener->GetPresShell()) {
       // Update CSD after the change in alpha visibility
       presShell->ThemeChanged();
     }
   }
 }
 
 void nsWindow::OnScaleChanged(GtkAllocation *aAllocation) {
 #ifdef MOZ_WAYLAND
@@ -6791,19 +6789,17 @@ static nsIFrame *FindTitlebarFrame(nsIFr
     }
   }
   return nullptr;
 }
 
 void nsWindow::ForceTitlebarRedraw(void) {
   MOZ_ASSERT(mDrawInTitlebar, "We should not redraw invisible titlebar.");
 
-  nsIPresShell *shell =
-      mWidgetListener ? mWidgetListener->GetPresShell() : nullptr;
-  if (!shell) {
+  if (!mWidgetListener || !mWidgetListener->GetPresShell()) {
     return;
   }
   nsView *view = nsView::GetViewFor(this);
   if (!view) {
     return;
   }
   nsIFrame *frame = view->GetFrame();
   if (!frame) {
--- a/widget/nsBaseWidget.cpp
+++ b/widget/nsBaseWidget.cpp
@@ -1147,17 +1147,17 @@ bool nsBaseWidget::ShowContextMenuAfterM
 
     gContextMenuAfterMouseUpCached = true;
   }
   return gContextMenuAfterMouseUp;
 }
 
 Document* nsBaseWidget::GetDocument() const {
   if (mWidgetListener) {
-    if (nsIPresShell* presShell = mWidgetListener->GetPresShell()) {
+    if (PresShell* presShell = mWidgetListener->GetPresShell()) {
       return presShell->GetDocument();
     }
   }
   return nullptr;
 }
 
 void nsBaseWidget::CreateCompositorVsyncDispatcher() {
   // Parent directly listens to the vsync source whereas
@@ -1666,18 +1666,17 @@ void nsBaseWidget::NotifyWindowMoved(int
   }
 }
 
 void nsBaseWidget::NotifyPresShell(NotificationFunc aNotificationFunc) {
   if (!mWidgetListener) {
     return;
   }
 
-  nsIPresShell* presShell = mWidgetListener->GetPresShell();
-  if (presShell) {
+  if (PresShell* presShell = mWidgetListener->GetPresShell()) {
     (presShell->*aNotificationFunc)();
   }
 }
 
 void nsBaseWidget::NotifySizeMoveDone() {
   NotifyPresShell(&nsIPresShell::WindowSizeMoveDone);
 }
 
--- a/widget/nsIWidgetListener.cpp
+++ b/widget/nsIWidgetListener.cpp
@@ -2,29 +2,29 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsIWidgetListener.h"
 
 #include "nsRegion.h"
 #include "nsView.h"
-#include "nsIPresShell.h"
 #include "nsIWidget.h"
 #include "nsIXULWindow.h"
 
 #include "mozilla/BasicEvents.h"
+#include "mozilla/PresShell.h"
 
 using namespace mozilla;
 
 nsIXULWindow* nsIWidgetListener::GetXULWindow() { return nullptr; }
 
 nsView* nsIWidgetListener::GetView() { return nullptr; }
 
-nsIPresShell* nsIWidgetListener::GetPresShell() { return nullptr; }
+PresShell* nsIWidgetListener::GetPresShell() { return nullptr; }
 
 bool nsIWidgetListener::WindowMoved(nsIWidget* aWidget, int32_t aX,
                                     int32_t aY) {
   return false;
 }
 
 bool nsIWidgetListener::WindowResized(nsIWidget* aWidget, int32_t aWidth,
                                       int32_t aHeight) {
--- a/widget/nsIWidgetListener.h
+++ b/widget/nsIWidgetListener.h
@@ -10,20 +10,23 @@
 #include "mozilla/EventForwards.h"
 #include "mozilla/layers/LayersTypes.h"
 #include "mozilla/TimeStamp.h"
 
 #include "nsRegionFwd.h"
 #include "Units.h"
 
 class nsView;
-class nsIPresShell;
 class nsIWidget;
 class nsIXULWindow;
 
+namespace mozilla {
+class PresShell;
+}  // namespace mozilla
+
 /**
  * sizemode is an adjunct to widget size
  */
 enum nsSizeMode {
   nsSizeMode_Normal = 0,
   nsSizeMode_Minimized,
   nsSizeMode_Maximized,
   nsSizeMode_Fullscreen,
@@ -51,17 +54,17 @@ class nsIWidgetListener {
   /**
    * If this listener is for an nsView, return it.
    */
   virtual nsView* GetView();
 
   /**
    * Return the presshell for this widget listener.
    */
-  virtual nsIPresShell* GetPresShell();
+  virtual mozilla::PresShell* GetPresShell();
 
   /**
    * Called when a window is moved to location (x, y). Returns true if the
    * notification was handled. Coordinates are outer window screen coordinates.
    */
   virtual bool WindowMoved(nsIWidget* aWidget, int32_t aX, int32_t aY);
 
   /**
--- a/widget/windows/nsWindowBase.cpp
+++ b/widget/windows/nsWindowBase.cpp
@@ -2,21 +2,21 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsWindowBase.h"
 
 #include "gfxPrefs.h"
 #include "mozilla/MiscEvents.h"
+#include "mozilla/PresShell.h"
 #include "KeyboardLayout.h"
 #include "WinUtils.h"
 #include "npapi.h"
 #include "nsAutoPtr.h"
-#include "nsIPresShell.h"
 
 using namespace mozilla;
 using namespace mozilla::widget;
 
 static const wchar_t kUser32LibName[] = L"user32.dll";
 bool nsWindowBase::sTouchInjectInitialized = false;
 InjectTouchInputPtr nsWindowBase::sInjectTouchFuncPtr;
 
@@ -104,18 +104,17 @@ bool nsWindowBase::InjectTouchPoint(uint
     WinUtils::Log("InjectTouchInput failure. GetLastError=%d", GetLastError());
     return false;
   }
   return true;
 }
 
 void nsWindowBase::ChangedDPI() {
   if (mWidgetListener) {
-    nsIPresShell* presShell = mWidgetListener->GetPresShell();
-    if (presShell) {
+    if (PresShell* presShell = mWidgetListener->GetPresShell()) {
       presShell->BackingScaleFactorChanged();
     }
   }
 }
 
 nsresult nsWindowBase::SynthesizeNativeTouchPoint(
     uint32_t aPointerId, nsIWidget::TouchPointerState aPointerState,
     LayoutDeviceIntPoint aPoint, double aPointerPressure,
--- a/xpfe/appshell/nsWebShellWindow.cpp
+++ b/xpfe/appshell/nsWebShellWindow.cpp
@@ -252,19 +252,20 @@ nsresult nsWebShellWindow::Initialize(
 
     rv = webNav->LoadURI(urlString, loadURIOptions);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return rv;
 }
 
-nsIPresShell* nsWebShellWindow::GetPresShell() {
-  if (!mDocShell) return nullptr;
-
+PresShell* nsWebShellWindow::GetPresShell() {
+  if (!mDocShell) {
+    return nullptr;
+  }
   return mDocShell->GetPresShell();
 }
 
 bool nsWebShellWindow::WindowMoved(nsIWidget* aWidget, int32_t x, int32_t y) {
   nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
   if (pm) {
     nsCOMPtr<nsPIDOMWindowOuter> window =
         mDocShell ? mDocShell->GetWindow() : nullptr;
@@ -363,18 +364,17 @@ void nsWebShellWindow::SizeModeChanged(n
         ourWindow->SetFullScreen(false);
       }
     }
 
     // And always fire a user-defined sizemodechange event on the window
     ourWindow->DispatchCustomEvent(NS_LITERAL_STRING("sizemodechange"));
   }
 
-  nsIPresShell* presShell;
-  if ((presShell = GetPresShell())) {
+  if (PresShell* presShell = GetPresShell()) {
     presShell->GetPresContext()->SizeModeChanged(sizeMode);
   }
 
   // Note the current implementation of SetSizeMode just stores
   // the new state; it doesn't actually resize. So here we store
   // the state and pass the event on to the OS. The day is coming
   // when we'll handle the event here, and the return result will
   // then need to be different.
@@ -729,17 +729,17 @@ NS_IMETHODIMP nsWebShellWindow::Destroy(
   }
   return nsXULWindow::Destroy();
 }
 
 nsIXULWindow* nsWebShellWindow::WidgetListenerDelegate::GetXULWindow() {
   return mWebShellWindow->GetXULWindow();
 }
 
-nsIPresShell* nsWebShellWindow::WidgetListenerDelegate::GetPresShell() {
+PresShell* nsWebShellWindow::WidgetListenerDelegate::GetPresShell() {
   return mWebShellWindow->GetPresShell();
 }
 
 bool nsWebShellWindow::WidgetListenerDelegate::WindowMoved(nsIWidget* aWidget,
                                                            int32_t aX,
                                                            int32_t aY) {
   RefPtr<nsWebShellWindow> holder = mWebShellWindow;
   return holder->WindowMoved(aWidget, aX, aY);
--- a/xpfe/appshell/nsWebShellWindow.h
+++ b/xpfe/appshell/nsWebShellWindow.h
@@ -15,16 +15,17 @@
 #include "nsITabParent.h"
 
 /* Forward declarations.... */
 class nsIURI;
 
 struct nsWidgetInitData;
 
 namespace mozilla {
+class PresShell;
 class WebShellWindowTimerCallback;
 }  // namespace mozilla
 
 class nsWebShellWindow final : public nsXULWindow,
                                public nsIWebProgressListener {
  public:
   // The implementation of non-refcounted nsIWidgetListener, which would hold a
   // strong reference on stack before calling nsWebShellWindow's
@@ -32,17 +33,17 @@ class nsWebShellWindow final : public ns
   class WidgetListenerDelegate : public nsIWidgetListener {
    public:
     explicit WidgetListenerDelegate(nsWebShellWindow* aWebShellWindow)
         : mWebShellWindow(aWebShellWindow) {}
 
     MOZ_CAN_RUN_SCRIPT_BOUNDARY
     virtual nsIXULWindow* GetXULWindow() override;
     MOZ_CAN_RUN_SCRIPT_BOUNDARY
-    virtual nsIPresShell* GetPresShell() override;
+    virtual mozilla::PresShell* GetPresShell() override;
     MOZ_CAN_RUN_SCRIPT_BOUNDARY
     virtual bool WindowMoved(nsIWidget* aWidget, int32_t x, int32_t y) override;
     MOZ_CAN_RUN_SCRIPT_BOUNDARY
     virtual bool WindowResized(nsIWidget* aWidget, int32_t aWidth,
                                int32_t aHeight) override;
     MOZ_CAN_RUN_SCRIPT_BOUNDARY
     virtual bool RequestWindowClose(nsIWidget* aWidget) override;
     MOZ_CAN_RUN_SCRIPT_BOUNDARY
@@ -90,17 +91,17 @@ class nsWebShellWindow final : public ns
   // nsIWebProgressListener
   NS_DECL_NSIWEBPROGRESSLISTENER
 
   // nsIBaseWindow
   NS_IMETHOD Destroy() override;
 
   // nsIWidgetListener methods for WidgetListenerDelegate.
   nsIXULWindow* GetXULWindow() { return this; }
-  nsIPresShell* GetPresShell();
+  mozilla::PresShell* GetPresShell();
   MOZ_CAN_RUN_SCRIPT
   bool WindowMoved(nsIWidget* aWidget, int32_t aX, int32_t aY);
   MOZ_CAN_RUN_SCRIPT
   bool WindowResized(nsIWidget* aWidget, int32_t aWidth, int32_t aHeight);
   MOZ_CAN_RUN_SCRIPT bool RequestWindowClose(nsIWidget* aWidget);
   MOZ_CAN_RUN_SCRIPT void SizeModeChanged(nsSizeMode aSizeMode);
   MOZ_CAN_RUN_SCRIPT void UIResolutionChanged();
   MOZ_CAN_RUN_SCRIPT void FullscreenWillChange(bool aInFullscreen);