summaryrefslogtreecommitdiffstats
path: root/dom/base/nsDOMTokenList.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /dom/base/nsDOMTokenList.h
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/base/nsDOMTokenList.h')
-rw-r--r--dom/base/nsDOMTokenList.h98
1 files changed, 98 insertions, 0 deletions
diff --git a/dom/base/nsDOMTokenList.h b/dom/base/nsDOMTokenList.h
new file mode 100644
index 0000000000..618bc0d4f7
--- /dev/null
+++ b/dom/base/nsDOMTokenList.h
@@ -0,0 +1,98 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * Implementation of DOMTokenList specified by HTML5.
+ */
+
+#ifndef nsDOMTokenList_h___
+#define nsDOMTokenList_h___
+
+#include "nsCOMPtr.h"
+#include "nsContentUtils.h"
+#include "nsDOMString.h"
+#include "nsWhitespaceTokenizer.h"
+#include "nsWrapperCache.h"
+#include "mozilla/dom/BindingDeclarations.h"
+#include "mozilla/dom/DOMTokenListSupportedTokens.h"
+
+namespace mozilla {
+class ErrorResult;
+namespace dom {
+class DocGroup;
+class Element;
+} // namespace dom
+} // namespace mozilla
+
+class nsAttrValue;
+class nsAtom;
+
+// nsISupports must be on the primary inheritance chain
+
+class nsDOMTokenList : public nsISupports, public nsWrapperCache {
+ protected:
+ typedef mozilla::dom::Element Element;
+ typedef mozilla::dom::DocGroup DocGroup;
+ typedef nsWhitespaceTokenizerTemplate<nsContentUtils::IsHTMLWhitespace>
+ WhitespaceTokenizer;
+
+ public:
+ NS_DECL_CYCLE_COLLECTING_ISUPPORTS
+ NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMTokenList)
+
+ nsDOMTokenList(Element* aElement, nsAtom* aAttrAtom,
+ const mozilla::dom::DOMTokenListSupportedTokenArray = nullptr);
+
+ virtual JSObject* WrapObject(JSContext* cx,
+ JS::Handle<JSObject*> aGivenProto) override;
+
+ Element* GetParentObject() { return mElement; }
+
+ DocGroup* GetDocGroup() const;
+
+ void RemoveDuplicates(const nsAttrValue* aAttr);
+ uint32_t Length();
+ void Item(uint32_t aIndex, nsAString& aResult) {
+ bool found;
+ IndexedGetter(aIndex, found, aResult);
+ if (!found) {
+ SetDOMStringToNull(aResult);
+ }
+ }
+ void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aResult);
+ bool Contains(const nsAString& aToken);
+ void Add(const nsAString& aToken, mozilla::ErrorResult& aError);
+ void Add(const nsTArray<nsString>& aTokens, mozilla::ErrorResult& aError);
+ void Remove(const nsAString& aToken, mozilla::ErrorResult& aError);
+ void Remove(const nsTArray<nsString>& aTokens, mozilla::ErrorResult& aError);
+ bool Replace(const nsAString& aToken, const nsAString& aNewToken,
+ mozilla::ErrorResult& aError);
+ bool Toggle(const nsAString& aToken,
+ const mozilla::dom::Optional<bool>& force,
+ mozilla::ErrorResult& aError);
+ bool Supports(const nsAString& aToken, mozilla::ErrorResult& aError);
+
+ void GetValue(nsAString& aResult);
+ void SetValue(const nsAString& aValue, mozilla::ErrorResult& rv);
+
+ protected:
+ virtual ~nsDOMTokenList();
+
+ nsresult CheckToken(const nsAString& aStr);
+ nsresult CheckTokens(const nsTArray<nsString>& aStr);
+ void AddInternal(const nsAttrValue* aAttr, const nsTArray<nsString>& aTokens);
+ void RemoveInternal(const nsAttrValue* aAttr,
+ const nsTArray<nsString>& aTokens);
+ bool ReplaceInternal(const nsAttrValue* aAttr, const nsAString& aToken,
+ const nsAString& aNewToken);
+ inline const nsAttrValue* GetParsedAttr();
+
+ nsCOMPtr<Element> mElement;
+ RefPtr<nsAtom> mAttrAtom;
+ const mozilla::dom::DOMTokenListSupportedTokenArray mSupportedTokens;
+};
+
+#endif // nsDOMTokenList_h___