2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-04-01 08:09:22 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_WheelHandlingHelper_h_
|
|
|
|
#define mozilla_WheelHandlingHelper_h_
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/EventForwards.h"
|
|
|
|
#include "nsCoord.h"
|
2020-07-15 16:44:39 +03:00
|
|
|
#include "nsIFrame.h" // for AutoWeakFrame only
|
2015-04-21 18:04:57 +03:00
|
|
|
#include "nsPoint.h"
|
2014-04-01 08:09:22 +04:00
|
|
|
|
2020-07-15 16:44:39 +03:00
|
|
|
class nsIFrame;
|
2014-04-01 08:09:22 +04:00
|
|
|
class nsIScrollableFrame;
|
|
|
|
class nsITimer;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2014-04-01 08:09:23 +04:00
|
|
|
class EventStateManager;
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/**
|
|
|
|
* DeltaValues stores two delta values which are along X and Y axis. This is
|
|
|
|
* useful for arguments and results of some methods.
|
|
|
|
*/
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
struct DeltaValues {
|
|
|
|
DeltaValues() : deltaX(0.0), deltaY(0.0) {}
|
|
|
|
|
|
|
|
DeltaValues(double aDeltaX, double aDeltaY)
|
|
|
|
: deltaX(aDeltaX), deltaY(aDeltaY) {}
|
|
|
|
|
|
|
|
explicit DeltaValues(WidgetWheelEvent* aEvent);
|
|
|
|
|
|
|
|
double deltaX;
|
|
|
|
double deltaY;
|
|
|
|
};
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/**
|
|
|
|
* WheelHandlingUtils provides some static methods which are useful at handling
|
|
|
|
* wheel events.
|
|
|
|
*/
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
class WheelHandlingUtils {
|
|
|
|
public:
|
2015-10-16 07:19:27 +03:00
|
|
|
/**
|
|
|
|
* Returns true if aFrame is a scrollable frame and it can be scrolled to
|
|
|
|
* either aDirectionX or aDirectionY along each axis. Or if aFrame is a
|
|
|
|
* plugin frame (in this case, aDirectionX and aDirectionY are ignored).
|
|
|
|
* Otherwise, false.
|
|
|
|
*/
|
|
|
|
static bool CanScrollOn(nsIFrame* aFrame, double aDirectionX,
|
|
|
|
double aDirectionY);
|
2014-04-01 08:09:22 +04:00
|
|
|
/**
|
|
|
|
* Returns true if the scrollable frame can be scrolled to either aDirectionX
|
|
|
|
* or aDirectionY along each axis. Otherwise, false.
|
|
|
|
*/
|
|
|
|
static bool CanScrollOn(nsIScrollableFrame* aScrollFrame, double aDirectionX,
|
|
|
|
double aDirectionY);
|
|
|
|
|
2018-02-22 21:40:44 +03:00
|
|
|
// For more details about the concept of a disregarded direction, refer to the
|
|
|
|
// code in struct mozilla::layers::ScrollMetadata which defines
|
|
|
|
// mDisregardedDirection.
|
|
|
|
static Maybe<layers::ScrollDirection> GetDisregardedWheelScrollDirection(
|
|
|
|
const nsIFrame* aFrame);
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
private:
|
|
|
|
static bool CanScrollInRange(nscoord aMin, nscoord aValue, nscoord aMax,
|
|
|
|
double aDirection);
|
|
|
|
};
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/**
|
|
|
|
* ScrollbarsForWheel manages scrollbars state during wheel operation.
|
|
|
|
* E.g., on some platforms, scrollbars should show only while user attempts to
|
|
|
|
* scroll. At that time, scrollbars which may be possible to scroll by
|
|
|
|
* operation of wheel at the point should show temporarily.
|
|
|
|
*/
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
class ScrollbarsForWheel {
|
2014-04-01 08:09:22 +04:00
|
|
|
public:
|
2014-04-01 08:09:23 +04:00
|
|
|
static void PrepareToScrollText(EventStateManager* aESM,
|
2014-04-01 08:09:22 +04:00
|
|
|
nsIFrame* aTargetFrame,
|
2014-04-01 08:09:22 +04:00
|
|
|
WidgetWheelEvent* aEvent);
|
2014-04-01 08:09:22 +04:00
|
|
|
static void SetActiveScrollTarget(nsIScrollableFrame* aScrollTarget);
|
|
|
|
// Hide all scrollbars (both mActiveOwner's and mActivatedScrollTargets')
|
|
|
|
static void MayInactivate();
|
|
|
|
static void Inactivate();
|
|
|
|
static bool IsActive();
|
|
|
|
static void OwnWheelTransaction(bool aOwn);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static const size_t kNumberOfTargets = 4;
|
2014-04-01 08:09:22 +04:00
|
|
|
static const DeltaValues directions[kNumberOfTargets];
|
2017-03-01 20:03:14 +03:00
|
|
|
static AutoWeakFrame sActiveOwner;
|
|
|
|
static AutoWeakFrame sActivatedScrollTargets[kNumberOfTargets];
|
2014-04-01 08:09:22 +04:00
|
|
|
static bool sHadWheelStart;
|
|
|
|
static bool sOwnWheelTransaction;
|
|
|
|
|
|
|
|
/**
|
2015-09-10 19:59:55 +03:00
|
|
|
* These two methods are called upon eWheelOperationStart/eWheelOperationEnd
|
|
|
|
* events to show/hide the right scrollbars.
|
2014-04-01 08:09:22 +04:00
|
|
|
*/
|
|
|
|
static void TemporarilyActivateAllPossibleScrollTargets(
|
2014-04-01 08:09:23 +04:00
|
|
|
EventStateManager* aESM, nsIFrame* aTargetFrame,
|
2014-04-01 08:09:22 +04:00
|
|
|
WidgetWheelEvent* aEvent);
|
2014-04-01 08:09:22 +04:00
|
|
|
static void DeactivateAllTemporarilyActivatedScrollTargets();
|
|
|
|
};
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/**
|
|
|
|
* WheelTransaction manages a series of wheel events as a transaction.
|
|
|
|
* While in a transaction, every wheel event should scroll the same scrollable
|
|
|
|
* element even if a different scrollable element is under the mouse cursor.
|
|
|
|
*
|
|
|
|
* Additionally, this class also manages wheel scroll speed acceleration.
|
|
|
|
*/
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
class WheelTransaction {
|
2014-04-01 08:09:22 +04:00
|
|
|
public:
|
|
|
|
static nsIFrame* GetTargetFrame() { return sTargetFrame; }
|
|
|
|
static void EndTransaction();
|
2015-10-16 07:19:27 +03:00
|
|
|
/**
|
|
|
|
* WillHandleDefaultAction() is called before handling aWheelEvent on
|
|
|
|
* aTargetFrame.
|
|
|
|
*
|
|
|
|
* @return false if the caller cannot continue to handle the default
|
|
|
|
* action. Otherwise, true.
|
|
|
|
*/
|
|
|
|
static bool WillHandleDefaultAction(WidgetWheelEvent* aWheelEvent,
|
2017-03-01 20:03:14 +03:00
|
|
|
AutoWeakFrame& aTargetWeakFrame);
|
2015-10-16 07:19:27 +03:00
|
|
|
static bool WillHandleDefaultAction(WidgetWheelEvent* aWheelEvent,
|
|
|
|
nsIFrame* aTargetFrame) {
|
2017-03-01 20:03:14 +03:00
|
|
|
AutoWeakFrame targetWeakFrame(aTargetFrame);
|
2015-10-16 07:19:27 +03:00
|
|
|
return WillHandleDefaultAction(aWheelEvent, targetWeakFrame);
|
|
|
|
}
|
2014-04-01 08:09:22 +04:00
|
|
|
static void OnEvent(WidgetEvent* aEvent);
|
2014-04-01 08:09:22 +04:00
|
|
|
static void Shutdown();
|
|
|
|
|
|
|
|
static void OwnScrollbars(bool aOwn);
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
static DeltaValues AccelerateWheelDelta(WidgetWheelEvent* aEvent,
|
|
|
|
bool aAllowScrollSpeedOverride);
|
2014-04-01 08:09:22 +04:00
|
|
|
|
|
|
|
protected:
|
2015-10-16 07:19:27 +03:00
|
|
|
static void BeginTransaction(nsIFrame* aTargetFrame,
|
2018-02-22 21:40:44 +03:00
|
|
|
const WidgetWheelEvent* aEvent);
|
2015-10-16 07:19:27 +03:00
|
|
|
// Be careful, UpdateTransaction may fire a DOM event, therefore, the target
|
|
|
|
// frame might be destroyed in the event handler.
|
2018-02-22 21:40:44 +03:00
|
|
|
static bool UpdateTransaction(const WidgetWheelEvent* aEvent);
|
2015-10-16 07:19:27 +03:00
|
|
|
static void MayEndTransaction();
|
|
|
|
|
2017-04-25 01:33:13 +03:00
|
|
|
static LayoutDeviceIntPoint GetScreenPoint(WidgetGUIEvent* aEvent);
|
2014-04-01 08:09:22 +04:00
|
|
|
static void OnFailToScrollTarget();
|
|
|
|
static void OnTimeout(nsITimer* aTimer, void* aClosure);
|
|
|
|
static void SetTimeout();
|
2014-04-01 08:09:22 +04:00
|
|
|
static DeltaValues OverrideSystemScrollSpeed(WidgetWheelEvent* aEvent);
|
2014-04-01 08:09:22 +04:00
|
|
|
static double ComputeAcceleratedWheelDelta(double aDelta, int32_t aFactor);
|
|
|
|
static bool OutOfTime(uint32_t aBaseTime, uint32_t aThreshold);
|
|
|
|
|
2017-03-01 20:03:14 +03:00
|
|
|
static AutoWeakFrame sTargetFrame;
|
2014-04-01 08:09:22 +04:00
|
|
|
static uint32_t sTime; // in milliseconds
|
|
|
|
static uint32_t sMouseMoved; // in milliseconds
|
|
|
|
static nsITimer* sTimer;
|
|
|
|
static int32_t sScrollSeriesCounter;
|
|
|
|
static bool sOwnScrollbars;
|
|
|
|
};
|
|
|
|
|
2018-03-15 11:31:07 +03:00
|
|
|
// For some kinds of scrollings, the delta values of WidgetWheelEvent are
|
|
|
|
// possbile to be adjusted. For example, the user has configured the pref to let
|
|
|
|
// [vertical wheel + Shift key] to perform horizontal scrolling instead of
|
|
|
|
// vertical scrolling.
|
|
|
|
// The values in this enumeration list all kinds of scrollings whose delta
|
|
|
|
// values are possible to be adjusted.
|
|
|
|
enum class WheelDeltaAdjustmentStrategy : uint8_t {
|
|
|
|
// There is no strategy, don't adjust delta values in any cases.
|
|
|
|
eNone,
|
|
|
|
// This strategy means we're receiving a horizontalized scroll, so we should
|
|
|
|
// apply horizontalization strategy for its delta values.
|
|
|
|
// Horizontalized scrolling means treating vertical wheel scrolling as
|
|
|
|
// horizontal scrolling by adjusting delta values.
|
|
|
|
// It's important to keep in mind with the percise concept of horizontalized
|
|
|
|
// scrolling: Delta values are *ONLY* going to be adjusted during the process
|
|
|
|
// of its default action handling; in views of any programmes other than the
|
|
|
|
// default action handler, such as a DOM event listener or a plugin, delta
|
|
|
|
// values are never going to be adjusted, they will still retrive original
|
|
|
|
// delta values when horizontalization occured for default actions.
|
|
|
|
eHorizontalize,
|
2018-03-15 16:57:19 +03:00
|
|
|
// The following two strategies mean we're receving an auto-dir scroll, so we
|
|
|
|
// should apply auto-dir adjustment to the delta of the wheel event if needed.
|
|
|
|
// Auto-dir is a feature which treats any single-wheel scroll as a scroll in
|
|
|
|
// the only one scrollable direction if the target has only one scrollable
|
|
|
|
// direction. For example, if the user scrolls a vertical wheel inside a
|
|
|
|
// target which is horizontally scrollable but vertical unscrollable, then the
|
|
|
|
// vertical scroll is converted to a horizontal scroll for that target.
|
|
|
|
// So why do we need two different strategies for auto-dir scrolling? That's
|
|
|
|
// because when a wheel scroll is converted due to auto-dir, there is one
|
|
|
|
// thing called "honoured target" which decides which side the converted
|
|
|
|
// scroll goes towards. If the content of the honoured target horizontally
|
|
|
|
// is RTL content, then an upward scroll maps to a rightward scroll and a
|
|
|
|
// downward scroll maps to a leftward scroll; otherwise, an upward scroll maps
|
|
|
|
// to a leftward scroll and a downward scroll maps to a rightward scroll.
|
|
|
|
// |eAutoDir| considers the scrolling target as the honoured target.
|
|
|
|
// |eAutoDirWithRootHonour| takes the root element of the document with the
|
|
|
|
// scrolling element, and considers that as the honoured target. But note that
|
|
|
|
// there's one exception: for targets in an HTML document, the real root
|
|
|
|
// element(I.e. the <html> element) is typically not considered as a root
|
|
|
|
// element, but the <body> element is typically considered as a root element.
|
|
|
|
// If there is no <body> element, then consider the <html> element instead.
|
|
|
|
// And also note that like |eHorizontalize|, delta values are *ONLY* going to
|
|
|
|
// be adjusted during the process of its default action handling; in views of
|
|
|
|
// any programmes other than the default action handler, such as a DOM event
|
|
|
|
// listener or a plugin, delta values are never going to be adjusted.
|
|
|
|
eAutoDir,
|
|
|
|
eAutoDirWithRootHonour,
|
2018-03-16 14:23:53 +03:00
|
|
|
// Not an actual strategy. This is just used as an upper bound for
|
|
|
|
// ContiguousEnumSerializer.
|
|
|
|
eSentinel,
|
2018-03-15 11:31:07 +03:00
|
|
|
};
|
|
|
|
|
Bug 143038 Make users can scroll contents horizontally with vertical wheel operation with a modifier r=smaug
This patch declares a new default action, "horizontal scroll", this scrolls
content horizontally with deltaY of wheel events and ignores deltaX and deltaZ.
This is used for default action with Shift key in default setting except on
macOS. On macOS, legacy mouse's vertical wheel operation with Shift key causes
native horizontal wheel event. Therefore, we don't need to use this new
default action on macOS. Additionally, old default action with Shift key,
navigating history, is moved to with Alt key. This makes same settings between
macOS and the others. So, this is better for users who use macOS and another
OS and web app developers who check wheel events only on macOS or other
platform(s).
For simpler implementation, default action handlers moves deltaY values to
deltaX values temporarily *only* while they handle wheel events. This is
performed by AutoWheelDeltaAdjuster and restored after handling it
automatically.
So, in other words, even if default action is "horizontal scroll", web apps
receives wheel events whose deltaY is not zero but its content will be
scrolled horizontally. This is same as Chromium, so, this behavior shouldn't
cause any incompatible behavior with it.
MozReview-Commit-ID: E4X3yZzLEAl
--HG--
extra : rebase_source : e20d854c6b0a181ad4c9e7304bd9ad14256481ff
2017-10-04 19:12:35 +03:00
|
|
|
/**
|
2018-03-15 11:31:07 +03:00
|
|
|
* When a *pure* vertical wheel event should be treated as if it was a
|
|
|
|
* horizontal scroll because the user wants to horizontalize the wheel scroll,
|
|
|
|
* an instance of this class will adjust the delta values upon calling
|
|
|
|
* Horizontalize(). And the horizontalized delta values will be restored
|
|
|
|
* automatically when the instance of this class is being destructed. Or you can
|
|
|
|
* restore them in advance by calling CancelHorizontalization().
|
Bug 143038 Make users can scroll contents horizontally with vertical wheel operation with a modifier r=smaug
This patch declares a new default action, "horizontal scroll", this scrolls
content horizontally with deltaY of wheel events and ignores deltaX and deltaZ.
This is used for default action with Shift key in default setting except on
macOS. On macOS, legacy mouse's vertical wheel operation with Shift key causes
native horizontal wheel event. Therefore, we don't need to use this new
default action on macOS. Additionally, old default action with Shift key,
navigating history, is moved to with Alt key. This makes same settings between
macOS and the others. So, this is better for users who use macOS and another
OS and web app developers who check wheel events only on macOS or other
platform(s).
For simpler implementation, default action handlers moves deltaY values to
deltaX values temporarily *only* while they handle wheel events. This is
performed by AutoWheelDeltaAdjuster and restored after handling it
automatically.
So, in other words, even if default action is "horizontal scroll", web apps
receives wheel events whose deltaY is not zero but its content will be
scrolled horizontally. This is same as Chromium, so, this behavior shouldn't
cause any incompatible behavior with it.
MozReview-Commit-ID: E4X3yZzLEAl
--HG--
extra : rebase_source : e20d854c6b0a181ad4c9e7304bd9ad14256481ff
2017-10-04 19:12:35 +03:00
|
|
|
*/
|
2018-03-15 11:31:07 +03:00
|
|
|
class MOZ_STACK_CLASS WheelDeltaHorizontalizer final {
|
Bug 143038 Make users can scroll contents horizontally with vertical wheel operation with a modifier r=smaug
This patch declares a new default action, "horizontal scroll", this scrolls
content horizontally with deltaY of wheel events and ignores deltaX and deltaZ.
This is used for default action with Shift key in default setting except on
macOS. On macOS, legacy mouse's vertical wheel operation with Shift key causes
native horizontal wheel event. Therefore, we don't need to use this new
default action on macOS. Additionally, old default action with Shift key,
navigating history, is moved to with Alt key. This makes same settings between
macOS and the others. So, this is better for users who use macOS and another
OS and web app developers who check wheel events only on macOS or other
platform(s).
For simpler implementation, default action handlers moves deltaY values to
deltaX values temporarily *only* while they handle wheel events. This is
performed by AutoWheelDeltaAdjuster and restored after handling it
automatically.
So, in other words, even if default action is "horizontal scroll", web apps
receives wheel events whose deltaY is not zero but its content will be
scrolled horizontally. This is same as Chromium, so, this behavior shouldn't
cause any incompatible behavior with it.
MozReview-Commit-ID: E4X3yZzLEAl
--HG--
extra : rebase_source : e20d854c6b0a181ad4c9e7304bd9ad14256481ff
2017-10-04 19:12:35 +03:00
|
|
|
public:
|
|
|
|
/**
|
2018-03-15 11:31:07 +03:00
|
|
|
* @param aWheelEvent A wheel event whose delta values will be adjusted
|
|
|
|
* upon calling Horizontalize().
|
|
|
|
*/
|
|
|
|
explicit WheelDeltaHorizontalizer(WidgetWheelEvent& aWheelEvent)
|
|
|
|
: mWheelEvent(aWheelEvent),
|
2018-06-14 22:26:29 +03:00
|
|
|
mOldDeltaX(0.0),
|
|
|
|
mOldDeltaZ(0.0),
|
|
|
|
mOldOverflowDeltaX(0.0),
|
|
|
|
mOldLineOrPageDeltaX(0),
|
2018-03-15 11:31:07 +03:00
|
|
|
mHorizontalized(false) {}
|
|
|
|
/**
|
|
|
|
* Converts vertical scrolling into horizontal scrolling by adjusting the
|
|
|
|
* its delta values.
|
Bug 143038 Make users can scroll contents horizontally with vertical wheel operation with a modifier r=smaug
This patch declares a new default action, "horizontal scroll", this scrolls
content horizontally with deltaY of wheel events and ignores deltaX and deltaZ.
This is used for default action with Shift key in default setting except on
macOS. On macOS, legacy mouse's vertical wheel operation with Shift key causes
native horizontal wheel event. Therefore, we don't need to use this new
default action on macOS. Additionally, old default action with Shift key,
navigating history, is moved to with Alt key. This makes same settings between
macOS and the others. So, this is better for users who use macOS and another
OS and web app developers who check wheel events only on macOS or other
platform(s).
For simpler implementation, default action handlers moves deltaY values to
deltaX values temporarily *only* while they handle wheel events. This is
performed by AutoWheelDeltaAdjuster and restored after handling it
automatically.
So, in other words, even if default action is "horizontal scroll", web apps
receives wheel events whose deltaY is not zero but its content will be
scrolled horizontally. This is same as Chromium, so, this behavior shouldn't
cause any incompatible behavior with it.
MozReview-Commit-ID: E4X3yZzLEAl
--HG--
extra : rebase_source : e20d854c6b0a181ad4c9e7304bd9ad14256481ff
2017-10-04 19:12:35 +03:00
|
|
|
*/
|
2018-03-15 11:31:07 +03:00
|
|
|
void Horizontalize();
|
|
|
|
~WheelDeltaHorizontalizer();
|
|
|
|
void CancelHorizontalization();
|
Bug 143038 Make users can scroll contents horizontally with vertical wheel operation with a modifier r=smaug
This patch declares a new default action, "horizontal scroll", this scrolls
content horizontally with deltaY of wheel events and ignores deltaX and deltaZ.
This is used for default action with Shift key in default setting except on
macOS. On macOS, legacy mouse's vertical wheel operation with Shift key causes
native horizontal wheel event. Therefore, we don't need to use this new
default action on macOS. Additionally, old default action with Shift key,
navigating history, is moved to with Alt key. This makes same settings between
macOS and the others. So, this is better for users who use macOS and another
OS and web app developers who check wheel events only on macOS or other
platform(s).
For simpler implementation, default action handlers moves deltaY values to
deltaX values temporarily *only* while they handle wheel events. This is
performed by AutoWheelDeltaAdjuster and restored after handling it
automatically.
So, in other words, even if default action is "horizontal scroll", web apps
receives wheel events whose deltaY is not zero but its content will be
scrolled horizontally. This is same as Chromium, so, this behavior shouldn't
cause any incompatible behavior with it.
MozReview-Commit-ID: E4X3yZzLEAl
--HG--
extra : rebase_source : e20d854c6b0a181ad4c9e7304bd9ad14256481ff
2017-10-04 19:12:35 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
WidgetWheelEvent& mWheelEvent;
|
|
|
|
double mOldDeltaX;
|
|
|
|
double mOldDeltaZ;
|
|
|
|
double mOldOverflowDeltaX;
|
|
|
|
int32_t mOldLineOrPageDeltaX;
|
2018-03-15 11:31:07 +03:00
|
|
|
bool mHorizontalized;
|
Bug 143038 Make users can scroll contents horizontally with vertical wheel operation with a modifier r=smaug
This patch declares a new default action, "horizontal scroll", this scrolls
content horizontally with deltaY of wheel events and ignores deltaX and deltaZ.
This is used for default action with Shift key in default setting except on
macOS. On macOS, legacy mouse's vertical wheel operation with Shift key causes
native horizontal wheel event. Therefore, we don't need to use this new
default action on macOS. Additionally, old default action with Shift key,
navigating history, is moved to with Alt key. This makes same settings between
macOS and the others. So, this is better for users who use macOS and another
OS and web app developers who check wheel events only on macOS or other
platform(s).
For simpler implementation, default action handlers moves deltaY values to
deltaX values temporarily *only* while they handle wheel events. This is
performed by AutoWheelDeltaAdjuster and restored after handling it
automatically.
So, in other words, even if default action is "horizontal scroll", web apps
receives wheel events whose deltaY is not zero but its content will be
scrolled horizontally. This is same as Chromium, so, this behavior shouldn't
cause any incompatible behavior with it.
MozReview-Commit-ID: E4X3yZzLEAl
--HG--
extra : rebase_source : e20d854c6b0a181ad4c9e7304bd9ad14256481ff
2017-10-04 19:12:35 +03:00
|
|
|
};
|
|
|
|
|
2018-03-15 19:48:35 +03:00
|
|
|
/**
|
|
|
|
* This class is used to adjust the delta values for wheel scrolling with the
|
|
|
|
* auto-dir functionality.
|
|
|
|
* A traditional wheel scroll only allows the user use the wheel in the same
|
|
|
|
* scrollable direction as that of the scrolling target to scroll the target,
|
|
|
|
* whereas an auto-dir scroll lets the user use any wheel(either a vertical
|
|
|
|
* wheel or a horizontal tilt wheel) to scroll a frame which is scrollable in
|
|
|
|
* only one direction. For detailed information on auto-dir scrolling,
|
|
|
|
* @see mozilla::WheelDeltaAdjustmentStrategy.
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS AutoDirWheelDeltaAdjuster {
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* @param aDeltaX DeltaX for a wheel event whose delta values will
|
|
|
|
* be adjusted upon calling Adjust() when
|
|
|
|
* ShouldBeAdjusted() returns true.
|
|
|
|
* @param aDeltaY DeltaY for a wheel event, like DeltaX.
|
|
|
|
*/
|
|
|
|
AutoDirWheelDeltaAdjuster(double& aDeltaX, double& aDeltaY)
|
|
|
|
: mDeltaX(aDeltaX),
|
|
|
|
mDeltaY(aDeltaY),
|
|
|
|
mCheckedIfShouldBeAdjusted(false),
|
|
|
|
mShouldBeAdjusted(false) {}
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Gets whether the values of the delta should be adjusted for auto-dir
|
|
|
|
* scrolling. Note that if Adjust() has been called, this function simply
|
|
|
|
* returns false.
|
|
|
|
*
|
|
|
|
* @return true if the delta should be adjusted; otherwise false.
|
|
|
|
*/
|
|
|
|
bool ShouldBeAdjusted();
|
|
|
|
/**
|
|
|
|
* Adjusts the values of the delta values for auto-dir scrolling when
|
|
|
|
* ShouldBeAdjusted() returns true. If you call it when ShouldBeAdjusted()
|
|
|
|
* returns false, this function will simply do nothing.
|
|
|
|
*/
|
|
|
|
void Adjust();
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Called by Adjust() if Adjust() successfully adjusted the delta values.
|
|
|
|
*/
|
|
|
|
virtual void OnAdjusted() {}
|
|
|
|
|
|
|
|
virtual bool CanScrollAlongXAxis() const = 0;
|
|
|
|
virtual bool CanScrollAlongYAxis() const = 0;
|
|
|
|
virtual bool CanScrollUpwards() const = 0;
|
|
|
|
virtual bool CanScrollDownwards() const = 0;
|
|
|
|
virtual bool CanScrollLeftwards() const = 0;
|
|
|
|
virtual bool CanScrollRightwards() const = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets whether the horizontal content starts at rightside.
|
|
|
|
*
|
|
|
|
* @return If the content is in vertical-RTL writing mode(E.g. "writing-mode:
|
|
|
|
* vertical-rl" in CSS), or if it's in horizontal-RTL writing-mode
|
|
|
|
* (E.g. "writing-mode: horizontal-tb; direction: rtl;" in CSS), then
|
|
|
|
* this function returns true. From the representation perspective,
|
|
|
|
* frames whose horizontal contents start at rightside also cause
|
|
|
|
* their horizontal scrollbars, if any, initially start at rightside.
|
|
|
|
* So we can also learn about the initial side of the horizontal
|
|
|
|
* scrollbar for the frame by calling this function.
|
|
|
|
*/
|
|
|
|
virtual bool IsHorizontalContentRightToLeft() const = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
double& mDeltaX;
|
|
|
|
double& mDeltaY;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool mCheckedIfShouldBeAdjusted;
|
|
|
|
bool mShouldBeAdjusted;
|
|
|
|
};
|
|
|
|
|
2018-03-19 12:05:45 +03:00
|
|
|
/**
|
|
|
|
* This is the implementation of AutoDirWheelDeltaAdjuster for EventStateManager
|
|
|
|
*
|
|
|
|
* Detailed comments about some member functions are given in the base class
|
|
|
|
* AutoDirWheelDeltaAdjuster.
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS ESMAutoDirWheelDeltaAdjuster final
|
|
|
|
: public AutoDirWheelDeltaAdjuster {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @param aEvent The auto-dir wheel scroll event.
|
|
|
|
* @param aScrollFrame The scroll target for the event.
|
|
|
|
* @param aHonoursRoot If set to true, the honoured frame is the root
|
|
|
|
* frame in the same document where the target is;
|
|
|
|
* If false, the honoured frame is the scroll
|
|
|
|
* target. For the concept of an honoured target,
|
|
|
|
* @see mozilla::WheelDeltaAdjustmentStrategy
|
|
|
|
*/
|
|
|
|
ESMAutoDirWheelDeltaAdjuster(WidgetWheelEvent& aEvent, nsIFrame& aScrollFrame,
|
|
|
|
bool aHonoursRoot);
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual void OnAdjusted() override;
|
|
|
|
virtual bool CanScrollAlongXAxis() const override;
|
|
|
|
virtual bool CanScrollAlongYAxis() const override;
|
|
|
|
virtual bool CanScrollUpwards() const override;
|
|
|
|
virtual bool CanScrollDownwards() const override;
|
|
|
|
virtual bool CanScrollLeftwards() const override;
|
|
|
|
virtual bool CanScrollRightwards() const override;
|
|
|
|
virtual bool IsHorizontalContentRightToLeft() const override;
|
|
|
|
|
|
|
|
nsIScrollableFrame* mScrollTargetFrame;
|
|
|
|
bool mIsHorizontalContentRightToLeft;
|
|
|
|
|
|
|
|
int32_t& mLineOrPageDeltaX;
|
|
|
|
int32_t& mLineOrPageDeltaY;
|
|
|
|
double& mOverflowDeltaX;
|
|
|
|
double& mOverflowDeltaY;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class is used for restoring the delta in an auto-dir wheel.
|
|
|
|
*
|
|
|
|
* An instance of this calss monitors auto-dir adjustment which may happen
|
|
|
|
* during its lifetime. If the delta values is adjusted during its lifetime, the
|
|
|
|
* instance will restore the adjusted delta when it's being destrcuted.
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS ESMAutoDirWheelDeltaRestorer final {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @param aEvent The wheel scroll event to be monitored.
|
|
|
|
*/
|
|
|
|
explicit ESMAutoDirWheelDeltaRestorer(WidgetWheelEvent& aEvent);
|
|
|
|
~ESMAutoDirWheelDeltaRestorer();
|
|
|
|
|
|
|
|
private:
|
|
|
|
WidgetWheelEvent& mEvent;
|
|
|
|
double mOldDeltaX;
|
|
|
|
double mOldDeltaY;
|
|
|
|
int32_t mOldLineOrPageDeltaX;
|
|
|
|
int32_t mOldLineOrPageDeltaY;
|
|
|
|
double mOldOverflowDeltaX;
|
|
|
|
double mOldOverflowDeltaY;
|
|
|
|
};
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
#endif // mozilla_WheelHandlingHelper_h_
|