#pragma once
#include "Element.h"
namespace WebCore {
class DOMTokenList {
WTF_MAKE_FAST_ALLOCATED;
public:
using IsSupportedTokenFunction = WTF::Function<bool(Document&, StringView)>;
DOMTokenList(Element&, const QualifiedName& attributeName, IsSupportedTokenFunction&& isSupportedToken = { });
void associatedAttributeValueChanged(const AtomString&);
void ref() { m_element.ref(); }
void deref() { m_element.deref(); }
unsigned length() const;
const AtomString& item(unsigned index) const;
WEBCORE_EXPORT bool contains(const AtomString&) const;
ExceptionOr<void> add(const Vector<String>&);
ExceptionOr<void> add(const AtomString&);
ExceptionOr<void> remove(const Vector<String>&);
ExceptionOr<void> remove(const AtomString&);
WEBCORE_EXPORT ExceptionOr<bool> toggle(const AtomString&, Optional<bool> force);
ExceptionOr<bool> replace(const AtomString& token, const AtomString& newToken);
ExceptionOr<bool> supports(StringView token);
Element& element() const { return m_element; }
WEBCORE_EXPORT void setValue(const String&);
WEBCORE_EXPORT const AtomString& value() const;
private:
void updateTokensFromAttributeValue(const String&);
void updateAssociatedAttributeFromTokens();
WEBCORE_EXPORT Vector<AtomString>& tokens();
const Vector<AtomString>& 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<AtomString> m_tokens;
IsSupportedTokenFunction m_isSupportedToken;
};
inline unsigned DOMTokenList::length() const
{
return tokens().size();
}
inline const AtomString& DOMTokenList::item(unsigned index) const
{
auto& tokens = this->tokens();
return index < tokens.size() ? tokens[index] : nullAtom();
}
}