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/BindingDeclarations.h"
20 #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 using Element
= mozilla::dom::Element
;
38 using DocGroup
= mozilla::dom::DocGroup
;
39 using WhitespaceTokenizer
=
40 nsWhitespaceTokenizerTemplate
<nsContentUtils::IsHTMLWhitespace
>;
43 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
44 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_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;
57 void Item(uint32_t aIndex
, nsAString
& aResult
) {
59 IndexedGetter(aIndex
, found
, aResult
);
61 SetDOMStringToNull(aResult
);
64 void IndexedGetter(uint32_t aIndex
, bool& aFound
, nsAString
& aResult
);
65 bool Contains(const nsAString
& aToken
);
66 void Add(const nsAString
& aToken
, mozilla::ErrorResult
& aError
);
67 void Add(const nsTArray
<nsString
>& aTokens
, mozilla::ErrorResult
& aError
);
68 void Remove(const nsAString
& aToken
, mozilla::ErrorResult
& aError
);
69 void Remove(const nsTArray
<nsString
>& aTokens
, mozilla::ErrorResult
& aError
);
70 bool Replace(const nsAString
& aToken
, const nsAString
& aNewToken
,
71 mozilla::ErrorResult
& aError
);
72 bool Toggle(const nsAString
& aToken
,
73 const mozilla::dom::Optional
<bool>& force
,
74 mozilla::ErrorResult
& aError
);
75 bool Supports(const nsAString
& aToken
, mozilla::ErrorResult
& aError
);
77 void GetValue(nsAString
& aResult
);
78 void SetValue(const nsAString
& aValue
, mozilla::ErrorResult
& rv
);
81 virtual ~nsDOMTokenList();
83 void CheckToken(const nsAString
& aToken
, mozilla::ErrorResult
& aRv
);
84 void CheckTokens(const nsTArray
<nsString
>& aTokens
,
85 mozilla::ErrorResult
& aRv
);
86 void AddInternal(const nsAttrValue
* aAttr
, const nsTArray
<nsString
>& aTokens
);
87 void RemoveInternal(const nsAttrValue
* aAttr
,
88 const nsTArray
<nsString
>& aTokens
);
89 bool ReplaceInternal(const nsAttrValue
* aAttr
, const nsAString
& aToken
,
90 const nsAString
& aNewToken
);
91 inline const nsAttrValue
* GetParsedAttr();
93 nsCOMPtr
<Element
> mElement
;
94 RefPtr
<nsAtom
> mAttrAtom
;
95 const mozilla::dom::DOMTokenListSupportedTokenArray mSupportedTokens
;
98 #endif // nsDOMTokenList_h___