dom/events/Touch.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/Touch.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,161 @@
     1.4 +/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "mozilla/dom/Touch.h"
    1.10 +
    1.11 +#include "mozilla/dom/EventTarget.h"
    1.12 +#include "mozilla/dom/TouchBinding.h"
    1.13 +#include "mozilla/dom/TouchEvent.h"
    1.14 +#include "nsGlobalWindow.h"
    1.15 +#include "nsContentUtils.h"
    1.16 +#include "nsIContent.h"
    1.17 +
    1.18 +namespace mozilla {
    1.19 +namespace dom {
    1.20 +
    1.21 +Touch::Touch(EventTarget* aTarget,
    1.22 +             int32_t aIdentifier,
    1.23 +             int32_t aPageX,
    1.24 +             int32_t aPageY,
    1.25 +             int32_t aScreenX,
    1.26 +             int32_t aScreenY,
    1.27 +             int32_t aClientX,
    1.28 +             int32_t aClientY,
    1.29 +             int32_t aRadiusX,
    1.30 +             int32_t aRadiusY,
    1.31 +             float aRotationAngle,
    1.32 +             float aForce)
    1.33 +{
    1.34 +  SetIsDOMBinding();
    1.35 +  mTarget = aTarget;
    1.36 +  mIdentifier = aIdentifier;
    1.37 +  mPagePoint = CSSIntPoint(aPageX, aPageY);
    1.38 +  mScreenPoint = nsIntPoint(aScreenX, aScreenY);
    1.39 +  mClientPoint = CSSIntPoint(aClientX, aClientY);
    1.40 +  mRefPoint = nsIntPoint(0, 0);
    1.41 +  mPointsInitialized = true;
    1.42 +  mRadius.x = aRadiusX;
    1.43 +  mRadius.y = aRadiusY;
    1.44 +  mRotationAngle = aRotationAngle;
    1.45 +  mForce = aForce;
    1.46 +
    1.47 +  mChanged = false;
    1.48 +  mMessage = 0;
    1.49 +  nsJSContext::LikelyShortLivingObjectCreated();
    1.50 +}
    1.51 +
    1.52 +Touch::Touch(int32_t aIdentifier,
    1.53 +             nsIntPoint aPoint,
    1.54 +             nsIntPoint aRadius,
    1.55 +             float aRotationAngle,
    1.56 +             float aForce)
    1.57 +{
    1.58 +  SetIsDOMBinding();
    1.59 +  mIdentifier = aIdentifier;
    1.60 +  mPagePoint = CSSIntPoint(0, 0);
    1.61 +  mScreenPoint = nsIntPoint(0, 0);
    1.62 +  mClientPoint = CSSIntPoint(0, 0);
    1.63 +  mRefPoint = aPoint;
    1.64 +  mPointsInitialized = false;
    1.65 +  mRadius = aRadius;
    1.66 +  mRotationAngle = aRotationAngle;
    1.67 +  mForce = aForce;
    1.68 +
    1.69 +  mChanged = false;
    1.70 +  mMessage = 0;
    1.71 +  nsJSContext::LikelyShortLivingObjectCreated();
    1.72 +}
    1.73 +
    1.74 +Touch::~Touch()
    1.75 +{
    1.76 +}
    1.77 +
    1.78 +// static
    1.79 +bool
    1.80 +Touch::PrefEnabled(JSContext* aCx, JSObject* aGlobal)
    1.81 +{
    1.82 +  return TouchEvent::PrefEnabled(aCx, aGlobal);
    1.83 +}
    1.84 +
    1.85 +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(Touch, mTarget)
    1.86 +
    1.87 +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Touch)
    1.88 +  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
    1.89 +  NS_INTERFACE_MAP_ENTRY(nsISupports)
    1.90 +NS_INTERFACE_MAP_END
    1.91 +
    1.92 +NS_IMPL_CYCLE_COLLECTING_ADDREF(Touch)
    1.93 +NS_IMPL_CYCLE_COLLECTING_RELEASE(Touch)
    1.94 +
    1.95 +EventTarget*
    1.96 +Touch::Target() const
    1.97 +{
    1.98 +  nsCOMPtr<nsIContent> content = do_QueryInterface(mTarget);
    1.99 +  if (content && content->ChromeOnlyAccess() &&
   1.100 +      !nsContentUtils::CanAccessNativeAnon()) {
   1.101 +    return content->FindFirstNonChromeOnlyAccessContent();
   1.102 +  }
   1.103 +
   1.104 +  return mTarget;
   1.105 +}
   1.106 +
   1.107 +void
   1.108 +Touch::InitializePoints(nsPresContext* aPresContext, WidgetEvent* aEvent)
   1.109 +{
   1.110 +  if (mPointsInitialized) {
   1.111 +    return;
   1.112 +  }
   1.113 +  mClientPoint = Event::GetClientCoords(
   1.114 +    aPresContext, aEvent, LayoutDeviceIntPoint::FromUntyped(mRefPoint),
   1.115 +    mClientPoint);
   1.116 +  mPagePoint = Event::GetPageCoords(
   1.117 +    aPresContext, aEvent, LayoutDeviceIntPoint::FromUntyped(mRefPoint),
   1.118 +    mClientPoint);
   1.119 +  mScreenPoint = Event::GetScreenCoords(aPresContext, aEvent,
   1.120 +    LayoutDeviceIntPoint::FromUntyped(mRefPoint));
   1.121 +  mPointsInitialized = true;
   1.122 +}
   1.123 +
   1.124 +void
   1.125 +Touch::SetTarget(EventTarget* aTarget)
   1.126 +{
   1.127 +  mTarget = aTarget;
   1.128 +}
   1.129 +
   1.130 +bool
   1.131 +Touch::Equals(Touch* aTouch)
   1.132 +{
   1.133 +  return mRefPoint == aTouch->mRefPoint &&
   1.134 +         mForce == aTouch->Force() &&
   1.135 +         mRotationAngle == aTouch->RotationAngle() &&
   1.136 +         mRadius.x == aTouch->RadiusX() &&
   1.137 +         mRadius.y == aTouch->RadiusY();
   1.138 +}
   1.139 +
   1.140 +JSObject*
   1.141 +Touch::WrapObject(JSContext* aCx)
   1.142 +{
   1.143 +  return TouchBinding::Wrap(aCx, this);
   1.144 +}
   1.145 +
   1.146 +// Parent ourselves to the window of the target. This achieves the desirable
   1.147 +// effects of parenting to the target, but avoids making the touch inaccessible
   1.148 +// when the target happens to be NAC and therefore reflected into the XBL scope.
   1.149 +EventTarget*
   1.150 +Touch::GetParentObject()
   1.151 +{
   1.152 +  if (!mTarget) {
   1.153 +    return nullptr;
   1.154 +  }
   1.155 +  nsCOMPtr<nsPIDOMWindow> outer = do_QueryInterface(mTarget->GetOwnerGlobal());
   1.156 +  if (!outer) {
   1.157 +    return nullptr;
   1.158 +  }
   1.159 +  MOZ_ASSERT(outer->IsOuterWindow());
   1.160 +  return static_cast<nsGlobalWindow*>(outer->GetCurrentInnerWindow());
   1.161 +}
   1.162 +
   1.163 +} // namespace dom
   1.164 +} // namespace mozilla

mercurial