Bug 1496864 - When performing a main thread scroll, update the main thread's view of the visual viewport offset right away. r=kats
authorBotond Ballo <botond@mozilla.com>
Thu, 08 Nov 2018 22:24:44 +0000
changeset 445332 83db18e6c2bfc3a65a82ab0deed7e650e84353bb
parent 445331 c8909b617c85ee40c56d847953492bce7b9472f3
child 445333 4d51790935602e7a4921daca92f2672cc04d8835
push id109718
push userrgurzau@mozilla.com
push dateFri, 09 Nov 2018 05:49:16 +0000
treeherdermozilla-inbound@58c02c05d2db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1496864
milestone65.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 1496864 - When performing a main thread scroll, update the main thread's view of the visual viewport offset right away. r=kats Differential Revision: https://phabricator.services.mozilla.com/D11228
layout/generic/nsGfxScrollFrame.cpp
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -2943,22 +2943,29 @@ ScrollFrameHelper::ScrollToImpl(nsPoint 
   if (mLastScrollOrigin == nsGkAtoms::apz) {
     mApzScrollPos = GetScrollPosition();
   }
 
   // If the new scroll offset is going to clobber APZ's scroll offset, for
   // the RCD-RSF this will have the effect of resetting the visual viewport
   // offset to be the same as the new scroll (= layout viewport) offset.
   // The APZ callback transform, which reflects the difference between these
-  // offsets, will subsequently be cleared. However, it we wait for APZ to
+  // offsets, will subsequently be cleared. However, if we wait for APZ to
   // clear it, the main thread could end up using the old value and get
   // incorrect results, so just clear it now.
   if (mIsRoot && nsLayoutUtils::CanScrollOriginClobberApz(mLastScrollOrigin)) {
     content->SetProperty(nsGkAtoms::apzCallbackTransform, new CSSPoint(),
                          nsINode::DeleteProperty<CSSPoint>);
+
+    // Similarly, update the main thread's view of the visual viewport
+    // offset. Otherwise, if we perform calculations that depend on this
+    // offset (e.g. by using nsIDOMWindowUtils.getVisualViewportOffset()
+    // in chrome JS code) before it's updated by the next APZ repaint,
+    // we could get incorrect results.
+    presContext->PresShell()->SetVisualViewportOffset(pt);
   }
 
   ScrollVisual();
 
   bool schedulePaint = true;
   if (nsLayoutUtils::AsyncPanZoomEnabled(mOuter) &&
       !nsLayoutUtils::ShouldDisableApzForElement(content) &&
       gfxPrefs::APZPaintSkipping()) {