michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 sw=2 et tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_WheelHandlingHelper_h_ michael@0: #define mozilla_WheelHandlingHelper_h_ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/EventForwards.h" michael@0: #include "nsCoord.h" michael@0: #include "nsIFrame.h" michael@0: michael@0: class nsIScrollableFrame; michael@0: class nsITimer; michael@0: michael@0: struct nsIntPoint; michael@0: michael@0: namespace mozilla { michael@0: michael@0: class EventStateManager; michael@0: michael@0: /** michael@0: * DeltaValues stores two delta values which are along X and Y axis. This is michael@0: * useful for arguments and results of some methods. michael@0: */ michael@0: michael@0: struct DeltaValues michael@0: { michael@0: DeltaValues() michael@0: : deltaX(0.0) michael@0: , deltaY(0.0) michael@0: { michael@0: } michael@0: michael@0: DeltaValues(double aDeltaX, double aDeltaY) michael@0: : deltaX(aDeltaX) michael@0: , deltaY(aDeltaY) michael@0: { michael@0: } michael@0: michael@0: explicit DeltaValues(WidgetWheelEvent* aEvent); michael@0: michael@0: double deltaX; michael@0: double deltaY; michael@0: }; michael@0: michael@0: /** michael@0: * WheelHandlingUtils provides some static methods which are useful at handling michael@0: * wheel events. michael@0: */ michael@0: michael@0: class WheelHandlingUtils michael@0: { michael@0: public: michael@0: /** michael@0: * Returns true if the scrollable frame can be scrolled to either aDirectionX michael@0: * or aDirectionY along each axis. Otherwise, false. michael@0: */ michael@0: static bool CanScrollOn(nsIScrollableFrame* aScrollFrame, michael@0: double aDirectionX, double aDirectionY); michael@0: michael@0: private: michael@0: static bool CanScrollInRange(nscoord aMin, nscoord aValue, nscoord aMax, michael@0: double aDirection); michael@0: }; michael@0: michael@0: /** michael@0: * ScrollbarsForWheel manages scrollbars state during wheel operation. michael@0: * E.g., on some platforms, scrollbars should show only while user attempts to michael@0: * scroll. At that time, scrollbars which may be possible to scroll by michael@0: * operation of wheel at the point should show temporarily. michael@0: */ michael@0: michael@0: class ScrollbarsForWheel michael@0: { michael@0: public: michael@0: static void PrepareToScrollText(EventStateManager* aESM, michael@0: nsIFrame* aTargetFrame, michael@0: WidgetWheelEvent* aEvent); michael@0: static void SetActiveScrollTarget(nsIScrollableFrame* aScrollTarget); michael@0: // Hide all scrollbars (both mActiveOwner's and mActivatedScrollTargets') michael@0: static void MayInactivate(); michael@0: static void Inactivate(); michael@0: static bool IsActive(); michael@0: static void OwnWheelTransaction(bool aOwn); michael@0: michael@0: protected: michael@0: static const size_t kNumberOfTargets = 4; michael@0: static const DeltaValues directions[kNumberOfTargets]; michael@0: static nsWeakFrame sActiveOwner; michael@0: static nsWeakFrame sActivatedScrollTargets[kNumberOfTargets]; michael@0: static bool sHadWheelStart; michael@0: static bool sOwnWheelTransaction; michael@0: michael@0: michael@0: /** michael@0: * These two methods are called upon NS_WHEEL_START/NS_WHEEL_STOP events michael@0: * to show/hide the right scrollbars. michael@0: */ michael@0: static void TemporarilyActivateAllPossibleScrollTargets( michael@0: EventStateManager* aESM, michael@0: nsIFrame* aTargetFrame, michael@0: WidgetWheelEvent* aEvent); michael@0: static void DeactivateAllTemporarilyActivatedScrollTargets(); michael@0: }; michael@0: michael@0: /** michael@0: * WheelTransaction manages a series of wheel events as a transaction. michael@0: * While in a transaction, every wheel event should scroll the same scrollable michael@0: * element even if a different scrollable element is under the mouse cursor. michael@0: * michael@0: * Additionally, this class also manages wheel scroll speed acceleration. michael@0: */ michael@0: michael@0: class WheelTransaction michael@0: { michael@0: public: michael@0: static nsIFrame* GetTargetFrame() { return sTargetFrame; } michael@0: static void BeginTransaction(nsIFrame* aTargetFrame, michael@0: WidgetWheelEvent* aEvent); michael@0: // Be careful, UpdateTransaction may fire a DOM event, therefore, the target michael@0: // frame might be destroyed in the event handler. michael@0: static bool UpdateTransaction(WidgetWheelEvent* aEvent); michael@0: static void MayEndTransaction(); michael@0: static void EndTransaction(); michael@0: static void OnEvent(WidgetEvent* aEvent); michael@0: static void Shutdown(); michael@0: static uint32_t GetTimeoutTime(); michael@0: michael@0: static void OwnScrollbars(bool aOwn); michael@0: michael@0: static DeltaValues AccelerateWheelDelta(WidgetWheelEvent* aEvent, michael@0: bool aAllowScrollSpeedOverride); michael@0: michael@0: protected: michael@0: static const uint32_t kScrollSeriesTimeout = 80; // in milliseconds michael@0: static nsIntPoint GetScreenPoint(WidgetGUIEvent* aEvent); michael@0: static void OnFailToScrollTarget(); michael@0: static void OnTimeout(nsITimer* aTimer, void* aClosure); michael@0: static void SetTimeout(); michael@0: static uint32_t GetIgnoreMoveDelayTime(); michael@0: static int32_t GetAccelerationStart(); michael@0: static int32_t GetAccelerationFactor(); michael@0: static DeltaValues OverrideSystemScrollSpeed(WidgetWheelEvent* aEvent); michael@0: static double ComputeAcceleratedWheelDelta(double aDelta, int32_t aFactor); michael@0: static bool OutOfTime(uint32_t aBaseTime, uint32_t aThreshold); michael@0: michael@0: static nsWeakFrame sTargetFrame; michael@0: static uint32_t sTime; // in milliseconds michael@0: static uint32_t sMouseMoved; // in milliseconds michael@0: static nsITimer* sTimer; michael@0: static int32_t sScrollSeriesCounter; michael@0: static bool sOwnScrollbars; michael@0: }; michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_WheelHandlingHelper_h_