dom/events/WheelHandlingHelper.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:0aaefdfaa226
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/. */
6
7 #ifndef mozilla_WheelHandlingHelper_h_
8 #define mozilla_WheelHandlingHelper_h_
9
10 #include "mozilla/Attributes.h"
11 #include "mozilla/EventForwards.h"
12 #include "nsCoord.h"
13 #include "nsIFrame.h"
14
15 class nsIScrollableFrame;
16 class nsITimer;
17
18 struct nsIntPoint;
19
20 namespace mozilla {
21
22 class EventStateManager;
23
24 /**
25 * DeltaValues stores two delta values which are along X and Y axis. This is
26 * useful for arguments and results of some methods.
27 */
28
29 struct DeltaValues
30 {
31 DeltaValues()
32 : deltaX(0.0)
33 , deltaY(0.0)
34 {
35 }
36
37 DeltaValues(double aDeltaX, double aDeltaY)
38 : deltaX(aDeltaX)
39 , deltaY(aDeltaY)
40 {
41 }
42
43 explicit DeltaValues(WidgetWheelEvent* aEvent);
44
45 double deltaX;
46 double deltaY;
47 };
48
49 /**
50 * WheelHandlingUtils provides some static methods which are useful at handling
51 * wheel events.
52 */
53
54 class WheelHandlingUtils
55 {
56 public:
57 /**
58 * Returns true if the scrollable frame can be scrolled to either aDirectionX
59 * or aDirectionY along each axis. Otherwise, false.
60 */
61 static bool CanScrollOn(nsIScrollableFrame* aScrollFrame,
62 double aDirectionX, double aDirectionY);
63
64 private:
65 static bool CanScrollInRange(nscoord aMin, nscoord aValue, nscoord aMax,
66 double aDirection);
67 };
68
69 /**
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.
74 */
75
76 class ScrollbarsForWheel
77 {
78 public:
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);
88
89 protected:
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;
96
97
98 /**
99 * These two methods are called upon NS_WHEEL_START/NS_WHEEL_STOP events
100 * to show/hide the right scrollbars.
101 */
102 static void TemporarilyActivateAllPossibleScrollTargets(
103 EventStateManager* aESM,
104 nsIFrame* aTargetFrame,
105 WidgetWheelEvent* aEvent);
106 static void DeactivateAllTemporarilyActivatedScrollTargets();
107 };
108
109 /**
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.
113 *
114 * Additionally, this class also manages wheel scroll speed acceleration.
115 */
116
117 class WheelTransaction
118 {
119 public:
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();
131
132 static void OwnScrollbars(bool aOwn);
133
134 static DeltaValues AccelerateWheelDelta(WidgetWheelEvent* aEvent,
135 bool aAllowScrollSpeedOverride);
136
137 protected:
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);
149
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;
156 };
157
158 } // namespace mozilla
159
160 #endif // mozilla_WheelHandlingHelper_h_

mercurial