Bug 1550519 - Show a translucent parent highlight when a subgrid is highlighted....
[gecko.git] / dom / base / nsDOMTokenList.h
blob36a32dc01d256af40addbdda042c27d432049611
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/Element.h"
20 #include "mozilla/dom/BindingDeclarations.h"
21 #include "mozilla/dom/DOMTokenListSupportedTokens.h"
23 namespace mozilla {
24 class ErrorResult;
25 namespace dom {
26 class DocGroup;
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 typedef mozilla::dom::Element Element;
38 typedef mozilla::dom::DocGroup DocGroup;
39 typedef nsWhitespaceTokenizerTemplate<nsContentUtils::IsHTMLWhitespace>
40 WhitespaceTokenizer;
42 public:
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);
57 uint32_t Length();
58 void Item(uint32_t aIndex, nsAString& aResult) {
59 bool found;
60 IndexedGetter(aIndex, found, aResult);
61 if (!found) {
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);
82 protected:
83 virtual ~nsDOMTokenList();
85 nsresult CheckToken(const nsAString& aStr);
86 nsresult CheckTokens(const nsTArray<nsString>& aStr);
87 void RemoveDuplicatesInternal(nsTArray<RefPtr<nsAtom>>* aArray,
88 uint32_t aStart);
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___