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> {
|
2021-03-07 16:14:04 +01:00
|
|
|
public:
|
2021-03-08 11:22:18 +01:00
|
|
|
using WrapperType = Bindings::CSSStyleSheetWrapper;
|
|
|
|
|
2022-03-29 16:51:31 +01:00
|
|
|
static NonnullRefPtr<CSSStyleSheet> create(NonnullRefPtrVector<CSSRule> rules, Optional<AK::URL> location)
|
2021-03-07 16:14:04 +01:00
|
|
|
{
|
2022-03-29 16:51:31 +01:00
|
|
|
return adopt_ref(*new CSSStyleSheet(move(rules), move(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; }
|
|
|
|
|
2021-03-08 16:16:28 +01:00
|
|
|
virtual String type() const override { return "text/css"; }
|
2021-03-07 16:14:04 +01:00
|
|
|
|
2021-09-28 16:18:20 +01:00
|
|
|
CSSRuleList const& rules() const { return m_rules; }
|
|
|
|
CSSRuleList& rules() { return m_rules; }
|
2021-09-29 19:41:46 +02:00
|
|
|
void set_rules(NonnullRefPtr<CSSRuleList> rules) { m_rules = move(rules); }
|
|
|
|
|
|
|
|
CSSRuleList* css_rules() { return m_rules; }
|
|
|
|
CSSRuleList const* css_rules() const { return m_rules; }
|
2021-03-07 16:14:04 +01:00
|
|
|
|
2021-09-29 20:28:32 +02: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 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-03-29 16:51:31 +01:00
|
|
|
explicit CSSStyleSheet(NonnullRefPtrVector<CSSRule>, Optional<AK::URL> location);
|
2021-03-07 16:14:04 +01:00
|
|
|
|
2021-09-29 19:41:46 +02:00
|
|
|
NonnullRefPtr<CSSRuleList> m_rules;
|
2021-09-29 23:46:16 +02:00
|
|
|
|
2021-12-05 15:30:40 +01:00
|
|
|
WeakPtr<CSSRule> m_owner_css_rule;
|
2022-03-09 19:57:15 +01:00
|
|
|
|
|
|
|
WeakPtr<StyleSheetList> m_style_sheet_list;
|
2021-03-07 16:14:04 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2021-03-08 11:22:18 +01:00
|
|
|
|
|
|
|
namespace Web::Bindings {
|
|
|
|
|
|
|
|
CSSStyleSheetWrapper* wrap(JS::GlobalObject&, CSS::CSSStyleSheet&);
|
|
|
|
|
|
|
|
}
|