Bug 1892041 - Part 1: Update test262 features. r=spidermonkey-reviewers,dminor
[gecko.git] / dom / base / nsDOMTokenList.h
blobe2ac5c02248e24af228db7e5d8118a5276800bd7
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/. */
7 /*
8 * Implementation of DOMTokenList specified by HTML5.
9 */
11 #ifndef nsDOMTokenList_h___
12 #define nsDOMTokenList_h___
14 #include "nsCOMPtr.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"
22 namespace mozilla {
23 class ErrorResult;
24 namespace dom {
25 class DocGroup;
26 class Element;
27 } // namespace dom
28 } // namespace mozilla
30 class nsAttrValue;
31 class nsAtom;
33 // nsISupports must be on the primary inheritance chain
35 class nsDOMTokenList : public nsISupports, public nsWrapperCache {
36 protected:
37 using Element = mozilla::dom::Element;
38 using DocGroup = mozilla::dom::DocGroup;
39 using WhitespaceTokenizer =
40 nsWhitespaceTokenizerTemplate<nsContentUtils::IsHTMLWhitespace>;
42 public:
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;
56 uint32_t Length();
57 void Item(uint32_t aIndex, nsAString& aResult) {
58 bool found;
59 IndexedGetter(aIndex, found, aResult);
60 if (!found) {
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);
80 protected:
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___