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>
|
2024-01-09 16:05:03 -07:00
|
|
|
#include <LibWeb/Bindings/PlatformObject.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
|
2024-01-09 16:05:03 -07:00
|
|
|
class CSSRuleList : public Bindings::PlatformObject {
|
|
|
|
WEB_PLATFORM_OBJECT(CSSRuleList, Bindings::PlatformObject);
|
2023-11-19 19:47:52 +01:00
|
|
|
JS_DECLARE_ALLOCATOR(CSSRuleList);
|
2022-08-07 13:51:40 +02:00
|
|
|
|
2021-09-28 15:17:11 +01:00
|
|
|
public:
|
2023-08-13 13:05:26 +02:00
|
|
|
[[nodiscard]] static JS::NonnullGCPtr<CSSRuleList> create(JS::Realm&, JS::MarkedVector<CSSRule*> const&);
|
|
|
|
[[nodiscard]] static 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
|
|
|
|
2024-07-25 18:15:51 +12:00
|
|
|
virtual Optional<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
|
|
|
|
2024-02-24 07:46:59 +00:00
|
|
|
void set_rules(Badge<CSSStyleSheet>, Vector<JS::NonnullGCPtr<CSSRule>> rules) { m_rules = move(rules); }
|
|
|
|
|
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-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2022-08-07 15:46:44 +02:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
2023-02-26 16:09:02 -07:00
|
|
|
Vector<JS::NonnullGCPtr<CSSRule>> m_rules;
|
2021-09-28 15:17:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|