Skip to content

Commit f8554f1

Browse files
committed
Bug 884748 - Make nsTouchEvent::touches store Touch instead of nsIDOMTouch; r=dzbarsky
1 parent 3351011 commit f8554f1

File tree

8 files changed

+59
-73
lines changed

8 files changed

+59
-73
lines changed

content/events/src/nsDOMTouchEvent.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using namespace mozilla;
1515
using namespace mozilla::dom;
1616

1717
// TouchList
18-
nsDOMTouchList::nsDOMTouchList(nsTArray<nsCOMPtr<nsIDOMTouch> > &aTouches)
18+
nsDOMTouchList::nsDOMTouchList(const nsTArray< nsRefPtr<Touch> >& aTouches)
1919
{
2020
mPoints.AppendElements(aTouches);
2121
nsJSContext::LikelyShortLivingObjectCreated();
@@ -53,11 +53,9 @@ nsDOMTouchList::IdentifiedTouch(int32_t aIdentifier, nsIDOMTouch** aRetVal)
5353
{
5454
*aRetVal = nullptr;
5555
for (uint32_t i = 0; i < mPoints.Length(); ++i) {
56-
nsCOMPtr<nsIDOMTouch> point = mPoints[i];
57-
int32_t identifier;
58-
if (point && NS_SUCCEEDED(point->GetIdentifier(&identifier)) &&
59-
aIdentifier == identifier) {
60-
point.swap(*aRetVal);
56+
nsRefPtr<Touch> point = mPoints[i];
57+
if (point && point->Identifier() == aIdentifier) {
58+
point.forget(aRetVal);
6159
break;
6260
}
6361
}
@@ -151,8 +149,8 @@ nsDOMTouchEvent::Touches()
151149
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
152150
if (mEvent->message == NS_TOUCH_END || mEvent->message == NS_TOUCH_CANCEL) {
153151
// for touchend events, remove any changed touches from the touches array
154-
nsTArray<nsCOMPtr<nsIDOMTouch> > unchangedTouches;
155-
const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
152+
nsTArray< nsRefPtr<Touch> > unchangedTouches;
153+
const nsTArray< nsRefPtr<Touch> >& touches = touchEvent->touches;
156154
for (uint32_t i = 0; i < touches.Length(); ++i) {
157155
if (!touches[i]->mChanged) {
158156
unchangedTouches.AppendElement(touches[i]);
@@ -178,16 +176,15 @@ nsDOMTouchList*
178176
nsDOMTouchEvent::TargetTouches()
179177
{
180178
if (!mTargetTouches) {
181-
nsTArray<nsCOMPtr<nsIDOMTouch> > targetTouches;
179+
nsTArray< nsRefPtr<Touch> > targetTouches;
182180
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
183-
const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
181+
const nsTArray< nsRefPtr<Touch> >& touches = touchEvent->touches;
184182
for (uint32_t i = 0; i < touches.Length(); ++i) {
185183
// for touchend/cancel events, don't append to the target list if this is a
186184
// touch that is ending
187185
if ((mEvent->message != NS_TOUCH_END &&
188186
mEvent->message != NS_TOUCH_CANCEL) || !touches[i]->mChanged) {
189-
EventTarget* targetPtr = touches[i]->GetTarget();
190-
if (targetPtr == mEvent->originalTarget) {
187+
if (touches[i]->mTarget == mEvent->originalTarget) {
191188
targetTouches.AppendElement(touches[i]);
192189
}
193190
}
@@ -209,9 +206,9 @@ nsDOMTouchList*
209206
nsDOMTouchEvent::ChangedTouches()
210207
{
211208
if (!mChangedTouches) {
212-
nsTArray<nsCOMPtr<nsIDOMTouch> > changedTouches;
209+
nsTArray< nsRefPtr<Touch> > changedTouches;
213210
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
214-
const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
211+
const nsTArray< nsRefPtr<Touch> >& touches = touchEvent->touches;
215212
for (uint32_t i = 0; i < touches.Length(); ++i) {
216213
if (touches[i]->mChanged) {
217214
changedTouches.AppendElement(touches[i]);

content/events/src/nsDOMTouchEvent.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
class nsDOMTouchList MOZ_FINAL : public nsIDOMTouchList
1717
{
18+
typedef mozilla::dom::Touch Touch;
19+
1820
public:
1921
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
2022
NS_DECL_CYCLE_COLLECTION_CLASS(nsDOMTouchList)
@@ -24,9 +26,9 @@ class nsDOMTouchList MOZ_FINAL : public nsIDOMTouchList
2426
{
2527
nsJSContext::LikelyShortLivingObjectCreated();
2628
}
27-
nsDOMTouchList(nsTArray<nsCOMPtr<nsIDOMTouch> > &aTouches);
29+
nsDOMTouchList(const nsTArray< nsRefPtr<Touch> >& aTouches);
2830

29-
void Append(nsIDOMTouch* aPoint)
31+
void Append(Touch* aPoint)
3032
{
3133
mPoints.AppendElement(aPoint);
3234
}
@@ -37,7 +39,7 @@ class nsDOMTouchList MOZ_FINAL : public nsIDOMTouchList
3739
}
3840

3941
protected:
40-
nsTArray<nsCOMPtr<nsIDOMTouch> > mPoints;
42+
nsTArray< nsRefPtr<Touch> > mPoints;
4143
};
4244

4345
class nsDOMTouchEvent : public nsDOMUIEvent,

content/events/src/nsEventStateManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@ nsEventStateManager::MapEventCoordinatesForChildProcess(
15531553
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aEvent);
15541554
// Then offset all the touch points by that distance, to put them
15551555
// in the space where top-left is 0,0.
1556-
const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
1556+
const nsTArray< nsRefPtr<Touch> >& touches = touchEvent->touches;
15571557
for (uint32_t i = 0; i < touches.Length(); ++i) {
15581558
nsIDOMTouch* touch = touches[i];
15591559
if (touch) {
@@ -1637,7 +1637,7 @@ nsEventStateManager::HandleCrossProcessEvent(nsEvent *aEvent,
16371637
// This loop is similar to the one used in
16381638
// PresShell::DispatchTouchEvent().
16391639
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aEvent);
1640-
const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
1640+
const nsTArray< nsRefPtr<Touch> >& touches = touchEvent->touches;
16411641
for (uint32_t i = 0; i < touches.Length(); ++i) {
16421642
nsIDOMTouch* touch = touches[i];
16431643
// NB: the |mChanged| check is an optimization, subprocesses can

gfx/layers/ipc/AsyncPanZoomController.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ AsyncPanZoomController::ReceiveInputEvent(const nsInputEvent& aEvent,
269269
switch (aEvent.eventStructType) {
270270
case NS_TOUCH_EVENT: {
271271
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aOutEvent);
272-
const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
272+
const nsTArray< nsRefPtr<dom::Touch> >& touches = touchEvent->touches;
273273
for (uint32_t i = 0; i < touches.Length(); ++i) {
274274
nsIDOMTouch* touch = touches[i];
275275
if (touch) {

layout/base/nsIPresShell.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include <stdio.h> // for FILE definition
3737
#include "nsChangeHint.h"
3838
#include "nsGUIEvent.h"
39-
#include "nsInterfaceHashtable.h"
39+
#include "nsRefPtrHashtable.h"
4040
#include "nsEventStates.h"
4141
#include "nsPresArena.h"
4242
#include "nsIImageLoadingContent.h"
@@ -1129,7 +1129,7 @@ class nsIPresShell : public nsIPresShell_base
11291129

11301130
static CapturingContentInfo gCaptureInfo;
11311131

1132-
static nsInterfaceHashtable<nsUint32HashKey, nsIDOMTouch> gCaptureTouchList;
1132+
static nsRefPtrHashtable<nsUint32HashKey, mozilla::dom::Touch> gCaptureTouchList;
11331133
static bool gPreventMouseEvents;
11341134

11351135
/**

layout/base/nsPresShell.cpp

Lines changed: 34 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ CapturingContentInfo nsIPresShell::gCaptureInfo =
198198
{ false /* mAllowed */, false /* mPointerLock */, false /* mRetargetToElement */,
199199
false /* mPreventDrag */, nullptr /* mContent */ };
200200
nsIContent* nsIPresShell::gKeyDownTarget;
201-
nsInterfaceHashtable<nsUint32HashKey, nsIDOMTouch> nsIPresShell::gCaptureTouchList;
201+
nsRefPtrHashtable<nsUint32HashKey, dom::Touch> nsIPresShell::gCaptureTouchList;
202202
bool nsIPresShell::gPreventMouseEvents = false;
203203

204204
// convert a color value to a string, in the CSS format #RRGGBB
@@ -5862,11 +5862,11 @@ PresShell::RecordMouseLocation(nsGUIEvent* aEvent)
58625862
}
58635863

58645864
static void
5865-
EvictTouchPoint(nsCOMPtr<nsIDOMTouch>& aTouch)
5865+
EvictTouchPoint(nsRefPtr<dom::Touch>& aTouch)
58665866
{
58675867
nsIWidget *widget = nullptr;
58685868
// is there an easier/better way to dig out the widget?
5869-
nsCOMPtr<nsINode> node(do_QueryInterface(aTouch->GetTarget()));
5869+
nsCOMPtr<nsINode> node(do_QueryInterface(aTouch->mTarget));
58705870
if (!node) {
58715871
return;
58725872
}
@@ -5899,21 +5899,21 @@ EvictTouchPoint(nsCOMPtr<nsIDOMTouch>& aTouch)
58995899
}
59005900

59015901
static PLDHashOperator
5902-
AppendToTouchList(const uint32_t& aKey, nsCOMPtr<nsIDOMTouch>& aData, void *aTouchList)
5902+
AppendToTouchList(const uint32_t& aKey, nsRefPtr<dom::Touch>& aData, void *aTouchList)
59035903
{
5904-
nsTArray<nsCOMPtr<nsIDOMTouch> > *touches = static_cast<nsTArray<nsCOMPtr<nsIDOMTouch> > *>(aTouchList);
5904+
nsTArray< nsRefPtr<dom::Touch> >* touches =
5905+
static_cast<nsTArray< nsRefPtr<dom::Touch> >*>(aTouchList);
59055906
aData->mChanged = false;
59065907
touches->AppendElement(aData);
59075908
return PL_DHASH_NEXT;
59085909
}
59095910

59105911
static PLDHashOperator
5911-
FindAnyTarget(const uint32_t& aKey, nsCOMPtr<nsIDOMTouch>& aData,
5912+
FindAnyTarget(const uint32_t& aKey, nsRefPtr<dom::Touch>& aData,
59125913
void* aAnyTarget)
59135914
{
59145915
if (aData) {
5915-
nsCOMPtr<nsIDOMEventTarget> target;
5916-
aData->GetTarget(getter_AddRefs(target));
5916+
dom::EventTarget* target = aData->Target();
59175917
if (target) {
59185918
nsCOMPtr<nsIContent>* content =
59195919
static_cast<nsCOMPtr<nsIContent>*>(aAnyTarget);
@@ -6133,7 +6133,7 @@ PresShell::HandleEvent(nsIFrame *aFrame,
61336133
// the start of a new touch session and evict any old touches in the
61346134
// queue
61356135
if (touchEvent->touches.Length() == 1) {
6136-
nsTArray<nsCOMPtr<nsIDOMTouch> > touches;
6136+
nsTArray< nsRefPtr<dom::Touch> > touches;
61376137
gCaptureTouchList.Enumerate(&AppendToTouchList, (void *)&touches);
61386138
for (uint32_t i = 0; i < touches.Length(); ++i) {
61396139
EvictTouchPoint(touches[i]);
@@ -6152,12 +6152,10 @@ PresShell::HandleEvent(nsIFrame *aFrame,
61526152
// Add any new touches to the queue
61536153
for (int32_t i = touchEvent->touches.Length(); i; ) {
61546154
--i;
6155-
nsIDOMTouch *touch = touchEvent->touches[i];
6156-
Touch *domtouch = static_cast<Touch*>(touch);
6155+
dom::Touch* touch = touchEvent->touches[i];
61576156
touch->mMessage = aEvent->message;
61586157

6159-
int32_t id = 0;
6160-
touch->GetIdentifier(&id);
6158+
int32_t id = touch->Identifier();
61616159
if (!gCaptureTouchList.Get(id, nullptr)) {
61626160
// This event is a new touch. Mark it as a changedTouch and
61636161
// add it to the queue.
@@ -6177,7 +6175,7 @@ PresShell::HandleEvent(nsIFrame *aFrame,
61776175
while (anyTarget && !anyTarget->IsElement()) {
61786176
anyTarget = anyTarget->GetParent();
61796177
}
6180-
domtouch->SetTarget(anyTarget);
6178+
touch->SetTarget(anyTarget);
61816179
gCaptureTouchList.Put(id, touch);
61826180
} else {
61836181
nsIFrame* newTargetFrame = nullptr;
@@ -6217,13 +6215,11 @@ PresShell::HandleEvent(nsIFrame *aFrame,
62176215
// This touch is an old touch, we need to ensure that is not
62186216
// marked as changed and set its target correctly
62196217
touch->mChanged = false;
6220-
int32_t id;
6221-
touch->GetIdentifier(&id);
6218+
int32_t id = touch->Identifier();
62226219

6223-
nsCOMPtr<nsIDOMTouch> oldTouch;
6224-
gCaptureTouchList.Get(id, getter_AddRefs(oldTouch));
6220+
nsRefPtr<dom::Touch> oldTouch = gCaptureTouchList.GetWeak(id);
62256221
if (oldTouch) {
6226-
domtouch->SetTarget(oldTouch->GetTarget());
6222+
touch->SetTarget(oldTouch->mTarget);
62276223
gCaptureTouchList.Put(id, touch);
62286224
}
62296225
}
@@ -6286,24 +6282,21 @@ PresShell::HandleEvent(nsIFrame *aFrame,
62866282
case NS_TOUCH_END: {
62876283
// get the correct shell to dispatch to
62886284
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aEvent);
6289-
nsTArray<nsCOMPtr<nsIDOMTouch> > &touches = touchEvent->touches;
6285+
nsTArray< nsRefPtr<dom::Touch> >& touches = touchEvent->touches;
62906286
for (uint32_t i = 0; i < touches.Length(); ++i) {
6291-
nsIDOMTouch *touch = touches[i];
6287+
dom::Touch* touch = touches[i];
62926288
if (!touch) {
62936289
break;
62946290
}
62956291

6296-
int32_t id;
6297-
touch->GetIdentifier(&id);
6298-
nsCOMPtr<nsIDOMTouch> oldTouch;
6299-
gCaptureTouchList.Get(id, getter_AddRefs(oldTouch));
6292+
nsRefPtr<dom::Touch> oldTouch =
6293+
gCaptureTouchList.GetWeak(touch->Identifier());
63006294
if (!oldTouch) {
63016295
break;
63026296
}
63036297

6304-
nsCOMPtr<nsIDOMEventTarget> targetPtr;
6305-
oldTouch->GetTarget(getter_AddRefs(targetPtr));
6306-
nsCOMPtr<nsIContent> content = do_QueryInterface(targetPtr);
6298+
nsCOMPtr<nsIContent> content =
6299+
do_QueryInterface(oldTouch->Target());
63076300
if (!content) {
63086301
break;
63096302
}
@@ -6681,28 +6674,24 @@ PresShell::HandleEventInternal(nsEvent* aEvent, nsEventStatus* aStatus)
66816674
// Remove the changed touches
66826675
// need to make sure we only remove touches that are ending here
66836676
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aEvent);
6684-
nsTArray<nsCOMPtr<nsIDOMTouch> > &touches = touchEvent->touches;
6677+
nsTArray< nsRefPtr<dom::Touch> >& touches = touchEvent->touches;
66856678
for (uint32_t i = 0; i < touches.Length(); ++i) {
6686-
nsIDOMTouch *touch = touches[i];
6687-
Touch *domtouch = static_cast<Touch*>(touch);
6679+
dom::Touch* touch = touches[i];
66886680
if (!touch) {
66896681
continue;
66906682
}
66916683
touch->mMessage = aEvent->message;
66926684
touch->mChanged = true;
6693-
nsCOMPtr<nsIDOMTouch> oldTouch;
66946685

6695-
int32_t id;
6696-
touch->GetIdentifier(&id);
6697-
6698-
gCaptureTouchList.Get(id, getter_AddRefs(oldTouch));
6686+
int32_t id = touch->Identifier();
6687+
nsRefPtr<dom::Touch> oldTouch = gCaptureTouchList.GetWeak(id);
66996688
if (!oldTouch) {
67006689
continue;
67016690
}
6702-
nsCOMPtr<EventTarget> targetPtr = oldTouch->GetTarget();
6691+
nsCOMPtr<EventTarget> targetPtr = oldTouch->mTarget;
67036692

67046693
mCurrentEventContent = do_QueryInterface(targetPtr);
6705-
domtouch->SetTarget(targetPtr);
6694+
touch->SetTarget(targetPtr);
67066695
gCaptureTouchList.Remove(id);
67076696
}
67086697
// add any touches left in the touch list, but ensure changed=false
@@ -6712,36 +6701,33 @@ PresShell::HandleEventInternal(nsEvent* aEvent, nsEventStatus* aStatus)
67126701
case NS_TOUCH_MOVE: {
67136702
// Check for touches that changed. Mark them add to queue
67146703
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aEvent);
6715-
nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
6704+
nsTArray< nsRefPtr<dom::Touch> >& touches = touchEvent->touches;
67166705
bool haveChanged = false;
67176706
for (int32_t i = touches.Length(); i; ) {
67186707
--i;
6719-
nsIDOMTouch *touch = touches[i];
6720-
Touch *domtouch = static_cast<Touch*>(touch);
6708+
dom::Touch* touch = touches[i];
67216709
if (!touch) {
67226710
continue;
67236711
}
6724-
int32_t id;
6725-
touch->GetIdentifier(&id);
6712+
int32_t id = touch->Identifier();
67266713
touch->mMessage = aEvent->message;
67276714

6728-
nsCOMPtr<nsIDOMTouch> oldTouch;
6729-
gCaptureTouchList.Get(id, getter_AddRefs(oldTouch));
6715+
nsRefPtr<dom::Touch> oldTouch = gCaptureTouchList.GetWeak(id);
67306716
if (!oldTouch) {
67316717
touches.RemoveElementAt(i);
67326718
continue;
67336719
}
6734-
if(domtouch->Equals(oldTouch)) {
6720+
if (touch->Equals(oldTouch)) {
67356721
touch->mChanged = true;
67366722
haveChanged = true;
67376723
}
67386724

6739-
nsCOMPtr<EventTarget> targetPtr = oldTouch->GetTarget();
6725+
nsCOMPtr<dom::EventTarget> targetPtr = oldTouch->mTarget;
67406726
if (!targetPtr) {
67416727
touches.RemoveElementAt(i);
67426728
continue;
67436729
}
6744-
domtouch->SetTarget(targetPtr);
6730+
touch->SetTarget(targetPtr);
67456731

67466732
gCaptureTouchList.Put(id, touch);
67476733
// if we're moving from touchstart to touchmove for this touch

widget/nsGUIEvent.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "nsStyleConsts.h"
3131
#include "nsAutoPtr.h"
3232
#include "mozilla/dom/EventTarget.h"
33+
#include "mozilla/dom/Touch.h"
3334

3435
namespace mozilla {
3536
namespace dom {
@@ -1651,7 +1652,7 @@ class nsTouchEvent : public nsInputEvent
16511652
MOZ_COUNT_DTOR(nsTouchEvent);
16521653
}
16531654

1654-
nsTArray<nsCOMPtr<nsIDOMTouch> > touches;
1655+
nsTArray< nsRefPtr<mozilla::dom::Touch> > touches;
16551656
};
16561657

16571658
/**

widget/nsGUIEventIPC.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ struct ParamTraits<nsTouchEvent>
206206
WriteParam(aMsg, static_cast<const nsInputEvent&>(aParam));
207207
// Sigh, Touch bites us again! We want to be able to do
208208
// WriteParam(aMsg, aParam.touches);
209-
const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = aParam.touches;
209+
const nsTArray< nsRefPtr<mozilla::dom::Touch> >& touches = aParam.touches;
210210
WriteParam(aMsg, touches.Length());
211211
for (uint32_t i = 0; i < touches.Length(); ++i) {
212-
mozilla::dom::Touch* touch = static_cast<mozilla::dom::Touch*>(touches[i].get());
212+
mozilla::dom::Touch* touch = touches[i];
213213
WriteParam(aMsg, touch->mIdentifier);
214214
WriteParam(aMsg, touch->mRefPoint);
215215
WriteParam(aMsg, touch->mRadius);

0 commit comments

Comments
 (0)