1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/events/WheelHandlingHelper.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,160 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 sw=2 et tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozilla_WheelHandlingHelper_h_ 1.11 +#define mozilla_WheelHandlingHelper_h_ 1.12 + 1.13 +#include "mozilla/Attributes.h" 1.14 +#include "mozilla/EventForwards.h" 1.15 +#include "nsCoord.h" 1.16 +#include "nsIFrame.h" 1.17 + 1.18 +class nsIScrollableFrame; 1.19 +class nsITimer; 1.20 + 1.21 +struct nsIntPoint; 1.22 + 1.23 +namespace mozilla { 1.24 + 1.25 +class EventStateManager; 1.26 + 1.27 +/** 1.28 + * DeltaValues stores two delta values which are along X and Y axis. This is 1.29 + * useful for arguments and results of some methods. 1.30 + */ 1.31 + 1.32 +struct DeltaValues 1.33 +{ 1.34 + DeltaValues() 1.35 + : deltaX(0.0) 1.36 + , deltaY(0.0) 1.37 + { 1.38 + } 1.39 + 1.40 + DeltaValues(double aDeltaX, double aDeltaY) 1.41 + : deltaX(aDeltaX) 1.42 + , deltaY(aDeltaY) 1.43 + { 1.44 + } 1.45 + 1.46 + explicit DeltaValues(WidgetWheelEvent* aEvent); 1.47 + 1.48 + double deltaX; 1.49 + double deltaY; 1.50 +}; 1.51 + 1.52 +/** 1.53 + * WheelHandlingUtils provides some static methods which are useful at handling 1.54 + * wheel events. 1.55 + */ 1.56 + 1.57 +class WheelHandlingUtils 1.58 +{ 1.59 +public: 1.60 + /** 1.61 + * Returns true if the scrollable frame can be scrolled to either aDirectionX 1.62 + * or aDirectionY along each axis. Otherwise, false. 1.63 + */ 1.64 + static bool CanScrollOn(nsIScrollableFrame* aScrollFrame, 1.65 + double aDirectionX, double aDirectionY); 1.66 + 1.67 +private: 1.68 + static bool CanScrollInRange(nscoord aMin, nscoord aValue, nscoord aMax, 1.69 + double aDirection); 1.70 +}; 1.71 + 1.72 +/** 1.73 + * ScrollbarsForWheel manages scrollbars state during wheel operation. 1.74 + * E.g., on some platforms, scrollbars should show only while user attempts to 1.75 + * scroll. At that time, scrollbars which may be possible to scroll by 1.76 + * operation of wheel at the point should show temporarily. 1.77 + */ 1.78 + 1.79 +class ScrollbarsForWheel 1.80 +{ 1.81 +public: 1.82 + static void PrepareToScrollText(EventStateManager* aESM, 1.83 + nsIFrame* aTargetFrame, 1.84 + WidgetWheelEvent* aEvent); 1.85 + static void SetActiveScrollTarget(nsIScrollableFrame* aScrollTarget); 1.86 + // Hide all scrollbars (both mActiveOwner's and mActivatedScrollTargets') 1.87 + static void MayInactivate(); 1.88 + static void Inactivate(); 1.89 + static bool IsActive(); 1.90 + static void OwnWheelTransaction(bool aOwn); 1.91 + 1.92 +protected: 1.93 + static const size_t kNumberOfTargets = 4; 1.94 + static const DeltaValues directions[kNumberOfTargets]; 1.95 + static nsWeakFrame sActiveOwner; 1.96 + static nsWeakFrame sActivatedScrollTargets[kNumberOfTargets]; 1.97 + static bool sHadWheelStart; 1.98 + static bool sOwnWheelTransaction; 1.99 + 1.100 + 1.101 + /** 1.102 + * These two methods are called upon NS_WHEEL_START/NS_WHEEL_STOP events 1.103 + * to show/hide the right scrollbars. 1.104 + */ 1.105 + static void TemporarilyActivateAllPossibleScrollTargets( 1.106 + EventStateManager* aESM, 1.107 + nsIFrame* aTargetFrame, 1.108 + WidgetWheelEvent* aEvent); 1.109 + static void DeactivateAllTemporarilyActivatedScrollTargets(); 1.110 +}; 1.111 + 1.112 +/** 1.113 + * WheelTransaction manages a series of wheel events as a transaction. 1.114 + * While in a transaction, every wheel event should scroll the same scrollable 1.115 + * element even if a different scrollable element is under the mouse cursor. 1.116 + * 1.117 + * Additionally, this class also manages wheel scroll speed acceleration. 1.118 + */ 1.119 + 1.120 +class WheelTransaction 1.121 +{ 1.122 +public: 1.123 + static nsIFrame* GetTargetFrame() { return sTargetFrame; } 1.124 + static void BeginTransaction(nsIFrame* aTargetFrame, 1.125 + WidgetWheelEvent* aEvent); 1.126 + // Be careful, UpdateTransaction may fire a DOM event, therefore, the target 1.127 + // frame might be destroyed in the event handler. 1.128 + static bool UpdateTransaction(WidgetWheelEvent* aEvent); 1.129 + static void MayEndTransaction(); 1.130 + static void EndTransaction(); 1.131 + static void OnEvent(WidgetEvent* aEvent); 1.132 + static void Shutdown(); 1.133 + static uint32_t GetTimeoutTime(); 1.134 + 1.135 + static void OwnScrollbars(bool aOwn); 1.136 + 1.137 + static DeltaValues AccelerateWheelDelta(WidgetWheelEvent* aEvent, 1.138 + bool aAllowScrollSpeedOverride); 1.139 + 1.140 +protected: 1.141 + static const uint32_t kScrollSeriesTimeout = 80; // in milliseconds 1.142 + static nsIntPoint GetScreenPoint(WidgetGUIEvent* aEvent); 1.143 + static void OnFailToScrollTarget(); 1.144 + static void OnTimeout(nsITimer* aTimer, void* aClosure); 1.145 + static void SetTimeout(); 1.146 + static uint32_t GetIgnoreMoveDelayTime(); 1.147 + static int32_t GetAccelerationStart(); 1.148 + static int32_t GetAccelerationFactor(); 1.149 + static DeltaValues OverrideSystemScrollSpeed(WidgetWheelEvent* aEvent); 1.150 + static double ComputeAcceleratedWheelDelta(double aDelta, int32_t aFactor); 1.151 + static bool OutOfTime(uint32_t aBaseTime, uint32_t aThreshold); 1.152 + 1.153 + static nsWeakFrame sTargetFrame; 1.154 + static uint32_t sTime; // in milliseconds 1.155 + static uint32_t sMouseMoved; // in milliseconds 1.156 + static nsITimer* sTimer; 1.157 + static int32_t sScrollSeriesCounter; 1.158 + static bool sOwnScrollbars; 1.159 +}; 1.160 + 1.161 +} // namespace mozilla 1.162 + 1.163 +#endif // mozilla_WheelHandlingHelper_h_