Bug 900096 - Cleanup Touch some; r=dzbarsky
authorMs2ger <ms2ger@gmail.com>
Fri, 02 Aug 2013 09:06:35 +0200
changeset 148530 4782b24db6b3666ff979da12da29d8523efeff2b
parent 148529 d26846484b7c2ac8db05e2618f19c84900f2c8f2
child 148531 136f1614f09240b3e9bc9032d0fe8ca70570f2ca
push id4085
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 20:29:25 +0000
treeherdermozilla-aurora@ede8780a15bc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdzbarsky
bugs900096
milestone25.0a1
Bug 900096 - Cleanup Touch some; r=dzbarsky
content/events/src/Touch.cpp
content/events/src/Touch.h
content/events/src/nsDOMTouchEvent.cpp
content/events/src/nsEventStateManager.cpp
dom/interfaces/events/nsIDOMTouchEvent.idl
gfx/layers/ipc/AsyncPanZoomController.cpp
layout/base/nsPresShell.cpp
layout/xul/base/src/nsBoxFrame.cpp
widget/xpwidgets/InputData.cpp
--- a/content/events/src/Touch.cpp
+++ b/content/events/src/Touch.cpp
@@ -141,29 +141,23 @@ Touch::InitializePoints(nsPresContext* a
     aPresContext, aEvent, LayoutDeviceIntPoint::FromUntyped(mRefPoint),
     mClientPoint);
   mScreenPoint = nsDOMEvent::GetScreenCoords(aPresContext, aEvent,
     LayoutDeviceIntPoint::FromUntyped(mRefPoint));
   mPointsInitialized = true;
 }
 
 bool
-Touch::Equals(nsIDOMTouch* aTouch)
+Touch::Equals(Touch* 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 != force) ||
-         (mRotationAngle != orientation) ||
-         (mRadius.x != radiusX) || (mRadius.y != radiusY);
+  return mRefPoint == aTouch->mRefPoint &&
+         mForce == aTouch->Force() &&
+         mRotationAngle == aTouch->RotationAngle() &&
+         mRadius.x == aTouch->RadiusX() &&
+         mRadius.y == aTouch->RadiusY();
 }
 
 /* virtual */ JSObject*
 Touch::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
 {
   return TouchBinding::Wrap(aCx, aScope, this);
 }
 
--- a/content/events/src/Touch.h
+++ b/content/events/src/Touch.h
@@ -80,17 +80,17 @@ public:
   NS_DECL_NSIDOMTOUCH
 
   void InitializePoints(nsPresContext* aPresContext, nsEvent* aEvent);
 
   void SetTarget(mozilla::dom::EventTarget *aTarget)
   {
     mTarget = aTarget;
   }
-  bool Equals(nsIDOMTouch* aTouch);
+  bool Equals(Touch* aTouch);
 
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
   EventTarget* GetParentObject() { return mTarget; }
 
   // WebIDL
   int32_t Identifier() const { return mIdentifier; }
   EventTarget* Target() const;
@@ -100,16 +100,20 @@ public:
   int32_t ClientY() const { return mClientPoint.y; }
   int32_t PageX() const { return mPagePoint.x; }
   int32_t PageY() const { return mPagePoint.y; }
   int32_t RadiusX() const { return mRadius.x; }
   int32_t RadiusY() const { return mRadius.y; }
   float RotationAngle() const { return mRotationAngle; }
   float Force() const { return mForce; }
 
+  nsCOMPtr<EventTarget> mTarget;
+  nsIntPoint mRefPoint;
+  bool mChanged;
+  uint32_t mMessage;
   int32_t mIdentifier;
   CSSIntPoint mPagePoint;
   CSSIntPoint mClientPoint;
   nsIntPoint mScreenPoint;
   nsIntPoint mRadius;
   float mRotationAngle;
   float mForce;
 protected:
--- a/content/events/src/nsDOMTouchEvent.cpp
+++ b/content/events/src/nsDOMTouchEvent.cpp
@@ -80,19 +80,18 @@ nsDOMTouchEvent::nsDOMTouchEvent(mozilla
                                  nsTouchEvent* aEvent)
   : nsDOMUIEvent(aOwner, aPresContext,
                  aEvent ? aEvent : new nsTouchEvent(false, 0, nullptr))
 {
   if (aEvent) {
     mEventIsInternal = false;
 
     for (uint32_t i = 0; i < aEvent->touches.Length(); ++i) {
-      nsIDOMTouch *touch = aEvent->touches[i];
-      dom::Touch *domtouch = static_cast<dom::Touch*>(touch);
-      domtouch->InitializePoints(mPresContext, aEvent);
+      Touch* touch = aEvent->touches[i];
+      touch->InitializePoints(mPresContext, aEvent);
     }
   } else {
     mEventIsInternal = true;
     mEvent->time = PR_Now();
   }
 }
 
 nsDOMTouchEvent::~nsDOMTouchEvent()
--- a/content/events/src/nsEventStateManager.cpp
+++ b/content/events/src/nsEventStateManager.cpp
@@ -1552,17 +1552,17 @@ nsEventStateManager::MapEventCoordinates
     aEvent->refPoint = aOffset;
   } else {
     aEvent->refPoint = LayoutDeviceIntPoint();
     nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aEvent);
     // Then offset all the touch points by that distance, to put them
     // in the space where top-left is 0,0.
     const nsTArray< nsRefPtr<Touch> >& touches = touchEvent->touches;
     for (uint32_t i = 0; i < touches.Length(); ++i) {
-      nsIDOMTouch* touch = touches[i];
+      Touch* touch = touches[i];
       if (touch) {
         touch->mRefPoint += LayoutDeviceIntPoint::ToUntyped(aOffset);
       }
     }
   }
 }
 
 /*static*/ void
@@ -1636,25 +1636,25 @@ nsEventStateManager::HandleCrossProcessE
     // all of them and collect the unique set of targets for event
     // forwarding.
     //
     // This loop is similar to the one used in
     // PresShell::DispatchTouchEvent().
     nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aEvent);
     const nsTArray< nsRefPtr<Touch> >& touches = touchEvent->touches;
     for (uint32_t i = 0; i < touches.Length(); ++i) {
-      nsIDOMTouch* touch = touches[i];
+      Touch* 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
       // not free).
       if (!touch || !touch->mChanged) {
         continue;
       }
-      nsCOMPtr<EventTarget> targetPtr = touch->GetTarget();
+      nsCOMPtr<EventTarget> targetPtr = touch->mTarget;
       if (!targetPtr) {
         continue;
       }
       nsCOMPtr<nsIContent> target = do_QueryInterface(targetPtr);
       if (IsRemoteTarget(target) && !targets.Contains(target)) {
         targets.AppendElement(target);
       }
     }
--- a/dom/interfaces/events/nsIDOMTouchEvent.idl
+++ b/dom/interfaces/events/nsIDOMTouchEvent.idl
@@ -9,38 +9,30 @@
 #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)]
+[scriptable, builtinclass, uuid(2311671f-ff7e-43d2-adfb-d9e07006955e)]
 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<mozilla::dom::EventTarget> mTarget;
-    mozilla::dom::EventTarget *GetTarget() { return mTarget; }
-    void SetTarget(mozilla::dom::EventTarget *target) { mTarget = target; }
-    nsIntPoint mRefPoint;
-    bool mChanged;
-    uint32_t mMessage;
-  %}
 };
 
 [scriptable, builtinclass, uuid(60706eb7-d50d-4379-b01c-e78e6af84213)]
 interface nsIDOMTouchList : nsISupports {
   readonly attribute unsigned long length;
   nsIDOMTouch item(in unsigned long index);
   nsIDOMTouch identifiedTouch(in long identifier);
 };
--- a/gfx/layers/ipc/AsyncPanZoomController.cpp
+++ b/gfx/layers/ipc/AsyncPanZoomController.cpp
@@ -274,17 +274,17 @@ AsyncPanZoomController::ReceiveInputEven
     break;
   }
 
   switch (aEvent.eventStructType) {
   case NS_TOUCH_EVENT: {
     nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aOutEvent);
     const nsTArray< nsRefPtr<dom::Touch> >& touches = touchEvent->touches;
     for (uint32_t i = 0; i < touches.Length(); ++i) {
-      nsIDOMTouch* touch = touches[i];
+      dom::Touch* touch = touches[i];
       if (touch) {
         CSSPoint refCSSPoint = WidgetSpaceToCompensatedViewportSpace(
           ScreenPoint::FromUnknownPoint(gfx::Point(
             touch->mRefPoint.x, touch->mRefPoint.y)),
           currentResolution);
         LayoutDevicePoint refPoint = refCSSPoint * mFrameMetrics.mDevPixelsPerCSSPixel;
         touch->mRefPoint = nsIntPoint(refPoint.x, refPoint.y);
       }
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -6730,17 +6730,17 @@ PresShell::HandleEventInternal(nsEvent* 
           int32_t id = touch->Identifier();
           touch->mMessage = aEvent->message;
 
           nsRefPtr<dom::Touch> oldTouch = gCaptureTouchList.GetWeak(id);
           if (!oldTouch) {
             touches.RemoveElementAt(i);
             continue;
           }
-          if (touch->Equals(oldTouch)) {
+          if (!touch->Equals(oldTouch)) {
             touch->mChanged = true;
             haveChanged = true;
           }
 
           nsCOMPtr<dom::EventTarget> targetPtr = oldTouch->mTarget;
           if (!targetPtr) {
             touches.RemoveElementAt(i);
             continue;
@@ -6882,22 +6882,22 @@ PresShell::DispatchTouchEvent(nsEvent *a
   bool canPrevent = aEvent->message == NS_TOUCH_START ||
               (aEvent->message == NS_TOUCH_MOVE && aTouchIsNew);
   bool preventDefault = false;
   nsEventStatus tmpStatus = nsEventStatus_eIgnore;
   nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aEvent);
 
   // loop over all touches and dispatch events on any that have changed
   for (uint32_t i = 0; i < touchEvent->touches.Length(); ++i) {
-    nsIDOMTouch *touch = touchEvent->touches[i];
+    dom::Touch* touch = touchEvent->touches[i];
     if (!touch || !touch->mChanged) {
       continue;
     }
 
-    nsCOMPtr<EventTarget> targetPtr = touch->GetTarget();
+    nsCOMPtr<EventTarget> targetPtr = touch->mTarget;
     nsCOMPtr<nsIContent> content = do_QueryInterface(targetPtr);
     if (!content) {
       continue;
     }
 
     nsIDocument* doc = content->OwnerDoc();
     nsIContent* capturingContent = GetCapturingContent();
     if (capturingContent) {
--- a/layout/xul/base/src/nsBoxFrame.cpp
+++ b/layout/xul/base/src/nsBoxFrame.cpp
@@ -2072,19 +2072,18 @@ nsBoxFrame::GetEventPoint(nsGUIEvent* aE
   if (aEvent->eventStructType == NS_TOUCH_EVENT) {
     nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aEvent);
     // return false if there is more than one touch on the page, or if
     // we can't find a touch point
     if (touchEvent->touches.Length() != 1) {
       return false;
     }
 
-    nsIDOMTouch *touch = touchEvent->touches.SafeElementAt(0);
+    dom::Touch* touch = touchEvent->touches.SafeElementAt(0);
     if (!touch) {
       return false;
     }
-    Touch* domtouch = static_cast<Touch*>(touch);
-    aPoint = domtouch->mRefPoint;
+    aPoint = touch->mRefPoint;
   } else {
     aPoint = LayoutDeviceIntPoint::ToUntyped(aEvent->refPoint);
   }
   return true;
 }
--- a/widget/xpwidgets/InputData.cpp
+++ b/widget/xpwidgets/InputData.cpp
@@ -40,26 +40,24 @@ MultiTouchInput::MultiTouchInput(const n
       mType = MULTITOUCH_CANCEL;
       break;
     default:
       NS_WARNING("Did not assign a type to a MultiTouchInput");
       break;
   }
 
   for (size_t i = 0; i < aTouchEvent.touches.Length(); i++) {
-    Touch* domTouch = static_cast<Touch*>(aTouchEvent.touches[i].get());
+    const Touch* domTouch = aTouchEvent.touches[i];
 
     // 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);
+    int32_t identifier = domTouch->Identifier();
+    int32_t radiusX = domTouch->RadiusX();
+    int32_t radiusY = domTouch->RadiusY();
+    float rotationAngle = domTouch->RotationAngle();
+    float force = domTouch->Force();
 
     SingleTouchData data(identifier,
                          ScreenIntPoint::FromUnknownPoint(
                            gfx::IntPoint(domTouch->mRefPoint.x,
                                          domTouch->mRefPoint.y)),
                          ScreenSize(radiusX, radiusY),
                          rotationAngle,
                          force);