diff --git a/content/events/src/nsDOMTouchEvent.cpp b/content/events/src/nsDOMTouchEvent.cpp index 033dd72fb059..a1dd0952f0db 100644 --- a/content/events/src/nsDOMTouchEvent.cpp +++ b/content/events/src/nsDOMTouchEvent.cpp @@ -15,7 +15,7 @@ using namespace mozilla; using namespace mozilla::dom; // TouchList -nsDOMTouchList::nsDOMTouchList(nsTArray > &aTouches) +nsDOMTouchList::nsDOMTouchList(const nsTArray< nsRefPtr >& aTouches) { mPoints.AppendElements(aTouches); nsJSContext::LikelyShortLivingObjectCreated(); @@ -53,11 +53,9 @@ nsDOMTouchList::IdentifiedTouch(int32_t aIdentifier, nsIDOMTouch** aRetVal) { *aRetVal = nullptr; for (uint32_t i = 0; i < mPoints.Length(); ++i) { - nsCOMPtr point = mPoints[i]; - int32_t identifier; - if (point && NS_SUCCEEDED(point->GetIdentifier(&identifier)) && - aIdentifier == identifier) { - point.swap(*aRetVal); + nsRefPtr point = mPoints[i]; + if (point && point->Identifier() == aIdentifier) { + point.forget(aRetVal); break; } } @@ -151,8 +149,8 @@ nsDOMTouchEvent::Touches() nsTouchEvent* touchEvent = static_cast(mEvent); if (mEvent->message == NS_TOUCH_END || mEvent->message == NS_TOUCH_CANCEL) { // for touchend events, remove any changed touches from the touches array - nsTArray > unchangedTouches; - const nsTArray >& touches = touchEvent->touches; + nsTArray< nsRefPtr > unchangedTouches; + const nsTArray< nsRefPtr >& touches = touchEvent->touches; for (uint32_t i = 0; i < touches.Length(); ++i) { if (!touches[i]->mChanged) { unchangedTouches.AppendElement(touches[i]); @@ -178,16 +176,15 @@ nsDOMTouchList* nsDOMTouchEvent::TargetTouches() { if (!mTargetTouches) { - nsTArray > targetTouches; + nsTArray< nsRefPtr > targetTouches; nsTouchEvent* touchEvent = static_cast(mEvent); - const nsTArray >& touches = touchEvent->touches; + const nsTArray< nsRefPtr >& 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) { + if (touches[i]->mTarget == mEvent->originalTarget) { targetTouches.AppendElement(touches[i]); } } @@ -209,9 +206,9 @@ nsDOMTouchList* nsDOMTouchEvent::ChangedTouches() { if (!mChangedTouches) { - nsTArray > changedTouches; + nsTArray< nsRefPtr > changedTouches; nsTouchEvent* touchEvent = static_cast(mEvent); - const nsTArray >& touches = touchEvent->touches; + const nsTArray< nsRefPtr >& touches = touchEvent->touches; for (uint32_t i = 0; i < touches.Length(); ++i) { if (touches[i]->mChanged) { changedTouches.AppendElement(touches[i]); diff --git a/content/events/src/nsDOMTouchEvent.h b/content/events/src/nsDOMTouchEvent.h index 9fbf5699795e..44152da894b1 100644 --- a/content/events/src/nsDOMTouchEvent.h +++ b/content/events/src/nsDOMTouchEvent.h @@ -15,6 +15,8 @@ class nsDOMTouchList MOZ_FINAL : public nsIDOMTouchList { + typedef mozilla::dom::Touch Touch; + public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_CLASS(nsDOMTouchList) @@ -24,9 +26,9 @@ public: { nsJSContext::LikelyShortLivingObjectCreated(); } - nsDOMTouchList(nsTArray > &aTouches); + nsDOMTouchList(const nsTArray< nsRefPtr >& aTouches); - void Append(nsIDOMTouch* aPoint) + void Append(Touch* aPoint) { mPoints.AppendElement(aPoint); } @@ -37,7 +39,7 @@ public: } protected: - nsTArray > mPoints; + nsTArray< nsRefPtr > mPoints; }; class nsDOMTouchEvent : public nsDOMUIEvent, diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index 7a23186405c6..48aa7a9de744 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -1553,7 +1553,7 @@ nsEventStateManager::MapEventCoordinatesForChildProcess( nsTouchEvent* touchEvent = static_cast(aEvent); // Then offset all the touch points by that distance, to put them // in the space where top-left is 0,0. - const nsTArray >& touches = touchEvent->touches; + const nsTArray< nsRefPtr >& touches = touchEvent->touches; for (uint32_t i = 0; i < touches.Length(); ++i) { nsIDOMTouch* touch = touches[i]; if (touch) { @@ -1637,7 +1637,7 @@ nsEventStateManager::HandleCrossProcessEvent(nsEvent *aEvent, // This loop is similar to the one used in // PresShell::DispatchTouchEvent(). nsTouchEvent* touchEvent = static_cast(aEvent); - const nsTArray >& touches = touchEvent->touches; + const nsTArray< nsRefPtr >& touches = touchEvent->touches; for (uint32_t i = 0; i < touches.Length(); ++i) { nsIDOMTouch* touch = touches[i]; // NB: the |mChanged| check is an optimization, subprocesses can diff --git a/gfx/layers/ipc/AsyncPanZoomController.cpp b/gfx/layers/ipc/AsyncPanZoomController.cpp index e3996ce25523..48a64c7517e3 100644 --- a/gfx/layers/ipc/AsyncPanZoomController.cpp +++ b/gfx/layers/ipc/AsyncPanZoomController.cpp @@ -269,7 +269,7 @@ AsyncPanZoomController::ReceiveInputEvent(const nsInputEvent& aEvent, switch (aEvent.eventStructType) { case NS_TOUCH_EVENT: { nsTouchEvent* touchEvent = static_cast(aOutEvent); - const nsTArray >& touches = touchEvent->touches; + const nsTArray< nsRefPtr >& touches = touchEvent->touches; for (uint32_t i = 0; i < touches.Length(); ++i) { nsIDOMTouch* touch = touches[i]; if (touch) { diff --git a/layout/base/nsIPresShell.h b/layout/base/nsIPresShell.h index 5ab3aff4801a..223517e2d4fd 100644 --- a/layout/base/nsIPresShell.h +++ b/layout/base/nsIPresShell.h @@ -36,7 +36,7 @@ #include // for FILE definition #include "nsChangeHint.h" #include "nsGUIEvent.h" -#include "nsInterfaceHashtable.h" +#include "nsRefPtrHashtable.h" #include "nsEventStates.h" #include "nsPresArena.h" #include "nsIImageLoadingContent.h" @@ -1129,7 +1129,7 @@ public: static CapturingContentInfo gCaptureInfo; - static nsInterfaceHashtable gCaptureTouchList; + static nsRefPtrHashtable gCaptureTouchList; static bool gPreventMouseEvents; /** diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 2735bb9c68d1..d1f94b8d643a 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -198,7 +198,7 @@ CapturingContentInfo nsIPresShell::gCaptureInfo = { false /* mAllowed */, false /* mPointerLock */, false /* mRetargetToElement */, false /* mPreventDrag */, nullptr /* mContent */ }; nsIContent* nsIPresShell::gKeyDownTarget; -nsInterfaceHashtable nsIPresShell::gCaptureTouchList; +nsRefPtrHashtable nsIPresShell::gCaptureTouchList; bool nsIPresShell::gPreventMouseEvents = false; // convert a color value to a string, in the CSS format #RRGGBB @@ -5862,11 +5862,11 @@ PresShell::RecordMouseLocation(nsGUIEvent* aEvent) } static void -EvictTouchPoint(nsCOMPtr& aTouch) +EvictTouchPoint(nsRefPtr& aTouch) { nsIWidget *widget = nullptr; // is there an easier/better way to dig out the widget? - nsCOMPtr node(do_QueryInterface(aTouch->GetTarget())); + nsCOMPtr node(do_QueryInterface(aTouch->mTarget)); if (!node) { return; } @@ -5899,21 +5899,21 @@ EvictTouchPoint(nsCOMPtr& aTouch) } static PLDHashOperator -AppendToTouchList(const uint32_t& aKey, nsCOMPtr& aData, void *aTouchList) +AppendToTouchList(const uint32_t& aKey, nsRefPtr& aData, void *aTouchList) { - nsTArray > *touches = static_cast > *>(aTouchList); + nsTArray< nsRefPtr >* touches = + static_cast >*>(aTouchList); aData->mChanged = false; touches->AppendElement(aData); return PL_DHASH_NEXT; } static PLDHashOperator -FindAnyTarget(const uint32_t& aKey, nsCOMPtr& aData, +FindAnyTarget(const uint32_t& aKey, nsRefPtr& aData, void* aAnyTarget) { if (aData) { - nsCOMPtr target; - aData->GetTarget(getter_AddRefs(target)); + dom::EventTarget* target = aData->Target(); if (target) { nsCOMPtr* content = static_cast*>(aAnyTarget); @@ -6133,7 +6133,7 @@ PresShell::HandleEvent(nsIFrame *aFrame, // the start of a new touch session and evict any old touches in the // queue if (touchEvent->touches.Length() == 1) { - nsTArray > touches; + nsTArray< nsRefPtr > touches; gCaptureTouchList.Enumerate(&AppendToTouchList, (void *)&touches); for (uint32_t i = 0; i < touches.Length(); ++i) { EvictTouchPoint(touches[i]); @@ -6152,12 +6152,10 @@ PresShell::HandleEvent(nsIFrame *aFrame, // Add any new touches to the queue for (int32_t i = touchEvent->touches.Length(); i; ) { --i; - nsIDOMTouch *touch = touchEvent->touches[i]; - Touch *domtouch = static_cast(touch); + dom::Touch* touch = touchEvent->touches[i]; touch->mMessage = aEvent->message; - int32_t id = 0; - touch->GetIdentifier(&id); + int32_t id = touch->Identifier(); if (!gCaptureTouchList.Get(id, nullptr)) { // This event is a new touch. Mark it as a changedTouch and // add it to the queue. @@ -6177,7 +6175,7 @@ PresShell::HandleEvent(nsIFrame *aFrame, while (anyTarget && !anyTarget->IsElement()) { anyTarget = anyTarget->GetParent(); } - domtouch->SetTarget(anyTarget); + touch->SetTarget(anyTarget); gCaptureTouchList.Put(id, touch); } else { nsIFrame* newTargetFrame = nullptr; @@ -6217,13 +6215,11 @@ PresShell::HandleEvent(nsIFrame *aFrame, // This touch is an old touch, we need to ensure that is not // marked as changed and set its target correctly touch->mChanged = false; - int32_t id; - touch->GetIdentifier(&id); + int32_t id = touch->Identifier(); - nsCOMPtr oldTouch; - gCaptureTouchList.Get(id, getter_AddRefs(oldTouch)); + nsRefPtr oldTouch = gCaptureTouchList.GetWeak(id); if (oldTouch) { - domtouch->SetTarget(oldTouch->GetTarget()); + touch->SetTarget(oldTouch->mTarget); gCaptureTouchList.Put(id, touch); } } @@ -6286,24 +6282,21 @@ PresShell::HandleEvent(nsIFrame *aFrame, case NS_TOUCH_END: { // get the correct shell to dispatch to nsTouchEvent* touchEvent = static_cast(aEvent); - nsTArray > &touches = touchEvent->touches; + nsTArray< nsRefPtr >& touches = touchEvent->touches; for (uint32_t i = 0; i < touches.Length(); ++i) { - nsIDOMTouch *touch = touches[i]; + dom::Touch* touch = touches[i]; if (!touch) { break; } - int32_t id; - touch->GetIdentifier(&id); - nsCOMPtr oldTouch; - gCaptureTouchList.Get(id, getter_AddRefs(oldTouch)); + nsRefPtr oldTouch = + gCaptureTouchList.GetWeak(touch->Identifier()); if (!oldTouch) { break; } - nsCOMPtr targetPtr; - oldTouch->GetTarget(getter_AddRefs(targetPtr)); - nsCOMPtr content = do_QueryInterface(targetPtr); + nsCOMPtr content = + do_QueryInterface(oldTouch->Target()); if (!content) { break; } @@ -6681,28 +6674,24 @@ PresShell::HandleEventInternal(nsEvent* aEvent, nsEventStatus* aStatus) // Remove the changed touches // need to make sure we only remove touches that are ending here nsTouchEvent* touchEvent = static_cast(aEvent); - nsTArray > &touches = touchEvent->touches; + nsTArray< nsRefPtr >& touches = touchEvent->touches; for (uint32_t i = 0; i < touches.Length(); ++i) { - nsIDOMTouch *touch = touches[i]; - Touch *domtouch = static_cast(touch); + dom::Touch* touch = touches[i]; if (!touch) { continue; } touch->mMessage = aEvent->message; touch->mChanged = true; - nsCOMPtr oldTouch; - int32_t id; - touch->GetIdentifier(&id); - - gCaptureTouchList.Get(id, getter_AddRefs(oldTouch)); + int32_t id = touch->Identifier(); + nsRefPtr oldTouch = gCaptureTouchList.GetWeak(id); if (!oldTouch) { continue; } - nsCOMPtr targetPtr = oldTouch->GetTarget(); + nsCOMPtr targetPtr = oldTouch->mTarget; mCurrentEventContent = do_QueryInterface(targetPtr); - domtouch->SetTarget(targetPtr); + touch->SetTarget(targetPtr); gCaptureTouchList.Remove(id); } // add any touches left in the touch list, but ensure changed=false @@ -6712,36 +6701,33 @@ PresShell::HandleEventInternal(nsEvent* aEvent, nsEventStatus* aStatus) case NS_TOUCH_MOVE: { // Check for touches that changed. Mark them add to queue nsTouchEvent* touchEvent = static_cast(aEvent); - nsTArray >& touches = touchEvent->touches; + nsTArray< nsRefPtr >& touches = touchEvent->touches; bool haveChanged = false; for (int32_t i = touches.Length(); i; ) { --i; - nsIDOMTouch *touch = touches[i]; - Touch *domtouch = static_cast(touch); + dom::Touch* touch = touches[i]; if (!touch) { continue; } - int32_t id; - touch->GetIdentifier(&id); + int32_t id = touch->Identifier(); touch->mMessage = aEvent->message; - nsCOMPtr oldTouch; - gCaptureTouchList.Get(id, getter_AddRefs(oldTouch)); + nsRefPtr oldTouch = gCaptureTouchList.GetWeak(id); if (!oldTouch) { touches.RemoveElementAt(i); continue; } - if(domtouch->Equals(oldTouch)) { + if (touch->Equals(oldTouch)) { touch->mChanged = true; haveChanged = true; } - nsCOMPtr targetPtr = oldTouch->GetTarget(); + nsCOMPtr targetPtr = oldTouch->mTarget; if (!targetPtr) { touches.RemoveElementAt(i); continue; } - domtouch->SetTarget(targetPtr); + touch->SetTarget(targetPtr); gCaptureTouchList.Put(id, touch); // if we're moving from touchstart to touchmove for this touch diff --git a/widget/nsGUIEvent.h b/widget/nsGUIEvent.h index 25e62c1ae2d3..f77c18583104 100644 --- a/widget/nsGUIEvent.h +++ b/widget/nsGUIEvent.h @@ -30,6 +30,7 @@ #include "nsStyleConsts.h" #include "nsAutoPtr.h" #include "mozilla/dom/EventTarget.h" +#include "mozilla/dom/Touch.h" namespace mozilla { namespace dom { @@ -1651,7 +1652,7 @@ public: MOZ_COUNT_DTOR(nsTouchEvent); } - nsTArray > touches; + nsTArray< nsRefPtr > touches; }; /** diff --git a/widget/nsGUIEventIPC.h b/widget/nsGUIEventIPC.h index 567774395381..07dfc84ab89f 100644 --- a/widget/nsGUIEventIPC.h +++ b/widget/nsGUIEventIPC.h @@ -206,10 +206,10 @@ struct ParamTraits WriteParam(aMsg, static_cast(aParam)); // Sigh, Touch bites us again! We want to be able to do // WriteParam(aMsg, aParam.touches); - const nsTArray >& touches = aParam.touches; + const nsTArray< nsRefPtr >& touches = aParam.touches; WriteParam(aMsg, touches.Length()); for (uint32_t i = 0; i < touches.Length(); ++i) { - mozilla::dom::Touch* touch = static_cast(touches[i].get()); + mozilla::dom::Touch* touch = touches[i]; WriteParam(aMsg, touch->mIdentifier); WriteParam(aMsg, touch->mRefPoint); WriteParam(aMsg, touch->mRadius);