2013-04-05 08:49:00 +00:00
|
|
|
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
|
|
|
/* 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 06:42:19 +00:00
|
|
|
|
2013-08-19 10:15:55 +00:00
|
|
|
#include "mozilla/dom/EventTarget.h"
|
2013-04-21 06:42:19 +00:00
|
|
|
#include "mozilla/dom/TouchBinding.h"
|
2014-02-28 14:58:42 +00:00
|
|
|
#include "mozilla/dom/TouchEvent.h"
|
2013-04-21 06:42:19 +00:00
|
|
|
#include "nsContentUtils.h"
|
2013-09-30 21:26:04 +00:00
|
|
|
#include "nsIContent.h"
|
2013-04-05 08:49:00 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-02-28 14:58:42 +00:00
|
|
|
Touch::Touch(EventTarget* aTarget,
|
2013-08-19 10:15:55 +00: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)
|
|
|
|
{
|
|
|
|
SetIsDOMBinding();
|
|
|
|
mTarget = aTarget;
|
|
|
|
mIdentifier = aIdentifier;
|
|
|
|
mPagePoint = CSSIntPoint(aPageX, aPageY);
|
|
|
|
mScreenPoint = nsIntPoint(aScreenX, aScreenY);
|
|
|
|
mClientPoint = CSSIntPoint(aClientX, aClientY);
|
|
|
|
mRefPoint = nsIntPoint(0, 0);
|
|
|
|
mPointsInitialized = true;
|
|
|
|
mRadius.x = aRadiusX;
|
|
|
|
mRadius.y = aRadiusY;
|
|
|
|
mRotationAngle = aRotationAngle;
|
|
|
|
mForce = aForce;
|
|
|
|
|
|
|
|
mChanged = false;
|
|
|
|
mMessage = 0;
|
|
|
|
nsJSContext::LikelyShortLivingObjectCreated();
|
|
|
|
}
|
|
|
|
|
|
|
|
Touch::Touch(int32_t aIdentifier,
|
|
|
|
nsIntPoint aPoint,
|
|
|
|
nsIntPoint aRadius,
|
|
|
|
float aRotationAngle,
|
|
|
|
float aForce)
|
|
|
|
{
|
|
|
|
SetIsDOMBinding();
|
|
|
|
mIdentifier = aIdentifier;
|
|
|
|
mPagePoint = CSSIntPoint(0, 0);
|
|
|
|
mScreenPoint = nsIntPoint(0, 0);
|
|
|
|
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 14:58:42 +00:00
|
|
|
// static
|
|
|
|
bool
|
2014-02-06 18:28:14 +00:00
|
|
|
Touch::PrefEnabled(JSContext* aCx, JSObject* aGlobal)
|
2013-04-21 06:42:19 +00:00
|
|
|
{
|
2014-02-28 14:58:42 +00:00
|
|
|
return TouchEvent::PrefEnabled(aCx, aGlobal);
|
2013-04-21 06:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(Touch, mTarget)
|
2013-04-05 08:49:00 +00:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Touch)
|
2013-04-21 06:42:19 +00:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2013-04-05 08:49:00 +00:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(Touch)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(Touch)
|
|
|
|
|
2013-04-21 06:42:19 +00:00
|
|
|
EventTarget*
|
|
|
|
Touch::Target() const
|
2013-04-05 08:49:00 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(mTarget);
|
|
|
|
if (content && content->ChromeOnlyAccess() &&
|
|
|
|
!nsContentUtils::CanAccessNativeAnon()) {
|
2013-04-21 06:42:19 +00:00
|
|
|
return content->FindFirstNonChromeOnlyAccessContent();
|
2013-04-05 08:49:00 +00:00
|
|
|
}
|
2013-04-21 06:42:19 +00:00
|
|
|
|
|
|
|
return mTarget;
|
2013-04-05 08:49:00 +00:00
|
|
|
}
|
|
|
|
|
2013-05-17 20:17:53 +00:00
|
|
|
void
|
2013-10-02 03:46:04 +00:00
|
|
|
Touch::InitializePoints(nsPresContext* aPresContext, WidgetEvent* aEvent)
|
2013-05-17 20:17:53 +00:00
|
|
|
{
|
|
|
|
if (mPointsInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
2014-03-05 00:37:43 +00:00
|
|
|
mClientPoint = Event::GetClientCoords(
|
2013-08-02 07:05:16 +00:00
|
|
|
aPresContext, aEvent, LayoutDeviceIntPoint::FromUntyped(mRefPoint),
|
|
|
|
mClientPoint);
|
2014-03-05 00:37:43 +00:00
|
|
|
mPagePoint = Event::GetPageCoords(
|
2013-08-02 07:05:16 +00:00
|
|
|
aPresContext, aEvent, LayoutDeviceIntPoint::FromUntyped(mRefPoint),
|
|
|
|
mClientPoint);
|
2014-03-05 00:37:43 +00:00
|
|
|
mScreenPoint = Event::GetScreenCoords(aPresContext, aEvent,
|
2013-08-02 07:05:16 +00:00
|
|
|
LayoutDeviceIntPoint::FromUntyped(mRefPoint));
|
2013-05-17 20:17:53 +00:00
|
|
|
mPointsInitialized = true;
|
|
|
|
}
|
|
|
|
|
2013-08-19 10:15:55 +00:00
|
|
|
void
|
2014-02-28 14:58:42 +00:00
|
|
|
Touch::SetTarget(EventTarget* aTarget)
|
2013-08-19 10:15:55 +00:00
|
|
|
{
|
|
|
|
mTarget = aTarget;
|
|
|
|
}
|
|
|
|
|
2013-04-05 08:49:00 +00:00
|
|
|
bool
|
2013-08-02 07:06:35 +00: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 08:49:00 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 14:58:42 +00:00
|
|
|
JSObject*
|
2013-04-25 16:29:54 +00:00
|
|
|
Touch::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
2013-04-21 06:42:19 +00:00
|
|
|
{
|
|
|
|
return TouchBinding::Wrap(aCx, aScope, this);
|
|
|
|
}
|
|
|
|
|
2013-04-05 08:49:00 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|