From 10f3eae40e0aa37205ab31b2c300dd378cf036f9 Mon Sep 17 00:00:00 2001 From: David Zbarsky Date: Mon, 29 Jul 2013 21:11:01 -0700 Subject: [PATCH] Backout 40683014a638 for causing mochitest orange --- content/events/src/Touch.cpp | 100 ++++++++++++++++++++- content/events/src/Touch.h | 12 +-- content/events/src/nsDOMTouchEvent.cpp | 4 +- content/events/src/nsEventStateManager.cpp | 4 +- dom/base/nsGlobalWindow.h | 1 - dom/interfaces/events/nsIDOMTouchEvent.idl | 33 +++++++ gfx/layers/ipc/AsyncPanZoomController.cpp | 2 +- layout/base/nsPresShell.cpp | 2 +- layout/xul/base/src/nsBoxFrame.cpp | 2 +- widget/InputData.h | 10 +-- widget/xpwidgets/InputData.cpp | 18 ++-- 11 files changed, 159 insertions(+), 29 deletions(-) diff --git a/content/events/src/Touch.cpp b/content/events/src/Touch.cpp index f74c304266b..fc47c824ea6 100644 --- a/content/events/src/Touch.cpp +++ b/content/events/src/Touch.cpp @@ -25,12 +25,27 @@ NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(Touch, mTarget) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Touch) NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY + NS_INTERFACE_MAP_ENTRY(nsIDOMTouch) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END NS_IMPL_CYCLE_COLLECTING_ADDREF(Touch) NS_IMPL_CYCLE_COLLECTING_RELEASE(Touch) +NS_IMETHODIMP +Touch::GetIdentifier(int32_t* aIdentifier) +{ + *aIdentifier = Identifier(); + return NS_OK; +} + +NS_IMETHODIMP +Touch::GetTarget(nsIDOMEventTarget** aTarget) +{ + NS_ADDREF(*aTarget = Target()); + return NS_OK; +} + EventTarget* Touch::Target() const { @@ -43,6 +58,76 @@ Touch::Target() const return mTarget; } +NS_IMETHODIMP +Touch::GetScreenX(int32_t* aScreenX) +{ + *aScreenX = ScreenX(); + return NS_OK; +} + +NS_IMETHODIMP +Touch::GetScreenY(int32_t* aScreenY) +{ + *aScreenY = ScreenY(); + return NS_OK; +} + +NS_IMETHODIMP +Touch::GetClientX(int32_t* aClientX) +{ + *aClientX = ClientX(); + return NS_OK; +} + +NS_IMETHODIMP +Touch::GetClientY(int32_t* aClientY) +{ + *aClientY = ClientY(); + return NS_OK; +} + +NS_IMETHODIMP +Touch::GetPageX(int32_t* aPageX) +{ + *aPageX = PageX(); + return NS_OK; +} + +NS_IMETHODIMP +Touch::GetPageY(int32_t* aPageY) +{ + *aPageY = PageY(); + return NS_OK; +} + +NS_IMETHODIMP +Touch::GetRadiusX(int32_t* aRadiusX) +{ + *aRadiusX = RadiusX(); + return NS_OK; +} + +NS_IMETHODIMP +Touch::GetRadiusY(int32_t* aRadiusY) +{ + *aRadiusY = RadiusY(); + return NS_OK; +} + +NS_IMETHODIMP +Touch::GetRotationAngle(float* aRotationAngle) +{ + *aRotationAngle = RotationAngle(); + return NS_OK; +} + +NS_IMETHODIMP +Touch::GetForce(float* aForce) +{ + *aForce = Force(); + return NS_OK; +} + void Touch::InitializePoints(nsPresContext* aPresContext, nsEvent* aEvent) { @@ -62,12 +147,19 @@ Touch::InitializePoints(nsPresContext* aPresContext, nsEvent* aEvent) } bool -Touch::Equals(Touch* aTouch) +Touch::Equals(nsIDOMTouch* aTouch) { + float force; + float orientation; + int32_t radiusX, radiusY; + aTouch->GetForce(&force); + aTouch->GetRotationAngle(&orientation); + aTouch->GetRadiusX(&radiusX); + aTouch->GetRadiusY(&radiusY); return mRefPoint != aTouch->mRefPoint || - (mForce != aTouch->Force()) || - (mRotationAngle != aTouch->RotationAngle()) || - (mRadius.x != aTouch->RadiusX()) || (mRadius.y != aTouch->RadiusY()); + (mForce != force) || + (mRotationAngle != orientation) || + (mRadius.x != radiusX) || (mRadius.y != radiusY); } /* virtual */ JSObject* diff --git a/content/events/src/Touch.h b/content/events/src/Touch.h index 654ab1a88b1..e0feb98268f 100644 --- a/content/events/src/Touch.h +++ b/content/events/src/Touch.h @@ -6,6 +6,7 @@ #ifndef mozilla_dom_Touch_h #define mozilla_dom_Touch_h +#include "nsIDOMTouchEvent.h" #include "nsString.h" #include "nsTArray.h" #include "mozilla/Attributes.h" @@ -17,7 +18,7 @@ namespace mozilla { namespace dom { -class Touch MOZ_FINAL : public nsISupports +class Touch MOZ_FINAL : public nsIDOMTouch , public nsWrapperCache { public: @@ -76,6 +77,7 @@ public: } NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Touch) + NS_DECL_NSIDOMTOUCH void InitializePoints(nsPresContext* aPresContext, nsEvent* aEvent); @@ -83,7 +85,7 @@ public: { mTarget = aTarget; } - bool Equals(Touch* aTouch); + bool Equals(nsIDOMTouch* aTouch); virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aScope) MOZ_OVERRIDE; @@ -110,12 +112,6 @@ public: nsIntPoint mRadius; float mRotationAngle; float mForce; - nsCOMPtr mTarget; - mozilla::dom::EventTarget *GetTarget() { return mTarget; } - nsIntPoint mRefPoint; - bool mChanged; - uint32_t mMessage; - protected: bool mPointsInitialized; }; diff --git a/content/events/src/nsDOMTouchEvent.cpp b/content/events/src/nsDOMTouchEvent.cpp index 0a44cd60167..e053aff703d 100644 --- a/content/events/src/nsDOMTouchEvent.cpp +++ b/content/events/src/nsDOMTouchEvent.cpp @@ -63,7 +63,9 @@ nsDOMTouchEvent::nsDOMTouchEvent(mozilla::dom::EventTarget* aOwner, mEventIsInternal = false; for (uint32_t i = 0; i < aEvent->touches.Length(); ++i) { - aEvent->touches[i]->InitializePoints(mPresContext, aEvent); + nsIDOMTouch *touch = aEvent->touches[i]; + dom::Touch *domtouch = static_cast(touch); + domtouch->InitializePoints(mPresContext, aEvent); } } else { mEventIsInternal = true; diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index 0e41ead5366..a33d9d1dc7e 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -1557,7 +1557,7 @@ nsEventStateManager::MapEventCoordinatesForChildProcess( // in the space where top-left is 0,0. const nsTArray< nsRefPtr >& touches = touchEvent->touches; for (uint32_t i = 0; i < touches.Length(); ++i) { - Touch* touch = touches[i]; + nsIDOMTouch* touch = touches[i]; if (touch) { touch->mRefPoint += aOffsetIntPoint; } @@ -1641,7 +1641,7 @@ nsEventStateManager::HandleCrossProcessEvent(nsEvent *aEvent, nsTouchEvent* touchEvent = static_cast(aEvent); const nsTArray< nsRefPtr >& touches = touchEvent->touches; for (uint32_t i = 0; i < touches.Length(); ++i) { - Touch* touch = touches[i]; + nsIDOMTouch* touch = touches[i]; // NB: the |mChanged| check is an optimization, subprocesses can // compute this for themselves. If the touch hasn't changed, we // may be able to avoid forwarding the event entirely (which is diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index fe4e229fd7d..8ed4be2c02f 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -62,7 +62,6 @@ #include "mozilla/dom/Gamepad.h" #endif #include "nsIDocument.h" -#include "nsIDOMTouchEvent.h" #include "mozilla/dom/EventTarget.h" #include "Units.h" diff --git a/dom/interfaces/events/nsIDOMTouchEvent.idl b/dom/interfaces/events/nsIDOMTouchEvent.idl index e3e76009482..fbd2e9949b5 100644 --- a/dom/interfaces/events/nsIDOMTouchEvent.idl +++ b/dom/interfaces/events/nsIDOMTouchEvent.idl @@ -4,6 +4,39 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsIDOMUIEvent.idl" +%{C++ +#include "nsWeakPtr.h" +#include "nsPoint.h" +%} +interface nsIVariant; + +/** + * @see http://dvcs.w3.org/hg/webevents/raw-file/tip/touchevents.html + */ + +[scriptable, builtinclass, uuid(98bc0f7d-5bff-4387-9c42-58af54b48dd5)] +interface nsIDOMTouch : nsISupports { + readonly attribute long identifier; + readonly attribute nsIDOMEventTarget target; + readonly attribute long pageX; + readonly attribute long pageY; + readonly attribute long screenX; + readonly attribute long screenY; + readonly attribute long clientX; + readonly attribute long clientY; + readonly attribute long radiusX; + readonly attribute long radiusY; + readonly attribute float rotationAngle; + readonly attribute float force; + %{C++ + nsCOMPtr mTarget; + mozilla::dom::EventTarget *GetTarget() { return mTarget; } + void SetTarget(mozilla::dom::EventTarget *target) { mTarget = target; } + nsIntPoint mRefPoint; + bool mChanged; + uint32_t mMessage; + %} +}; [scriptable, uuid(6d5484f7-92ac-45f8-9388-39b5bad055ce)] interface nsITouchEventReceiver : nsISupports { diff --git a/gfx/layers/ipc/AsyncPanZoomController.cpp b/gfx/layers/ipc/AsyncPanZoomController.cpp index dfa49bf2ef2..50776b667cf 100644 --- a/gfx/layers/ipc/AsyncPanZoomController.cpp +++ b/gfx/layers/ipc/AsyncPanZoomController.cpp @@ -270,7 +270,7 @@ AsyncPanZoomController::ReceiveInputEvent(const nsInputEvent& aEvent, nsTouchEvent* touchEvent = static_cast(aOutEvent); const nsTArray< nsRefPtr >& touches = touchEvent->touches; for (uint32_t i = 0; i < touches.Length(); ++i) { - dom::Touch* touch = touches[i]; + nsIDOMTouch* touch = touches[i]; if (touch) { CSSPoint refCSSPoint = WidgetSpaceToCompensatedViewportSpace( ScreenPoint::FromUnknownPoint(gfx::Point( diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 6b6db07ccb9..826a977a4ca 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -6886,7 +6886,7 @@ PresShell::DispatchTouchEvent(nsEvent *aEvent, // loop over all touches and dispatch events on any that have changed for (uint32_t i = 0; i < touchEvent->touches.Length(); ++i) { - Touch *touch = touchEvent->touches[i]; + nsIDOMTouch *touch = touchEvent->touches[i]; if (!touch || !touch->mChanged) { continue; } diff --git a/layout/xul/base/src/nsBoxFrame.cpp b/layout/xul/base/src/nsBoxFrame.cpp index cc574ea53ef..fbd75e6f0d9 100644 --- a/layout/xul/base/src/nsBoxFrame.cpp +++ b/layout/xul/base/src/nsBoxFrame.cpp @@ -2077,7 +2077,7 @@ nsBoxFrame::GetEventPoint(nsGUIEvent* aEvent, nsIntPoint &aPoint) { return false; } - Touch *touch = touchEvent->touches.SafeElementAt(0); + nsIDOMTouch *touch = touchEvent->touches.SafeElementAt(0); if (!touch) { return false; } diff --git a/widget/InputData.h b/widget/InputData.h index 6dd7127c665..4d2d05cd808 100644 --- a/widget/InputData.h +++ b/widget/InputData.h @@ -70,11 +70,11 @@ protected: /** * Data container for a single touch input. Similar to dom::Touch, but used in * off-main-thread situations. This is more for just storing touch data, whereas - * dom::Touch is more useful for dispatching through the DOM (which can only - * happen on the main thread). dom::Touch also bears the problem of storing - * pointers to nsIWidget instances which can only be used on the main thread, - * so if instead we used dom::Touch and ever set these pointers - * off-main-thread, Bad Things Can Happen(tm). + * dom::Touch derives from nsIDOMTouch so it is more useful for dispatching + * through the DOM (which can only happen on the main thread). dom::Touch also + * bears the problem of storing pointers to nsIWidget instances which can only + * be used on the main thread, so if instead we used dom::Touch and ever set + * these pointers off-main-thread, Bad Things Can Happen(tm). * * Note that this doesn't inherit from InputData because this itself is not an * event. It is only a container/struct that should have any number of instances diff --git a/widget/xpwidgets/InputData.cpp b/widget/xpwidgets/InputData.cpp index 7b6cc45a90a..73edfeada44 100644 --- a/widget/xpwidgets/InputData.cpp +++ b/widget/xpwidgets/InputData.cpp @@ -47,14 +47,22 @@ MultiTouchInput::MultiTouchInput(const nsTouchEvent& aTouchEvent) for (size_t i = 0; i < aTouchEvent.touches.Length(); i++) { Touch* domTouch = static_cast(aTouchEvent.touches[i].get()); - SingleTouchData data(domTouch->Identifier(), + // Extract data from weird interfaces. + int32_t identifier, radiusX, radiusY; + float rotationAngle, force; + domTouch->GetIdentifier(&identifier); + domTouch->GetRadiusX(&radiusX); + domTouch->GetRadiusY(&radiusY); + domTouch->GetRotationAngle(&rotationAngle); + domTouch->GetForce(&force); + + SingleTouchData data(identifier, ScreenIntPoint::FromUnknownPoint( gfx::IntPoint(domTouch->mRefPoint.x, domTouch->mRefPoint.y)), - ScreenSize(domTouch->RadiusX(), - domTouch->RadiusY()), - domTouch->RotationAngle(), - domTouch->Force()); + ScreenSize(radiusX, radiusY), + rotationAngle, + force); mTouches.AppendElement(data); }