1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/src/nsDOMTokenList.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,84 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +/* 1.9 + * Implementation of DOMTokenList specified by HTML5. 1.10 + */ 1.11 + 1.12 +#ifndef nsDOMTokenList_h___ 1.13 +#define nsDOMTokenList_h___ 1.14 + 1.15 +#include "nsCOMPtr.h" 1.16 +#include "nsDOMString.h" 1.17 +#include "nsWrapperCache.h" 1.18 +#include "mozilla/dom/Element.h" 1.19 +#include "mozilla/dom/BindingDeclarations.h" 1.20 + 1.21 +namespace mozilla { 1.22 +class ErrorResult; 1.23 + 1.24 +} // namespace mozilla 1.25 + 1.26 +class nsAttrValue; 1.27 +class nsIAtom; 1.28 + 1.29 +// nsISupports must be on the primary inheritance chain 1.30 +// because nsDOMSettableTokenList is traversed by Element. 1.31 +class nsDOMTokenList : public nsISupports, 1.32 + public nsWrapperCache 1.33 +{ 1.34 +protected: 1.35 + typedef mozilla::dom::Element Element; 1.36 + 1.37 +public: 1.38 + NS_DECL_CYCLE_COLLECTING_ISUPPORTS 1.39 + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMTokenList) 1.40 + 1.41 + nsDOMTokenList(Element* aElement, nsIAtom* aAttrAtom); 1.42 + 1.43 + virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE; 1.44 + 1.45 + Element* GetParentObject() 1.46 + { 1.47 + return mElement; 1.48 + } 1.49 + 1.50 + uint32_t Length(); 1.51 + void Item(uint32_t aIndex, nsAString& aResult) 1.52 + { 1.53 + bool found; 1.54 + IndexedGetter(aIndex, found, aResult); 1.55 + if (!found) { 1.56 + SetDOMStringToNull(aResult); 1.57 + } 1.58 + } 1.59 + void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aResult); 1.60 + bool Contains(const nsAString& aToken, mozilla::ErrorResult& aError); 1.61 + void Add(const nsAString& aToken, mozilla::ErrorResult& aError); 1.62 + void Add(const nsTArray<nsString>& aTokens, 1.63 + mozilla::ErrorResult& aError); 1.64 + void Remove(const nsAString& aToken, mozilla::ErrorResult& aError); 1.65 + void Remove(const nsTArray<nsString>& aTokens, 1.66 + mozilla::ErrorResult& aError); 1.67 + bool Toggle(const nsAString& aToken, 1.68 + const mozilla::dom::Optional<bool>& force, 1.69 + mozilla::ErrorResult& aError); 1.70 + void Stringify(nsAString& aResult); 1.71 + 1.72 +protected: 1.73 + virtual ~nsDOMTokenList(); 1.74 + 1.75 + nsresult CheckToken(const nsAString& aStr); 1.76 + nsresult CheckTokens(const nsTArray<nsString>& aStr); 1.77 + void AddInternal(const nsAttrValue* aAttr, 1.78 + const nsTArray<nsString>& aTokens); 1.79 + void RemoveInternal(const nsAttrValue* aAttr, 1.80 + const nsTArray<nsString>& aTokens); 1.81 + inline const nsAttrValue* GetParsedAttr(); 1.82 + 1.83 + nsCOMPtr<Element> mElement; 1.84 + nsCOMPtr<nsIAtom> mAttrAtom; 1.85 +}; 1.86 + 1.87 +#endif // nsDOMTokenList_h___