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/. */
7 #ifndef mozilla_dom_WheelEvent_h_
8 #define mozilla_dom_WheelEvent_h_
10 #include "mozilla/dom/MouseEvent.h"
11 #include "mozilla/dom/WheelEventBinding.h"
12 #include "mozilla/EventForwards.h"
14 namespace mozilla::dom
{
16 class WheelEvent
: public MouseEvent
{
18 WheelEvent(EventTarget
* aOwner
, nsPresContext
* aPresContext
,
19 WidgetWheelEvent
* aWheelEvent
);
21 NS_INLINE_DECL_REFCOUNTING_INHERITED(WheelEvent
, MouseEvent
)
23 static already_AddRefed
<WheelEvent
> Constructor(const GlobalObject
& aGlobal
,
24 const nsAString
& aType
,
25 const WheelEventInit
& aParam
);
27 virtual JSObject
* WrapObjectInternal(
28 JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) override
{
29 return WheelEvent_Binding::Wrap(aCx
, this, aGivenProto
);
32 double DevToCssPixels(double aDevPxValue
) const {
33 if (!mAppUnitsPerDevPixel
) {
36 return aDevPxValue
* mAppUnitsPerDevPixel
/ AppUnitsPerCSSPixel();
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
);
47 int32_t WheelDelta(CallerType aCallerType
) {
48 int32_t y
= WheelDeltaY(aCallerType
);
49 return y
? y
: WheelDeltaX(aCallerType
);
52 static constexpr int32_t kNativeTicksToWheelDelta
= 120;
53 static constexpr double kTrustedDeltaToWheelDelta
= 3.0;
55 int32_t WheelDeltaX(CallerType
);
56 int32_t WheelDeltaY(CallerType
);
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
);
67 ~WheelEvent() = default;
69 double ToWebExposedDelta(WidgetWheelEvent
&, double aDelta
,
70 nscoord aLineOrPageAmount
, CallerType
);
73 int32_t mAppUnitsPerDevPixel
;
76 } // namespace mozilla::dom
78 already_AddRefed
<mozilla::dom::WheelEvent
> NS_NewDOMWheelEvent(
79 mozilla::dom::EventTarget
* aOwner
, nsPresContext
* aPresContext
,
80 mozilla::WidgetWheelEvent
* aEvent
);
82 #endif // mozilla_dom_WheelEvent_h_