dom/events/Touch.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "mozilla/dom/Touch.h"
     8 #include "mozilla/dom/EventTarget.h"
     9 #include "mozilla/dom/TouchBinding.h"
    10 #include "mozilla/dom/TouchEvent.h"
    11 #include "nsGlobalWindow.h"
    12 #include "nsContentUtils.h"
    13 #include "nsIContent.h"
    15 namespace mozilla {
    16 namespace dom {
    18 Touch::Touch(EventTarget* aTarget,
    19              int32_t aIdentifier,
    20              int32_t aPageX,
    21              int32_t aPageY,
    22              int32_t aScreenX,
    23              int32_t aScreenY,
    24              int32_t aClientX,
    25              int32_t aClientY,
    26              int32_t aRadiusX,
    27              int32_t aRadiusY,
    28              float aRotationAngle,
    29              float aForce)
    30 {
    31   SetIsDOMBinding();
    32   mTarget = aTarget;
    33   mIdentifier = aIdentifier;
    34   mPagePoint = CSSIntPoint(aPageX, aPageY);
    35   mScreenPoint = nsIntPoint(aScreenX, aScreenY);
    36   mClientPoint = CSSIntPoint(aClientX, aClientY);
    37   mRefPoint = nsIntPoint(0, 0);
    38   mPointsInitialized = true;
    39   mRadius.x = aRadiusX;
    40   mRadius.y = aRadiusY;
    41   mRotationAngle = aRotationAngle;
    42   mForce = aForce;
    44   mChanged = false;
    45   mMessage = 0;
    46   nsJSContext::LikelyShortLivingObjectCreated();
    47 }
    49 Touch::Touch(int32_t aIdentifier,
    50              nsIntPoint aPoint,
    51              nsIntPoint aRadius,
    52              float aRotationAngle,
    53              float aForce)
    54 {
    55   SetIsDOMBinding();
    56   mIdentifier = aIdentifier;
    57   mPagePoint = CSSIntPoint(0, 0);
    58   mScreenPoint = nsIntPoint(0, 0);
    59   mClientPoint = CSSIntPoint(0, 0);
    60   mRefPoint = aPoint;
    61   mPointsInitialized = false;
    62   mRadius = aRadius;
    63   mRotationAngle = aRotationAngle;
    64   mForce = aForce;
    66   mChanged = false;
    67   mMessage = 0;
    68   nsJSContext::LikelyShortLivingObjectCreated();
    69 }
    71 Touch::~Touch()
    72 {
    73 }
    75 // static
    76 bool
    77 Touch::PrefEnabled(JSContext* aCx, JSObject* aGlobal)
    78 {
    79   return TouchEvent::PrefEnabled(aCx, aGlobal);
    80 }
    82 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(Touch, mTarget)
    84 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Touch)
    85   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
    86   NS_INTERFACE_MAP_ENTRY(nsISupports)
    87 NS_INTERFACE_MAP_END
    89 NS_IMPL_CYCLE_COLLECTING_ADDREF(Touch)
    90 NS_IMPL_CYCLE_COLLECTING_RELEASE(Touch)
    92 EventTarget*
    93 Touch::Target() const
    94 {
    95   nsCOMPtr<nsIContent> content = do_QueryInterface(mTarget);
    96   if (content && content->ChromeOnlyAccess() &&
    97       !nsContentUtils::CanAccessNativeAnon()) {
    98     return content->FindFirstNonChromeOnlyAccessContent();
    99   }
   101   return mTarget;
   102 }
   104 void
   105 Touch::InitializePoints(nsPresContext* aPresContext, WidgetEvent* aEvent)
   106 {
   107   if (mPointsInitialized) {
   108     return;
   109   }
   110   mClientPoint = Event::GetClientCoords(
   111     aPresContext, aEvent, LayoutDeviceIntPoint::FromUntyped(mRefPoint),
   112     mClientPoint);
   113   mPagePoint = Event::GetPageCoords(
   114     aPresContext, aEvent, LayoutDeviceIntPoint::FromUntyped(mRefPoint),
   115     mClientPoint);
   116   mScreenPoint = Event::GetScreenCoords(aPresContext, aEvent,
   117     LayoutDeviceIntPoint::FromUntyped(mRefPoint));
   118   mPointsInitialized = true;
   119 }
   121 void
   122 Touch::SetTarget(EventTarget* aTarget)
   123 {
   124   mTarget = aTarget;
   125 }
   127 bool
   128 Touch::Equals(Touch* aTouch)
   129 {
   130   return mRefPoint == aTouch->mRefPoint &&
   131          mForce == aTouch->Force() &&
   132          mRotationAngle == aTouch->RotationAngle() &&
   133          mRadius.x == aTouch->RadiusX() &&
   134          mRadius.y == aTouch->RadiusY();
   135 }
   137 JSObject*
   138 Touch::WrapObject(JSContext* aCx)
   139 {
   140   return TouchBinding::Wrap(aCx, this);
   141 }
   143 // Parent ourselves to the window of the target. This achieves the desirable
   144 // effects of parenting to the target, but avoids making the touch inaccessible
   145 // when the target happens to be NAC and therefore reflected into the XBL scope.
   146 EventTarget*
   147 Touch::GetParentObject()
   148 {
   149   if (!mTarget) {
   150     return nullptr;
   151   }
   152   nsCOMPtr<nsPIDOMWindow> outer = do_QueryInterface(mTarget->GetOwnerGlobal());
   153   if (!outer) {
   154     return nullptr;
   155   }
   156   MOZ_ASSERT(outer->IsOuterWindow());
   157   return static_cast<nsGlobalWindow*>(outer->GetCurrentInnerWindow());
   158 }
   160 } // namespace dom
   161 } // namespace mozilla

mercurial