/src/mozilla-central/dom/base/nsDOMTokenList.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | /* |
8 | | * Implementation of DOMTokenList specified by HTML5. |
9 | | */ |
10 | | |
11 | | #ifndef nsDOMTokenList_h___ |
12 | | #define nsDOMTokenList_h___ |
13 | | |
14 | | #include "nsCOMPtr.h" |
15 | | #include "nsContentUtils.h" |
16 | | #include "nsDOMString.h" |
17 | | #include "nsWhitespaceTokenizer.h" |
18 | | #include "nsWrapperCache.h" |
19 | | #include "mozilla/dom/Element.h" |
20 | | #include "mozilla/dom/BindingDeclarations.h" |
21 | | #include "mozilla/dom/DOMTokenListSupportedTokens.h" |
22 | | |
23 | | namespace mozilla { |
24 | | class ErrorResult; |
25 | | namespace dom { |
26 | | class DocGroup; |
27 | | } // namespace dom |
28 | | } // namespace mozilla |
29 | | |
30 | | class nsAttrValue; |
31 | | class nsAtom; |
32 | | |
33 | | // nsISupports must be on the primary inheritance chain |
34 | | |
35 | | class nsDOMTokenList : public nsISupports, |
36 | | public nsWrapperCache |
37 | | { |
38 | | protected: |
39 | | typedef mozilla::dom::Element Element; |
40 | | typedef mozilla::dom::DocGroup DocGroup; |
41 | | typedef nsWhitespaceTokenizerTemplate<nsContentUtils::IsHTMLWhitespace> |
42 | | WhitespaceTokenizer; |
43 | | |
44 | | public: |
45 | | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
46 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMTokenList) |
47 | | |
48 | | nsDOMTokenList(Element* aElement, nsAtom* aAttrAtom, |
49 | | const mozilla::dom::DOMTokenListSupportedTokenArray = nullptr); |
50 | | |
51 | | virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override; |
52 | | |
53 | | Element* GetParentObject() |
54 | 0 | { |
55 | 0 | return mElement; |
56 | 0 | } |
57 | | |
58 | | DocGroup* GetDocGroup() const; |
59 | | |
60 | | void RemoveDuplicates(const nsAttrValue* aAttr); |
61 | | uint32_t Length(); |
62 | | void Item(uint32_t aIndex, nsAString& aResult) |
63 | 0 | { |
64 | 0 | bool found; |
65 | 0 | IndexedGetter(aIndex, found, aResult); |
66 | 0 | if (!found) { |
67 | 0 | SetDOMStringToNull(aResult); |
68 | 0 | } |
69 | 0 | } |
70 | | void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aResult); |
71 | | bool Contains(const nsAString& aToken); |
72 | | void Add(const nsAString& aToken, mozilla::ErrorResult& aError); |
73 | | void Add(const nsTArray<nsString>& aTokens, |
74 | | mozilla::ErrorResult& aError); |
75 | | void Remove(const nsAString& aToken, mozilla::ErrorResult& aError); |
76 | | void Remove(const nsTArray<nsString>& aTokens, |
77 | | mozilla::ErrorResult& aError); |
78 | | bool Replace(const nsAString& aToken, |
79 | | const nsAString& aNewToken, |
80 | | mozilla::ErrorResult& aError); |
81 | | bool Toggle(const nsAString& aToken, |
82 | | const mozilla::dom::Optional<bool>& force, |
83 | | mozilla::ErrorResult& aError); |
84 | | bool Supports(const nsAString& aToken, |
85 | | mozilla::ErrorResult& aError); |
86 | | |
87 | 0 | void GetValue(nsAString& aResult) { Stringify(aResult); } |
88 | | void SetValue(const nsAString& aValue, mozilla::ErrorResult& rv); |
89 | | void Stringify(nsAString& aResult); |
90 | | |
91 | | protected: |
92 | | virtual ~nsDOMTokenList(); |
93 | | |
94 | | nsresult CheckToken(const nsAString& aStr); |
95 | | nsresult CheckTokens(const nsTArray<nsString>& aStr); |
96 | | void RemoveDuplicatesInternal(nsTArray<RefPtr<nsAtom>>* aArray, |
97 | | uint32_t aStart); |
98 | | void AddInternal(const nsAttrValue* aAttr, |
99 | | const nsTArray<nsString>& aTokens); |
100 | | void RemoveInternal(const nsAttrValue* aAttr, |
101 | | const nsTArray<nsString>& aTokens); |
102 | | bool ReplaceInternal(const nsAttrValue* aAttr, |
103 | | const nsAString& aToken, |
104 | | const nsAString& aNewToken); |
105 | | inline const nsAttrValue* GetParsedAttr(); |
106 | | |
107 | | nsCOMPtr<Element> mElement; |
108 | | RefPtr<nsAtom> mAttrAtom; |
109 | | const mozilla::dom::DOMTokenListSupportedTokenArray mSupportedTokens; |
110 | | }; |
111 | | |
112 | | #endif // nsDOMTokenList_h___ |