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>
|
2021-03-07 12:14:04 -03:00
|
|
|
#include <AK/NonnullRefPtrVector.h>
|
|
|
|
|
#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>
|
|
|
|
|
#include <LibWeb/Loader/Resource.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:
|
2022-08-28 08:42:07 -03:00
|
|
|
static CSSStyleSheet* create(HTML::Window&, CSSRuleList& rules, Optional<AK::URL> location);
|
2021-03-07 12:14:04 -03:00
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
explicit CSSStyleSheet(HTML::Window&, CSSRuleList&, Optional<AK::URL> location);
|
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; }
|
|
|
|
|
|
2021-03-08 12:16:28 -03:00
|
|
|
virtual String type() const override { return "text/css"; }
|
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
|
|
|
|
2021-09-29 15:28:32 -03:00
|
|
|
DOM::ExceptionOr<unsigned> insert_rule(StringView rule, unsigned index);
|
|
|
|
|
DOM::ExceptionOr<void> remove_rule(unsigned index);
|
|
|
|
|
DOM::ExceptionOr<void> delete_rule(unsigned index);
|
|
|
|
|
|
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&);
|
2021-03-07 12:14:04 -03:00
|
|
|
|
2022-03-09 15:57:15 -03:00
|
|
|
void set_style_sheet_list(Badge<StyleSheetList>, StyleSheetList*);
|
|
|
|
|
|
2021-03-07 12:14:04 -03:00
|
|
|
private:
|
2022-08-07 08:29:49 -03:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
|
2022-08-07 08:51:40 -03:00
|
|
|
CSSRuleList* m_rules { nullptr };
|
2021-09-29 18:46:16 -03:00
|
|
|
|
2022-08-07 08:29:49 -03:00
|
|
|
JS::GCPtr<StyleSheetList> m_style_sheet_list;
|
2022-08-07 10:46:44 -03:00
|
|
|
CSSRule* m_owner_css_rule { nullptr };
|
2021-03-07 12:14:04 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|