LCOV - code coverage report
Current view: top level - dom/events - Touch.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 102 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 21 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #include "mozilla/dom/Touch.h"
       8             : 
       9             : #include "mozilla/dom/EventTarget.h"
      10             : #include "mozilla/dom/TouchEvent.h"
      11             : #include "nsGlobalWindow.h"
      12             : #include "nsContentUtils.h"
      13             : #include "nsIContent.h"
      14             : 
      15             : namespace mozilla {
      16             : namespace dom {
      17             : 
      18             : // static
      19             : already_AddRefed<Touch>
      20           0 : Touch::Constructor(const GlobalObject& aGlobal,
      21             :                    const TouchInit& aParam,
      22             :                    ErrorResult& aRv)
      23             : {
      24             :   // Annoyingly many parameters, make sure the ordering is the same as in the
      25             :   // Touch constructor.
      26             :   RefPtr<Touch> touch = new Touch(aParam.mTarget,
      27           0 :                                   aParam.mIdentifier,
      28           0 :                                   aParam.mPageX,
      29           0 :                                   aParam.mPageY,
      30           0 :                                   aParam.mScreenX,
      31           0 :                                   aParam.mScreenY,
      32           0 :                                   aParam.mClientX,
      33           0 :                                   aParam.mClientY,
      34           0 :                                   aParam.mRadiusX,
      35           0 :                                   aParam.mRadiusY,
      36           0 :                                   aParam.mRotationAngle,
      37           0 :                                   aParam.mForce);
      38           0 :   return touch.forget();
      39             : }
      40             : 
      41           0 : Touch::Touch(EventTarget* aTarget,
      42             :              int32_t aIdentifier,
      43             :              int32_t aPageX,
      44             :              int32_t aPageY,
      45             :              int32_t aScreenX,
      46             :              int32_t aScreenY,
      47             :              int32_t aClientX,
      48             :              int32_t aClientY,
      49             :              int32_t aRadiusX,
      50             :              int32_t aRadiusY,
      51             :              float aRotationAngle,
      52           0 :              float aForce)
      53             : {
      54           0 :   mTarget = aTarget;
      55           0 :   mIdentifier = aIdentifier;
      56           0 :   mPagePoint = CSSIntPoint(aPageX, aPageY);
      57           0 :   mScreenPoint = CSSIntPoint(aScreenX, aScreenY);
      58           0 :   mClientPoint = CSSIntPoint(aClientX, aClientY);
      59           0 :   mRefPoint = LayoutDeviceIntPoint(0, 0);
      60           0 :   mPointsInitialized = true;
      61           0 :   mRadius.x = aRadiusX;
      62           0 :   mRadius.y = aRadiusY;
      63           0 :   mRotationAngle = aRotationAngle;
      64           0 :   mForce = aForce;
      65             : 
      66           0 :   mChanged = false;
      67           0 :   mMessage = 0;
      68           0 :   nsJSContext::LikelyShortLivingObjectCreated();
      69           0 : }
      70             : 
      71           0 : Touch::Touch(int32_t aIdentifier,
      72             :              LayoutDeviceIntPoint aPoint,
      73             :              LayoutDeviceIntPoint aRadius,
      74             :              float aRotationAngle,
      75           0 :              float aForce)
      76             : {
      77           0 :   mIdentifier = aIdentifier;
      78           0 :   mPagePoint = CSSIntPoint(0, 0);
      79           0 :   mScreenPoint = CSSIntPoint(0, 0);
      80           0 :   mClientPoint = CSSIntPoint(0, 0);
      81           0 :   mRefPoint = aPoint;
      82           0 :   mPointsInitialized = false;
      83           0 :   mRadius = aRadius;
      84           0 :   mRotationAngle = aRotationAngle;
      85           0 :   mForce = aForce;
      86             : 
      87           0 :   mChanged = false;
      88           0 :   mMessage = 0;
      89           0 :   nsJSContext::LikelyShortLivingObjectCreated();
      90           0 : }
      91             : 
      92           0 : Touch::Touch(const Touch& aOther)
      93             :   : mTarget(aOther.mTarget)
      94             :   , mRefPoint(aOther.mRefPoint)
      95           0 :   , mChanged(aOther.mChanged)
      96           0 :   , mMessage(aOther.mMessage)
      97           0 :   , mIdentifier(aOther.mIdentifier)
      98             :   , mPagePoint(aOther.mPagePoint)
      99             :   , mClientPoint(aOther.mClientPoint)
     100             :   , mScreenPoint(aOther.mScreenPoint)
     101             :   , mRadius(aOther.mRadius)
     102           0 :   , mRotationAngle(aOther.mRotationAngle)
     103           0 :   , mForce(aOther.mForce)
     104           0 :   , mPointsInitialized(aOther.mPointsInitialized)
     105             : {
     106           0 :   nsJSContext::LikelyShortLivingObjectCreated();
     107           0 : }
     108             : 
     109           0 : Touch::~Touch()
     110             : {
     111           0 : }
     112             : 
     113             : // static
     114             : bool
     115           0 : Touch::PrefEnabled(JSContext* aCx, JSObject* aGlobal)
     116             : {
     117           0 :   return TouchEvent::PrefEnabled(aCx, aGlobal);
     118             : }
     119             : 
     120           0 : NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Touch, mTarget)
     121             : 
     122           0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Touch)
     123           0 :   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
     124           0 :   NS_INTERFACE_MAP_ENTRY(nsISupports)
     125           0 : NS_INTERFACE_MAP_END
     126             : 
     127           0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(Touch)
     128           0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(Touch)
     129             : 
     130             : EventTarget*
     131           0 : Touch::GetTarget() const
     132             : {
     133           0 :   nsCOMPtr<nsIContent> content = do_QueryInterface(mTarget);
     134           0 :   if (content && content->ChromeOnlyAccess() &&
     135           0 :       !nsContentUtils::LegacyIsCallerNativeCode() &&
     136           0 :       !nsContentUtils::CanAccessNativeAnon()) {
     137           0 :     return content->FindFirstNonChromeOnlyAccessContent();
     138             :   }
     139             : 
     140           0 :   return mTarget;
     141             : }
     142             : 
     143             : int32_t
     144           0 : Touch::ScreenX(CallerType aCallerType) const
     145             : {
     146           0 :   if (nsContentUtils::ResistFingerprinting(aCallerType)) {
     147           0 :     return ClientX();
     148             :   }
     149             : 
     150           0 :   return mScreenPoint.x;
     151             : }
     152             : 
     153             : int32_t
     154           0 : Touch::ScreenY(CallerType aCallerType) const
     155             : {
     156           0 :   if (nsContentUtils::ResistFingerprinting(aCallerType)) {
     157           0 :     return ClientY();
     158             :   }
     159             : 
     160           0 :   return mScreenPoint.y;
     161             : }
     162             : 
     163             : void
     164           0 : Touch::InitializePoints(nsPresContext* aPresContext, WidgetEvent* aEvent)
     165             : {
     166           0 :   if (mPointsInitialized) {
     167           0 :     return;
     168             :   }
     169             :   mClientPoint = Event::GetClientCoords(
     170           0 :     aPresContext, aEvent, mRefPoint, mClientPoint);
     171             :   mPagePoint = Event::GetPageCoords(
     172           0 :     aPresContext, aEvent, mRefPoint, mClientPoint);
     173           0 :   mScreenPoint = Event::GetScreenCoords(aPresContext, aEvent, mRefPoint);
     174           0 :   mPointsInitialized = true;
     175             : }
     176             : 
     177             : void
     178           0 : Touch::SetTarget(EventTarget* aTarget)
     179             : {
     180           0 :   mTarget = aTarget;
     181           0 : }
     182             : 
     183             : bool
     184           0 : Touch::Equals(Touch* aTouch)
     185             : {
     186           0 :   return mRefPoint == aTouch->mRefPoint &&
     187           0 :          mForce == aTouch->Force() &&
     188           0 :          mRotationAngle == aTouch->RotationAngle() &&
     189           0 :          mRadius.x == aTouch->RadiusX() &&
     190           0 :          mRadius.y == aTouch->RadiusY();
     191             : }
     192             : 
     193             : JSObject*
     194           0 : Touch::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
     195             : {
     196           0 :   return TouchBinding::Wrap(aCx, this, aGivenProto);
     197             : }
     198             : 
     199             : // Parent ourselves to the global of the target. This achieves the desirable
     200             : // effects of parenting to the target, but avoids making the touch inaccessible
     201             : // when the target happens to be NAC and therefore reflected into the XBL scope.
     202             : nsIGlobalObject*
     203           0 : Touch::GetParentObject()
     204             : {
     205           0 :   if (!mTarget) {
     206           0 :     return nullptr;
     207             :   }
     208           0 :   return mTarget->GetOwnerGlobal();
     209             : }
     210             : 
     211             : } // namespace dom
     212             : } // namespace mozilla

Generated by: LCOV version 1.13