2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-08-12 01:55:14 -07:00
|
|
|
|
|
|
|
/*
|
2013-01-15 00:35:59 -08:00
|
|
|
* Implementation of DOMTokenList specified by HTML5.
|
2009-08-12 01:55:14 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef nsDOMTokenList_h___
|
|
|
|
#define nsDOMTokenList_h___
|
|
|
|
|
2012-10-16 04:51:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDOMString.h"
|
|
|
|
#include "nsWrapperCache.h"
|
2009-08-12 01:55:14 -07:00
|
|
|
|
2012-09-05 13:49:53 -07:00
|
|
|
namespace mozilla {
|
|
|
|
class ErrorResult;
|
2012-11-14 14:10:07 -08:00
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
class Element;
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2009-08-12 01:55:14 -07:00
|
|
|
class nsAttrValue;
|
2012-10-16 04:51:00 -07:00
|
|
|
class nsIAtom;
|
2009-08-12 01:55:14 -07:00
|
|
|
|
2013-01-15 00:35:59 -08:00
|
|
|
// nsISupports must be on the primary inheritance chain
|
2012-11-14 14:10:07 -08:00
|
|
|
// because nsDOMSettableTokenList is traversed by Element.
|
2013-01-15 00:35:59 -08:00
|
|
|
class nsDOMTokenList : public nsISupports,
|
2011-08-22 02:14:13 -07:00
|
|
|
public nsWrapperCache
|
2009-08-12 01:55:14 -07:00
|
|
|
{
|
2012-11-14 14:10:08 -08:00
|
|
|
protected:
|
2012-11-14 14:10:07 -08:00
|
|
|
typedef mozilla::dom::Element Element;
|
|
|
|
|
2009-08-12 01:55:14 -07:00
|
|
|
public:
|
2011-08-22 02:14:13 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMTokenList)
|
2009-08-12 01:55:14 -07:00
|
|
|
|
2012-11-14 14:10:07 -08:00
|
|
|
nsDOMTokenList(Element* aElement, nsIAtom* aAttrAtom);
|
2009-08-12 01:55:14 -07:00
|
|
|
|
|
|
|
void DropReference();
|
|
|
|
|
2013-04-25 09:29:54 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx,
|
|
|
|
JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
|
2011-08-22 02:14:13 -07:00
|
|
|
|
2012-11-14 14:10:07 -08:00
|
|
|
Element* GetParentObject()
|
2011-08-22 02:14:13 -07:00
|
|
|
{
|
|
|
|
return mElement;
|
|
|
|
}
|
|
|
|
|
2012-09-05 13:49:53 -07:00
|
|
|
uint32_t Length();
|
|
|
|
void Item(uint32_t aIndex, nsAString& aResult)
|
|
|
|
{
|
|
|
|
bool found;
|
|
|
|
IndexedGetter(aIndex, found, aResult);
|
|
|
|
if (!found) {
|
|
|
|
SetDOMStringToNull(aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aResult);
|
|
|
|
bool Contains(const nsAString& aToken, mozilla::ErrorResult& aError);
|
|
|
|
void Add(const nsAString& aToken, mozilla::ErrorResult& aError);
|
|
|
|
void Remove(const nsAString& aToken, mozilla::ErrorResult& aError);
|
|
|
|
bool Toggle(const nsAString& aToken, mozilla::ErrorResult& aError);
|
|
|
|
void Stringify(nsAString& aResult);
|
|
|
|
|
2012-06-04 16:49:57 -07:00
|
|
|
protected:
|
2012-06-18 19:30:09 -07:00
|
|
|
virtual ~nsDOMTokenList();
|
2012-06-04 16:49:57 -07:00
|
|
|
|
2009-08-12 01:55:14 -07:00
|
|
|
nsresult CheckToken(const nsAString& aStr);
|
|
|
|
void AddInternal(const nsAttrValue* aAttr, const nsAString& aToken);
|
|
|
|
void RemoveInternal(const nsAttrValue* aAttr, const nsAString& aToken);
|
2012-10-16 04:51:00 -07:00
|
|
|
inline const nsAttrValue* GetParsedAttr();
|
2009-08-12 01:55:14 -07:00
|
|
|
|
2012-11-14 14:10:07 -08:00
|
|
|
Element* mElement;
|
2009-08-12 01:55:14 -07:00
|
|
|
nsCOMPtr<nsIAtom> mAttrAtom;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsDOMTokenList_h___
|