|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 /* |
|
6 * Implementation of DOMTokenList specified by HTML5. |
|
7 */ |
|
8 |
|
9 #ifndef nsDOMTokenList_h___ |
|
10 #define nsDOMTokenList_h___ |
|
11 |
|
12 #include "nsCOMPtr.h" |
|
13 #include "nsDOMString.h" |
|
14 #include "nsWrapperCache.h" |
|
15 #include "mozilla/dom/Element.h" |
|
16 #include "mozilla/dom/BindingDeclarations.h" |
|
17 |
|
18 namespace mozilla { |
|
19 class ErrorResult; |
|
20 |
|
21 } // namespace mozilla |
|
22 |
|
23 class nsAttrValue; |
|
24 class nsIAtom; |
|
25 |
|
26 // nsISupports must be on the primary inheritance chain |
|
27 // because nsDOMSettableTokenList is traversed by Element. |
|
28 class nsDOMTokenList : public nsISupports, |
|
29 public nsWrapperCache |
|
30 { |
|
31 protected: |
|
32 typedef mozilla::dom::Element Element; |
|
33 |
|
34 public: |
|
35 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
36 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMTokenList) |
|
37 |
|
38 nsDOMTokenList(Element* aElement, nsIAtom* aAttrAtom); |
|
39 |
|
40 virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE; |
|
41 |
|
42 Element* GetParentObject() |
|
43 { |
|
44 return mElement; |
|
45 } |
|
46 |
|
47 uint32_t Length(); |
|
48 void Item(uint32_t aIndex, nsAString& aResult) |
|
49 { |
|
50 bool found; |
|
51 IndexedGetter(aIndex, found, aResult); |
|
52 if (!found) { |
|
53 SetDOMStringToNull(aResult); |
|
54 } |
|
55 } |
|
56 void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aResult); |
|
57 bool Contains(const nsAString& aToken, mozilla::ErrorResult& aError); |
|
58 void Add(const nsAString& aToken, mozilla::ErrorResult& aError); |
|
59 void Add(const nsTArray<nsString>& aTokens, |
|
60 mozilla::ErrorResult& aError); |
|
61 void Remove(const nsAString& aToken, mozilla::ErrorResult& aError); |
|
62 void Remove(const nsTArray<nsString>& aTokens, |
|
63 mozilla::ErrorResult& aError); |
|
64 bool Toggle(const nsAString& aToken, |
|
65 const mozilla::dom::Optional<bool>& force, |
|
66 mozilla::ErrorResult& aError); |
|
67 void Stringify(nsAString& aResult); |
|
68 |
|
69 protected: |
|
70 virtual ~nsDOMTokenList(); |
|
71 |
|
72 nsresult CheckToken(const nsAString& aStr); |
|
73 nsresult CheckTokens(const nsTArray<nsString>& aStr); |
|
74 void AddInternal(const nsAttrValue* aAttr, |
|
75 const nsTArray<nsString>& aTokens); |
|
76 void RemoveInternal(const nsAttrValue* aAttr, |
|
77 const nsTArray<nsString>& aTokens); |
|
78 inline const nsAttrValue* GetParsedAttr(); |
|
79 |
|
80 nsCOMPtr<Element> mElement; |
|
81 nsCOMPtr<nsIAtom> mAttrAtom; |
|
82 }; |
|
83 |
|
84 #endif // nsDOMTokenList_h___ |