mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 884748 - Make nsTouchEvent::touches store Touch instead of nsIDOMTouch; r=dzbarsky
This commit is contained in:
parent
33510110c0
commit
f8554f1603
@ -15,7 +15,7 @@ using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
// TouchList
|
||||
nsDOMTouchList::nsDOMTouchList(nsTArray<nsCOMPtr<nsIDOMTouch> > &aTouches)
|
||||
nsDOMTouchList::nsDOMTouchList(const nsTArray< nsRefPtr<Touch> >& 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<nsIDOMTouch> point = mPoints[i];
|
||||
int32_t identifier;
|
||||
if (point && NS_SUCCEEDED(point->GetIdentifier(&identifier)) &&
|
||||
aIdentifier == identifier) {
|
||||
point.swap(*aRetVal);
|
||||
nsRefPtr<Touch> point = mPoints[i];
|
||||
if (point && point->Identifier() == aIdentifier) {
|
||||
point.forget(aRetVal);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -151,8 +149,8 @@ nsDOMTouchEvent::Touches()
|
||||
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;
|
||||
nsTArray< nsRefPtr<Touch> > unchangedTouches;
|
||||
const nsTArray< nsRefPtr<Touch> >& 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<nsCOMPtr<nsIDOMTouch> > targetTouches;
|
||||
nsTArray< nsRefPtr<Touch> > targetTouches;
|
||||
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
|
||||
const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
|
||||
const nsTArray< nsRefPtr<Touch> >& 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<nsCOMPtr<nsIDOMTouch> > changedTouches;
|
||||
nsTArray< nsRefPtr<Touch> > changedTouches;
|
||||
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
|
||||
const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
|
||||
const nsTArray< nsRefPtr<Touch> >& touches = touchEvent->touches;
|
||||
for (uint32_t i = 0; i < touches.Length(); ++i) {
|
||||
if (touches[i]->mChanged) {
|
||||
changedTouches.AppendElement(touches[i]);
|
||||
|
@ -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<nsCOMPtr<nsIDOMTouch> > &aTouches);
|
||||
nsDOMTouchList(const nsTArray< nsRefPtr<Touch> >& aTouches);
|
||||
|
||||
void Append(nsIDOMTouch* aPoint)
|
||||
void Append(Touch* aPoint)
|
||||
{
|
||||
mPoints.AppendElement(aPoint);
|
||||
}
|
||||
@ -37,7 +39,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
nsTArray<nsCOMPtr<nsIDOMTouch> > mPoints;
|
||||
nsTArray< nsRefPtr<Touch> > mPoints;
|
||||
};
|
||||
|
||||
class nsDOMTouchEvent : public nsDOMUIEvent,
|
||||
|
@ -1553,7 +1553,7 @@ nsEventStateManager::MapEventCoordinatesForChildProcess(
|
||||
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<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
|
||||
const nsTArray< nsRefPtr<Touch> >& 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<nsTouchEvent*>(aEvent);
|
||||
const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
|
||||
const nsTArray< nsRefPtr<Touch> >& 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
|
||||
|
@ -269,7 +269,7 @@ AsyncPanZoomController::ReceiveInputEvent(const nsInputEvent& aEvent,
|
||||
switch (aEvent.eventStructType) {
|
||||
case NS_TOUCH_EVENT: {
|
||||
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aOutEvent);
|
||||
const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
|
||||
const nsTArray< nsRefPtr<dom::Touch> >& touches = touchEvent->touches;
|
||||
for (uint32_t i = 0; i < touches.Length(); ++i) {
|
||||
nsIDOMTouch* touch = touches[i];
|
||||
if (touch) {
|
||||
|
@ -36,7 +36,7 @@
|
||||
#include <stdio.h> // 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<nsUint32HashKey, nsIDOMTouch> gCaptureTouchList;
|
||||
static nsRefPtrHashtable<nsUint32HashKey, mozilla::dom::Touch> gCaptureTouchList;
|
||||
static bool gPreventMouseEvents;
|
||||
|
||||
/**
|
||||
|
@ -198,7 +198,7 @@ CapturingContentInfo nsIPresShell::gCaptureInfo =
|
||||
{ false /* mAllowed */, false /* mPointerLock */, false /* mRetargetToElement */,
|
||||
false /* mPreventDrag */, nullptr /* mContent */ };
|
||||
nsIContent* nsIPresShell::gKeyDownTarget;
|
||||
nsInterfaceHashtable<nsUint32HashKey, nsIDOMTouch> nsIPresShell::gCaptureTouchList;
|
||||
nsRefPtrHashtable<nsUint32HashKey, dom::Touch> 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<nsIDOMTouch>& aTouch)
|
||||
EvictTouchPoint(nsRefPtr<dom::Touch>& aTouch)
|
||||
{
|
||||
nsIWidget *widget = nullptr;
|
||||
// is there an easier/better way to dig out the widget?
|
||||
nsCOMPtr<nsINode> node(do_QueryInterface(aTouch->GetTarget()));
|
||||
nsCOMPtr<nsINode> node(do_QueryInterface(aTouch->mTarget));
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
@ -5899,21 +5899,21 @@ EvictTouchPoint(nsCOMPtr<nsIDOMTouch>& aTouch)
|
||||
}
|
||||
|
||||
static PLDHashOperator
|
||||
AppendToTouchList(const uint32_t& aKey, nsCOMPtr<nsIDOMTouch>& aData, void *aTouchList)
|
||||
AppendToTouchList(const uint32_t& aKey, nsRefPtr<dom::Touch>& aData, void *aTouchList)
|
||||
{
|
||||
nsTArray<nsCOMPtr<nsIDOMTouch> > *touches = static_cast<nsTArray<nsCOMPtr<nsIDOMTouch> > *>(aTouchList);
|
||||
nsTArray< nsRefPtr<dom::Touch> >* touches =
|
||||
static_cast<nsTArray< nsRefPtr<dom::Touch> >*>(aTouchList);
|
||||
aData->mChanged = false;
|
||||
touches->AppendElement(aData);
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
static PLDHashOperator
|
||||
FindAnyTarget(const uint32_t& aKey, nsCOMPtr<nsIDOMTouch>& aData,
|
||||
FindAnyTarget(const uint32_t& aKey, nsRefPtr<dom::Touch>& aData,
|
||||
void* aAnyTarget)
|
||||
{
|
||||
if (aData) {
|
||||
nsCOMPtr<nsIDOMEventTarget> target;
|
||||
aData->GetTarget(getter_AddRefs(target));
|
||||
dom::EventTarget* target = aData->Target();
|
||||
if (target) {
|
||||
nsCOMPtr<nsIContent>* content =
|
||||
static_cast<nsCOMPtr<nsIContent>*>(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<nsCOMPtr<nsIDOMTouch> > touches;
|
||||
nsTArray< nsRefPtr<dom::Touch> > 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*>(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<nsIDOMTouch> oldTouch;
|
||||
gCaptureTouchList.Get(id, getter_AddRefs(oldTouch));
|
||||
nsRefPtr<dom::Touch> 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<nsTouchEvent*>(aEvent);
|
||||
nsTArray<nsCOMPtr<nsIDOMTouch> > &touches = touchEvent->touches;
|
||||
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) {
|
||||
break;
|
||||
}
|
||||
|
||||
int32_t id;
|
||||
touch->GetIdentifier(&id);
|
||||
nsCOMPtr<nsIDOMTouch> oldTouch;
|
||||
gCaptureTouchList.Get(id, getter_AddRefs(oldTouch));
|
||||
nsRefPtr<dom::Touch> oldTouch =
|
||||
gCaptureTouchList.GetWeak(touch->Identifier());
|
||||
if (!oldTouch) {
|
||||
break;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMEventTarget> targetPtr;
|
||||
oldTouch->GetTarget(getter_AddRefs(targetPtr));
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(targetPtr);
|
||||
nsCOMPtr<nsIContent> 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<nsTouchEvent*>(aEvent);
|
||||
nsTArray<nsCOMPtr<nsIDOMTouch> > &touches = touchEvent->touches;
|
||||
nsTArray< nsRefPtr<dom::Touch> >& touches = touchEvent->touches;
|
||||
for (uint32_t i = 0; i < touches.Length(); ++i) {
|
||||
nsIDOMTouch *touch = touches[i];
|
||||
Touch *domtouch = static_cast<Touch*>(touch);
|
||||
dom::Touch* touch = touches[i];
|
||||
if (!touch) {
|
||||
continue;
|
||||
}
|
||||
touch->mMessage = aEvent->message;
|
||||
touch->mChanged = true;
|
||||
nsCOMPtr<nsIDOMTouch> oldTouch;
|
||||
|
||||
int32_t id;
|
||||
touch->GetIdentifier(&id);
|
||||
|
||||
gCaptureTouchList.Get(id, getter_AddRefs(oldTouch));
|
||||
int32_t id = touch->Identifier();
|
||||
nsRefPtr<dom::Touch> oldTouch = gCaptureTouchList.GetWeak(id);
|
||||
if (!oldTouch) {
|
||||
continue;
|
||||
}
|
||||
nsCOMPtr<EventTarget> targetPtr = oldTouch->GetTarget();
|
||||
nsCOMPtr<EventTarget> 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<nsTouchEvent*>(aEvent);
|
||||
nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
|
||||
nsTArray< nsRefPtr<dom::Touch> >& touches = touchEvent->touches;
|
||||
bool haveChanged = false;
|
||||
for (int32_t i = touches.Length(); i; ) {
|
||||
--i;
|
||||
nsIDOMTouch *touch = touches[i];
|
||||
Touch *domtouch = static_cast<Touch*>(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<nsIDOMTouch> oldTouch;
|
||||
gCaptureTouchList.Get(id, getter_AddRefs(oldTouch));
|
||||
nsRefPtr<dom::Touch> oldTouch = gCaptureTouchList.GetWeak(id);
|
||||
if (!oldTouch) {
|
||||
touches.RemoveElementAt(i);
|
||||
continue;
|
||||
}
|
||||
if(domtouch->Equals(oldTouch)) {
|
||||
if (touch->Equals(oldTouch)) {
|
||||
touch->mChanged = true;
|
||||
haveChanged = true;
|
||||
}
|
||||
|
||||
nsCOMPtr<EventTarget> targetPtr = oldTouch->GetTarget();
|
||||
nsCOMPtr<dom::EventTarget> 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
|
||||
|
@ -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<nsCOMPtr<nsIDOMTouch> > touches;
|
||||
nsTArray< nsRefPtr<mozilla::dom::Touch> > touches;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -206,10 +206,10 @@ struct ParamTraits<nsTouchEvent>
|
||||
WriteParam(aMsg, static_cast<const nsInputEvent&>(aParam));
|
||||
// Sigh, Touch bites us again! We want to be able to do
|
||||
// WriteParam(aMsg, aParam.touches);
|
||||
const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = aParam.touches;
|
||||
const nsTArray< nsRefPtr<mozilla::dom::Touch> >& touches = aParam.touches;
|
||||
WriteParam(aMsg, touches.Length());
|
||||
for (uint32_t i = 0; i < touches.Length(); ++i) {
|
||||
mozilla::dom::Touch* touch = static_cast<mozilla::dom::Touch*>(touches[i].get());
|
||||
mozilla::dom::Touch* touch = touches[i];
|
||||
WriteParam(aMsg, touch->mIdentifier);
|
||||
WriteParam(aMsg, touch->mRefPoint);
|
||||
WriteParam(aMsg, touch->mRadius);
|
||||
|
Loading…
Reference in New Issue
Block a user