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 #ifndef mozilla_dom_Touch_h_
8 #define mozilla_dom_Touch_h_
10 #include "mozilla/Attributes.h"
11 #include "mozilla/EventForwards.h"
12 #include "mozilla/MouseEvents.h"
13 #include "mozilla/dom/BindingDeclarations.h"
14 #include "mozilla/dom/TouchBinding.h"
15 #include "nsWrapperCache.h"
20 namespace mozilla::dom
{
24 class Touch final
: public nsISupports
,
25 public nsWrapperCache
,
26 public WidgetPointerHelper
{
28 static bool PrefEnabled(JSContext
* aCx
, JSObject
* aGlobal
);
30 static already_AddRefed
<Touch
> Constructor(const GlobalObject
& aGlobal
,
31 const TouchInit
& aParam
);
33 Touch(EventTarget
* aTarget
, int32_t aIdentifier
, int32_t aPageX
,
34 int32_t aPageY
, int32_t aScreenX
, int32_t aScreenY
, int32_t aClientX
,
35 int32_t aClientY
, int32_t aRadiusX
, int32_t aRadiusY
,
36 float aRotationAngle
, float aForce
);
37 Touch(int32_t aIdentifier
, LayoutDeviceIntPoint aPoint
,
38 LayoutDeviceIntPoint aRadius
, float aRotationAngle
, float aForce
);
39 Touch(int32_t aIdentifier
, LayoutDeviceIntPoint aPoint
,
40 LayoutDeviceIntPoint aRadius
, float aRotationAngle
, float aForce
,
41 int32_t aTiltX
, int32_t aTiltY
, int32_t aTwist
);
42 Touch(const Touch
& aOther
);
44 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
45 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(Touch
)
47 void InitializePoints(nsPresContext
* aPresContext
, WidgetEvent
* aEvent
);
49 // Note, this sets both mOriginalTarget and mTarget.
50 void SetTouchTarget(EventTarget
* aTarget
);
52 bool Equals(Touch
* aTouch
) const;
54 // Update this touch's touch area to be the same as aTouch
55 void SetSameAs(const Touch
* aTouch
);
57 virtual JSObject
* WrapObject(JSContext
* aCx
,
58 JS::Handle
<JSObject
*> aGivenProto
) override
;
60 nsIGlobalObject
* GetParentObject() const;
63 int32_t Identifier() const { return mIdentifier
; }
64 EventTarget
* GetTarget() const;
65 int32_t ScreenX(CallerType aCallerType
) const;
66 int32_t ScreenY(CallerType aCallerType
) const;
67 int32_t ClientX() const { return mClientPoint
.x
; }
68 int32_t ClientY() const { return mClientPoint
.y
; }
69 int32_t PageX() const { return mPagePoint
.x
; }
70 int32_t PageY() const { return mPagePoint
.y
; }
71 int32_t RadiusX(CallerType aCallerType
) const;
72 int32_t RadiusY(CallerType aCallerType
) const;
73 float RotationAngle(CallerType aCallerType
) const;
74 float Force(CallerType aCallerType
) const;
76 EventTarget
* GetOriginalTarget() const;
78 nsCOMPtr
<EventTarget
> mOriginalTarget
;
79 nsCOMPtr
<EventTarget
> mTarget
;
80 LayoutDeviceIntPoint mRefPoint
;
83 // Is this touch instance being suppressed to dispatch touch event to content.
84 // We can't remove touch instance from WidgetTouchEvent::mTouches because we
85 // still need it when dispatching pointer events.
86 bool mIsTouchEventSuppressed
;
90 CSSIntPoint mPagePoint
;
91 CSSIntPoint mClientPoint
;
92 CSSIntPoint mScreenPoint
;
93 LayoutDeviceIntPoint mRadius
;
100 bool mPointsInitialized
;
103 } // namespace mozilla::dom
105 #endif // mozilla_dom_Touch_h_