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 :
45 : class nsDOMTouch : public nsIDOMTouch
46 0 : {
47 : public:
48 0 : nsDOMTouch(nsIDOMEventTarget* aTarget,
49 : PRInt32 aIdentifier,
50 : PRInt32 aPageX,
51 : PRInt32 aPageY,
52 : PRInt32 aScreenX,
53 : PRInt32 aScreenY,
54 : PRInt32 aClientX,
55 : PRInt32 aClientY,
56 : PRInt32 aRadiusX,
57 : PRInt32 aRadiusY,
58 : float aRotationAngle,
59 : float aForce)
60 0 : {
61 0 : mTarget = aTarget;
62 0 : mIdentifier = aIdentifier;
63 0 : mPagePoint = nsIntPoint(aPageX, aPageY);
64 0 : mScreenPoint = nsIntPoint(aScreenX, aScreenY);
65 0 : mClientPoint = nsIntPoint(aClientX, aClientY);
66 0 : mRefPoint = nsIntPoint(0, 0);
67 0 : mPointsInitialized = true;
68 0 : mRadius.x = aRadiusX;
69 0 : mRadius.y = aRadiusY;
70 0 : mRotationAngle = aRotationAngle;
71 0 : mForce = aForce;
72 :
73 0 : mChanged = false;
74 0 : mMessage = 0;
75 0 : }
76 0 : nsDOMTouch(PRInt32 aIdentifier,
77 : nsIntPoint aPoint,
78 : nsIntPoint aRadius,
79 : float aRotationAngle,
80 : float aForce)
81 0 : {
82 0 : mIdentifier = aIdentifier;
83 0 : mPagePoint = nsIntPoint(0, 0);
84 0 : mScreenPoint = nsIntPoint(0, 0);
85 0 : mClientPoint = nsIntPoint(0, 0);
86 0 : mRefPoint = aPoint;
87 0 : mPointsInitialized = false;
88 0 : mRadius = aRadius;
89 0 : mRotationAngle = aRotationAngle;
90 0 : mForce = aForce;
91 :
92 0 : mChanged = false;
93 0 : mMessage = 0;
94 0 : }
95 0 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
96 1464 : NS_DECL_CYCLE_COLLECTION_CLASS(nsDOMTouch)
97 : NS_DECL_NSIDOMTOUCH
98 0 : void InitializePoints(nsPresContext* aPresContext, nsEvent* aEvent)
99 : {
100 0 : if (mPointsInitialized) {
101 0 : return;
102 : }
103 : mClientPoint = nsDOMEvent::GetClientCoords(aPresContext,
104 : aEvent,
105 : mRefPoint,
106 0 : mClientPoint);
107 : mPagePoint = nsDOMEvent::GetPageCoords(aPresContext,
108 : aEvent,
109 : mRefPoint,
110 0 : mClientPoint);
111 0 : mScreenPoint = nsDOMEvent::GetScreenCoords(aPresContext, aEvent, mRefPoint);
112 0 : mPointsInitialized = true;
113 : }
114 : void SetTarget(nsIDOMEventTarget *aTarget)
115 : {
116 : mTarget = aTarget;
117 : }
118 : bool Equals(nsIDOMTouch* aTouch);
119 : protected:
120 : bool mPointsInitialized;
121 : PRInt32 mIdentifier;
122 : nsIntPoint mPagePoint;
123 : nsIntPoint mClientPoint;
124 : nsIntPoint mScreenPoint;
125 : nsIntPoint mRadius;
126 : float mRotationAngle;
127 : float mForce;
128 : };
129 :
130 : class nsDOMTouchList : public nsIDOMTouchList
131 0 : {
132 : public:
133 0 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
134 1464 : NS_DECL_CYCLE_COLLECTION_CLASS(nsDOMTouchList)
135 : NS_DECL_NSIDOMTOUCHLIST
136 :
137 0 : nsDOMTouchList() { }
138 : nsDOMTouchList(nsTArray<nsCOMPtr<nsIDOMTouch> > &aTouches);
139 :
140 0 : void Append(nsIDOMTouch* aPoint)
141 : {
142 0 : mPoints.AppendElement(aPoint);
143 0 : }
144 :
145 0 : nsIDOMTouch* GetItemAt(PRUint32 aIndex)
146 : {
147 0 : return mPoints.SafeElementAt(aIndex, nsnull);
148 : }
149 : protected:
150 : nsTArray<nsCOMPtr<nsIDOMTouch> > mPoints;
151 : };
152 :
153 : class nsDOMTouchEvent : public nsDOMUIEvent,
154 : public nsIDOMTouchEvent
155 : {
156 : public:
157 : nsDOMTouchEvent(nsPresContext* aPresContext, nsTouchEvent* aEvent);
158 : virtual ~nsDOMTouchEvent();
159 :
160 : NS_DECL_ISUPPORTS_INHERITED
161 1464 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMTouchEvent, nsDOMUIEvent)
162 : NS_DECL_NSIDOMTOUCHEVENT
163 :
164 0 : NS_FORWARD_TO_NSDOMUIEVENT
165 :
166 : static bool PrefEnabled();
167 : protected:
168 : nsCOMPtr<nsIDOMTouchList> mTouches;
169 : nsCOMPtr<nsIDOMTouchList> mTargetTouches;
170 : nsCOMPtr<nsIDOMTouchList> mChangedTouches;
171 : };
172 :
173 : #endif /* !defined(nsDOMTouchEvent_h_) */
|