1 : /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is nsDOMTouchEvent.
16 : *
17 : * The Initial Developer of the Original Code is the Mozilla Foundation.
18 : * Portions created by the Initial Developer are Copyright (C) 2011
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : * Olli Pettay <Olli.Pettay@helsinki.fi> (Original Author)
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either the GNU General Public License Version 2 or later (the "GPL"), or
26 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 : #ifndef nsDOMTouchEvent_h_
38 : #define nsDOMTouchEvent_h_
39 :
40 : #include "nsDOMUIEvent.h"
41 : #include "nsIDOMTouchEvent.h"
42 : #include "nsString.h"
43 : #include "nsTArray.h"
44 : #include "nsIDocument.h"
45 : #include "dombindings.h"
46 :
47 : class nsDOMTouch : public nsIDOMTouch
48 0 : {
49 : public:
50 0 : nsDOMTouch(nsIDOMEventTarget* aTarget,
51 : PRInt32 aIdentifier,
52 : PRInt32 aPageX,
53 : PRInt32 aPageY,
54 : PRInt32 aScreenX,
55 : PRInt32 aScreenY,
56 : PRInt32 aClientX,
57 : PRInt32 aClientY,
58 : PRInt32 aRadiusX,
59 : PRInt32 aRadiusY,
60 : float aRotationAngle,
61 : float aForce)
62 0 : {
63 0 : mTarget = aTarget;
64 0 : mIdentifier = aIdentifier;
65 0 : mPagePoint = nsIntPoint(aPageX, aPageY);
66 0 : mScreenPoint = nsIntPoint(aScreenX, aScreenY);
67 0 : mClientPoint = nsIntPoint(aClientX, aClientY);
68 0 : mRefPoint = nsIntPoint(0, 0);
69 0 : mPointsInitialized = true;
70 0 : mRadius.x = aRadiusX;
71 0 : mRadius.y = aRadiusY;
72 0 : mRotationAngle = aRotationAngle;
73 0 : mForce = aForce;
74 :
75 0 : mChanged = false;
76 0 : mMessage = 0;
77 0 : }
78 0 : nsDOMTouch(PRInt32 aIdentifier,
79 : nsIntPoint aPoint,
80 : nsIntPoint aRadius,
81 : float aRotationAngle,
82 : float aForce)
83 0 : {
84 0 : mIdentifier = aIdentifier;
85 0 : mPagePoint = nsIntPoint(0, 0);
86 0 : mScreenPoint = nsIntPoint(0, 0);
87 0 : mClientPoint = nsIntPoint(0, 0);
88 0 : mRefPoint = aPoint;
89 0 : mPointsInitialized = false;
90 0 : mRadius = aRadius;
91 0 : mRotationAngle = aRotationAngle;
92 0 : mForce = aForce;
93 :
94 0 : mChanged = false;
95 0 : mMessage = 0;
96 0 : }
97 0 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
98 1396 : NS_DECL_CYCLE_COLLECTION_CLASS(nsDOMTouch)
99 : NS_DECL_NSIDOMTOUCH
100 0 : void InitializePoints(nsPresContext* aPresContext, nsEvent* aEvent)
101 : {
102 0 : if (mPointsInitialized) {
103 0 : return;
104 : }
105 : mClientPoint = nsDOMEvent::GetClientCoords(aPresContext,
106 : aEvent,
107 : mRefPoint,
108 0 : mClientPoint);
109 : mPagePoint = nsDOMEvent::GetPageCoords(aPresContext,
110 : aEvent,
111 : mRefPoint,
112 0 : mClientPoint);
113 0 : mScreenPoint = nsDOMEvent::GetScreenCoords(aPresContext, aEvent, mRefPoint);
114 0 : mPointsInitialized = true;
115 : }
116 : void SetTarget(nsIDOMEventTarget *aTarget)
117 : {
118 : mTarget = aTarget;
119 : }
120 : bool Equals(nsIDOMTouch* aTouch);
121 : protected:
122 : bool mPointsInitialized;
123 : PRInt32 mIdentifier;
124 : nsIntPoint mPagePoint;
125 : nsIntPoint mClientPoint;
126 : nsIntPoint mScreenPoint;
127 : nsIntPoint mRadius;
128 : float mRotationAngle;
129 : float mForce;
130 : };
131 :
132 : class nsDOMTouchList MOZ_FINAL : public nsIDOMTouchList,
133 : public nsWrapperCache
134 0 : {
135 : public:
136 0 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
137 1396 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMTouchList)
138 : NS_DECL_NSIDOMTOUCHLIST
139 :
140 0 : nsDOMTouchList(nsISupports *aParent) : mParent(aParent)
141 : {
142 0 : SetIsProxy();
143 0 : }
144 0 : nsDOMTouchList(nsISupports *aParent,
145 : nsTArray<nsCOMPtr<nsIDOMTouch> > &aTouches)
146 : : mPoints(aTouches),
147 0 : mParent(aParent)
148 : {
149 0 : SetIsProxy();
150 0 : }
151 :
152 0 : virtual JSObject* WrapObject(JSContext *cx, XPCWrappedNativeScope *scope,
153 : bool *triedToWrap)
154 : {
155 : return mozilla::dom::binding::TouchList::create(cx, scope, this,
156 0 : triedToWrap);
157 : }
158 :
159 0 : nsISupports *GetParentObject()
160 : {
161 0 : return mParent;
162 : }
163 :
164 0 : void Append(nsIDOMTouch* aPoint)
165 : {
166 0 : mPoints.AppendElement(aPoint);
167 0 : }
168 :
169 : protected:
170 : nsTArray<nsCOMPtr<nsIDOMTouch> > mPoints;
171 : nsCOMPtr<nsISupports> mParent;
172 : };
173 :
174 : class nsDOMTouchEvent : public nsDOMUIEvent,
175 : public nsIDOMTouchEvent
176 : {
177 : public:
178 : nsDOMTouchEvent(nsPresContext* aPresContext, nsTouchEvent* aEvent);
179 : virtual ~nsDOMTouchEvent();
180 :
181 : NS_DECL_ISUPPORTS_INHERITED
182 1396 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMTouchEvent, nsDOMUIEvent)
183 : NS_DECL_NSIDOMTOUCHEVENT
184 :
185 0 : NS_FORWARD_TO_NSDOMUIEVENT
186 :
187 : static bool PrefEnabled();
188 : protected:
189 : nsCOMPtr<nsIDOMTouchList> mTouches;
190 : nsCOMPtr<nsIDOMTouchList> mTargetTouches;
191 : nsCOMPtr<nsIDOMTouchList> mChangedTouches;
192 : };
193 :
194 : #endif /* !defined(nsDOMTouchEvent_h_) */
|