michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * Implementation of DOMTokenList specified by HTML5. michael@0: */ michael@0: michael@0: #ifndef nsDOMTokenList_h___ michael@0: #define nsDOMTokenList_h___ michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "nsDOMString.h" michael@0: #include "nsWrapperCache.h" michael@0: #include "mozilla/dom/Element.h" michael@0: #include "mozilla/dom/BindingDeclarations.h" michael@0: michael@0: namespace mozilla { michael@0: class ErrorResult; michael@0: michael@0: } // namespace mozilla michael@0: michael@0: class nsAttrValue; michael@0: class nsIAtom; michael@0: michael@0: // nsISupports must be on the primary inheritance chain michael@0: // because nsDOMSettableTokenList is traversed by Element. michael@0: class nsDOMTokenList : public nsISupports, michael@0: public nsWrapperCache michael@0: { michael@0: protected: michael@0: typedef mozilla::dom::Element Element; michael@0: michael@0: public: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMTokenList) michael@0: michael@0: nsDOMTokenList(Element* aElement, nsIAtom* aAttrAtom); michael@0: michael@0: virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE; michael@0: michael@0: Element* GetParentObject() michael@0: { michael@0: return mElement; michael@0: } michael@0: michael@0: uint32_t Length(); michael@0: void Item(uint32_t aIndex, nsAString& aResult) michael@0: { michael@0: bool found; michael@0: IndexedGetter(aIndex, found, aResult); michael@0: if (!found) { michael@0: SetDOMStringToNull(aResult); michael@0: } michael@0: } michael@0: void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aResult); michael@0: bool Contains(const nsAString& aToken, mozilla::ErrorResult& aError); michael@0: void Add(const nsAString& aToken, mozilla::ErrorResult& aError); michael@0: void Add(const nsTArray& aTokens, michael@0: mozilla::ErrorResult& aError); michael@0: void Remove(const nsAString& aToken, mozilla::ErrorResult& aError); michael@0: void Remove(const nsTArray& aTokens, michael@0: mozilla::ErrorResult& aError); michael@0: bool Toggle(const nsAString& aToken, michael@0: const mozilla::dom::Optional& force, michael@0: mozilla::ErrorResult& aError); michael@0: void Stringify(nsAString& aResult); michael@0: michael@0: protected: michael@0: virtual ~nsDOMTokenList(); michael@0: michael@0: nsresult CheckToken(const nsAString& aStr); michael@0: nsresult CheckTokens(const nsTArray& aStr); michael@0: void AddInternal(const nsAttrValue* aAttr, michael@0: const nsTArray& aTokens); michael@0: void RemoveInternal(const nsAttrValue* aAttr, michael@0: const nsTArray& aTokens); michael@0: inline const nsAttrValue* GetParsedAttr(); michael@0: michael@0: nsCOMPtr mElement; michael@0: nsCOMPtr mAttrAtom; michael@0: }; michael@0: michael@0: #endif // nsDOMTokenList_h___