WheelEvent.h (3793B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 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 file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_WheelEvent_h_ 8 #define mozilla_dom_WheelEvent_h_ 9 10 #include "mozilla/EventForwards.h" 11 #include "mozilla/dom/MouseEvent.h" 12 #include "mozilla/dom/WheelEventBinding.h" 13 14 namespace mozilla::dom { 15 16 class WheelEvent : public MouseEvent { 17 public: 18 WheelEvent(EventTarget* aOwner, nsPresContext* aPresContext, 19 WidgetWheelEvent* aWheelEvent); 20 21 NS_INLINE_DECL_REFCOUNTING_INHERITED(WheelEvent, MouseEvent) 22 23 static already_AddRefed<WheelEvent> Constructor(const GlobalObject& aGlobal, 24 const nsAString& aType, 25 const WheelEventInit& aParam); 26 27 virtual JSObject* WrapObjectInternal( 28 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override { 29 return WheelEvent_Binding::Wrap(aCx, this, aGivenProto); 30 } 31 32 double DevToCssPixels(double aDevPxValue) const { 33 if (!mAppUnitsPerDevPixel) { 34 return aDevPxValue; 35 } 36 return aDevPxValue * mAppUnitsPerDevPixel / AppUnitsPerCSSPixel(); 37 } 38 39 // NOTE: DeltaX(), DeltaY() and DeltaZ() return CSS pixels when deltaMode is 40 // DOM_DELTA_PIXEL. (The internal event's delta values are device pixels 41 // if it's dispatched by widget) 42 double DeltaX(CallerType); 43 double DeltaY(CallerType); 44 double DeltaZ(CallerType); 45 uint32_t DeltaMode(CallerType); 46 47 int32_t WheelDelta(CallerType aCallerType) { 48 int32_t y = WheelDeltaY(aCallerType); 49 return y ? y : WheelDeltaX(aCallerType); 50 } 51 52 static constexpr int32_t kNativeTicksToWheelDelta = 120; 53 static constexpr double kTrustedDeltaToWheelDelta = 3.0; 54 55 int32_t WheelDeltaX(CallerType); 56 int32_t WheelDeltaY(CallerType); 57 58 void InitWheelEvent(const nsAString& aType, bool aCanBubble, bool aCancelable, 59 nsGlobalWindowInner* aView, int32_t aDetail, 60 int32_t aScreenX, int32_t aScreenY, int32_t aClientX, 61 int32_t aClientY, uint16_t aButton, 62 EventTarget* aRelatedTarget, 63 const nsAString& aModifiersList, double aDeltaX, 64 double aDeltaY, double aDeltaZ, uint32_t aDeltaMode) { 65 InitWheelEventInternal(aType, aCanBubble, aCancelable, aView, aDetail, 66 aScreenX, aScreenY, aClientX, aClientY, aButton, 67 aRelatedTarget, aModifiersList, aDeltaX, aDeltaY, 68 aDeltaZ, aDeltaMode); 69 } 70 71 protected: 72 ~WheelEvent() = default; 73 74 void InitWheelEventInternal(const nsAString& aType, bool aCanBubble, 75 bool aCancelable, nsGlobalWindowInner* aView, 76 int32_t aDetail, double aScreenX, double aScreenY, 77 double aClientX, double aClientY, 78 uint16_t aButton, EventTarget* aRelatedTarget, 79 const nsAString& aModifiersList, double aDeltaX, 80 double aDeltaY, double aDeltaZ, 81 uint32_t aDeltaMode); 82 83 double ToWebExposedDelta(WidgetWheelEvent&, double aDelta, 84 nscoord aLineOrPageAmount, CallerType); 85 86 private: 87 int32_t mAppUnitsPerDevPixel; 88 }; 89 90 } // namespace mozilla::dom 91 92 already_AddRefed<mozilla::dom::WheelEvent> NS_NewDOMWheelEvent( 93 mozilla::dom::EventTarget* aOwner, nsPresContext* aPresContext, 94 mozilla::WidgetWheelEvent* aEvent); 95 96 #endif // mozilla_dom_WheelEvent_h_