michael@0: /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/dom/Touch.h" michael@0: michael@0: #include "mozilla/dom/EventTarget.h" michael@0: #include "mozilla/dom/TouchBinding.h" michael@0: #include "mozilla/dom/TouchEvent.h" michael@0: #include "nsGlobalWindow.h" michael@0: #include "nsContentUtils.h" michael@0: #include "nsIContent.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: Touch::Touch(EventTarget* aTarget, michael@0: int32_t aIdentifier, michael@0: int32_t aPageX, michael@0: int32_t aPageY, michael@0: int32_t aScreenX, michael@0: int32_t aScreenY, michael@0: int32_t aClientX, michael@0: int32_t aClientY, michael@0: int32_t aRadiusX, michael@0: int32_t aRadiusY, michael@0: float aRotationAngle, michael@0: float aForce) michael@0: { michael@0: SetIsDOMBinding(); michael@0: mTarget = aTarget; michael@0: mIdentifier = aIdentifier; michael@0: mPagePoint = CSSIntPoint(aPageX, aPageY); michael@0: mScreenPoint = nsIntPoint(aScreenX, aScreenY); michael@0: mClientPoint = CSSIntPoint(aClientX, aClientY); michael@0: mRefPoint = nsIntPoint(0, 0); michael@0: mPointsInitialized = true; michael@0: mRadius.x = aRadiusX; michael@0: mRadius.y = aRadiusY; michael@0: mRotationAngle = aRotationAngle; michael@0: mForce = aForce; michael@0: michael@0: mChanged = false; michael@0: mMessage = 0; michael@0: nsJSContext::LikelyShortLivingObjectCreated(); michael@0: } michael@0: michael@0: Touch::Touch(int32_t aIdentifier, michael@0: nsIntPoint aPoint, michael@0: nsIntPoint aRadius, michael@0: float aRotationAngle, michael@0: float aForce) michael@0: { michael@0: SetIsDOMBinding(); michael@0: mIdentifier = aIdentifier; michael@0: mPagePoint = CSSIntPoint(0, 0); michael@0: mScreenPoint = nsIntPoint(0, 0); michael@0: mClientPoint = CSSIntPoint(0, 0); michael@0: mRefPoint = aPoint; michael@0: mPointsInitialized = false; michael@0: mRadius = aRadius; michael@0: mRotationAngle = aRotationAngle; michael@0: mForce = aForce; michael@0: michael@0: mChanged = false; michael@0: mMessage = 0; michael@0: nsJSContext::LikelyShortLivingObjectCreated(); michael@0: } michael@0: michael@0: Touch::~Touch() michael@0: { michael@0: } michael@0: michael@0: // static michael@0: bool michael@0: Touch::PrefEnabled(JSContext* aCx, JSObject* aGlobal) michael@0: { michael@0: return TouchEvent::PrefEnabled(aCx, aGlobal); michael@0: } michael@0: michael@0: NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(Touch, mTarget) michael@0: michael@0: NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Touch) michael@0: NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY michael@0: NS_INTERFACE_MAP_ENTRY(nsISupports) michael@0: NS_INTERFACE_MAP_END michael@0: michael@0: NS_IMPL_CYCLE_COLLECTING_ADDREF(Touch) michael@0: NS_IMPL_CYCLE_COLLECTING_RELEASE(Touch) michael@0: michael@0: EventTarget* michael@0: Touch::Target() const michael@0: { michael@0: nsCOMPtr content = do_QueryInterface(mTarget); michael@0: if (content && content->ChromeOnlyAccess() && michael@0: !nsContentUtils::CanAccessNativeAnon()) { michael@0: return content->FindFirstNonChromeOnlyAccessContent(); michael@0: } michael@0: michael@0: return mTarget; michael@0: } michael@0: michael@0: void michael@0: Touch::InitializePoints(nsPresContext* aPresContext, WidgetEvent* aEvent) michael@0: { michael@0: if (mPointsInitialized) { michael@0: return; michael@0: } michael@0: mClientPoint = Event::GetClientCoords( michael@0: aPresContext, aEvent, LayoutDeviceIntPoint::FromUntyped(mRefPoint), michael@0: mClientPoint); michael@0: mPagePoint = Event::GetPageCoords( michael@0: aPresContext, aEvent, LayoutDeviceIntPoint::FromUntyped(mRefPoint), michael@0: mClientPoint); michael@0: mScreenPoint = Event::GetScreenCoords(aPresContext, aEvent, michael@0: LayoutDeviceIntPoint::FromUntyped(mRefPoint)); michael@0: mPointsInitialized = true; michael@0: } michael@0: michael@0: void michael@0: Touch::SetTarget(EventTarget* aTarget) michael@0: { michael@0: mTarget = aTarget; michael@0: } michael@0: michael@0: bool michael@0: Touch::Equals(Touch* aTouch) michael@0: { michael@0: return mRefPoint == aTouch->mRefPoint && michael@0: mForce == aTouch->Force() && michael@0: mRotationAngle == aTouch->RotationAngle() && michael@0: mRadius.x == aTouch->RadiusX() && michael@0: mRadius.y == aTouch->RadiusY(); michael@0: } michael@0: michael@0: JSObject* michael@0: Touch::WrapObject(JSContext* aCx) michael@0: { michael@0: return TouchBinding::Wrap(aCx, this); michael@0: } michael@0: michael@0: // Parent ourselves to the window of the target. This achieves the desirable michael@0: // effects of parenting to the target, but avoids making the touch inaccessible michael@0: // when the target happens to be NAC and therefore reflected into the XBL scope. michael@0: EventTarget* michael@0: Touch::GetParentObject() michael@0: { michael@0: if (!mTarget) { michael@0: return nullptr; michael@0: } michael@0: nsCOMPtr outer = do_QueryInterface(mTarget->GetOwnerGlobal()); michael@0: if (!outer) { michael@0: return nullptr; michael@0: } michael@0: MOZ_ASSERT(outer->IsOuterWindow()); michael@0: return static_cast(outer->GetCurrentInnerWindow()); michael@0: } michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla