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/. */
8 * Implementation of DOMTokenList specified by HTML5.
11 #ifndef nsDOMTokenList_h___
12 #define nsDOMTokenList_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"
28 } // namespace mozilla
33 // nsISupports must be on the primary inheritance chain
35 class nsDOMTokenList
: public nsISupports
, public nsWrapperCache
{
37 typedef mozilla::dom::Element Element
;
38 typedef mozilla::dom::DocGroup DocGroup
;
39 typedef nsWhitespaceTokenizerTemplate
<nsContentUtils::IsHTMLWhitespace
>
43 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
44 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMTokenList
)
46 nsDOMTokenList(Element
* aElement
, nsAtom
* aAttrAtom
,
47 const mozilla::dom::DOMTokenListSupportedTokenArray
= nullptr);
49 virtual JSObject
* WrapObject(JSContext
* cx
,
50 JS::Handle
<JSObject
*> aGivenProto
) override
;
52 Element
* GetParentObject() { return mElement
; }
54 DocGroup
* GetDocGroup() const;
56 void RemoveDuplicates(const nsAttrValue
* aAttr
);
58 void Item(uint32_t aIndex
, nsAString
& aResult
) {
60 IndexedGetter(aIndex
, found
, aResult
);
62 SetDOMStringToNull(aResult
);
65 void IndexedGetter(uint32_t aIndex
, bool& aFound
, nsAString
& aResult
);
66 bool Contains(const nsAString
& aToken
);
67 void Add(const nsAString
& aToken
, mozilla::ErrorResult
& aError
);
68 void Add(const nsTArray
<nsString
>& aTokens
, mozilla::ErrorResult
& aError
);
69 void Remove(const nsAString
& aToken
, mozilla::ErrorResult
& aError
);
70 void Remove(const nsTArray
<nsString
>& aTokens
, mozilla::ErrorResult
& aError
);
71 bool Replace(const nsAString
& aToken
, const nsAString
& aNewToken
,
72 mozilla::ErrorResult
& aError
);
73 bool Toggle(const nsAString
& aToken
,
74 const mozilla::dom::Optional
<bool>& force
,
75 mozilla::ErrorResult
& aError
);
76 bool Supports(const nsAString
& aToken
, mozilla::ErrorResult
& aError
);
78 void GetValue(nsAString
& aResult
) { Stringify(aResult
); }
79 void SetValue(const nsAString
& aValue
, mozilla::ErrorResult
& rv
);
80 void Stringify(nsAString
& aResult
);
83 virtual ~nsDOMTokenList();
85 nsresult
CheckToken(const nsAString
& aStr
);
86 nsresult
CheckTokens(const nsTArray
<nsString
>& aStr
);
87 void RemoveDuplicatesInternal(nsTArray
<RefPtr
<nsAtom
>>* aArray
,
89 void AddInternal(const nsAttrValue
* aAttr
, const nsTArray
<nsString
>& aTokens
);
90 void RemoveInternal(const nsAttrValue
* aAttr
,
91 const nsTArray
<nsString
>& aTokens
);
92 bool ReplaceInternal(const nsAttrValue
* aAttr
, const nsAString
& aToken
,
93 const nsAString
& aNewToken
);
94 inline const nsAttrValue
* GetParsedAttr();
96 nsCOMPtr
<Element
> mElement
;
97 RefPtr
<nsAtom
> mAttrAtom
;
98 const mozilla::dom::DOMTokenListSupportedTokenArray mSupportedTokens
;
101 #endif // nsDOMTokenList_h___