Bug 734503 - Add new DOM binding for TouchList; r=jst.

This commit is contained in:
Peter Van der Beken 2013-07-10 11:53:53 +02:00
parent c143803fda
commit 9cbb0938bb
13 changed files with 96 additions and 86 deletions

View File

@ -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<nsIDOMTouchList> CreateTouchList();
already_AddRefed<nsIDOMTouchList>
already_AddRefed<nsDOMTouchList> CreateTouchList();
already_AddRefed<nsDOMTouchList>
CreateTouchList(mozilla::dom::Touch& aTouch,
const mozilla::dom::Sequence<mozilla::dom::OwningNonNull<mozilla::dom::Touch> >& aTouches);
already_AddRefed<nsIDOMTouchList>
already_AddRefed<nsDOMTouchList>
CreateTouchList(const mozilla::dom::Sequence<mozilla::dom::OwningNonNull<mozilla::dom::Touch> >& aTouches);
void SetStyleSheetChangeEventsEnabled(bool aValue)

View File

@ -9297,7 +9297,7 @@ NS_IMETHODIMP
nsDocument::CreateTouchList(nsIVariant* aPoints,
nsIDOMTouchList** aRetVal)
{
nsRefPtr<nsDOMTouchList> retval = new nsDOMTouchList();
nsRefPtr<nsDOMTouchList> 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<nsIDOMTouchList>
already_AddRefed<nsDOMTouchList>
nsIDocument::CreateTouchList()
{
nsRefPtr<nsDOMTouchList> retval = new nsDOMTouchList();
nsRefPtr<nsDOMTouchList> retval = new nsDOMTouchList(ToSupports(this));
return retval.forget();
}
already_AddRefed<nsIDOMTouchList>
already_AddRefed<nsDOMTouchList>
nsIDocument::CreateTouchList(Touch& aTouch,
const Sequence<OwningNonNull<Touch> >& aTouches)
{
nsRefPtr<nsDOMTouchList> retval = new nsDOMTouchList();
nsRefPtr<nsDOMTouchList> 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<nsIDOMTouchList>
already_AddRefed<nsDOMTouchList>
nsIDocument::CreateTouchList(const Sequence<OwningNonNull<Touch> >& aTouches)
{
nsRefPtr<nsDOMTouchList> retval = new nsDOMTouchList();
nsRefPtr<nsDOMTouchList> retval = new nsDOMTouchList(ToSupports(this));
for (uint32_t i = 0; i < aTouches.Length(); ++i) {
retval->Append(aTouches[i].get());
}

View File

@ -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<Touch> >& 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<JSObject*> 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<Touch> 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;
}

View File

@ -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<Touch> >& aTouches)
: mParent(aParent)
, mPoints(aTouches)
{
SetIsDOMBinding();
nsJSContext::LikelyShortLivingObjectCreated();
}
nsDOMTouchList(const nsTArray< nsRefPtr<Touch> >& aTouches);
void Append(Touch* aPoint)
{
mPoints.AppendElement(aPoint);
}
nsIDOMTouch* GetItemAt(uint32_t aIndex)
virtual JSObject*
WrapObject(JSContext* aCx, JS::Handle<JSObject*> 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<nsISupports> mParent;
nsTArray< nsRefPtr<Touch> > mPoints;
};

View File

@ -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<nsDOMTouchList*>(aNative);
return list->GetItemAt(aIndex);
}
NS_IMETHODIMP
nsDOMClassInfo::Convert(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, uint32_t type, jsval *vp,

View File

@ -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

View File

@ -138,7 +138,6 @@ DOMCI_CLASS(IDBKeyRange)
DOMCI_CLASS(IDBIndex)
DOMCI_CLASS(IDBOpenDBRequest)
DOMCI_CLASS(TouchList)
DOMCI_CLASS(MozCSSKeyframeRule)
DOMCI_CLASS(MozCSSKeyframesRule)

View File

@ -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')

View File

@ -16,7 +16,6 @@
*/
interface StyleSheetList;
interface TouchList;
interface WindowProxy;
interface nsISupports;

View File

@ -4,7 +4,6 @@
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
interface TouchList;
interface WindowProxy;
[PrefControlled]

View File

@ -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);
};

View File

@ -343,6 +343,7 @@ webidl_files = \
TimeRanges.webidl \
Touch.webidl \
TouchEvent.webidl \
TouchList.webidl \
TransitionEvent.webidl \
TreeColumns.webidl \
TreeWalker.webidl \

View File

@ -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',
}