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
--- 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 =