diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index a93c77f28ee..4467d7edfd1 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -32,6 +32,7 @@ class nsAString; class nsBindingManager; class nsCSSStyleSheet; class nsDOMNavigationTiming; +class nsDOMTouchList; class nsEventStates; class nsFrameLoader; class nsHTMLCSSStyleSheet; @@ -50,7 +51,6 @@ class nsIDOMDocumentFragment; class nsIDOMDocumentType; class nsIDOMElement; class nsIDOMNodeList; -class nsIDOMTouchList; class nsIDOMXPathExpression; class nsIDOMXPathNSResolver; class nsILayoutHistoryState; @@ -2099,11 +2099,11 @@ public: int32_t aScreenX, int32_t aScreenY, int32_t aClientX, int32_t aClientY, int32_t aRadiusX, int32_t aRadiusY, float aRotationAngle, float aForce); - already_AddRefed CreateTouchList(); - already_AddRefed + already_AddRefed CreateTouchList(); + already_AddRefed CreateTouchList(mozilla::dom::Touch& aTouch, const mozilla::dom::Sequence >& aTouches); - already_AddRefed + already_AddRefed CreateTouchList(const mozilla::dom::Sequence >& aTouches); void SetStyleSheetChangeEventsEnabled(bool aValue) diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index ecf40a50299..5a337187052 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -9297,7 +9297,7 @@ NS_IMETHODIMP nsDocument::CreateTouchList(nsIVariant* aPoints, nsIDOMTouchList** aRetVal) { - nsRefPtr retval = new nsDOMTouchList(); + nsRefPtr retval = new nsDOMTouchList(ToSupports(this)); if (aPoints) { uint16_t type; aPoints->GetDataType(&type); @@ -9334,18 +9334,18 @@ nsDocument::CreateTouchList(nsIVariant* aPoints, return NS_OK; } -already_AddRefed +already_AddRefed nsIDocument::CreateTouchList() { - nsRefPtr retval = new nsDOMTouchList(); + nsRefPtr retval = new nsDOMTouchList(ToSupports(this)); return retval.forget(); } -already_AddRefed +already_AddRefed nsIDocument::CreateTouchList(Touch& aTouch, const Sequence >& aTouches) { - nsRefPtr retval = new nsDOMTouchList(); + nsRefPtr retval = new nsDOMTouchList(ToSupports(this)); retval->Append(&aTouch); for (uint32_t i = 0; i < aTouches.Length(); ++i) { retval->Append(aTouches[i].get()); @@ -9353,10 +9353,10 @@ nsIDocument::CreateTouchList(Touch& aTouch, return retval.forget(); } -already_AddRefed +already_AddRefed nsIDocument::CreateTouchList(const Sequence >& aTouches) { - nsRefPtr retval = new nsDOMTouchList(); + nsRefPtr retval = new nsDOMTouchList(ToSupports(this)); for (uint32_t i = 0; i < aTouches.Length(); ++i) { retval->Append(aTouches[i].get()); } diff --git a/content/events/src/nsDOMTouchEvent.cpp b/content/events/src/nsDOMTouchEvent.cpp index a1dd0952f0d..b91bf53a691 100644 --- a/content/events/src/nsDOMTouchEvent.cpp +++ b/content/events/src/nsDOMTouchEvent.cpp @@ -10,56 +10,67 @@ #include "mozilla/Preferences.h" #include "nsPresContext.h" #include "mozilla/dom/Touch.h" +#include "mozilla/dom/TouchListBinding.h" using namespace mozilla; using namespace mozilla::dom; // TouchList -nsDOMTouchList::nsDOMTouchList(const nsTArray< nsRefPtr >& aTouches) -{ - mPoints.AppendElements(aTouches); - nsJSContext::LikelyShortLivingObjectCreated(); -} - -DOMCI_DATA(TouchList, 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) NS_INTERFACE_MAP_END -NS_IMPL_CYCLE_COLLECTION_1(nsDOMTouchList, mPoints) +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(nsDOMTouchList, mParent, mPoints) NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMTouchList) NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMTouchList) +/* virtual */ JSObject* +nsDOMTouchList::WrapObject(JSContext* aCx, JS::Handle aScope) +{ + return TouchListBinding::Wrap(aCx, aScope, this); +} + +/* static */ bool +nsDOMTouchList::PrefEnabled() +{ + return nsDOMTouchEvent::PrefEnabled(); +} + NS_IMETHODIMP nsDOMTouchList::GetLength(uint32_t* aLength) { - *aLength = mPoints.Length(); + *aLength = Length(); return NS_OK; } NS_IMETHODIMP nsDOMTouchList::Item(uint32_t aIndex, nsIDOMTouch** aRetVal) { - NS_IF_ADDREF(*aRetVal = mPoints.SafeElementAt(aIndex, nullptr)); + NS_IF_ADDREF(*aRetVal = Item(aIndex)); return NS_OK; } NS_IMETHODIMP nsDOMTouchList::IdentifiedTouch(int32_t aIdentifier, nsIDOMTouch** aRetVal) { - *aRetVal = nullptr; + NS_IF_ADDREF(*aRetVal = IdentifiedTouch(aIdentifier)); + return NS_OK; +} + +Touch* +nsDOMTouchList::IdentifiedTouch(int32_t aIdentifier) const +{ for (uint32_t i = 0; i < mPoints.Length(); ++i) { - nsRefPtr point = mPoints[i]; + Touch* point = mPoints[i]; if (point && point->Identifier() == aIdentifier) { - point.forget(aRetVal); - break; + return point; } } - return NS_OK; + return nullptr; } // TouchEvent @@ -156,9 +167,9 @@ nsDOMTouchEvent::Touches() unchangedTouches.AppendElement(touches[i]); } } - mTouches = new nsDOMTouchList(unchangedTouches); + mTouches = new nsDOMTouchList(ToSupports(this), unchangedTouches); } else { - mTouches = new nsDOMTouchList(touchEvent->touches); + mTouches = new nsDOMTouchList(ToSupports(this), touchEvent->touches); } } return mTouches; @@ -189,7 +200,7 @@ nsDOMTouchEvent::TargetTouches() } } } - mTargetTouches = new nsDOMTouchList(targetTouches); + mTargetTouches = new nsDOMTouchList(ToSupports(this), targetTouches); } return mTargetTouches; } @@ -214,7 +225,7 @@ nsDOMTouchEvent::ChangedTouches() changedTouches.AppendElement(touches[i]); } } - mChangedTouches = new nsDOMTouchList(changedTouches); + mChangedTouches = new nsDOMTouchList(ToSupports(this), changedTouches); } return mChangedTouches; } diff --git a/content/events/src/nsDOMTouchEvent.h b/content/events/src/nsDOMTouchEvent.h index 44152da894b..5676f7a49bd 100644 --- a/content/events/src/nsDOMTouchEvent.h +++ b/content/events/src/nsDOMTouchEvent.h @@ -12,33 +12,68 @@ #include "mozilla/Attributes.h" #include "nsJSEnvironment.h" #include "mozilla/dom/TouchEventBinding.h" +#include "nsWrapperCache.h" class nsDOMTouchList MOZ_FINAL : public nsIDOMTouchList + , public nsWrapperCache { typedef mozilla::dom::Touch Touch; 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(nsISupports* aParent) + : mParent(aParent) { + SetIsDOMBinding(); + nsJSContext::LikelyShortLivingObjectCreated(); + } + nsDOMTouchList(nsISupports* aParent, + const nsTArray< nsRefPtr >& aTouches) + : mParent(aParent) + , mPoints(aTouches) + { + SetIsDOMBinding(); nsJSContext::LikelyShortLivingObjectCreated(); } - nsDOMTouchList(const nsTArray< nsRefPtr >& aTouches); void Append(Touch* aPoint) { mPoints.AppendElement(aPoint); } - nsIDOMTouch* GetItemAt(uint32_t aIndex) + virtual JSObject* + WrapObject(JSContext* aCx, JS::Handle aScope) MOZ_OVERRIDE; + + nsISupports* GetParentObject() const { - return mPoints.SafeElementAt(aIndex, nullptr); + return mParent; } + static bool PrefEnabled(); + + uint32_t Length() const + { + return mPoints.Length(); + } + Touch* Item(uint32_t aIndex) const + { + return mPoints.SafeElementAt(aIndex); + } + Touch* IndexedGetter(uint32_t aIndex, bool& aFound) const + { + aFound = aIndex < mPoints.Length(); + if (!aFound) { + return nullptr; + } + return mPoints[aIndex]; + } + Touch* IdentifiedTouch(int32_t aIdentifier) const; + protected: + nsCOMPtr mParent; nsTArray< nsRefPtr > mPoints; }; diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 882175a54fd..2533187d5c0 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -685,8 +685,6 @@ static nsDOMClassInfoData sClassInfoData[] = { NS_DEFINE_CLASSINFO_DATA(IDBOpenDBRequest, IDBEventTargetSH, IDBEVENTTARGET_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(TouchList, nsDOMTouchListSH, - ARRAY_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(MozCSSKeyframeRule, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) @@ -1676,11 +1674,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN_MAYBE_DISABLE(TouchList, nsIDOMTouchList, - !nsDOMTouchEvent::PrefEnabled()) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMTouchList) - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(MozCSSKeyframeRule, nsIDOMMozCSSKeyframeRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozCSSKeyframeRule) DOM_CLASSINFO_MAP_END @@ -2096,14 +2089,6 @@ nsDOMClassInfo::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, return NS_OK; } -nsISupports* -nsDOMTouchListSH::GetItemAt(nsISupports *aNative, uint32_t aIndex, - nsWrapperCache **aCache, nsresult *aResult) -{ - nsDOMTouchList* list = static_cast(aNative); - return list->GetItemAt(aIndex); -} - NS_IMETHODIMP nsDOMClassInfo::Convert(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *obj, uint32_t type, jsval *vp, diff --git a/dom/base/nsDOMClassInfo.h b/dom/base/nsDOMClassInfo.h index 1bda3d84b51..5921cd6dbb7 100644 --- a/dom/base/nsDOMClassInfo.h +++ b/dom/base/nsDOMClassInfo.h @@ -762,27 +762,6 @@ public: } }; -class nsDOMTouchListSH : public nsArraySH -{ - protected: - nsDOMTouchListSH(nsDOMClassInfoData* aData) : nsArraySH(aData) - { - } - - virtual ~nsDOMTouchListSH() - { - } - - virtual nsISupports* GetItemAt(nsISupports *aNative, uint32_t aIndex, - nsWrapperCache **aCache, nsresult *aResult) MOZ_OVERRIDE; - - public: - static nsIClassInfo* doCreate(nsDOMClassInfoData* aData) - { - return new nsDOMTouchListSH(aData); - } -}; - // WebApps Storage helpers class nsStorage2SH : public nsDOMGenericSH diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h index 366cea57ea4..47c8c1d4eb8 100644 --- a/dom/base/nsDOMClassInfoClasses.h +++ b/dom/base/nsDOMClassInfoClasses.h @@ -138,7 +138,6 @@ DOMCI_CLASS(IDBKeyRange) DOMCI_CLASS(IDBIndex) DOMCI_CLASS(IDBOpenDBRequest) -DOMCI_CLASS(TouchList) DOMCI_CLASS(MozCSSKeyframeRule) DOMCI_CLASS(MozCSSKeyframesRule) diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 6e75fac534a..a0770c6e9b8 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -1136,6 +1136,11 @@ DOMInterfaces = { 'nativeType': 'nsDOMTouchEvent', }, +'TouchList': { + 'nativeType': 'nsDOMTouchList', + 'headerFile': 'nsDOMTouchEvent.h', +}, + 'TransitionEvent': { 'nativeType': 'nsDOMTransitionEvent', }, @@ -1708,7 +1713,6 @@ addExternalIface('Selection', nativeType='nsISelection') addExternalIface('StyleSheetList') addExternalIface('SVGLength') addExternalIface('SVGNumber') -addExternalIface('TouchList', headerFile='nsIDOMTouchEvent.h') addExternalIface('URI', nativeType='nsIURI', headerFile='nsIURI.h', notflattened=True) addExternalIface('UserDataHandler') diff --git a/dom/webidl/Document.webidl b/dom/webidl/Document.webidl index 59f4902e338..778d55070a5 100644 --- a/dom/webidl/Document.webidl +++ b/dom/webidl/Document.webidl @@ -16,7 +16,6 @@ */ interface StyleSheetList; -interface TouchList; interface WindowProxy; interface nsISupports; diff --git a/dom/webidl/TouchEvent.webidl b/dom/webidl/TouchEvent.webidl index e3ec7619a5d..b76eabf258f 100644 --- a/dom/webidl/TouchEvent.webidl +++ b/dom/webidl/TouchEvent.webidl @@ -4,7 +4,6 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ -interface TouchList; interface WindowProxy; [PrefControlled] diff --git a/dom/webidl/TouchList.webidl b/dom/webidl/TouchList.webidl index 643ba0ecb82..5b2dca75bd1 100644 --- a/dom/webidl/TouchList.webidl +++ b/dom/webidl/TouchList.webidl @@ -4,14 +4,20 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. * * The origin of this IDL file is - * http://dvcs.w3.org/hg/webevents/raw-file/default/touchevents.html + * https://dvcs.w3.org/hg/webevents/raw-file/v1/touchevents.html * * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C * liability, trademark and document use rules apply. */ +[PrefControlled] interface TouchList { + [Pure] readonly attribute unsigned long length; getter Touch? item(unsigned long index); - Touch identifiedTouch(long identifier); +}; + +/* Mozilla extension. */ +partial interface TouchList { + Touch? identifiedTouch(long identifier); }; diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index fffd4751620..510cf83e8b7 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -343,6 +343,7 @@ webidl_files = \ TimeRanges.webidl \ Touch.webidl \ TouchEvent.webidl \ + TouchList.webidl \ TransitionEvent.webidl \ TreeColumns.webidl \ TreeWalker.webidl \ diff --git a/js/xpconnect/src/dom_quickstubs.qsconf b/js/xpconnect/src/dom_quickstubs.qsconf index ac569e21969..9ee4ddefa9f 100644 --- a/js/xpconnect/src/dom_quickstubs.qsconf +++ b/js/xpconnect/src/dom_quickstubs.qsconf @@ -53,8 +53,6 @@ members = [ # dom/interfaces/core 'nsIDOMDOMStringList.*', - 'nsIDOMTouchList.*', - # dom/interfaces/storage 'nsIDOMToString.toString', 'nsIDOMStorage.setItem', @@ -115,14 +113,8 @@ members = [ irregularFilenames = { # stowaways 'nsIDOMBlob': 'nsIDOMFile', - 'nsIIndexedDatabaseUsageCallback': 'nsIIndexedDatabaseManager', - - 'nsIDOMTouch': 'nsIDOMTouchEvent', - 'nsIDOMTouchList': 'nsIDOMTouchEvent', - 'nsITelephoneCallback': 'nsITelephone', - 'nsIDOMWindowPerformance': 'nsIDOMWindow', }