Fix for bug 717013 (Add new DOM binding for DOMTokenList). r=jst.

--HG--
extra : rebase_source : 6ae0abe3bbe33a140c62c193685e23529d44e6d4
This commit is contained in:
Peter Van der Beken 2011-08-22 11:14:13 +02:00
Родитель e9e7101bcd
Коммит 6ebfe4a8d3
11 изменённых файлов: 81 добавлений и 13 удалений

Просмотреть файл

@ -39,6 +39,7 @@
*/
#include "nsDOMSettableTokenList.h"
#include "dombindings.h"
nsDOMSettableTokenList::nsDOMSettableTokenList(nsGenericElement *aElement, nsIAtom* aAttrAtom)
@ -78,3 +79,10 @@ nsDOMSettableTokenList::SetValue(const nsAString& aValue)
return mElement->SetAttr(kNameSpaceID_None, mAttrAtom, aValue, true);
}
JSObject*
nsDOMSettableTokenList::WrapObject(JSContext *cx, XPCWrappedNativeScope *scope,
bool *triedToWrap)
{
return mozilla::dom::binding::DOMSettableTokenList::create(cx, scope, this,
triedToWrap);
}

Просмотреть файл

@ -59,6 +59,9 @@ public:
nsDOMSettableTokenList(nsGenericElement* aElement, nsIAtom* aAttrAtom);
virtual JSObject* WrapObject(JSContext *cx, XPCWrappedNativeScope *scope,
bool *triedToWrap);
protected:
virtual ~nsDOMSettableTokenList();
};

Просмотреть файл

@ -44,6 +44,7 @@
#include "nsContentUtils.h"
#include "nsDOMError.h"
#include "nsGenericElement.h"
#include "dombindings.h"
nsDOMTokenList::nsDOMTokenList(nsGenericElement *aElement, nsIAtom* aAttrAtom)
@ -52,21 +53,34 @@ nsDOMTokenList::nsDOMTokenList(nsGenericElement *aElement, nsIAtom* aAttrAtom)
{
// We don't add a reference to our element. If it goes away,
// we'll be told to drop our reference
SetIsProxy();
}
nsDOMTokenList::~nsDOMTokenList() { }
NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMTokenList)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMTokenList)
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMTokenList)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsDOMTokenList)
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_TRACE_END
DOMCI_DATA(DOMTokenList, nsDOMTokenList)
NS_INTERFACE_TABLE_HEAD(nsDOMTokenList)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_TABLE1(nsDOMTokenList,
nsIDOMDOMTokenList)
NS_INTERFACE_TABLE_TO_MAP_SEGUE
NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(nsDOMTokenList)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DOMTokenList)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsDOMTokenList)
NS_IMPL_RELEASE(nsDOMTokenList)
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMTokenList)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMTokenList)
void
nsDOMTokenList::DropReference()
@ -293,3 +307,12 @@ nsDOMTokenList::ToString(nsAString& aResult)
return NS_OK;
}
JSObject*
nsDOMTokenList::WrapObject(JSContext *cx, XPCWrappedNativeScope *scope,
bool *triedToWrap)
{
return mozilla::dom::binding::DOMTokenList::create(cx, scope, this,
triedToWrap);
}

Просмотреть файл

@ -46,16 +46,26 @@
class nsAttrValue;
class nsDOMTokenList : public nsIDOMDOMTokenList
class nsDOMTokenList : public nsIDOMDOMTokenList,
public nsWrapperCache
{
public:
NS_DECL_ISUPPORTS
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMTokenList)
NS_DECL_NSIDOMDOMTOKENLIST
nsDOMTokenList(nsGenericElement* aElement, nsIAtom* aAttrAtom);
void DropReference();
virtual JSObject* WrapObject(JSContext *cx, XPCWrappedNativeScope *scope,
bool *triedToWrap);
nsINode *GetParentObject()
{
return mElement;
}
protected:
~nsDOMTokenList();

Просмотреть файл

@ -1980,7 +1980,7 @@ nsGenericElement::GetChildrenList()
return slots->mChildrenList;
}
nsIDOMDOMTokenList*
nsDOMTokenList*
nsGenericElement::GetClassList(nsresult *aResult)
{
*aResult = NS_ERROR_OUT_OF_MEMORY;
@ -2468,6 +2468,9 @@ nsGenericElement::nsDOMSlots::Traverse(nsCycleCollectionTraversalCallback &cb, b
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mChildrenList");
cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIDOMNodeList*, mChildrenList));
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mClassList");
cb.NoteXPCOMChild(mClassList.get());
}
void
@ -2482,6 +2485,10 @@ nsGenericElement::nsDOMSlots::Unlink(bool aIsXUL)
if (aIsXUL)
NS_IF_RELEASE(mControllers);
mChildrenList = nsnull;
if (mClassList) {
mClassList->DropReference();
mClassList = nsnull;
}
}
nsGenericElement::nsGenericElement(already_AddRefed<nsINodeInfo> aNodeInfo)

Просмотреть файл

@ -597,7 +597,7 @@ public:
nsIContent* GetLastElementChild();
nsIContent* GetPreviousElementSibling();
nsIContent* GetNextElementSibling();
nsIDOMDOMTokenList* GetClassList(nsresult *aResult);
nsDOMTokenList* GetClassList(nsresult *aResult);
bool MozMatchesSelector(const nsAString& aSelector, nsresult* aResult);
/**

Просмотреть файл

@ -100,8 +100,8 @@ public:
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLOutputElement,
nsGenericHTMLFormElement)
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsHTMLOutputElement,
nsGenericHTMLFormElement)
virtual nsXPCClassInfo* GetClassInfo();
protected:
@ -136,13 +136,26 @@ nsHTMLOutputElement::~nsHTMLOutputElement()
}
}
NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLOutputElement)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsHTMLOutputElement,
nsGenericHTMLFormElement)
if (tmp->mTokenList) {
tmp->mTokenList->DropReference();
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTokenList)
}
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLOutputElement,
nsGenericHTMLFormElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mTokenList,
nsDOMTokenList)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_ADDREF_INHERITED(nsHTMLOutputElement, nsGenericElement)
NS_IMPL_RELEASE_INHERITED(nsHTMLOutputElement, nsGenericElement)
DOMCI_NODE_DATA(HTMLOutputElement, nsHTMLOutputElement)
NS_INTERFACE_TABLE_HEAD(nsHTMLOutputElement)
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(nsHTMLOutputElement)
NS_HTML_CONTENT_INTERFACE_TABLE3(nsHTMLOutputElement,
nsIDOMHTMLOutputElement,
nsIMutationObserver,

Просмотреть файл

@ -49,11 +49,11 @@ interface nsIDOMDOMTokenList : nsISupports
{
readonly attribute unsigned long length;
DOMString item(in unsigned long index);
[getter] DOMString item(in unsigned long index);
boolean contains([Null(Stringify)] in DOMString token);
void add([Null(Stringify)] in DOMString token);
void remove([Null(Stringify)] in DOMString token);
boolean toggle([Null(Stringify)] in DOMString token);
DOMString toString();
[stringifier] DOMString toString();
};

Просмотреть файл

@ -518,6 +518,7 @@ customIncludes = [
'nsINodeList.h',
'nsCSSPropertiesQS.h',
'nsDocument.h',
'nsDOMTokenList.h',
'nsGenericDOMDataNode.h',
'nsGenericElement.h',
'nsGenericHTMLElement.h',
@ -785,7 +786,7 @@ customMethodCalls = {
},
'nsIDOMElement_GetClassList': {
'thisType': 'nsGenericElement',
'code': ' nsIDOMDOMTokenList *result = self->GetClassList(&rv);'
'code': ' nsDOMTokenList *result = self->GetClassList(&rv);'
},
'nsIDOMElement_SetCapture': {
'thisType': 'nsGenericElement',

Просмотреть файл

@ -2,6 +2,8 @@ classes = {
'NodeList': 'nsINodeList',
'HTMLCollection': 'nsIHTMLCollection',
'HTMLOptionsCollection': 'nsHTMLOptionCollection',
'DOMTokenList': 'nsDOMTokenList',
'DOMSettableTokenList': 'nsDOMSettableTokenList',
}
irregularFilenames = {

Просмотреть файл

@ -43,6 +43,7 @@
#include "jsapi.h"
#include "jsproxy.h"
#include "xpcpublic.h"
#include "nsString.h"
namespace mozilla {
namespace dom {