2021-09-28 15:17:11 +01:00
|
|
|
/*
|
2022-04-23 11:29:31 +01:00
|
|
|
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
2022-08-07 13:51:40 +02:00
|
|
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
2023-02-28 00:05:39 +00:00
|
|
|
* Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
|
2021-09-28 15:17:11 +01:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-10-08 16:40:50 +01:00
|
|
|
#include <AK/Function.h>
|
2021-09-28 15:17:11 +01:00
|
|
|
#include <AK/Iterator.h>
|
|
|
|
#include <AK/RefPtr.h>
|
2022-08-07 13:51:40 +02:00
|
|
|
#include <LibWeb/Bindings/LegacyPlatformObject.h>
|
2021-09-28 15:17:11 +01:00
|
|
|
#include <LibWeb/CSS/CSSRule.h>
|
|
|
|
#include <LibWeb/Forward.h>
|
2022-09-25 17:03:42 +01:00
|
|
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
2021-09-28 15:17:11 +01:00
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
2021-10-15 19:38:39 +01:00
|
|
|
// https://www.w3.org/TR/cssom/#the-cssrulelist-interface
|
2022-08-07 13:51:40 +02:00
|
|
|
class CSSRuleList : public Bindings::LegacyPlatformObject {
|
2022-08-28 13:42:07 +02:00
|
|
|
WEB_PLATFORM_OBJECT(CSSRuleList, Bindings::LegacyPlatformObject);
|
2022-08-07 13:51:40 +02:00
|
|
|
|
2021-09-28 15:17:11 +01:00
|
|
|
public:
|
2023-02-12 23:03:41 +01:00
|
|
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSRuleList>> create(JS::Realm&, JS::MarkedVector<CSSRule*> const&);
|
|
|
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSRuleList>> create_empty(JS::Realm&);
|
2021-09-29 19:41:46 +02:00
|
|
|
|
2022-03-14 13:21:51 -06:00
|
|
|
~CSSRuleList() = default;
|
2021-09-28 15:17:11 +01:00
|
|
|
|
2022-08-07 15:46:44 +02:00
|
|
|
CSSRule const* item(size_t index) const
|
|
|
|
{
|
|
|
|
if (index >= length())
|
|
|
|
return nullptr;
|
2023-02-26 16:09:02 -07:00
|
|
|
return m_rules[index];
|
2022-08-07 15:46:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CSSRule* item(size_t index)
|
2021-09-28 15:17:11 +01:00
|
|
|
{
|
|
|
|
if (index >= length())
|
|
|
|
return nullptr;
|
2023-02-26 16:09:02 -07:00
|
|
|
return m_rules[index];
|
2021-09-28 15:17:11 +01:00
|
|
|
}
|
2022-08-07 15:46:44 +02:00
|
|
|
|
2021-09-28 15:17:11 +01:00
|
|
|
size_t length() const { return m_rules.size(); }
|
|
|
|
|
2023-02-26 16:09:02 -07:00
|
|
|
auto begin() const { return m_rules.begin(); }
|
|
|
|
auto begin() { return m_rules.begin(); }
|
2021-09-28 15:17:11 +01:00
|
|
|
|
2023-02-26 16:09:02 -07:00
|
|
|
auto end() const { return m_rules.end(); }
|
|
|
|
auto end() { return m_rules.end(); }
|
2021-09-28 15:17:11 +01:00
|
|
|
|
2022-08-07 13:51:40 +02:00
|
|
|
virtual bool is_supported_property_index(u32 index) const override;
|
2023-02-28 00:05:39 +00:00
|
|
|
virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override;
|
2021-09-29 19:41:46 +02:00
|
|
|
|
2022-09-25 17:03:42 +01:00
|
|
|
WebIDL::ExceptionOr<void> remove_a_css_rule(u32 index);
|
|
|
|
WebIDL::ExceptionOr<unsigned> insert_a_css_rule(Variant<StringView, CSSRule*>, u32 index);
|
2021-09-29 20:28:32 +02:00
|
|
|
|
2021-10-08 16:40:50 +01:00
|
|
|
void for_each_effective_style_rule(Function<void(CSSStyleRule const&)> const& callback) const;
|
2022-02-17 12:34:36 +00:00
|
|
|
// Returns whether the match state of any media queries changed after evaluation.
|
2022-03-07 23:08:26 +01:00
|
|
|
bool evaluate_media_queries(HTML::Window const&);
|
2023-05-26 23:30:54 +03:30
|
|
|
void for_each_effective_keyframes_at_rule(Function<void(CSSKeyframesRule const&)> const& callback) const;
|
2021-10-08 16:40:50 +01:00
|
|
|
|
2023-07-31 19:48:50 +01:00
|
|
|
Function<void()> on_change;
|
|
|
|
|
2021-09-28 15:17:11 +01:00
|
|
|
private:
|
2022-09-24 16:34:04 -06:00
|
|
|
explicit CSSRuleList(JS::Realm&);
|
|
|
|
|
2023-01-28 12:33:35 -05:00
|
|
|
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
|
2022-08-07 15:46:44 +02:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
2023-02-28 00:05:39 +00:00
|
|
|
// ^Bindings::LegacyPlatformObject
|
|
|
|
virtual bool supports_indexed_properties() const override { return true; }
|
|
|
|
virtual bool supports_named_properties() const override { return false; }
|
|
|
|
virtual bool has_indexed_property_setter() const override { return false; }
|
|
|
|
virtual bool has_named_property_setter() const override { return false; }
|
|
|
|
virtual bool has_named_property_deleter() const override { return false; }
|
|
|
|
virtual bool has_legacy_override_built_ins_interface_extended_attribute() const override { return false; }
|
|
|
|
virtual bool has_legacy_unenumerable_named_properties_interface_extended_attribute() const override { return false; }
|
|
|
|
virtual bool has_global_interface_extended_attribute() const override { return false; }
|
|
|
|
virtual bool indexed_property_setter_has_identifier() const override { return false; }
|
|
|
|
virtual bool named_property_setter_has_identifier() const override { return false; }
|
|
|
|
virtual bool named_property_deleter_has_identifier() const override { return false; }
|
|
|
|
|
2023-02-26 16:09:02 -07:00
|
|
|
Vector<JS::NonnullGCPtr<CSSRule>> m_rules;
|
2021-09-28 15:17:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|