2021-10-18 18:53:40 +03:00
|
|
|
/*
|
2022-01-31 21:07:22 +03:00
|
|
|
* Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
|
2022-08-08 16:19:46 +03:00
|
|
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
2023-02-28 03:05:39 +03:00
|
|
|
* Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
|
2021-10-18 18:53:40 +03:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-08-12 12:30:21 +03:00
|
|
|
#include <AK/FlyString.h>
|
2021-10-18 18:53:40 +03:00
|
|
|
#include <AK/Optional.h>
|
2023-08-12 12:30:21 +03:00
|
|
|
#include <AK/String.h>
|
2021-10-18 18:53:40 +03:00
|
|
|
#include <AK/StringView.h>
|
|
|
|
#include <AK/Vector.h>
|
2024-01-10 02:05:03 +03:00
|
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
2021-10-18 18:53:40 +03:00
|
|
|
#include <LibWeb/Forward.h>
|
2022-09-25 19:03:42 +03:00
|
|
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
2021-10-18 18:53:40 +03:00
|
|
|
|
|
|
|
namespace Web::DOM {
|
|
|
|
|
|
|
|
// https://dom.spec.whatwg.org/#domtokenlist
|
2024-01-10 02:05:03 +03:00
|
|
|
class DOMTokenList final : public Bindings::PlatformObject {
|
|
|
|
WEB_PLATFORM_OBJECT(DOMTokenList, Bindings::PlatformObject);
|
2023-11-19 21:47:52 +03:00
|
|
|
JS_DECLARE_ALLOCATOR(DOMTokenList);
|
2021-10-18 18:53:40 +03:00
|
|
|
|
|
|
|
public:
|
2023-08-12 12:30:21 +03:00
|
|
|
[[nodiscard]] static JS::NonnullGCPtr<DOMTokenList> create(Element& associated_element, FlyString associated_attribute);
|
2021-10-18 18:53:40 +03:00
|
|
|
~DOMTokenList() = default;
|
|
|
|
|
|
|
|
void associated_attribute_changed(StringView value);
|
2022-08-08 16:19:46 +03:00
|
|
|
|
|
|
|
virtual bool is_supported_property_index(u32 index) const override;
|
2023-02-28 03:05:39 +03:00
|
|
|
virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override;
|
2021-10-18 18:53:40 +03:00
|
|
|
|
|
|
|
size_t length() const { return m_token_set.size(); }
|
2023-08-12 12:30:21 +03:00
|
|
|
Optional<String> item(size_t index) const;
|
|
|
|
bool contains(String const& token);
|
|
|
|
WebIDL::ExceptionOr<void> add(Vector<String> const& tokens);
|
|
|
|
WebIDL::ExceptionOr<void> remove(Vector<String> const& tokens);
|
|
|
|
WebIDL::ExceptionOr<bool> toggle(String const& token, Optional<bool> force);
|
|
|
|
WebIDL::ExceptionOr<bool> replace(String const& token, String const& new_token);
|
2022-09-25 19:03:42 +03:00
|
|
|
WebIDL::ExceptionOr<bool> supports(StringView token);
|
2023-08-12 12:30:21 +03:00
|
|
|
String value() const;
|
|
|
|
void set_value(String const& value);
|
2021-10-18 18:53:40 +03:00
|
|
|
|
|
|
|
private:
|
2023-08-12 12:30:21 +03:00
|
|
|
DOMTokenList(Element& associated_element, FlyString associated_attribute);
|
2022-08-28 14:42:07 +03:00
|
|
|
|
2023-08-07 09:41:28 +03:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2023-01-01 17:32:48 +03:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
2022-09-25 19:03:42 +03:00
|
|
|
WebIDL::ExceptionOr<void> validate_token(StringView token) const;
|
2021-10-18 18:53:40 +03:00
|
|
|
void run_update_steps();
|
|
|
|
|
2023-01-01 17:32:48 +03:00
|
|
|
JS::NonnullGCPtr<Element> m_associated_element;
|
2023-08-12 12:30:21 +03:00
|
|
|
FlyString m_associated_attribute;
|
|
|
|
Vector<String> m_token_set;
|
2021-10-18 18:53:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|