Bug 1358017 - Part 7: Implements the "honour root" functionality for the auto-dir scrolling feature in non-APZ r=masayuki
authorZhang Junzhi <zjz@zjz.name>
Mon, 19 Mar 2018 18:03:48 +0800
changeset 413087 bc6c4a16c3d058949a04a652218aaf11ea02009b
parent 413086 f33f52fc4797e2246ae7bc0cdaf40bea6a648749
child 413088 6f644cb57eb3737f3d693d290ca3f64ddb0b9687
push id33833
push useraiakab@mozilla.com
push dateFri, 13 Apr 2018 09:41:15 +0000
treeherdermozilla-central@260e4c83c8a9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1358017
milestone61.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 1358017 - Part 7: Implements the "honour root" functionality for the auto-dir scrolling feature in non-APZ r=masayuki With this commit, all the auto-dir scrolling functionalities are completed in non-APZ. MozReview-Commit-ID: 9v9iPWIwB52
dom/events/WheelHandlingHelper.cpp
--- a/dom/events/WheelHandlingHelper.cpp
+++ b/dom/events/WheelHandlingHelper.cpp
@@ -11,17 +11,17 @@
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/dom/WheelEventBinding.h"
 #include "nsCOMPtr.h"
 #include "nsContentUtils.h"
 #include "nsIContent.h"
-#include "nsIDocument.h"
+#include "nsIDocumentInlines.h"         // for nsIDocument and HTMLBodyElement
 #include "nsIPresShell.h"
 #include "nsIScrollableFrame.h"
 #include "nsITextControlElement.h"
 #include "nsITimer.h"
 #include "nsPluginFrame.h"
 #include "nsPresContext.h"
 #include "prtime.h"
 #include "Units.h"
@@ -719,18 +719,42 @@ ESMAutoDirWheelDeltaAdjuster::ESMAutoDir
   , mLineOrPageDeltaX(aEvent.mLineOrPageDeltaX)
   , mLineOrPageDeltaY(aEvent.mLineOrPageDeltaY)
   , mOverflowDeltaX(aEvent.mOverflowDeltaX)
   , mOverflowDeltaY(aEvent.mOverflowDeltaY)
 {
   mScrollTargetFrame = aScrollFrame.GetScrollTargetFrame();
   MOZ_ASSERT(mScrollTargetFrame);
 
-  // TODO Currently, the honoured target is always the current scrolling frame.
-  nsIFrame* honouredFrame = &aScrollFrame;
+  nsIFrame* honouredFrame = nullptr;
+  if (aHonoursRoot) {
+    // If we are going to honour root, first try to get the frame for <body> as
+    // the honoured root, because <body> is in preference to <html> if the
+    // current document is an HTML document.
+    nsIDocument* document = aScrollFrame.PresShell()->GetDocument();
+    if (document) {
+      Element* bodyElement = document->GetBodyElement();
+      if (bodyElement) {
+        honouredFrame = bodyElement->GetPrimaryFrame();
+      }
+    }
+
+    if (!honouredFrame) {
+      // If there is no <body> frame, fall back to the real root frame.
+      honouredFrame = aScrollFrame.PresShell()->GetRootScrollFrame();
+    }
+
+    if (!honouredFrame) {
+      // If there is no root scroll frame, fall back to the current scrolling
+      // frame.
+      honouredFrame = &aScrollFrame;
+    }
+  } else {
+    honouredFrame = &aScrollFrame;
+  }
 
   WritingMode writingMode = honouredFrame->GetWritingMode();
   WritingMode::BlockDir blockDir = writingMode.GetBlockDir();
   WritingMode::InlineDir inlineDir = writingMode.GetInlineDir();
   // Get whether the honoured frame's content in the horizontal direction starts
   // from right to left(E.g. it's true either if "writing-mode: vertical-rl", or
   // if "writing-mode: horizontal-tb; direction: rtl;" in CSS).
   mIsHorizontalContentRightToLeft =