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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 * Portions Copyright 2013 Microsoft Open Technologies, Inc. */
9 #ifndef mozilla_dom_PointerEvent_h_
10 #define mozilla_dom_PointerEvent_h_
12 #include "mozilla/dom/MouseEvent.h"
13 #include "mozilla/dom/PointerEventBinding.h"
14 #include "mozilla/Maybe.h"
18 namespace mozilla::dom
{
20 struct PointerEventInit
;
22 class PointerEvent
: public MouseEvent
{
24 PointerEvent(EventTarget
* aOwner
, nsPresContext
* aPresContext
,
25 WidgetPointerEvent
* aEvent
);
27 NS_DECL_ISUPPORTS_INHERITED
28 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PointerEvent
, MouseEvent
)
30 virtual JSObject
* WrapObjectInternal(
31 JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) override
;
33 static already_AddRefed
<PointerEvent
> Constructor(
34 const GlobalObject
& aGlobal
, const nsAString
& aType
,
35 const PointerEventInit
& aParam
);
37 static already_AddRefed
<PointerEvent
> Constructor(
38 EventTarget
* aOwner
, const nsAString
& aType
,
39 const PointerEventInit
& aParam
);
41 PointerEvent
* AsPointerEvent() final
{ return this; }
45 double Height() const;
47 float TangentialPressure();
51 double AltitudeAngle();
52 double AzimuthAngle();
54 void GetPointerType(nsAString
& aPointerType
);
55 static bool EnableGetCoalescedEvents(JSContext
* aCx
, JSObject
* aGlobal
);
56 void GetCoalescedEvents(nsTArray
<RefPtr
<PointerEvent
>>& aPointerEvents
);
57 void GetPredictedEvents(nsTArray
<RefPtr
<PointerEvent
>>& aPointerEvents
);
60 ~PointerEvent() = default;
63 // This method returns the boolean to indicate whether spoofing pointer
64 // event for fingerprinting resistance.
65 bool ShouldResistFingerprinting(bool aForPointerId
= false) const;
67 // When the instance is a trusted `pointermove` event but the widget event
68 // does not have proper coalesced events (typically, the event is synthesized
69 // for tests or instantiated in the main process), this fills mCoalescedEvents
70 // with this instance.
71 void EnsureFillingCoalescedEvents(WidgetPointerEvent
& aWidgetEvent
);
73 nsTArray
<RefPtr
<PointerEvent
>> mCoalescedEvents
;
74 nsTArray
<RefPtr
<PointerEvent
>> mPredictedEvents
;
76 // This is used to store the pointerType assigned from constructor.
77 Maybe
<nsString
> mPointerType
;
79 Maybe
<int32_t> mTiltX
;
80 Maybe
<int32_t> mTiltY
;
81 Maybe
<double> mAltitudeAngle
;
82 Maybe
<double> mAzimuthAngle
;
84 // https://w3c.github.io/pointerevents/#dfn-coalesced-events
85 // https://w3c.github.io/pointerevents/#dfn-predicted-events
86 // The events in the coalesced/predicted events list of a trusted event will
88 // ... Empty coalesced events list and predicted events list of their own.
89 bool mCoalescedOrPredictedEvent
= false;
92 void ConvertPointerTypeToString(uint16_t aPointerTypeSrc
,
93 nsAString
& aPointerTypeDest
);
95 } // namespace mozilla::dom
97 already_AddRefed
<mozilla::dom::PointerEvent
> NS_NewDOMPointerEvent(
98 mozilla::dom::EventTarget
* aOwner
, nsPresContext
* aPresContext
,
99 mozilla::WidgetPointerEvent
* aEvent
);
101 #endif // mozilla_dom_PointerEvent_h_