2015-05-03 12:32:37 -07: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 01:49:00 -07: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-20 23:42:19 -07:00
|
|
|
|
2013-08-19 03:15:55 -07:00
|
|
|
#include "mozilla/dom/EventTarget.h"
|
2013-04-20 23:42:19 -07:00
|
|
|
#include "mozilla/dom/TouchBinding.h"
|
2014-02-28 06:58:42 -08:00
|
|
|
#include "mozilla/dom/TouchEvent.h"
|
2014-03-19 09:35:45 -07:00
|
|
|
#include "nsGlobalWindow.h"
|
2013-04-20 23:42:19 -07:00
|
|
|
#include "nsContentUtils.h"
|
2013-09-30 14:26:04 -07:00
|
|
|
#include "nsIContent.h"
|
2013-04-05 01:49:00 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-02-28 06:58:42 -08:00
|
|
|
Touch::Touch(EventTarget* aTarget,
|
2013-08-19 03:15:55 -07:00
|
|
|
int32_t aIdentifier,
|
|
|
|
int32_t aPageX,
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
mTarget = aTarget;
|
|
|
|
mIdentifier = aIdentifier;
|
|
|
|
mPagePoint = CSSIntPoint(aPageX, aPageY);
|
2015-02-15 10:52:28 -08:00
|
|
|
mScreenPoint = LayoutDeviceIntPoint(aScreenX, aScreenY);
|
2013-08-19 03:15:55 -07:00
|
|
|
mClientPoint = CSSIntPoint(aClientX, aClientY);
|
2015-02-01 14:27:31 -08:00
|
|
|
mRefPoint = LayoutDeviceIntPoint(0, 0);
|
2013-08-19 03:15:55 -07:00
|
|
|
mPointsInitialized = true;
|
|
|
|
mRadius.x = aRadiusX;
|
|
|
|
mRadius.y = aRadiusY;
|
|
|
|
mRotationAngle = aRotationAngle;
|
|
|
|
mForce = aForce;
|
|
|
|
|
|
|
|
mChanged = false;
|
|
|
|
mMessage = 0;
|
|
|
|
nsJSContext::LikelyShortLivingObjectCreated();
|
|
|
|
}
|
|
|
|
|
|
|
|
Touch::Touch(int32_t aIdentifier,
|
2015-02-01 14:27:31 -08:00
|
|
|
LayoutDeviceIntPoint aPoint,
|
2013-08-19 03:15:55 -07:00
|
|
|
nsIntPoint aRadius,
|
|
|
|
float aRotationAngle,
|
|
|
|
float aForce)
|
|
|
|
{
|
|
|
|
mIdentifier = aIdentifier;
|
|
|
|
mPagePoint = CSSIntPoint(0, 0);
|
2015-02-15 10:52:28 -08:00
|
|
|
mScreenPoint = LayoutDeviceIntPoint(0, 0);
|
2013-08-19 03:15:55 -07:00
|
|
|
mClientPoint = CSSIntPoint(0, 0);
|
|
|
|
mRefPoint = aPoint;
|
|
|
|
mPointsInitialized = false;
|
|
|
|
mRadius = aRadius;
|
|
|
|
mRotationAngle = aRotationAngle;
|
|
|
|
mForce = aForce;
|
|
|
|
|
|
|
|
mChanged = false;
|
|
|
|
mMessage = 0;
|
|
|
|
nsJSContext::LikelyShortLivingObjectCreated();
|
|
|
|
}
|
|
|
|
|
|
|
|
Touch::~Touch()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-28 06:58:42 -08:00
|
|
|
// static
|
|
|
|
bool
|
2014-02-06 10:28:14 -08:00
|
|
|
Touch::PrefEnabled(JSContext* aCx, JSObject* aGlobal)
|
2013-04-20 23:42:19 -07:00
|
|
|
{
|
2014-02-28 06:58:42 -08:00
|
|
|
return TouchEvent::PrefEnabled(aCx, aGlobal);
|
2013-04-20 23:42:19 -07:00
|
|
|
}
|
|
|
|
|
2014-04-29 01:57:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Touch, mTarget)
|
2013-04-05 01:49:00 -07:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Touch)
|
2013-04-20 23:42:19 -07:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2013-04-05 01:49:00 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(Touch)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(Touch)
|
|
|
|
|
2013-04-20 23:42:19 -07:00
|
|
|
EventTarget*
|
2014-05-05 03:48:50 -07:00
|
|
|
Touch::GetTarget() const
|
2013-04-05 01:49:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(mTarget);
|
|
|
|
if (content && content->ChromeOnlyAccess() &&
|
|
|
|
!nsContentUtils::CanAccessNativeAnon()) {
|
2013-04-20 23:42:19 -07:00
|
|
|
return content->FindFirstNonChromeOnlyAccessContent();
|
2013-04-05 01:49:00 -07:00
|
|
|
}
|
2013-04-20 23:42:19 -07:00
|
|
|
|
|
|
|
return mTarget;
|
2013-04-05 01:49:00 -07:00
|
|
|
}
|
|
|
|
|
2013-05-17 13:17:53 -07:00
|
|
|
void
|
2013-10-01 20:46:04 -07:00
|
|
|
Touch::InitializePoints(nsPresContext* aPresContext, WidgetEvent* aEvent)
|
2013-05-17 13:17:53 -07:00
|
|
|
{
|
|
|
|
if (mPointsInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
2014-03-04 16:37:43 -08:00
|
|
|
mClientPoint = Event::GetClientCoords(
|
2015-02-01 14:27:31 -08:00
|
|
|
aPresContext, aEvent, mRefPoint, mClientPoint);
|
2014-03-04 16:37:43 -08:00
|
|
|
mPagePoint = Event::GetPageCoords(
|
2015-02-01 14:27:31 -08:00
|
|
|
aPresContext, aEvent, mRefPoint, mClientPoint);
|
|
|
|
mScreenPoint = Event::GetScreenCoords(aPresContext, aEvent, mRefPoint);
|
2013-05-17 13:17:53 -07:00
|
|
|
mPointsInitialized = true;
|
|
|
|
}
|
|
|
|
|
2013-08-19 03:15:55 -07:00
|
|
|
void
|
2014-02-28 06:58:42 -08:00
|
|
|
Touch::SetTarget(EventTarget* aTarget)
|
2013-08-19 03:15:55 -07:00
|
|
|
{
|
|
|
|
mTarget = aTarget;
|
|
|
|
}
|
|
|
|
|
2013-04-05 01:49:00 -07:00
|
|
|
bool
|
2013-08-02 00:06:35 -07:00
|
|
|
Touch::Equals(Touch* aTouch)
|
|
|
|
{
|
|
|
|
return mRefPoint == aTouch->mRefPoint &&
|
|
|
|
mForce == aTouch->Force() &&
|
|
|
|
mRotationAngle == aTouch->RotationAngle() &&
|
|
|
|
mRadius.x == aTouch->RadiusX() &&
|
|
|
|
mRadius.y == aTouch->RadiusY();
|
2013-04-05 01:49:00 -07:00
|
|
|
}
|
|
|
|
|
2014-02-28 06:58:42 -08:00
|
|
|
JSObject*
|
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 07:13:33 -07:00
|
|
|
Touch::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-04-20 23:42:19 -07: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 07:13:33 -07:00
|
|
|
return TouchBinding::Wrap(aCx, this, aGivenProto);
|
2013-04-20 23:42:19 -07:00
|
|
|
}
|
|
|
|
|
2015-05-12 12:56:39 -07:00
|
|
|
// Parent ourselves to the global of the target. This achieves the desirable
|
2014-03-19 09:35:45 -07: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.
|
2015-05-12 12:56:39 -07:00
|
|
|
nsIGlobalObject*
|
2014-03-19 09:35:45 -07:00
|
|
|
Touch::GetParentObject()
|
|
|
|
{
|
|
|
|
if (!mTarget) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-05-12 12:56:39 -07:00
|
|
|
return mTarget->GetOwnerGlobal();
|
2014-03-19 09:35:45 -07:00
|
|
|
}
|
|
|
|
|
2013-04-05 01:49:00 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|