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