Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/events/Touch.cpp
Line
Count
Source (jump to first uncovered line)
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
7
#include "mozilla/dom/Touch.h"
8
9
#include "mozilla/dom/EventTarget.h"
10
#include "mozilla/dom/TouchEvent.h"
11
#include "nsGlobalWindow.h"
12
#include "nsContentUtils.h"
13
#include "nsIContent.h"
14
15
namespace mozilla {
16
namespace dom {
17
18
// static
19
already_AddRefed<Touch>
20
Touch::Constructor(const GlobalObject& aGlobal,
21
                   const TouchInit& aParam,
22
                   ErrorResult& aRv)
23
0
{
24
0
  // Annoyingly many parameters, make sure the ordering is the same as in the
25
0
  // Touch constructor.
26
0
  RefPtr<Touch> touch = new Touch(aParam.mTarget,
27
0
                                  aParam.mIdentifier,
28
0
                                  aParam.mPageX,
29
0
                                  aParam.mPageY,
30
0
                                  aParam.mScreenX,
31
0
                                  aParam.mScreenY,
32
0
                                  aParam.mClientX,
33
0
                                  aParam.mClientY,
34
0
                                  aParam.mRadiusX,
35
0
                                  aParam.mRadiusY,
36
0
                                  aParam.mRotationAngle,
37
0
                                  aParam.mForce);
38
0
  return touch.forget();
39
0
}
40
41
Touch::Touch(EventTarget* aTarget,
42
             int32_t aIdentifier,
43
             int32_t aPageX,
44
             int32_t aPageY,
45
             int32_t aScreenX,
46
             int32_t aScreenY,
47
             int32_t aClientX,
48
             int32_t aClientY,
49
             int32_t aRadiusX,
50
             int32_t aRadiusY,
51
             float aRotationAngle,
52
             float aForce)
53
  : mIsTouchEventSuppressed(false)
54
0
{
55
0
  mTarget = aTarget;
56
0
  mOriginalTarget = aTarget;
57
0
  mIdentifier = aIdentifier;
58
0
  mPagePoint = CSSIntPoint(aPageX, aPageY);
59
0
  mScreenPoint = CSSIntPoint(aScreenX, aScreenY);
60
0
  mClientPoint = CSSIntPoint(aClientX, aClientY);
61
0
  mRefPoint = LayoutDeviceIntPoint(0, 0);
62
0
  mPointsInitialized = true;
63
0
  mRadius.x = aRadiusX;
64
0
  mRadius.y = aRadiusY;
65
0
  mRotationAngle = aRotationAngle;
66
0
  mForce = aForce;
67
0
68
0
  mChanged = false;
69
0
  mMessage = 0;
70
0
  nsJSContext::LikelyShortLivingObjectCreated();
71
0
}
72
73
Touch::Touch(int32_t aIdentifier,
74
             LayoutDeviceIntPoint aPoint,
75
             LayoutDeviceIntPoint aRadius,
76
             float aRotationAngle,
77
             float aForce)
78
  : mIsTouchEventSuppressed(false)
79
0
{
80
0
  mIdentifier = aIdentifier;
81
0
  mPagePoint = CSSIntPoint(0, 0);
82
0
  mScreenPoint = CSSIntPoint(0, 0);
83
0
  mClientPoint = CSSIntPoint(0, 0);
84
0
  mRefPoint = aPoint;
85
0
  mPointsInitialized = false;
86
0
  mRadius = aRadius;
87
0
  mRotationAngle = aRotationAngle;
88
0
  mForce = aForce;
89
0
90
0
  mChanged = false;
91
0
  mMessage = 0;
92
0
  nsJSContext::LikelyShortLivingObjectCreated();
93
0
}
94
95
Touch::Touch(const Touch& aOther)
96
  : mOriginalTarget(aOther.mOriginalTarget)
97
  , mTarget(aOther.mTarget)
98
  , mRefPoint(aOther.mRefPoint)
99
  , mChanged(aOther.mChanged)
100
  , mIsTouchEventSuppressed(aOther.mIsTouchEventSuppressed)
101
  , mMessage(aOther.mMessage)
102
  , mIdentifier(aOther.mIdentifier)
103
  , mPagePoint(aOther.mPagePoint)
104
  , mClientPoint(aOther.mClientPoint)
105
  , mScreenPoint(aOther.mScreenPoint)
106
  , mRadius(aOther.mRadius)
107
  , mRotationAngle(aOther.mRotationAngle)
108
  , mForce(aOther.mForce)
109
  , mPointsInitialized(aOther.mPointsInitialized)
110
0
{
111
0
  nsJSContext::LikelyShortLivingObjectCreated();
112
0
}
113
114
Touch::~Touch()
115
0
{
116
0
}
117
118
// static
119
bool
120
Touch::PrefEnabled(JSContext* aCx, JSObject* aGlobal)
121
0
{
122
0
  return TouchEvent::PrefEnabled(aCx, aGlobal);
123
0
}
124
125
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Touch, mTarget, mOriginalTarget)
126
127
0
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Touch)
128
0
  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
129
0
  NS_INTERFACE_MAP_ENTRY(nsISupports)
130
0
NS_INTERFACE_MAP_END
131
132
NS_IMPL_CYCLE_COLLECTING_ADDREF(Touch)
133
NS_IMPL_CYCLE_COLLECTING_RELEASE(Touch)
134
135
EventTarget*
136
Touch::GetTarget() const
137
0
{
138
0
  nsCOMPtr<nsIContent> content = do_QueryInterface(mTarget);
139
0
  if (content && content->ChromeOnlyAccess() &&
140
0
      !nsContentUtils::LegacyIsCallerNativeCode() &&
141
0
      !nsContentUtils::CanAccessNativeAnon()) {
142
0
    return content->FindFirstNonChromeOnlyAccessContent();
143
0
  }
144
0
145
0
  return mTarget;
146
0
}
147
148
int32_t
149
Touch::ScreenX(CallerType aCallerType) const
150
0
{
151
0
  if (nsContentUtils::ResistFingerprinting(aCallerType)) {
152
0
    return ClientX();
153
0
  }
154
0
155
0
  return mScreenPoint.x;
156
0
}
157
158
int32_t
159
Touch::ScreenY(CallerType aCallerType) const
160
0
{
161
0
  if (nsContentUtils::ResistFingerprinting(aCallerType)) {
162
0
    return ClientY();
163
0
  }
164
0
165
0
  return mScreenPoint.y;
166
0
}
167
168
int32_t
169
Touch::RadiusX(CallerType aCallerType) const
170
0
{
171
0
  if (nsContentUtils::ResistFingerprinting(aCallerType)) {
172
0
    return 0;
173
0
  }
174
0
175
0
  return mRadius.x;
176
0
}
177
178
int32_t
179
Touch::RadiusY(CallerType aCallerType) const
180
0
{
181
0
  if (nsContentUtils::ResistFingerprinting(aCallerType)) {
182
0
    return 0;
183
0
  }
184
0
185
0
  return mRadius.y;
186
0
}
187
188
float
189
Touch::RotationAngle(CallerType aCallerType) const
190
0
{
191
0
  if (nsContentUtils::ResistFingerprinting(aCallerType)) {
192
0
    return 0.0f;
193
0
  }
194
0
195
0
  return mRotationAngle;
196
0
}
197
198
float
199
Touch::Force(CallerType aCallerType) const
200
0
{
201
0
  if (nsContentUtils::ResistFingerprinting(aCallerType)) {
202
0
    return 0.0f;
203
0
  }
204
0
205
0
  return mForce;
206
0
}
207
208
void
209
Touch::InitializePoints(nsPresContext* aPresContext, WidgetEvent* aEvent)
210
0
{
211
0
  if (mPointsInitialized) {
212
0
    return;
213
0
  }
214
0
  mClientPoint = Event::GetClientCoords(
215
0
    aPresContext, aEvent, mRefPoint, mClientPoint);
216
0
  mPagePoint = Event::GetPageCoords(
217
0
    aPresContext, aEvent, mRefPoint, mClientPoint);
218
0
  mScreenPoint = Event::GetScreenCoords(aPresContext, aEvent, mRefPoint);
219
0
  mPointsInitialized = true;
220
0
}
221
222
void
223
Touch::SetTouchTarget(EventTarget* aTarget)
224
0
{
225
0
  mOriginalTarget = aTarget;
226
0
  mTarget = aTarget;
227
0
}
228
229
bool
230
Touch::Equals(Touch* aTouch)
231
0
{
232
0
  return mRefPoint == aTouch->mRefPoint &&
233
0
         mForce == aTouch->mForce &&
234
0
         mRotationAngle == aTouch->mRotationAngle &&
235
0
         mRadius.x == aTouch->mRadius.x &&
236
0
         mRadius.y == aTouch->mRadius.y;
237
0
}
238
239
JSObject*
240
Touch::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
241
0
{
242
0
  return Touch_Binding::Wrap(aCx, this, aGivenProto);
243
0
}
244
245
// Parent ourselves to the global of the target. This achieves the desirable
246
// effects of parenting to the target, but avoids making the touch inaccessible
247
// when the target happens to be NAC and therefore reflected into the XBL scope.
248
nsIGlobalObject*
249
Touch::GetParentObject()
250
0
{
251
0
  if (!mOriginalTarget) {
252
0
    return nullptr;
253
0
  }
254
0
  return mOriginalTarget->GetOwnerGlobal();
255
0
}
256
257
} // namespace dom
258
} // namespace mozilla