2021-03-07 12:14:04 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2019-2021, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-03-07 12:14:04 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2021-09-30 17:57:35 -03:00
|
|
|
#include <AK/Function.h>
|
2023-07-31 13:46:57 -03:00
|
|
|
#include <LibWeb/CSS/CSSNamespaceRule.h>
|
2021-03-07 12:14:04 -03:00
|
|
|
#include <LibWeb/CSS/CSSRule.h>
|
2021-09-28 12:18:20 -03:00
|
|
|
#include <LibWeb/CSS/CSSRuleList.h>
|
2021-09-30 17:57:35 -03:00
|
|
|
#include <LibWeb/CSS/CSSStyleRule.h>
|
2021-03-07 12:14:04 -03:00
|
|
|
#include <LibWeb/CSS/StyleSheet.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
|
2021-09-30 17:57:35 -03:00
|
|
|
class CSSImportRule;
|
|
|
|
|
|
2021-12-05 11:33:49 -03:00
|
|
|
class CSSStyleSheet final
|
|
|
|
|
: public StyleSheet
|
|
|
|
|
, public Weakable<CSSStyleSheet> {
|
2022-08-28 08:42:07 -03:00
|
|
|
WEB_PLATFORM_OBJECT(CSSStyleSheet, StyleSheet);
|
2021-03-08 07:22:18 -03:00
|
|
|
|
2022-08-07 08:14:54 -03:00
|
|
|
public:
|
2023-08-13 08:05:26 -03:00
|
|
|
[[nodiscard]] static JS::NonnullGCPtr<CSSStyleSheet> create(JS::Realm&, CSSRuleList&, MediaList&, Optional<AK::URL> location);
|
2021-03-07 12:14:04 -03:00
|
|
|
|
2022-03-14 16:21:51 -03:00
|
|
|
virtual ~CSSStyleSheet() override = default;
|
2021-03-08 12:16:28 -03:00
|
|
|
|
2021-09-29 18:46:16 -03:00
|
|
|
void set_owner_css_rule(CSSRule* rule) { m_owner_css_rule = rule; }
|
|
|
|
|
|
2023-09-02 23:19:49 -03:00
|
|
|
virtual String type() const override { return "text/css"_string; }
|
2021-03-07 12:14:04 -03:00
|
|
|
|
2022-08-07 08:51:40 -03:00
|
|
|
CSSRuleList const& rules() const { return *m_rules; }
|
|
|
|
|
CSSRuleList& rules() { return *m_rules; }
|
|
|
|
|
void set_rules(CSSRuleList& rules) { m_rules = &rules; }
|
2021-09-29 14:41:46 -03:00
|
|
|
|
|
|
|
|
CSSRuleList* css_rules() { return m_rules; }
|
|
|
|
|
CSSRuleList const* css_rules() const { return m_rules; }
|
2021-03-07 12:14:04 -03:00
|
|
|
|
2022-09-25 13:03:42 -03:00
|
|
|
WebIDL::ExceptionOr<unsigned> insert_rule(StringView rule, unsigned index);
|
|
|
|
|
WebIDL::ExceptionOr<void> remove_rule(unsigned index);
|
|
|
|
|
WebIDL::ExceptionOr<void> delete_rule(unsigned index);
|
2021-09-29 15:28:32 -03:00
|
|
|
|
2021-09-30 17:57:35 -03:00
|
|
|
void for_each_effective_style_rule(Function<void(CSSStyleRule const&)> const& callback) const;
|
2022-02-17 09:34:36 -03:00
|
|
|
// Returns whether the match state of any media queries changed after evaluation.
|
2022-03-07 19:08:26 -03:00
|
|
|
bool evaluate_media_queries(HTML::Window const&);
|
2023-05-26 17:00:54 -03:00
|
|
|
void for_each_effective_keyframes_at_rule(Function<void(CSSKeyframesRule const&)> const& callback) const;
|
2021-03-07 12:14:04 -03:00
|
|
|
|
2022-03-09 15:57:15 -03:00
|
|
|
void set_style_sheet_list(Badge<StyleSheetList>, StyleSheetList*);
|
|
|
|
|
|
2023-07-31 13:46:57 -03:00
|
|
|
Optional<StringView> default_namespace() const;
|
2023-08-04 13:02:29 -03:00
|
|
|
Optional<StringView> namespace_uri(StringView namespace_prefix) const;
|
2023-07-29 13:51:15 -03:00
|
|
|
|
2021-03-07 12:14:04 -03:00
|
|
|
private:
|
2022-10-23 15:05:34 -03:00
|
|
|
CSSStyleSheet(JS::Realm&, CSSRuleList&, MediaList&, Optional<AK::URL> location);
|
2022-09-24 19:34:04 -03:00
|
|
|
|
2023-08-07 03:41:28 -03:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2022-08-07 08:29:49 -03:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
|
2023-07-31 13:46:57 -03:00
|
|
|
void recalculate_namespaces();
|
|
|
|
|
|
2023-02-26 20:09:02 -03:00
|
|
|
JS::GCPtr<CSSRuleList> m_rules;
|
2023-07-31 13:46:57 -03:00
|
|
|
JS::GCPtr<CSSNamespaceRule> m_default_namespace_rule;
|
2023-08-04 13:02:29 -03:00
|
|
|
HashMap<FlyString, JS::GCPtr<CSSNamespaceRule>> m_namespace_rules;
|
2021-09-29 18:46:16 -03:00
|
|
|
|
2022-08-07 08:29:49 -03:00
|
|
|
JS::GCPtr<StyleSheetList> m_style_sheet_list;
|
2023-02-26 20:09:02 -03:00
|
|
|
JS::GCPtr<CSSRule> m_owner_css_rule;
|
2021-03-07 12:14:04 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|