Bug 1517895 - Scroll the visual viewport in nsDocShell::SetCurScrollPosEx(). r=qdot
authorBotond Ballo <botond@mozilla.com>
Wed, 13 Mar 2019 23:07:17 +0000
changeset 521797 f363798d6481
parent 521796 a0bf4a689da4
child 521798 aee83b1af5f1
push id10867
push userdvarga@mozilla.com
push dateThu, 14 Mar 2019 15:20:45 +0000
treeherdermozilla-beta@abad13547875 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1517895
milestone67.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 1517895 - Scroll the visual viewport in nsDocShell::SetCurScrollPosEx(). r=qdot Differential Revision: https://phabricator.services.mozilla.com/D20031
docshell/base/nsDocShell.cpp
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -5620,17 +5620,44 @@ nsresult nsDocShell::SetCurScrollPosEx(i
   NS_ENSURE_TRUE(sf, NS_ERROR_FAILURE);
 
   nsIScrollableFrame::ScrollMode scrollMode = nsIScrollableFrame::INSTANT;
   if (sf->GetScrollStyles().mScrollBehavior ==
       NS_STYLE_SCROLL_BEHAVIOR_SMOOTH) {
     scrollMode = nsIScrollableFrame::SMOOTH_MSD;
   }
 
-  sf->ScrollTo(nsPoint(aCurHorizontalPos, aCurVerticalPos), scrollMode);
+  nsPoint targetPos(aCurHorizontalPos, aCurVerticalPos);
+  sf->ScrollTo(targetPos, scrollMode);
+
+  // Set the visual viewport offset as well.
+
+  nsCOMPtr<nsIPresShell> shell = GetPresShell();
+  NS_ENSURE_TRUE(shell, NS_ERROR_FAILURE);
+
+  nsPresContext* presContext = shell->GetPresContext();
+  NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
+
+  // Only the root content document can have a distinct visual viewport offset.
+  if (!presContext->IsRootContentDocument()) {
+    return NS_OK;
+  }
+
+  // Not on a platform with a distinct visual viewport - don't bother setting
+  // the visual viewport offset.
+  if (!shell->IsVisualViewportSizeSet()) {
+    return NS_OK;
+  }
+
+  // TODO: If scrollMode == SMOOTH_MSD, this will effectively override that
+  // and jump to the target position instantly. A proper solution here would
+  // involve giving nsIScrollableFrame a visual viewport smooth scrolling API.
+  shell->SetPendingVisualScrollUpdate(targetPos,
+                                      layers::FrameMetrics::eMainThread);
+
   return NS_OK;
 }
 
 //*****************************************************************************
 // nsDocShell::nsIScrollable
 //*****************************************************************************
 
 NS_IMETHODIMP