1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 sw=2 et tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_WheelHandlingHelper_h_
8 #define mozilla_WheelHandlingHelper_h_
10 #include "mozilla/Attributes.h"
11 #include "mozilla/EventForwards.h"
15 class nsIScrollableFrame
;
22 class EventStateManager
;
25 * DeltaValues stores two delta values which are along X and Y axis. This is
26 * useful for arguments and results of some methods.
37 DeltaValues(double aDeltaX
, double aDeltaY
)
43 explicit DeltaValues(WidgetWheelEvent
* aEvent
);
50 * WheelHandlingUtils provides some static methods which are useful at handling
54 class WheelHandlingUtils
58 * Returns true if the scrollable frame can be scrolled to either aDirectionX
59 * or aDirectionY along each axis. Otherwise, false.
61 static bool CanScrollOn(nsIScrollableFrame
* aScrollFrame
,
62 double aDirectionX
, double aDirectionY
);
65 static bool CanScrollInRange(nscoord aMin
, nscoord aValue
, nscoord aMax
,
70 * ScrollbarsForWheel manages scrollbars state during wheel operation.
71 * E.g., on some platforms, scrollbars should show only while user attempts to
72 * scroll. At that time, scrollbars which may be possible to scroll by
73 * operation of wheel at the point should show temporarily.
76 class ScrollbarsForWheel
79 static void PrepareToScrollText(EventStateManager
* aESM
,
80 nsIFrame
* aTargetFrame
,
81 WidgetWheelEvent
* aEvent
);
82 static void SetActiveScrollTarget(nsIScrollableFrame
* aScrollTarget
);
83 // Hide all scrollbars (both mActiveOwner's and mActivatedScrollTargets')
84 static void MayInactivate();
85 static void Inactivate();
86 static bool IsActive();
87 static void OwnWheelTransaction(bool aOwn
);
90 static const size_t kNumberOfTargets
= 4;
91 static const DeltaValues directions
[kNumberOfTargets
];
92 static nsWeakFrame sActiveOwner
;
93 static nsWeakFrame sActivatedScrollTargets
[kNumberOfTargets
];
94 static bool sHadWheelStart
;
95 static bool sOwnWheelTransaction
;
99 * These two methods are called upon NS_WHEEL_START/NS_WHEEL_STOP events
100 * to show/hide the right scrollbars.
102 static void TemporarilyActivateAllPossibleScrollTargets(
103 EventStateManager
* aESM
,
104 nsIFrame
* aTargetFrame
,
105 WidgetWheelEvent
* aEvent
);
106 static void DeactivateAllTemporarilyActivatedScrollTargets();
110 * WheelTransaction manages a series of wheel events as a transaction.
111 * While in a transaction, every wheel event should scroll the same scrollable
112 * element even if a different scrollable element is under the mouse cursor.
114 * Additionally, this class also manages wheel scroll speed acceleration.
117 class WheelTransaction
120 static nsIFrame
* GetTargetFrame() { return sTargetFrame
; }
121 static void BeginTransaction(nsIFrame
* aTargetFrame
,
122 WidgetWheelEvent
* aEvent
);
123 // Be careful, UpdateTransaction may fire a DOM event, therefore, the target
124 // frame might be destroyed in the event handler.
125 static bool UpdateTransaction(WidgetWheelEvent
* aEvent
);
126 static void MayEndTransaction();
127 static void EndTransaction();
128 static void OnEvent(WidgetEvent
* aEvent
);
129 static void Shutdown();
130 static uint32_t GetTimeoutTime();
132 static void OwnScrollbars(bool aOwn
);
134 static DeltaValues
AccelerateWheelDelta(WidgetWheelEvent
* aEvent
,
135 bool aAllowScrollSpeedOverride
);
138 static const uint32_t kScrollSeriesTimeout
= 80; // in milliseconds
139 static nsIntPoint
GetScreenPoint(WidgetGUIEvent
* aEvent
);
140 static void OnFailToScrollTarget();
141 static void OnTimeout(nsITimer
* aTimer
, void* aClosure
);
142 static void SetTimeout();
143 static uint32_t GetIgnoreMoveDelayTime();
144 static int32_t GetAccelerationStart();
145 static int32_t GetAccelerationFactor();
146 static DeltaValues
OverrideSystemScrollSpeed(WidgetWheelEvent
* aEvent
);
147 static double ComputeAcceleratedWheelDelta(double aDelta
, int32_t aFactor
);
148 static bool OutOfTime(uint32_t aBaseTime
, uint32_t aThreshold
);
150 static nsWeakFrame sTargetFrame
;
151 static uint32_t sTime
; // in milliseconds
152 static uint32_t sMouseMoved
; // in milliseconds
153 static nsITimer
* sTimer
;
154 static int32_t sScrollSeriesCounter
;
155 static bool sOwnScrollbars
;
158 } // namespace mozilla
160 #endif // mozilla_WheelHandlingHelper_h_