Bug 1522724 - Add scroll update type for nsIDOMWindowUtils.scrollToVisual(). r=botond
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Mon, 28 Jan 2019 21:48:43 +0000
changeset 455727 bc9fd5bd6046ba7e1b04ceeb6260d76d326748df
parent 455726 d660ac034e63124372cae5835fcd982363700f5c
child 455728 5206746db39306b58f37c7351c5f78ca685f6817
push id35457
push usercsabou@mozilla.com
push dateTue, 29 Jan 2019 09:20:40 +0000
treeherdermozilla-central@84104c5031c3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1522724
milestone66.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 1522724 - Add scroll update type for nsIDOMWindowUtils.scrollToVisual(). r=botond Depends on D17582 Differential Revision: https://phabricator.services.mozilla.com/D17583
dom/base/nsDOMWindowUtils.cpp
dom/interfaces/base/nsIDOMWindowUtils.idl
gfx/layers/apz/test/mochitest/helper_fullscreen.html
gfx/layers/apz/test/mochitest/helper_minimum_scale_1_0.html
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -1390,32 +1390,41 @@ nsDOMWindowUtils::GetScrollXYFloat(bool 
   NS_ENSURE_SUCCESS(rv, rv);
   *aScrollX = nsPresContext::AppUnitsToFloatCSSPixels(scrollPos.x);
   *aScrollY = nsPresContext::AppUnitsToFloatCSSPixels(scrollPos.y);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDOMWindowUtils::ScrollToVisual(float aOffsetX, float aOffsetY) {
+nsDOMWindowUtils::ScrollToVisual(float aOffsetX, float aOffsetY,
+                                 int32_t aUpdateType) {
   nsCOMPtr<Document> doc = GetDocument();
   NS_ENSURE_STATE(doc);
 
   nsPresContext* presContext = doc->GetPresContext();
   NS_ENSURE_TRUE(presContext, NS_ERROR_NOT_AVAILABLE);
 
   // This should only be called on the root content document.
   NS_ENSURE_TRUE(presContext->IsRootContentDocument(), NS_ERROR_INVALID_ARG);
 
-  // Use |eRestore| as the priority for now, as it's the conservative choice.
-  // If a JS call site needs higher priority, we can expose the update type
-  // as a parameter.
+  FrameMetrics::ScrollOffsetUpdateType updateType;
+  switch (aUpdateType) {
+    case UPDATE_TYPE_RESTORE:
+      updateType = FrameMetrics::eRestore;
+      break;
+    case UPDATE_TYPE_MAIN_THREAD:
+      updateType = FrameMetrics::eMainThread;
+      break;
+    default:
+      return NS_ERROR_INVALID_ARG;
+  }
+
   presContext->PresShell()->SetPendingVisualScrollUpdate(
-      CSSPoint::ToAppUnits(CSSPoint(aOffsetX, aOffsetY)),
-      FrameMetrics::eRestore);
+      CSSPoint::ToAppUnits(CSSPoint(aOffsetX, aOffsetY)), updateType);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetVisualViewportOffsetRelativeToLayoutViewport(
     float* aOffsetX, float* aOffsetY) {
   *aOffsetX = 0;
--- a/dom/interfaces/base/nsIDOMWindowUtils.idl
+++ b/dom/interfaces/base/nsIDOMWindowUtils.idl
@@ -834,18 +834,20 @@ interface nsIDOMWindowUtils : nsISupport
    * Only applicable to the window associated with the root content document.
    * Note: this does not take effect right away. Rather, the visual scroll
    *       request is sent to APZ with the next transaction, and will be
    *       reflected in the main thread with the subsequent APZ repaint request.
    * Please see the caveats mentioned at nsIPresShell::
    * SetPendingVisualViewportOffset(), and request APZ review if adding a new
    * call to this.
    */
-  void scrollToVisual(in float aOffsetX, in float aOffsetY);
- 
+  const long UPDATE_TYPE_RESTORE = 0;
+  const long UPDATE_TYPE_MAIN_THREAD = 1;
+  void scrollToVisual(in float aOffsetX, in float aOffsetY, in long aUpdateType);
+
   /**
    * Returns the offset of the window's visual viewport relative to the
    * layout viewport.
    */
   void getVisualViewportOffsetRelativeToLayoutViewport(out float aOffsetX,
                                                        out float aOffsetY);
 
   /**
--- a/gfx/layers/apz/test/mochitest/helper_fullscreen.html
+++ b/gfx/layers/apz/test/mochitest/helper_fullscreen.html
@@ -14,32 +14,34 @@
     }
   </style>
 </head>
 <body>
   <div style="background: blue; width: 100%; height: 100%;"></div>
   <div style="background: red; width: 200%; height: 100px;">overflowed element</div>
   <div id="target" style="background: green; width: 100px; height: 100px;"></div>
   <script type="application/javascript">
+    const utils = SpecialPowers.getDOMWindowUtils(window);
+
     function waitForFullscreenChange() {
       return new Promise(resolve => {
         document.addEventListener("fullscreenchange", resolve);
       });
     }
 
     async function test(testDriver) {
       target.requestFullscreen();
 
       await waitForFullscreenChange();
 
       is(document.fullscreenElement, target,
          "The target element should have been fullscreen-ed");
 
       // Try to move rightward, but it should NOT happen.
-      SpecialPowers.getDOMWindowUtils(window).scrollToVisual(200, 0);
+      utils.scrollToVisual(200, 0, utils.UPDATE_TYPE_MAIN_THREAD);
 
       await waitUntilApzStable();
 
       is(visualViewport.offsetLeft, 0,
          "The visual viewport offset should never be moved");
 
       document.exitFullscreen();
     }
--- a/gfx/layers/apz/test/mochitest/helper_minimum_scale_1_0.html
+++ b/gfx/layers/apz/test/mochitest/helper_minimum_scale_1_0.html
@@ -15,18 +15,20 @@
       position: absolute;
     }
   </style>
 </head>
 <body>
   <div style="width: 200%; height: 200%; background-color: green"></div>
   <div style="width: 100%; height: 100%; background-color: blue"></div>
   <script type="application/javascript">
+    const utils = SpecialPowers.getDOMWindowUtils(window);
+
     async function test(testDriver) {
-      SpecialPowers.getDOMWindowUtils(window).scrollToVisual(100, 0);
+      utils.scrollToVisual(100, 0, utils.UPDATE_TYPE_MAIN_THREAD);
 
       const promiseForVisualViewportScroll = new Promise(resolve => {
         window.visualViewport.addEventListener("scroll", () => {
           resolve();
         }, { once: true });
       });
 
       await waitUntilApzStable();