Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=2 sw=2 et tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef mozilla_WheelHandlingHelper_h_ |
michael@0 | 8 | #define mozilla_WheelHandlingHelper_h_ |
michael@0 | 9 | |
michael@0 | 10 | #include "mozilla/Attributes.h" |
michael@0 | 11 | #include "mozilla/EventForwards.h" |
michael@0 | 12 | #include "nsCoord.h" |
michael@0 | 13 | #include "nsIFrame.h" |
michael@0 | 14 | |
michael@0 | 15 | class nsIScrollableFrame; |
michael@0 | 16 | class nsITimer; |
michael@0 | 17 | |
michael@0 | 18 | struct nsIntPoint; |
michael@0 | 19 | |
michael@0 | 20 | namespace mozilla { |
michael@0 | 21 | |
michael@0 | 22 | class EventStateManager; |
michael@0 | 23 | |
michael@0 | 24 | /** |
michael@0 | 25 | * DeltaValues stores two delta values which are along X and Y axis. This is |
michael@0 | 26 | * useful for arguments and results of some methods. |
michael@0 | 27 | */ |
michael@0 | 28 | |
michael@0 | 29 | struct DeltaValues |
michael@0 | 30 | { |
michael@0 | 31 | DeltaValues() |
michael@0 | 32 | : deltaX(0.0) |
michael@0 | 33 | , deltaY(0.0) |
michael@0 | 34 | { |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | DeltaValues(double aDeltaX, double aDeltaY) |
michael@0 | 38 | : deltaX(aDeltaX) |
michael@0 | 39 | , deltaY(aDeltaY) |
michael@0 | 40 | { |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | explicit DeltaValues(WidgetWheelEvent* aEvent); |
michael@0 | 44 | |
michael@0 | 45 | double deltaX; |
michael@0 | 46 | double deltaY; |
michael@0 | 47 | }; |
michael@0 | 48 | |
michael@0 | 49 | /** |
michael@0 | 50 | * WheelHandlingUtils provides some static methods which are useful at handling |
michael@0 | 51 | * wheel events. |
michael@0 | 52 | */ |
michael@0 | 53 | |
michael@0 | 54 | class WheelHandlingUtils |
michael@0 | 55 | { |
michael@0 | 56 | public: |
michael@0 | 57 | /** |
michael@0 | 58 | * Returns true if the scrollable frame can be scrolled to either aDirectionX |
michael@0 | 59 | * or aDirectionY along each axis. Otherwise, false. |
michael@0 | 60 | */ |
michael@0 | 61 | static bool CanScrollOn(nsIScrollableFrame* aScrollFrame, |
michael@0 | 62 | double aDirectionX, double aDirectionY); |
michael@0 | 63 | |
michael@0 | 64 | private: |
michael@0 | 65 | static bool CanScrollInRange(nscoord aMin, nscoord aValue, nscoord aMax, |
michael@0 | 66 | double aDirection); |
michael@0 | 67 | }; |
michael@0 | 68 | |
michael@0 | 69 | /** |
michael@0 | 70 | * ScrollbarsForWheel manages scrollbars state during wheel operation. |
michael@0 | 71 | * E.g., on some platforms, scrollbars should show only while user attempts to |
michael@0 | 72 | * scroll. At that time, scrollbars which may be possible to scroll by |
michael@0 | 73 | * operation of wheel at the point should show temporarily. |
michael@0 | 74 | */ |
michael@0 | 75 | |
michael@0 | 76 | class ScrollbarsForWheel |
michael@0 | 77 | { |
michael@0 | 78 | public: |
michael@0 | 79 | static void PrepareToScrollText(EventStateManager* aESM, |
michael@0 | 80 | nsIFrame* aTargetFrame, |
michael@0 | 81 | WidgetWheelEvent* aEvent); |
michael@0 | 82 | static void SetActiveScrollTarget(nsIScrollableFrame* aScrollTarget); |
michael@0 | 83 | // Hide all scrollbars (both mActiveOwner's and mActivatedScrollTargets') |
michael@0 | 84 | static void MayInactivate(); |
michael@0 | 85 | static void Inactivate(); |
michael@0 | 86 | static bool IsActive(); |
michael@0 | 87 | static void OwnWheelTransaction(bool aOwn); |
michael@0 | 88 | |
michael@0 | 89 | protected: |
michael@0 | 90 | static const size_t kNumberOfTargets = 4; |
michael@0 | 91 | static const DeltaValues directions[kNumberOfTargets]; |
michael@0 | 92 | static nsWeakFrame sActiveOwner; |
michael@0 | 93 | static nsWeakFrame sActivatedScrollTargets[kNumberOfTargets]; |
michael@0 | 94 | static bool sHadWheelStart; |
michael@0 | 95 | static bool sOwnWheelTransaction; |
michael@0 | 96 | |
michael@0 | 97 | |
michael@0 | 98 | /** |
michael@0 | 99 | * These two methods are called upon NS_WHEEL_START/NS_WHEEL_STOP events |
michael@0 | 100 | * to show/hide the right scrollbars. |
michael@0 | 101 | */ |
michael@0 | 102 | static void TemporarilyActivateAllPossibleScrollTargets( |
michael@0 | 103 | EventStateManager* aESM, |
michael@0 | 104 | nsIFrame* aTargetFrame, |
michael@0 | 105 | WidgetWheelEvent* aEvent); |
michael@0 | 106 | static void DeactivateAllTemporarilyActivatedScrollTargets(); |
michael@0 | 107 | }; |
michael@0 | 108 | |
michael@0 | 109 | /** |
michael@0 | 110 | * WheelTransaction manages a series of wheel events as a transaction. |
michael@0 | 111 | * While in a transaction, every wheel event should scroll the same scrollable |
michael@0 | 112 | * element even if a different scrollable element is under the mouse cursor. |
michael@0 | 113 | * |
michael@0 | 114 | * Additionally, this class also manages wheel scroll speed acceleration. |
michael@0 | 115 | */ |
michael@0 | 116 | |
michael@0 | 117 | class WheelTransaction |
michael@0 | 118 | { |
michael@0 | 119 | public: |
michael@0 | 120 | static nsIFrame* GetTargetFrame() { return sTargetFrame; } |
michael@0 | 121 | static void BeginTransaction(nsIFrame* aTargetFrame, |
michael@0 | 122 | WidgetWheelEvent* aEvent); |
michael@0 | 123 | // Be careful, UpdateTransaction may fire a DOM event, therefore, the target |
michael@0 | 124 | // frame might be destroyed in the event handler. |
michael@0 | 125 | static bool UpdateTransaction(WidgetWheelEvent* aEvent); |
michael@0 | 126 | static void MayEndTransaction(); |
michael@0 | 127 | static void EndTransaction(); |
michael@0 | 128 | static void OnEvent(WidgetEvent* aEvent); |
michael@0 | 129 | static void Shutdown(); |
michael@0 | 130 | static uint32_t GetTimeoutTime(); |
michael@0 | 131 | |
michael@0 | 132 | static void OwnScrollbars(bool aOwn); |
michael@0 | 133 | |
michael@0 | 134 | static DeltaValues AccelerateWheelDelta(WidgetWheelEvent* aEvent, |
michael@0 | 135 | bool aAllowScrollSpeedOverride); |
michael@0 | 136 | |
michael@0 | 137 | protected: |
michael@0 | 138 | static const uint32_t kScrollSeriesTimeout = 80; // in milliseconds |
michael@0 | 139 | static nsIntPoint GetScreenPoint(WidgetGUIEvent* aEvent); |
michael@0 | 140 | static void OnFailToScrollTarget(); |
michael@0 | 141 | static void OnTimeout(nsITimer* aTimer, void* aClosure); |
michael@0 | 142 | static void SetTimeout(); |
michael@0 | 143 | static uint32_t GetIgnoreMoveDelayTime(); |
michael@0 | 144 | static int32_t GetAccelerationStart(); |
michael@0 | 145 | static int32_t GetAccelerationFactor(); |
michael@0 | 146 | static DeltaValues OverrideSystemScrollSpeed(WidgetWheelEvent* aEvent); |
michael@0 | 147 | static double ComputeAcceleratedWheelDelta(double aDelta, int32_t aFactor); |
michael@0 | 148 | static bool OutOfTime(uint32_t aBaseTime, uint32_t aThreshold); |
michael@0 | 149 | |
michael@0 | 150 | static nsWeakFrame sTargetFrame; |
michael@0 | 151 | static uint32_t sTime; // in milliseconds |
michael@0 | 152 | static uint32_t sMouseMoved; // in milliseconds |
michael@0 | 153 | static nsITimer* sTimer; |
michael@0 | 154 | static int32_t sScrollSeriesCounter; |
michael@0 | 155 | static bool sOwnScrollbars; |
michael@0 | 156 | }; |
michael@0 | 157 | |
michael@0 | 158 | } // namespace mozilla |
michael@0 | 159 | |
michael@0 | 160 | #endif // mozilla_WheelHandlingHelper_h_ |