Line data Source code
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/. */
6 : #ifndef mozilla_dom_TouchEvent_h_
7 : #define mozilla_dom_TouchEvent_h_
8 :
9 : #include "mozilla/dom/Touch.h"
10 : #include "mozilla/dom/TouchEventBinding.h"
11 : #include "mozilla/dom/UIEvent.h"
12 : #include "mozilla/Attributes.h"
13 : #include "mozilla/EventForwards.h"
14 : #include "mozilla/TouchEvents.h"
15 : #include "nsJSEnvironment.h"
16 : #include "nsWrapperCache.h"
17 :
18 : class nsAString;
19 :
20 : namespace mozilla {
21 : namespace dom {
22 :
23 : class TouchList final : public nsISupports
24 : , public nsWrapperCache
25 : {
26 : public:
27 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
28 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TouchList)
29 :
30 0 : explicit TouchList(nsISupports* aParent)
31 0 : : mParent(aParent)
32 : {
33 0 : nsJSContext::LikelyShortLivingObjectCreated();
34 0 : }
35 0 : TouchList(nsISupports* aParent,
36 : const WidgetTouchEvent::TouchArray& aTouches)
37 0 : : mParent(aParent)
38 0 : , mPoints(aTouches)
39 : {
40 0 : nsJSContext::LikelyShortLivingObjectCreated();
41 0 : }
42 :
43 0 : void Append(Touch* aPoint)
44 : {
45 0 : mPoints.AppendElement(aPoint);
46 0 : }
47 :
48 : virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
49 :
50 0 : nsISupports* GetParentObject() const
51 : {
52 0 : return mParent;
53 : }
54 :
55 : static bool PrefEnabled(JSContext* aCx, JSObject* aGlobal);
56 :
57 0 : uint32_t Length() const
58 : {
59 0 : return mPoints.Length();
60 : }
61 0 : Touch* Item(uint32_t aIndex) const
62 : {
63 0 : return mPoints.SafeElementAt(aIndex);
64 : }
65 0 : Touch* IndexedGetter(uint32_t aIndex, bool& aFound) const
66 : {
67 0 : aFound = aIndex < mPoints.Length();
68 0 : if (!aFound) {
69 0 : return nullptr;
70 : }
71 0 : return mPoints[aIndex];
72 : }
73 :
74 : protected:
75 0 : ~TouchList() {}
76 :
77 : nsCOMPtr<nsISupports> mParent;
78 : WidgetTouchEvent::TouchArray mPoints;
79 : };
80 :
81 : class TouchEvent : public UIEvent
82 : {
83 : public:
84 : TouchEvent(EventTarget* aOwner,
85 : nsPresContext* aPresContext,
86 : WidgetTouchEvent* aEvent);
87 :
88 : NS_DECL_ISUPPORTS_INHERITED
89 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TouchEvent, UIEvent)
90 :
91 0 : virtual JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
92 : {
93 0 : return TouchEventBinding::Wrap(aCx, this, aGivenProto);
94 : }
95 :
96 : already_AddRefed<TouchList>
97 : CopyTouches(const Sequence<OwningNonNull<Touch>>& aTouches);
98 :
99 : TouchList* Touches();
100 : TouchList* TargetTouches();
101 : TouchList* ChangedTouches();
102 :
103 : bool AltKey();
104 : bool MetaKey();
105 : bool CtrlKey();
106 : bool ShiftKey();
107 :
108 : void InitTouchEvent(const nsAString& aType,
109 : bool aCanBubble,
110 : bool aCancelable,
111 : nsGlobalWindow* aView,
112 : int32_t aDetail,
113 : bool aCtrlKey,
114 : bool aAltKey,
115 : bool aShiftKey,
116 : bool aMetaKey,
117 : TouchList* aTouches,
118 : TouchList* aTargetTouches,
119 : TouchList* aChangedTouches);
120 :
121 : static bool PrefEnabled(JSContext* aCx, JSObject* aGlobal);
122 : static bool PrefEnabled(nsIDocShell* aDocShell);
123 :
124 : static already_AddRefed<Event> Constructor(const GlobalObject& aGlobal,
125 : const nsAString& aType,
126 : const TouchEventInit& aParam,
127 : ErrorResult& aRv);
128 :
129 : protected:
130 0 : ~TouchEvent() {}
131 :
132 : RefPtr<TouchList> mTouches;
133 : RefPtr<TouchList> mTargetTouches;
134 : RefPtr<TouchList> mChangedTouches;
135 : };
136 :
137 : } // namespace dom
138 : } // namespace mozilla
139 :
140 : already_AddRefed<mozilla::dom::TouchEvent>
141 : NS_NewDOMTouchEvent(mozilla::dom::EventTarget* aOwner,
142 : nsPresContext* aPresContext,
143 : mozilla::WidgetTouchEvent* aEvent);
144 :
145 : #endif // mozilla_dom_TouchEvent_h_
|