2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-04-05 12:49:00 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/Touch.h"
|
2013-04-21 10:42:19 +04:00
|
|
|
|
2013-08-19 14:15:55 +04:00
|
|
|
#include "mozilla/dom/EventTarget.h"
|
2014-02-28 18:58:42 +04:00
|
|
|
#include "mozilla/dom/TouchEvent.h"
|
2014-03-19 20:35:45 +04:00
|
|
|
#include "nsGlobalWindow.h"
|
2013-04-21 10:42:19 +04:00
|
|
|
#include "nsContentUtils.h"
|
2013-10-01 01:26:04 +04:00
|
|
|
#include "nsIContent.h"
|
2013-04-05 12:49:00 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2015-12-29 16:46:18 +03:00
|
|
|
// static
|
|
|
|
already_AddRefed<Touch> Touch::Constructor(const GlobalObject& aGlobal,
|
2019-09-12 14:01:17 +03:00
|
|
|
const TouchInit& aParam) {
|
2015-12-29 16:46:18 +03:00
|
|
|
// Annoyingly many parameters, make sure the ordering is the same as in the
|
|
|
|
// Touch constructor.
|
|
|
|
RefPtr<Touch> touch = new Touch(
|
|
|
|
aParam.mTarget, aParam.mIdentifier, aParam.mPageX, aParam.mPageY,
|
|
|
|
aParam.mScreenX, aParam.mScreenY, aParam.mClientX, aParam.mClientY,
|
|
|
|
aParam.mRadiusX, aParam.mRadiusY, aParam.mRotationAngle, aParam.mForce);
|
|
|
|
return touch.forget();
|
|
|
|
}
|
|
|
|
|
2014-02-28 18:58:42 +04:00
|
|
|
Touch::Touch(EventTarget* aTarget, int32_t aIdentifier, int32_t aPageX,
|
2013-08-19 14:15:55 +04:00
|
|
|
int32_t aPageY, int32_t aScreenX, int32_t aScreenY,
|
|
|
|
int32_t aClientX, int32_t aClientY, int32_t aRadiusX,
|
|
|
|
int32_t aRadiusY, float aRotationAngle, float aForce)
|
2017-12-09 05:06:18 +03:00
|
|
|
: mIsTouchEventSuppressed(false) {
|
2013-08-19 14:15:55 +04:00
|
|
|
mTarget = aTarget;
|
2018-05-25 18:02:59 +03:00
|
|
|
mOriginalTarget = aTarget;
|
2013-08-19 14:15:55 +04:00
|
|
|
mIdentifier = aIdentifier;
|
|
|
|
mPagePoint = CSSIntPoint(aPageX, aPageY);
|
2015-11-10 19:32:40 +03:00
|
|
|
mScreenPoint = CSSIntPoint(aScreenX, aScreenY);
|
2013-08-19 14:15:55 +04:00
|
|
|
mClientPoint = CSSIntPoint(aClientX, aClientY);
|
2015-02-02 01:27:31 +03:00
|
|
|
mRefPoint = LayoutDeviceIntPoint(0, 0);
|
2013-08-19 14:15:55 +04:00
|
|
|
mPointsInitialized = true;
|
|
|
|
mRadius.x = aRadiusX;
|
|
|
|
mRadius.y = aRadiusY;
|
|
|
|
mRotationAngle = aRotationAngle;
|
|
|
|
mForce = aForce;
|
|
|
|
|
|
|
|
mChanged = false;
|
|
|
|
mMessage = 0;
|
|
|
|
nsJSContext::LikelyShortLivingObjectCreated();
|
|
|
|
}
|
|
|
|
|
|
|
|
Touch::Touch(int32_t aIdentifier, LayoutDeviceIntPoint aPoint,
|
2015-11-10 08:37:31 +03:00
|
|
|
LayoutDeviceIntPoint aRadius, float aRotationAngle, float aForce)
|
2017-12-09 05:06:18 +03:00
|
|
|
: mIsTouchEventSuppressed(false) {
|
2013-08-19 14:15:55 +04:00
|
|
|
mIdentifier = aIdentifier;
|
|
|
|
mPagePoint = CSSIntPoint(0, 0);
|
2015-11-10 19:32:40 +03:00
|
|
|
mScreenPoint = CSSIntPoint(0, 0);
|
2013-08-19 14:15:55 +04:00
|
|
|
mClientPoint = CSSIntPoint(0, 0);
|
|
|
|
mRefPoint = aPoint;
|
|
|
|
mPointsInitialized = false;
|
|
|
|
mRadius = aRadius;
|
|
|
|
mRotationAngle = aRotationAngle;
|
|
|
|
mForce = aForce;
|
|
|
|
|
|
|
|
mChanged = false;
|
|
|
|
mMessage = 0;
|
|
|
|
nsJSContext::LikelyShortLivingObjectCreated();
|
2015-04-29 23:29:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Touch::Touch(const Touch& aOther)
|
2018-05-25 18:02:59 +03:00
|
|
|
: mOriginalTarget(aOther.mOriginalTarget),
|
|
|
|
mTarget(aOther.mTarget),
|
2015-04-29 23:29:34 +03:00
|
|
|
mRefPoint(aOther.mRefPoint),
|
|
|
|
mChanged(aOther.mChanged),
|
2017-12-09 05:06:18 +03:00
|
|
|
mIsTouchEventSuppressed(aOther.mIsTouchEventSuppressed),
|
2015-04-29 23:29:34 +03:00
|
|
|
mMessage(aOther.mMessage),
|
|
|
|
mIdentifier(aOther.mIdentifier),
|
|
|
|
mPagePoint(aOther.mPagePoint),
|
|
|
|
mClientPoint(aOther.mClientPoint),
|
|
|
|
mScreenPoint(aOther.mScreenPoint),
|
|
|
|
mRadius(aOther.mRadius),
|
|
|
|
mRotationAngle(aOther.mRotationAngle),
|
|
|
|
mForce(aOther.mForce),
|
|
|
|
mPointsInitialized(aOther.mPointsInitialized) {
|
|
|
|
nsJSContext::LikelyShortLivingObjectCreated();
|
2013-08-19 14:15:55 +04:00
|
|
|
}
|
|
|
|
|
2020-02-20 18:56:28 +03:00
|
|
|
Touch::~Touch() = default;
|
2013-08-19 14:15:55 +04:00
|
|
|
|
2014-02-28 18:58:42 +04:00
|
|
|
// static
|
2014-02-06 22:28:14 +04:00
|
|
|
bool Touch::PrefEnabled(JSContext* aCx, JSObject* aGlobal) {
|
2014-02-28 18:58:42 +04:00
|
|
|
return TouchEvent::PrefEnabled(aCx, aGlobal);
|
2013-04-21 10:42:19 +04:00
|
|
|
}
|
|
|
|
|
2018-05-25 18:02:59 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Touch, mTarget, mOriginalTarget)
|
2013-04-05 12:49:00 +04:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Touch)
|
2013-04-21 10:42:19 +04:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2013-04-05 12:49:00 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(Touch)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(Touch)
|
|
|
|
|
2014-05-05 14:48:50 +04:00
|
|
|
EventTarget* Touch::GetTarget() const {
|
2013-04-05 12:49:00 +04:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(mTarget);
|
|
|
|
if (content && content->ChromeOnlyAccess() &&
|
2014-09-25 13:04:45 +04:00
|
|
|
!nsContentUtils::LegacyIsCallerNativeCode() &&
|
2013-04-05 12:49:00 +04:00
|
|
|
!nsContentUtils::CanAccessNativeAnon()) {
|
2013-04-21 10:42:19 +04:00
|
|
|
return content->FindFirstNonChromeOnlyAccessContent();
|
2013-04-05 12:49:00 +04:00
|
|
|
}
|
2013-04-21 10:42:19 +04:00
|
|
|
|
|
|
|
return mTarget;
|
2013-04-05 12:49:00 +04:00
|
|
|
}
|
|
|
|
|
2016-11-16 22:10:22 +03:00
|
|
|
int32_t Touch::ScreenX(CallerType aCallerType) const {
|
2016-12-17 08:25:52 +03:00
|
|
|
if (nsContentUtils::ResistFingerprinting(aCallerType)) {
|
2016-11-16 22:10:22 +03:00
|
|
|
return ClientX();
|
|
|
|
}
|
|
|
|
|
|
|
|
return mScreenPoint.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t Touch::ScreenY(CallerType aCallerType) const {
|
2016-12-17 08:25:52 +03:00
|
|
|
if (nsContentUtils::ResistFingerprinting(aCallerType)) {
|
2016-11-16 22:10:22 +03:00
|
|
|
return ClientY();
|
|
|
|
}
|
|
|
|
|
|
|
|
return mScreenPoint.y;
|
|
|
|
}
|
|
|
|
|
2017-07-31 12:30:38 +03:00
|
|
|
int32_t Touch::RadiusX(CallerType aCallerType) const {
|
|
|
|
if (nsContentUtils::ResistFingerprinting(aCallerType)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mRadius.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t Touch::RadiusY(CallerType aCallerType) const {
|
|
|
|
if (nsContentUtils::ResistFingerprinting(aCallerType)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mRadius.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
float Touch::RotationAngle(CallerType aCallerType) const {
|
|
|
|
if (nsContentUtils::ResistFingerprinting(aCallerType)) {
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mRotationAngle;
|
|
|
|
}
|
|
|
|
|
|
|
|
float Touch::Force(CallerType aCallerType) const {
|
|
|
|
if (nsContentUtils::ResistFingerprinting(aCallerType)) {
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mForce;
|
|
|
|
}
|
|
|
|
|
2013-10-02 07:46:04 +04:00
|
|
|
void Touch::InitializePoints(nsPresContext* aPresContext, WidgetEvent* aEvent) {
|
2013-05-18 00:17:53 +04:00
|
|
|
if (mPointsInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
2014-03-05 04:37:43 +04:00
|
|
|
mClientPoint =
|
2015-02-02 01:27:31 +03:00
|
|
|
Event::GetClientCoords(aPresContext, aEvent, mRefPoint, mClientPoint);
|
2014-03-05 04:37:43 +04:00
|
|
|
mPagePoint =
|
2015-02-02 01:27:31 +03:00
|
|
|
Event::GetPageCoords(aPresContext, aEvent, mRefPoint, mClientPoint);
|
|
|
|
mScreenPoint = Event::GetScreenCoords(aPresContext, aEvent, mRefPoint);
|
2013-05-18 00:17:53 +04:00
|
|
|
mPointsInitialized = true;
|
|
|
|
}
|
|
|
|
|
2018-05-25 18:02:59 +03:00
|
|
|
void Touch::SetTouchTarget(EventTarget* aTarget) {
|
|
|
|
mOriginalTarget = aTarget;
|
2013-08-19 14:15:55 +04:00
|
|
|
mTarget = aTarget;
|
|
|
|
}
|
|
|
|
|
2019-02-15 19:28:35 +03:00
|
|
|
bool Touch::Equals(Touch* aTouch) const {
|
2013-08-02 11:06:35 +04:00
|
|
|
return mRefPoint == aTouch->mRefPoint && mForce == aTouch->mForce &&
|
2017-07-31 12:30:38 +03:00
|
|
|
mRotationAngle == aTouch->mRotationAngle &&
|
|
|
|
mRadius.x == aTouch->mRadius.x && mRadius.y == aTouch->mRadius.y;
|
2013-04-05 12:49:00 +04:00
|
|
|
}
|
|
|
|
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
JSObject* Touch::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return Touch_Binding::Wrap(aCx, this, aGivenProto);
|
2013-04-21 10:42:19 +04:00
|
|
|
}
|
|
|
|
|
2015-05-12 22:56:39 +03:00
|
|
|
// Parent ourselves to the global of the target. This achieves the desirable
|
2014-03-19 20:35:45 +04:00
|
|
|
// effects of parenting to the target, but avoids making the touch inaccessible
|
|
|
|
// when the target happens to be NAC and therefore reflected into the XBL scope.
|
|
|
|
nsIGlobalObject* Touch::GetParentObject() {
|
2018-05-25 18:02:59 +03:00
|
|
|
if (!mOriginalTarget) {
|
2014-03-19 20:35:45 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
2018-05-25 18:02:59 +03:00
|
|
|
return mOriginalTarget->GetOwnerGlobal();
|
2014-03-19 20:35:45 +04:00
|
|
|
}
|
|
|
|
|
2013-04-05 12:49:00 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|