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