diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index 7b0f63a0a6c..a535dadc3b1 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -8465,7 +8465,8 @@ NS_IMETHODIMP nsDocument::CreateTouchList(nsIVariant* aPoints, nsIDOMTouchList** aRetVal) { - nsRefPtr retval = new nsDOMTouchList(); + nsRefPtr retval = + new nsDOMTouchList(static_cast(this)); if (aPoints) { PRUint16 type; aPoints->GetDataType(&type); diff --git a/content/events/src/nsDOMTouchEvent.cpp b/content/events/src/nsDOMTouchEvent.cpp index b8ce7eaf316..6b545c28f72 100644 --- a/content/events/src/nsDOMTouchEvent.cpp +++ b/content/events/src/nsDOMTouchEvent.cpp @@ -160,16 +160,13 @@ nsDOMTouch::Equals(nsIDOMTouch* aTouch) } // TouchList -nsDOMTouchList::nsDOMTouchList(nsTArray > &aTouches) -{ - mPoints.AppendElements(aTouches); -} DOMCI_DATA(TouchList, nsDOMTouchList) NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMTouchList) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMTouchList) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_ENTRY(nsIDOMTouchList) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(TouchList) @@ -177,10 +174,16 @@ NS_INTERFACE_MAP_END NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMTouchList) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY_OF_NSCOMPTR(mPoints) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mParent) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END - +NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsDOMTouchList) + NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER +NS_IMPL_CYCLE_COLLECTION_TRACE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMTouchList) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSTARRAY(mPoints) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mParent) + NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMTouchList) @@ -196,7 +199,7 @@ nsDOMTouchList::GetLength(PRUint32* aLength) NS_IMETHODIMP nsDOMTouchList::Item(PRUint32 aIndex, nsIDOMTouch** aRetVal) { - NS_IF_ADDREF(*aRetVal = mPoints.SafeElementAt(aIndex, nsnull)); + NS_IF_ADDREF(*aRetVal = nsDOMTouchList::GetItemAt(aIndex)); return NS_OK; } @@ -216,6 +219,12 @@ nsDOMTouchList::IdentifiedTouch(PRInt32 aIdentifier, nsIDOMTouch** aRetVal) return NS_OK; } +nsIDOMTouch* +nsDOMTouchList::GetItemAt(PRUint32 aIndex) +{ + return mPoints.SafeElementAt(aIndex, nsnull); +} + // TouchEvent nsDOMTouchEvent::nsDOMTouchEvent(nsPresContext* aPresContext, @@ -322,9 +331,11 @@ nsDOMTouchEvent::GetTouches(nsIDOMTouchList** aTouches) unchangedTouches.AppendElement(touches[i]); } } - t = new nsDOMTouchList(unchangedTouches); + t = new nsDOMTouchList(static_cast(this), + unchangedTouches); } else { - t = new nsDOMTouchList(touchEvent->touches); + t = new nsDOMTouchList(static_cast(this), + touchEvent->touches); } mTouches = t; return CallQueryInterface(mTouches, aTouches); @@ -354,7 +365,8 @@ nsDOMTouchEvent::GetTargetTouches(nsIDOMTouchList** aTargetTouches) } } } - mTargetTouches = new nsDOMTouchList(targetTouches); + mTargetTouches = new nsDOMTouchList(static_cast(this), + targetTouches); return CallQueryInterface(mTargetTouches, aTargetTouches); } @@ -376,7 +388,8 @@ nsDOMTouchEvent::GetChangedTouches(nsIDOMTouchList** aChangedTouches) changedTouches.AppendElement(touches[i]); } } - mChangedTouches = new nsDOMTouchList(changedTouches); + mChangedTouches = new nsDOMTouchList(static_cast(this), + changedTouches); return CallQueryInterface(mChangedTouches, aChangedTouches); } diff --git a/content/events/src/nsDOMTouchEvent.h b/content/events/src/nsDOMTouchEvent.h index 52119b2a0f8..b939565c853 100644 --- a/content/events/src/nsDOMTouchEvent.h +++ b/content/events/src/nsDOMTouchEvent.h @@ -41,6 +41,8 @@ #include "nsIDOMTouchEvent.h" #include "nsString.h" #include "nsTArray.h" +#include "nsIDocument.h" +#include "dombindings.h" class nsDOMTouch : public nsIDOMTouch { @@ -127,27 +129,46 @@ protected: float mForce; }; -class nsDOMTouchList : public nsIDOMTouchList +class nsDOMTouchList MOZ_FINAL : public nsIDOMTouchList, + public nsWrapperCache { public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_CLASS(nsDOMTouchList) + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMTouchList) NS_DECL_NSIDOMTOUCHLIST - nsDOMTouchList() { } - nsDOMTouchList(nsTArray > &aTouches); - + nsDOMTouchList(nsISupports *aParent) : mParent(aParent) + { + SetIsProxy(); + } + nsDOMTouchList(nsISupports *aParent, + nsTArray > &aTouches) + : mPoints(aTouches), + mParent(aParent) + { + SetIsProxy(); + } + + virtual JSObject* WrapObject(JSContext *cx, XPCWrappedNativeScope *scope, + bool *triedToWrap) + { + return mozilla::dom::binding::TouchList::create(cx, scope, this, + triedToWrap); + } + + nsISupports *GetParentObject() + { + return mParent; + } + void Append(nsIDOMTouch* aPoint) { mPoints.AppendElement(aPoint); } - nsIDOMTouch* GetItemAt(PRUint32 aIndex) - { - return mPoints.SafeElementAt(aIndex, nsnull); - } protected: nsTArray > mPoints; + nsCOMPtr mParent; }; class nsDOMTouchEvent : public nsDOMUIEvent, diff --git a/dom/interfaces/events/nsIDOMTouchEvent.idl b/dom/interfaces/events/nsIDOMTouchEvent.idl index f2993f68a62..a7ad489c2ab 100644 --- a/dom/interfaces/events/nsIDOMTouchEvent.idl +++ b/dom/interfaces/events/nsIDOMTouchEvent.idl @@ -73,7 +73,8 @@ interface nsIDOMTouch : nsISupports { [scriptable, uuid(60706eb7-d50d-4379-b01c-e78e6af84213)] interface nsIDOMTouchList : nsISupports { readonly attribute unsigned long length; - nsIDOMTouch item(in unsigned long index); + [getter,forward(getItemAt)] nsIDOMTouch item(in unsigned long index); + [noscript,notxpcom,nostdcall] nsIDOMTouch getItemAt(in unsigned long index); nsIDOMTouch identifiedTouch(in long identifier); }; diff --git a/js/xpconnect/src/dombindings.conf b/js/xpconnect/src/dombindings.conf index 7489fd3056e..afe9958f417 100644 --- a/js/xpconnect/src/dombindings.conf +++ b/js/xpconnect/src/dombindings.conf @@ -8,12 +8,16 @@ prefableClasses = { 'DOMSettableTokenList': 'nsDOMSettableTokenList', 'ClientRectList': 'nsClientRectList', 'PaintRequestList': 'nsPaintRequestList', + 'TouchList': 'nsDOMTouchList', } irregularFilenames = { 'nsHTMLOptionCollection': 'nsHTMLSelectElement', 'nsClientRectList': 'nsClientRect', 'nsPaintRequestList': 'nsPaintRequest', + 'nsIDOMTouch': 'nsIDOMTouchEvent', + 'nsIDOMTouchList': 'nsIDOMTouchEvent', + 'nsDOMTouchList': 'nsDOMTouchEvent', } customInheritance = {