#pragma once
#include "Element.h"
namespace WebCore {
class DOMTokenList {
WTF_MAKE_FAST_ALLOCATED;
public:
DOMTokenList(Element&, const QualifiedName& attributeName, WTF::Function<bool(StringView)>&& isSupportedToken = { });
void associatedAttributeValueChanged(const AtomicString&);
void ref() { m_element.ref(); }
void deref() { m_element.deref(); }
unsigned length() const;
const AtomicString& item(unsigned index) const;
WEBCORE_EXPORT bool contains(const AtomicString&) const;
ExceptionOr<void> add(const Vector<String>&);
ExceptionOr<void> add(const AtomicString&);
ExceptionOr<void> remove(const Vector<String>&);
ExceptionOr<void> remove(const AtomicString&);
WEBCORE_EXPORT ExceptionOr<bool> toggle(const AtomicString&, std::optional<bool> force);
ExceptionOr<void> replace(const AtomicString& token, const AtomicString& newToken);
ExceptionOr<bool> supports(StringView token);
Element& element() const { return m_element; }
WEBCORE_EXPORT void setValue(const String&);
WEBCORE_EXPORT const AtomicString& value() const;
private:
void updateTokensFromAttributeValue(const String&);
void updateAssociatedAttributeFromTokens();
WEBCORE_EXPORT Vector<AtomicString>& tokens();
const Vector<AtomicString>& tokens() const { return const_cast<DOMTokenList&>(*this).tokens(); }
static ExceptionOr<void> validateToken(const String&);
static ExceptionOr<void> validateTokens(const String* tokens, size_t length);
ExceptionOr<void> addInternal(const String* tokens, size_t length);
ExceptionOr<void> removeInternal(const String* tokens, size_t length);
Element& m_element;
const WebCore::QualifiedName& m_attributeName;
bool m_inUpdateAssociatedAttributeFromTokens { false };
bool m_tokensNeedUpdating { true };
Vector<AtomicString> m_tokens;
WTF::Function<bool(StringView)> m_isSupportedToken;
};
inline unsigned DOMTokenList::length() const
{
return tokens().size();
}
inline const AtomicString& DOMTokenList::item(unsigned index) const
{
auto& tokens = this->tokens();
return index < tokens.size() ? tokens[index] : nullAtom;
}
}