Bug 1509575 - Restore the visual viewport offset from the main thread during a first paint. r=kats
authorBotond Ballo <botond@mozilla.com>
Tue, 15 Jan 2019 01:30:53 +0000
changeset 513871 041f9c2bfce5c7dcb1eacd495be83252139f96a0
parent 513870 eba0c068601df32e0f8c5ec19d871bcfc60c68fb
child 513872 8a59ebb819c260b4375863f5722d01bd2efd0815
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1509575
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 1509575 - Restore the visual viewport offset from the main thread during a first paint. r=kats During a "first paint" transaction, compositor-side state such as APZ's copy of the visual viewport offset is overwritten. However, the scroll frame may persist on the main thread, and in such a case we want to restore the visual viewport offset stored in the scroll frame. This comes into play during e.g. navigation back to a page. Differential Revision: https://phabricator.services.mozilla.com/D16238
gfx/layers/apz/test/mochitest/helper_bug1509575.html
layout/base/nsLayoutUtils.cpp
--- a/gfx/layers/apz/test/mochitest/helper_bug1509575.html
+++ b/gfx/layers/apz/test/mochitest/helper_bug1509575.html
@@ -56,17 +56,17 @@ function* test(testDriver) {
 
   // Wait for the event listener to fire.
   yield true;
   ok(true, "MozAfterPaint fired");
 
   // Flush state just to be sure.
   yield waitForApzFlushedRepaints(testDriver);
 
-  todo_is(window.visualViewport.pageLeft, visualX, "visual viewport remains unchanged");
+  is(window.visualViewport.pageLeft, visualX, "visual viewport remains unchanged");
 }
 
 waitUntilApzStable()
 .then(runContinuation(test))
 .then(subtestDone);
 
   </script>
 </head>
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -8703,16 +8703,24 @@ static void MaybeReflowForInflationScree
     CSSPoint scrollPosition =
         CSSPoint::FromAppUnits(scrollableFrame->GetScrollPosition());
     CSSPoint apzScrollPosition =
         CSSPoint::FromAppUnits(scrollableFrame->GetApzScrollPosition());
     metrics.SetScrollOffset(scrollPosition);
     metrics.SetBaseScrollOffset(apzScrollPosition);
 
     if (aIsRootContent) {
+      if (aLayerManager->GetIsFirstPaint() &&
+          presShell->IsVisualViewportOffsetSet()) {
+        // Restore the visual viewport offset to the copy stored on the
+        // main thread.
+        presShell->SetPendingVisualScrollUpdate(
+            presShell->GetVisualViewportOffset(), FrameMetrics::eRestore);
+      }
+
       if (const Maybe<nsIPresShell::VisualScrollUpdate>& visualUpdate =
               presShell->GetPendingVisualScrollUpdate()) {
         metrics.SetVisualViewportOffset(
             CSSPoint::FromAppUnits(visualUpdate->mVisualScrollOffset));
         metrics.SetVisualScrollUpdateType(visualUpdate->mUpdateType);
         presShell->ClearPendingVisualScrollUpdate();
       }
     }