Bug 1358017 - Part 7: Implements the "honour root" functionality for the auto-dir scrolling feature in non-APZ r?masayuki draft
authorZhang Junzhi <zjz@zjz.name>
Mon, 19 Mar 2018 18:03:48 +0800
changeset 780971 47da690ab767b41d8dcb513d3ece5a984d9de521
parent 780970 b3a6498232f9f37b2f163f8a27ca79265064c6f6
child 780972 b06d085f707cf4690cd720ccc148f9e6b3128e24
push id106174
push userbmo:zjz@zjz.name
push dateThu, 12 Apr 2018 10:18:30 +0000
reviewersmasayuki
bugs1358017
milestone61.0a1
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 =