Bug 1478776 - Part 9: Helper function for layout viewport scroll position in PresShell. r=botond
authorJan Henning <jh+bugzilla@buttercookie.de>
Thu, 20 Dec 2018 21:35:55 +0000
changeset 451700 4d4e9b8110451b9393b44078e32d1c36b7c31968
parent 451699 767281b6922eda01f577939b69f988ab6efc9866
child 451701 1f867de12312ea29fe968e7b23f743d3e9da87d5
push id35251
push userccoroiu@mozilla.com
push dateFri, 21 Dec 2018 21:54:30 +0000
treeherdermozilla-central@74101900e7d4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1478776
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 1478776 - Part 9: Helper function for layout viewport scroll position in PresShell. r=botond This changes the semantics of the relative visual viewport offset calculation in the PresShell slightly, in that a missing root scroll frame will no longer force the relative offset to zero, even if the visual viewport itself has a non- zero scroll position [1]. On the other hand, the visual viewport's own relative offset calculations already work that way today, in that layout and visual viewport scroll positions are retrieved separately and then subtracted from one another regardless of whether those values are actually valid or merely a fallback because the PresShell/scroll frame weren't available. [1] Though I'm not sure under what circumstances this could really be relevant. Differential Revision: https://phabricator.services.mozilla.com/D14686
dom/base/VisualViewport.cpp
layout/base/PresShell.cpp
layout/base/nsIPresShell.h
--- a/dom/base/VisualViewport.cpp
+++ b/dom/base/VisualViewport.cpp
@@ -82,22 +82,18 @@ CSSPoint VisualViewport::VisualViewportO
     offset = CSSPoint::FromAppUnits(presShell->GetVisualViewportOffset());
   }
   return offset;
 }
 
 CSSPoint VisualViewport::LayoutViewportOffset() const {
   CSSPoint offset = CSSPoint(0, 0);
 
-  nsIPresShell* presShell = GetPresShell();
-  if (presShell) {
-    nsIScrollableFrame* sf = presShell->GetRootScrollFrameAsScrollable();
-    if (sf) {
-      offset = CSSPoint::FromAppUnits(sf->GetScrollPosition());
-    }
+  if (nsIPresShell* presShell = GetPresShell()) {
+    offset = CSSPoint::FromAppUnits(presShell->GetLayoutViewportOffset());
   }
   return offset;
 }
 
 double VisualViewport::PageLeft() const { return VisualViewportOffset().X(); }
 
 double VisualViewport::PageTop() const { return VisualViewportOffset().Y(); }
 
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -10049,19 +10049,23 @@ void nsIPresShell::SetVisualViewportOffs
 
     if (auto* window = nsGlobalWindowInner::Cast(mDocument->GetInnerWindow())) {
       window->VisualViewport()->PostScrollEvent(aPrevRelativeOffset);
     }
   }
 }
 
 nsPoint nsIPresShell::GetVisualViewportOffsetRelativeToLayoutViewport() const {
+  return GetVisualViewportOffset() - GetLayoutViewportOffset();
+}
+
+nsPoint nsIPresShell::GetLayoutViewportOffset() const {
   nsPoint result;
   if (nsIScrollableFrame* sf = GetRootScrollFrameAsScrollable()) {
-    result = GetVisualViewportOffset() - sf->GetScrollPosition();
+    result = sf->GetScrollPosition();
   }
   return result;
 }
 
 void nsIPresShell::RecomputeFontSizeInflationEnabled() {
   mFontSizeInflationEnabled = DetermineFontSizeInflationState();
 
   float fontScale = nsLayoutUtils::SystemFontScale();
--- a/layout/base/nsIPresShell.h
+++ b/layout/base/nsIPresShell.h
@@ -1649,16 +1649,18 @@ class nsIPresShell : public nsStubDocume
 
   void SetVisualViewportOffset(const nsPoint& aScrollOffset,
                                const nsPoint& aPrevRelativeOffset);
 
   nsPoint GetVisualViewportOffset() const { return mVisualViewportOffset; }
 
   nsPoint GetVisualViewportOffsetRelativeToLayoutViewport() const;
 
+  nsPoint GetLayoutViewportOffset() const;
+
   virtual void WindowSizeMoveDone() = 0;
   virtual void SysColorChanged() = 0;
   virtual void ThemeChanged() = 0;
   virtual void BackingScaleFactorChanged() = 0;
 
   /**
    * Documents belonging to an invisible DocShell must not be painted ever.
    */