|
1 /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 #ifndef mozilla_dom_TouchEvent_h_ |
|
6 #define mozilla_dom_TouchEvent_h_ |
|
7 |
|
8 #include "mozilla/dom/Touch.h" |
|
9 #include "mozilla/dom/TouchEventBinding.h" |
|
10 #include "mozilla/dom/UIEvent.h" |
|
11 #include "mozilla/Attributes.h" |
|
12 #include "mozilla/EventForwards.h" |
|
13 #include "nsJSEnvironment.h" |
|
14 #include "nsTArray.h" |
|
15 #include "nsWrapperCache.h" |
|
16 |
|
17 class nsAString; |
|
18 |
|
19 namespace mozilla { |
|
20 namespace dom { |
|
21 |
|
22 class TouchList MOZ_FINAL : public nsISupports |
|
23 , public nsWrapperCache |
|
24 { |
|
25 public: |
|
26 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
27 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TouchList) |
|
28 |
|
29 TouchList(nsISupports* aParent) |
|
30 : mParent(aParent) |
|
31 { |
|
32 SetIsDOMBinding(); |
|
33 nsJSContext::LikelyShortLivingObjectCreated(); |
|
34 } |
|
35 TouchList(nsISupports* aParent, |
|
36 const nsTArray<nsRefPtr<Touch> >& aTouches) |
|
37 : mParent(aParent) |
|
38 , mPoints(aTouches) |
|
39 { |
|
40 SetIsDOMBinding(); |
|
41 nsJSContext::LikelyShortLivingObjectCreated(); |
|
42 } |
|
43 |
|
44 void Append(Touch* aPoint) |
|
45 { |
|
46 mPoints.AppendElement(aPoint); |
|
47 } |
|
48 |
|
49 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
50 |
|
51 nsISupports* GetParentObject() const |
|
52 { |
|
53 return mParent; |
|
54 } |
|
55 |
|
56 static bool PrefEnabled(JSContext* aCx = nullptr, |
|
57 JSObject* aGlobal = nullptr); |
|
58 |
|
59 uint32_t Length() const |
|
60 { |
|
61 return mPoints.Length(); |
|
62 } |
|
63 Touch* Item(uint32_t aIndex) const |
|
64 { |
|
65 return mPoints.SafeElementAt(aIndex); |
|
66 } |
|
67 Touch* IndexedGetter(uint32_t aIndex, bool& aFound) const |
|
68 { |
|
69 aFound = aIndex < mPoints.Length(); |
|
70 if (!aFound) { |
|
71 return nullptr; |
|
72 } |
|
73 return mPoints[aIndex]; |
|
74 } |
|
75 Touch* IdentifiedTouch(int32_t aIdentifier) const; |
|
76 |
|
77 protected: |
|
78 nsCOMPtr<nsISupports> mParent; |
|
79 nsTArray<nsRefPtr<Touch> > mPoints; |
|
80 }; |
|
81 |
|
82 class TouchEvent : public UIEvent |
|
83 { |
|
84 public: |
|
85 TouchEvent(EventTarget* aOwner, |
|
86 nsPresContext* aPresContext, |
|
87 WidgetTouchEvent* aEvent); |
|
88 |
|
89 NS_DECL_ISUPPORTS_INHERITED |
|
90 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TouchEvent, UIEvent) |
|
91 |
|
92 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE |
|
93 { |
|
94 return TouchEventBinding::Wrap(aCx, this); |
|
95 } |
|
96 |
|
97 TouchList* Touches(); |
|
98 TouchList* TargetTouches(); |
|
99 TouchList* ChangedTouches(); |
|
100 |
|
101 bool AltKey(); |
|
102 bool MetaKey(); |
|
103 bool CtrlKey(); |
|
104 bool ShiftKey(); |
|
105 |
|
106 void InitTouchEvent(const nsAString& aType, |
|
107 bool aCanBubble, |
|
108 bool aCancelable, |
|
109 nsIDOMWindow* aView, |
|
110 int32_t aDetail, |
|
111 bool aCtrlKey, |
|
112 bool aAltKey, |
|
113 bool aShiftKey, |
|
114 bool aMetaKey, |
|
115 TouchList* aTouches, |
|
116 TouchList* aTargetTouches, |
|
117 TouchList* aChangedTouches, |
|
118 ErrorResult& aRv); |
|
119 |
|
120 static bool PrefEnabled(JSContext* aCx = nullptr, |
|
121 JSObject* aGlobal = nullptr); |
|
122 protected: |
|
123 nsRefPtr<TouchList> mTouches; |
|
124 nsRefPtr<TouchList> mTargetTouches; |
|
125 nsRefPtr<TouchList> mChangedTouches; |
|
126 }; |
|
127 |
|
128 } // namespace dom |
|
129 } // namespace mozilla |
|
130 |
|
131 #endif // mozilla_dom_TouchEvent_h_ |