Bug 1538511 - Get rid of nsIPresShell::ScrollMode (use mozilla::ScrollMode instead). r=kats
authorBotond Ballo <botond@mozilla.com>
Tue, 26 Mar 2019 00:51:57 +0000
changeset 466414 5840b7d8521a6c60a9dcee429f6682436101f27f
parent 466413 57847959cfa67e7d36d0d18e09a006197e154c5e
child 466415 6564e0b43b232e99438b95d252cd5a4b420edf7f
push id35768
push useropoprus@mozilla.com
push dateThu, 28 Mar 2019 09:55:54 +0000
treeherdermozilla-central@c045dd97faf2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1538511
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 1538511 - Get rid of nsIPresShell::ScrollMode (use mozilla::ScrollMode instead). r=kats Differential Revision: https://phabricator.services.mozilla.com/D24797
docshell/base/nsDocShell.cpp
dom/base/nsDOMWindowUtils.cpp
layout/base/PresShell.cpp
layout/base/nsIPresShell.h
layout/base/nsLayoutUtils.cpp
layout/generic/nsGfxScrollFrame.cpp
toolkit/components/sessionstore/SessionStoreUtils.cpp
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -5654,19 +5654,17 @@ nsresult nsDocShell::SetCurScrollPosEx(i
 
   // Not on a platform with a distinct visual viewport - don't bother setting
   // the visual viewport offset.
   if (!shell->IsVisualViewportSizeSet()) {
     return NS_OK;
   }
 
   shell->ScrollToVisual(targetPos, layers::FrameMetrics::eMainThread,
-                        scrollMode == ScrollMode::eInstant
-                            ? nsIPresShell::ScrollMode::eInstant
-                            : nsIPresShell::ScrollMode::eSmooth);
+                        scrollMode);
 
   return NS_OK;
 }
 
 //*****************************************************************************
 // nsDocShell::nsIScrollable
 //*****************************************************************************
 
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -1417,23 +1417,23 @@ nsDOMWindowUtils::ScrollToVisual(float a
       break;
     case UPDATE_TYPE_MAIN_THREAD:
       updateType = FrameMetrics::eMainThread;
       break;
     default:
       return NS_ERROR_INVALID_ARG;
   }
 
-  nsIPresShell::ScrollMode scrollMode;
+  ScrollMode scrollMode;
   switch (aScrollMode) {
     case SCROLL_MODE_INSTANT:
-      scrollMode = nsIPresShell::ScrollMode::eInstant;
+      scrollMode = ScrollMode::eInstant;
       break;
     case SCROLL_MODE_SMOOTH:
-      scrollMode = nsIPresShell::ScrollMode::eSmooth;
+      scrollMode = ScrollMode::eSmoothMsd;
       break;
     default:
       return NS_ERROR_INVALID_ARG;
   }
 
   presContext->PresShell()->ScrollToVisual(
       CSSPoint::ToAppUnits(CSSPoint(aOffsetX, aOffsetY)), updateType,
       scrollMode);
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -2272,66 +2272,65 @@ PresShell::PageMove(bool aForward, bool 
           nsISelectionController::SCROLL_FOR_CARET_MOVE);
 }
 
 NS_IMETHODIMP
 PresShell::ScrollPage(bool aForward) {
   nsIScrollableFrame* scrollFrame =
       GetScrollableFrameToScroll(nsIPresShell::eVertical);
   if (scrollFrame) {
-    scrollFrame->ScrollBy(
-        nsIntPoint(0, aForward ? 1 : -1), nsIScrollableFrame::PAGES,
-        mozilla::ScrollMode::eSmooth, nullptr, nullptr,
-        nsIScrollableFrame::NOT_MOMENTUM, nsIScrollableFrame::ENABLE_SNAP);
+    scrollFrame->ScrollBy(nsIntPoint(0, aForward ? 1 : -1),
+                          nsIScrollableFrame::PAGES, ScrollMode::eSmooth,
+                          nullptr, nullptr, nsIScrollableFrame::NOT_MOMENTUM,
+                          nsIScrollableFrame::ENABLE_SNAP);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PresShell::ScrollLine(bool aForward) {
   nsIScrollableFrame* scrollFrame =
       GetScrollableFrameToScroll(nsIPresShell::eVertical);
   if (scrollFrame) {
     int32_t lineCount =
         Preferences::GetInt("toolkit.scrollbox.verticalScrollDistance",
                             NS_DEFAULT_VERTICAL_SCROLL_DISTANCE);
     scrollFrame->ScrollBy(nsIntPoint(0, aForward ? lineCount : -lineCount),
-                          nsIScrollableFrame::LINES,
-                          mozilla::ScrollMode::eSmooth, nullptr, nullptr,
-                          nsIScrollableFrame::NOT_MOMENTUM,
+                          nsIScrollableFrame::LINES, ScrollMode::eSmooth,
+                          nullptr, nullptr, nsIScrollableFrame::NOT_MOMENTUM,
                           nsIScrollableFrame::ENABLE_SNAP);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PresShell::ScrollCharacter(bool aRight) {
   nsIScrollableFrame* scrollFrame =
       GetScrollableFrameToScroll(nsIPresShell::eHorizontal);
   if (scrollFrame) {
     int32_t h =
         Preferences::GetInt("toolkit.scrollbox.horizontalScrollDistance",
                             NS_DEFAULT_HORIZONTAL_SCROLL_DISTANCE);
-    scrollFrame->ScrollBy(
-        nsIntPoint(aRight ? h : -h, 0), nsIScrollableFrame::LINES,
-        mozilla::ScrollMode::eSmooth, nullptr, nullptr,
-        nsIScrollableFrame::NOT_MOMENTUM, nsIScrollableFrame::ENABLE_SNAP);
+    scrollFrame->ScrollBy(nsIntPoint(aRight ? h : -h, 0),
+                          nsIScrollableFrame::LINES, ScrollMode::eSmooth,
+                          nullptr, nullptr, nsIScrollableFrame::NOT_MOMENTUM,
+                          nsIScrollableFrame::ENABLE_SNAP);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PresShell::CompleteScroll(bool aForward) {
   nsIScrollableFrame* scrollFrame =
       GetScrollableFrameToScroll(nsIPresShell::eVertical);
   if (scrollFrame) {
-    scrollFrame->ScrollBy(
-        nsIntPoint(0, aForward ? 1 : -1), nsIScrollableFrame::WHOLE,
-        mozilla::ScrollMode::eSmooth, nullptr, nullptr,
-        nsIScrollableFrame::NOT_MOMENTUM, nsIScrollableFrame::ENABLE_SNAP);
+    scrollFrame->ScrollBy(nsIntPoint(0, aForward ? 1 : -1),
+                          nsIScrollableFrame::WHOLE, ScrollMode::eSmooth,
+                          nullptr, nullptr, nsIScrollableFrame::NOT_MOMENTUM,
+                          nsIScrollableFrame::ENABLE_SNAP);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PresShell::CompleteMove(bool aForward, bool aExtend) {
   // Beware! This may flush notifications via synchronous
   // ScrollSelectionIntoView.
@@ -3143,17 +3142,17 @@ nsresult nsIPresShell::GoToAnchor(const 
       // Scroll to the top/left if aAnchorName is "top" and there is no element
       // with such a name or id.
       rv = NS_OK;
       nsIScrollableFrame* sf = GetRootScrollFrameAsScrollable();
       // Check |aScroll| after setting |rv| so we set |rv| to the same
       // thing whether or not |aScroll| is true.
       if (aScroll && sf) {
         // Scroll to the top of the page
-        sf->ScrollTo(nsPoint(0, 0), mozilla::ScrollMode::eInstant);
+        sf->ScrollTo(nsPoint(0, 0), ScrollMode::eInstant);
       }
     }
   }
 
 #ifdef ACCESSIBILITY
   if (anchorTarget) {
     nsAccessibilityService* accService = AccService();
     if (accService) accService->NotifyOfAnchorJumpTo(anchorTarget);
@@ -3372,17 +3371,17 @@ static void ScrollToShowRect(nsIScrollab
       allowedRange.width = maxWidth - allowedRange.x;
       needToScroll = true;
     }
   }
 
   // If we don't need to scroll, then don't try since it might cancel
   // a current smooth scroll operation.
   if (needToScroll) {
-    mozilla::ScrollMode scrollMode = ScrollMode::eInstant;
+    ScrollMode scrollMode = ScrollMode::eInstant;
     bool autoBehaviorIsSmooth =
         (aFrameAsScrollable->GetScrollStyles().mScrollBehavior ==
          NS_STYLE_SCROLL_BEHAVIOR_SMOOTH);
     bool smoothScroll =
         (aFlags & nsIPresShell::SCROLL_SMOOTH) ||
         ((aFlags & nsIPresShell::SCROLL_SMOOTH_AUTO) && autoBehaviorIsSmooth);
     if (gfxPrefs::ScrollBehaviorEnabled() && smoothScroll) {
       scrollMode = ScrollMode::eSmoothMsd;
@@ -10715,17 +10714,19 @@ bool nsIPresShell::SetVisualViewportOffs
     }
   }
   return didChange;
 }
 
 void nsIPresShell::ScrollToVisual(
     const nsPoint& aVisualViewportOffset,
     FrameMetrics::ScrollOffsetUpdateType aUpdateType, ScrollMode aMode) {
-  if (aMode == ScrollMode::eSmooth) {
+  MOZ_ASSERT(aMode == ScrollMode::eInstant || aMode == ScrollMode::eSmoothMsd);
+
+  if (aMode == ScrollMode::eSmoothMsd) {
     if (nsIScrollableFrame* sf = GetRootScrollFrameAsScrollable()) {
       if (sf->SmoothScrollVisual(aVisualViewportOffset, aUpdateType)) {
         return;
       }
     }
   }
 
   // If the caller asked for instant scroll, or if we failed
--- a/layout/base/nsIPresShell.h
+++ b/layout/base/nsIPresShell.h
@@ -8,16 +8,17 @@
 
 #ifndef nsIPresShell_h___
 #define nsIPresShell_h___
 
 #include "mozilla/ArenaObjectID.h"
 #include "mozilla/EventForwards.h"
 #include "mozilla/FlushType.h"
 #include "mozilla/MemoryReporting.h"
+#include "mozilla/ScrollTypes.h"
 #include "mozilla/ServoStyleSet.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/StyleSheet.h"
 #include "mozilla/UniquePtr.h"
 #include "mozilla/WeakPtr.h"
 #include "FrameMetrics.h"
 #include "GeckoProfiler.h"
 #include "gfxPoint.h"
@@ -1684,35 +1685,29 @@ class nsIPresShell : public nsStubDocume
   // Represents an update to the visual scroll offset that will be sent to APZ.
   // The update type is used to determine priority compared to other scroll
   // updates.
   struct VisualScrollUpdate {
     nsPoint mVisualScrollOffset;
     FrameMetrics::ScrollOffsetUpdateType mUpdateType;
   };
 
-  // Scroll mode enum for ScrollToVisual(). We'd like to reuse
-  // nsIScrollableFrame::ScrollMode but that would require including
-  // nsIScrollableFrame.h from this header, which quickly sinks everything
-  // into a circular dependency quagmire.
-  enum class ScrollMode { eInstant, eSmooth };
-
   // Ask APZ in the next transaction to scroll to the given visual viewport
   // offset (relative to the document).
   // Use this sparingly, as it will clobber JS-driven scrolling that happens
   // in the same frame. This is mostly intended to be used in special
   // situations like "first paint" or session restore.
   // If scrolling "far away", i.e. not just within the existing layout
   // viewport, it's recommended to use both nsIScrollableFrame.ScrollTo*()
   // (via window.scrollTo if calling from JS) *and* this function; otherwise,
   // temporary checkerboarding may result.
   // Please request APZ review if adding a new call site.
   void ScrollToVisual(const nsPoint& aVisualViewportOffset,
                       FrameMetrics::ScrollOffsetUpdateType aUpdateType,
-                      ScrollMode aMode);
+                      mozilla::ScrollMode aMode);
   void ClearPendingVisualScrollUpdate() {
     mPendingVisualScrollUpdate = mozilla::Nothing();
   }
   const mozilla::Maybe<VisualScrollUpdate>& GetPendingVisualScrollUpdate()
       const {
     return mPendingVisualScrollUpdate;
   }
 
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -456,17 +456,18 @@ bool nsLayoutUtils::IsAnimationLoggingEn
         &sShouldLog, "layers.offmainthreadcomposition.log-animations");
   }
 
   return sShouldLog;
 }
 
 bool nsLayoutUtils::AreRetainedDisplayListsEnabled() {
 #ifdef MOZ_WIDGET_ANDROID
-  return gfxPrefs::LayoutRetainDisplayList();;
+  return gfxPrefs::LayoutRetainDisplayList();
+  ;
 #else
   if (XRE_IsContentProcess()) {
     return gfxPrefs::LayoutRetainDisplayList();
   }
 
   if (XRE_IsE10sParentProcess()) {
     return gfxPrefs::LayoutRetainDisplayListChrome();
   }
@@ -8824,18 +8825,17 @@ ScrollMetadata nsLayoutUtils::ComputeScr
     metrics.SetBaseScrollOffset(apzScrollPosition);
 
     if (aIsRootContent) {
       if (aLayerManager->GetIsFirstPaint() &&
           presShell->IsVisualViewportOffsetSet()) {
         // Restore the visual viewport offset to the copy stored on the
         // main thread.
         presShell->ScrollToVisual(presShell->GetVisualViewportOffset(),
-                                  FrameMetrics::eRestore,
-                                  nsIPresShell::ScrollMode::eInstant);
+                                  FrameMetrics::eRestore, ScrollMode::eInstant);
       }
 
       if (const Maybe<nsIPresShell::VisualScrollUpdate>& visualUpdate =
               presShell->GetPendingVisualScrollUpdate()) {
         metrics.SetVisualViewportOffset(
             CSSPoint::FromAppUnits(visualUpdate->mVisualScrollOffset));
         metrics.SetVisualScrollUpdateType(visualUpdate->mUpdateType);
         presShell->ClearPendingVisualScrollUpdate();
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -4466,19 +4466,18 @@ void ScrollFrameHelper::ScrollToRestored
       // It's very important to pass nsGkAtoms::restore here, so
       // ScrollToWithOrigin won't clear out mRestorePos.
       ScrollToWithOrigin(layoutScrollToPos, ScrollMode::eInstant,
                          nsGkAtoms::restore, nullptr);
       if (!weakFrame.IsAlive()) {
         return;
       }
       if (mIsRoot && mOuter->PresContext()->IsRootContentDocument()) {
-        mOuter->PresShell()->ScrollToVisual(visualScrollToPos,
-                                            FrameMetrics::eRestore,
-                                            nsIPresShell::ScrollMode::eInstant);
+        mOuter->PresShell()->ScrollToVisual(
+            visualScrollToPos, FrameMetrics::eRestore, ScrollMode::eInstant);
       }
       if (state == LoadingState::Loading || NS_SUBTREE_DIRTY(mOuter)) {
         // If we're trying to do a history scroll restore, then we want to
         // keep trying this until we succeed, because the page can be loading
         // incrementally. So re-get the scroll position for the next iteration,
         // it might not be exactly equal to mRestorePos due to rounding and
         // clamping.
         mLastPos = GetLogicalVisualViewportOffset();
--- a/toolkit/components/sessionstore/SessionStoreUtils.cpp
+++ b/toolkit/components/sessionstore/SessionStoreUtils.cpp
@@ -291,18 +291,17 @@ void SessionStoreUtils::RestoreScrollPos
 
   if (nsCOMPtr<Document> doc = aWindow.GetExtantDoc()) {
     if (nsPresContext* presContext = doc->GetPresContext()) {
       if (presContext->IsRootContentDocument()) {
         // Use eMainThread so this takes precedence over session history
         // (ScrollFrameHelper::ScrollToRestoredPosition()).
         presContext->PresShell()->ScrollToVisual(
             CSSPoint::ToAppUnits(CSSPoint(pos_X, pos_Y)),
-            layers::FrameMetrics::eMainThread,
-            nsIPresShell::ScrollMode::eInstant);
+            layers::FrameMetrics::eMainThread, ScrollMode::eInstant);
       }
     }
   }
 }
 
 // Implements the Luhn checksum algorithm as described at
 // http://wikipedia.org/wiki/Luhn_algorithm
 // Number digit lengths vary with network, but should fall within 12-19 range.