2021-03-07 16:14:04 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019-2021, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-03-07 16:14:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-09-30 22:57:35 +02:00
|
|
|
#include <AK/Function.h>
|
2021-03-07 16:14:04 +01:00
|
|
|
#include <AK/NonnullRefPtrVector.h>
|
|
|
|
#include <LibWeb/CSS/CSSRule.h>
|
2021-09-28 16:18:20 +01:00
|
|
|
#include <LibWeb/CSS/CSSRuleList.h>
|
2021-09-30 22:57:35 +02:00
|
|
|
#include <LibWeb/CSS/CSSStyleRule.h>
|
2021-03-07 16:14:04 +01:00
|
|
|
#include <LibWeb/CSS/StyleSheet.h>
|
|
|
|
#include <LibWeb/Loader/Resource.h>
|
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
2021-09-30 22:57:35 +02:00
|
|
|
class CSSImportRule;
|
|
|
|
|
2021-12-05 15:33:49 +01:00
|
|
|
class CSSStyleSheet final
|
|
|
|
: public StyleSheet
|
|
|
|
, public Weakable<CSSStyleSheet> {
|
2022-08-28 13:42:07 +02:00
|
|
|
WEB_PLATFORM_OBJECT(CSSStyleSheet, StyleSheet);
|
2021-03-08 11:22:18 +01:00
|
|
|
|
2022-08-07 13:14:54 +02:00
|
|
|
public:
|
2023-02-12 23:47:12 +01:00
|
|
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSStyleSheet>> create(JS::Realm&, CSSRuleList& rules, MediaList& media, Optional<AK::URL> location);
|
2021-03-07 16:14:04 +01:00
|
|
|
|
2022-03-14 13:21:51 -06:00
|
|
|
virtual ~CSSStyleSheet() override = default;
|
2021-03-08 16:16:28 +01:00
|
|
|
|
2021-09-29 23:46:16 +02:00
|
|
|
void set_owner_css_rule(CSSRule* rule) { m_owner_css_rule = rule; }
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
virtual DeprecatedString type() const override { return "text/css"; }
|
2021-03-07 16:14:04 +01:00
|
|
|
|
2022-08-07 13:51:40 +02:00
|
|
|
CSSRuleList const& rules() const { return *m_rules; }
|
|
|
|
CSSRuleList& rules() { return *m_rules; }
|
|
|
|
void set_rules(CSSRuleList& rules) { m_rules = &rules; }
|
2021-09-29 19:41:46 +02:00
|
|
|
|
|
|
|
CSSRuleList* css_rules() { return m_rules; }
|
|
|
|
CSSRuleList const* css_rules() const { return m_rules; }
|
2021-03-07 16:14:04 +01:00
|
|
|
|
2022-09-25 17:03:42 +01: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 20:28:32 +02:00
|
|
|
|
2021-09-30 22:57:35 +02: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&);
|
2021-03-07 16:14:04 +01:00
|
|
|
|
2022-03-09 19:57:15 +01:00
|
|
|
void set_style_sheet_list(Badge<StyleSheetList>, StyleSheetList*);
|
|
|
|
|
2021-03-07 16:14:04 +01:00
|
|
|
private:
|
2022-10-23 21:05:34 +03:00
|
|
|
CSSStyleSheet(JS::Realm&, CSSRuleList&, MediaList&, Optional<AK::URL> location);
|
2022-09-24 16:34:04 -06:00
|
|
|
|
2023-01-28 12:33:35 -05:00
|
|
|
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
|
2022-08-07 13:29:49 +02:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
2022-08-07 13:51:40 +02:00
|
|
|
CSSRuleList* m_rules { nullptr };
|
2021-09-29 23:46:16 +02:00
|
|
|
|
2022-08-07 13:29:49 +02:00
|
|
|
JS::GCPtr<StyleSheetList> m_style_sheet_list;
|
2022-08-07 15:46:44 +02:00
|
|
|
CSSRule* m_owner_css_rule { nullptr };
|
2021-03-07 16:14:04 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|