Bug 864145 - Cleanup nsDOMTouchEvent's TouchList getters; r=smaug
authorMs2ger <ms2ger@gmail.com>
Fri, 26 Apr 2013 08:48:00 +0200
changeset 140853 74182501aee7636033143c48eaae15ae66dae021
parent 140852 9805808576277d742e903eee4d6b85084bb52d67
child 140854 0fa3623e2a718894e5d7bebe75a242441e05895d
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs864145
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 864145 - Cleanup nsDOMTouchEvent's TouchList getters; r=smaug
content/events/src/nsDOMTouchEvent.cpp
content/events/src/nsDOMTouchEvent.h
dom/interfaces/events/nsIDOMTouchEvent.idl
dom/webidl/TouchEvent.webidl
--- a/content/events/src/nsDOMTouchEvent.cpp
+++ b/content/events/src/nsDOMTouchEvent.cpp
@@ -138,99 +138,106 @@ nsDOMTouchEvent::InitTouchEvent(const ns
                                           aCanBubble,
                                           aCancelable,
                                           aView,
                                           aDetail);
   NS_ENSURE_SUCCESS(rv, rv);
 
   static_cast<nsInputEvent*>(mEvent)->InitBasicModifiers(aCtrlKey, aAltKey,
                                                          aShiftKey, aMetaKey);
-  mTouches = aTouches;
-  mTargetTouches = aTargetTouches;
-  mChangedTouches = aChangedTouches;
+  mTouches = static_cast<nsDOMTouchList*>(aTouches);
+  mTargetTouches = static_cast<nsDOMTouchList*>(aTargetTouches);
+  mChangedTouches = static_cast<nsDOMTouchList*>(aChangedTouches);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMTouchEvent::GetTouches(nsIDOMTouchList** aTouches)
 {
   NS_ENSURE_ARG_POINTER(aTouches);
-  NS_ENSURE_STATE(mEvent);
-  nsRefPtr<nsDOMTouchList> t;
-
-  if (mTouches) {
-    return CallQueryInterface(mTouches, aTouches);
-  }
+  NS_ADDREF(*aTouches = Touches());
+  return NS_OK;
+}
 
-  nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
-  if (mEvent->message == NS_TOUCH_END || mEvent->message == NS_TOUCH_CANCEL) {
-    // for touchend events, remove any changed touches from the touches array
-    nsTArray<nsCOMPtr<nsIDOMTouch> > unchangedTouches;
-    const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
-    for (uint32_t i = 0; i < touches.Length(); ++i) {
-      if (!touches[i]->mChanged) {
-        unchangedTouches.AppendElement(touches[i]);
+nsDOMTouchList*
+nsDOMTouchEvent::Touches()
+{
+  if (!mTouches) {
+    nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
+    if (mEvent->message == NS_TOUCH_END || mEvent->message == NS_TOUCH_CANCEL) {
+      // for touchend events, remove any changed touches from the touches array
+      nsTArray<nsCOMPtr<nsIDOMTouch> > unchangedTouches;
+      const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
+      for (uint32_t i = 0; i < touches.Length(); ++i) {
+        if (!touches[i]->mChanged) {
+          unchangedTouches.AppendElement(touches[i]);
+        }
       }
+      mTouches = new nsDOMTouchList(unchangedTouches);
+    } else {
+      mTouches = new nsDOMTouchList(touchEvent->touches);
     }
-    t = new nsDOMTouchList(unchangedTouches);
-  } else {
-    t = new nsDOMTouchList(touchEvent->touches);
   }
-  mTouches = t;
-  return CallQueryInterface(mTouches, aTouches);
+  return mTouches;
 }
 
 NS_IMETHODIMP
 nsDOMTouchEvent::GetTargetTouches(nsIDOMTouchList** aTargetTouches)
 {
   NS_ENSURE_ARG_POINTER(aTargetTouches);
-  NS_ENSURE_STATE(mEvent);
-
-  if (mTargetTouches) {
-    return CallQueryInterface(mTargetTouches, aTargetTouches);
-  }
+  NS_ADDREF(*aTargetTouches = TargetTouches());
+  return NS_OK;
+}
 
-  nsTArray<nsCOMPtr<nsIDOMTouch> > targetTouches;
-  nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
-  const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
-  for (uint32_t i = 0; i < touches.Length(); ++i) {
-    // for touchend/cancel events, don't append to the target list if this is a
-    // touch that is ending
-    if ((mEvent->message != NS_TOUCH_END &&
-         mEvent->message != NS_TOUCH_CANCEL) || !touches[i]->mChanged) {
-      EventTarget* targetPtr = touches[i]->GetTarget();
-      if (targetPtr == mEvent->originalTarget) {
-        targetTouches.AppendElement(touches[i]);
+nsDOMTouchList*
+nsDOMTouchEvent::TargetTouches()
+{
+  if (!mTargetTouches) {
+    nsTArray<nsCOMPtr<nsIDOMTouch> > targetTouches;
+    nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
+    const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
+    for (uint32_t i = 0; i < touches.Length(); ++i) {
+      // for touchend/cancel events, don't append to the target list if this is a
+      // touch that is ending
+      if ((mEvent->message != NS_TOUCH_END &&
+           mEvent->message != NS_TOUCH_CANCEL) || !touches[i]->mChanged) {
+        EventTarget* targetPtr = touches[i]->GetTarget();
+        if (targetPtr == mEvent->originalTarget) {
+          targetTouches.AppendElement(touches[i]);
+        }
       }
     }
+    mTargetTouches = new nsDOMTouchList(targetTouches);
   }
-  mTargetTouches = new nsDOMTouchList(targetTouches);
-  return CallQueryInterface(mTargetTouches, aTargetTouches);
+  return mTargetTouches;
 }
 
 NS_IMETHODIMP
 nsDOMTouchEvent::GetChangedTouches(nsIDOMTouchList** aChangedTouches)
 {
   NS_ENSURE_ARG_POINTER(aChangedTouches);
-  NS_ENSURE_STATE(mEvent);
-
-  if (mChangedTouches) {
-    return CallQueryInterface(mChangedTouches, aChangedTouches);
-  }
+  NS_ADDREF(*aChangedTouches = ChangedTouches());
+  return NS_OK;
+}
 
-  nsTArray<nsCOMPtr<nsIDOMTouch> > changedTouches;
-  nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
-  const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
-  for (uint32_t i = 0; i < touches.Length(); ++i) {
-    if (touches[i]->mChanged) {
-      changedTouches.AppendElement(touches[i]);
+nsDOMTouchList*
+nsDOMTouchEvent::ChangedTouches()
+{
+  if (!mChangedTouches) {
+    nsTArray<nsCOMPtr<nsIDOMTouch> > changedTouches;
+    nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
+    const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
+    for (uint32_t i = 0; i < touches.Length(); ++i) {
+      if (touches[i]->mChanged) {
+        changedTouches.AppendElement(touches[i]);
+      }
     }
+    mChangedTouches = new nsDOMTouchList(changedTouches);
   }
-  mChangedTouches = new nsDOMTouchList(changedTouches);
-  return CallQueryInterface(mChangedTouches, aChangedTouches);
+  return mChangedTouches;
 }
 
 NS_IMETHODIMP
 nsDOMTouchEvent::GetAltKey(bool* aAltKey)
 {
   *aAltKey = AltKey();
   return NS_OK;
 }
--- a/content/events/src/nsDOMTouchEvent.h
+++ b/content/events/src/nsDOMTouchEvent.h
@@ -55,36 +55,19 @@ public:
   NS_FORWARD_TO_NSDOMUIEVENT
 
   virtual JSObject* WrapObject(JSContext* aCx,
 			       JS::Handle<JSObject*> aScope) MOZ_OVERRIDE
   {
     return mozilla::dom::TouchEventBinding::Wrap(aCx, aScope, this);
   }
 
-  already_AddRefed<nsIDOMTouchList> GetTouches()
-  {
-    nsCOMPtr<nsIDOMTouchList> t;
-    GetTouches(getter_AddRefs(t));
-    return t.forget();
-  }
-
-  already_AddRefed<nsIDOMTouchList> GetTargetTouches()
-  {
-    nsCOMPtr<nsIDOMTouchList> t;
-    GetTargetTouches(getter_AddRefs(t));
-    return t.forget();
-  }
-
-  already_AddRefed<nsIDOMTouchList> GetChangedTouches()
-  {
-    nsCOMPtr<nsIDOMTouchList> t;
-    GetChangedTouches(getter_AddRefs(t));
-    return t.forget();
-  }
+  nsDOMTouchList* Touches();
+  nsDOMTouchList* TargetTouches();
+  nsDOMTouchList* ChangedTouches();
 
   bool AltKey()
   {
     return static_cast<nsInputEvent*>(mEvent)->IsAlt();
   }
 
   bool MetaKey()
   {
@@ -117,14 +100,14 @@ public:
   {
     aRv = InitTouchEvent(aType, aCanBubble, aCancelable, aView, aDetail,
                          aCtrlKey, aAltKey, aShiftKey, aMetaKey,
                          aTouches, aTargetTouches, aChangedTouches);
   }
 
   static bool PrefEnabled();
 protected:
-  nsCOMPtr<nsIDOMTouchList> mTouches;
-  nsCOMPtr<nsIDOMTouchList> mTargetTouches;
-  nsCOMPtr<nsIDOMTouchList> mChangedTouches;
+  nsRefPtr<nsDOMTouchList> mTouches;
+  nsRefPtr<nsDOMTouchList> mTargetTouches;
+  nsRefPtr<nsDOMTouchList> mChangedTouches;
 };
 
 #endif /* !defined(nsDOMTouchEvent_h_) */
--- a/dom/interfaces/events/nsIDOMTouchEvent.idl
+++ b/dom/interfaces/events/nsIDOMTouchEvent.idl
@@ -33,17 +33,17 @@ interface nsIDOMTouch : nsISupports {
     mozilla::dom::EventTarget *GetTarget() { return mTarget; }
     void SetTarget(mozilla::dom::EventTarget *target) { mTarget = target; }
     nsIntPoint mRefPoint;
     bool mChanged;
     uint32_t mMessage;
   %}
 };
 
-[scriptable, uuid(60706eb7-d50d-4379-b01c-e78e6af84213)]
+[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);
 };
 
 [scriptable, builtinclass, uuid(9a043d55-f59e-4790-8fc7-1fab1c727732)]
 interface nsIDOMTouchEvent : nsIDOMUIEvent {
--- a/dom/webidl/TouchEvent.webidl
+++ b/dom/webidl/TouchEvent.webidl
@@ -4,19 +4,19 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
 interface TouchList;
 interface WindowProxy;
 
 [PrefControlled]
 interface TouchEvent : UIEvent {
-  readonly attribute TouchList? touches;
-  readonly attribute TouchList? targetTouches;
-  readonly attribute TouchList? changedTouches;
+  readonly attribute TouchList touches;
+  readonly attribute TouchList targetTouches;
+  readonly attribute TouchList changedTouches;
 
   readonly attribute boolean altKey;
   readonly attribute boolean metaKey;
   readonly attribute boolean ctrlKey;
   readonly attribute boolean shiftKey;
 
   [Throws]
   void initTouchEvent(DOMString type,