| 
									
										
										
										
											2021-03-07 16:14:04 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:19:50 +02:00
										 |  |  |  * Copyright (c) 2019-2021, Andreas Kling <andreas@ladybird.org> | 
					
						
							| 
									
										
										
										
											2024-02-24 07:46:59 +00:00
										 |  |  |  * Copyright (c) 2024, Tim Ledbetter <timledbetter@gmail.com> | 
					
						
							| 
									
										
										
										
											2021-03-07 16:14:04 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											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>
 | 
					
						
							| 
									
										
										
										
											2023-07-31 17:46:57 +01:00
										 |  |  | #include <LibWeb/CSS/CSSNamespaceRule.h>
 | 
					
						
							| 
									
										
										
										
											2021-03-07 16:14:04 +01:00
										 |  |  | #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>
 | 
					
						
							| 
									
										
										
										
											2024-02-24 07:46:59 +00:00
										 |  |  | #include <LibWeb/WebIDL/Types.h>
 | 
					
						
							| 
									
										
										
										
											2021-03-07 16:14:04 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::CSS { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-30 22:57:35 +02:00
										 |  |  | class CSSImportRule; | 
					
						
							| 
									
										
										
										
											2024-09-22 18:10:46 +02:00
										 |  |  | class FontLoader; | 
					
						
							| 
									
										
										
										
											2021-09-30 22:57:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-24 07:46:59 +00:00
										 |  |  | struct CSSStyleSheetInit { | 
					
						
							|  |  |  |     Optional<String> base_url {}; | 
					
						
							|  |  |  |     Variant<JS::Handle<MediaList>, String> media { String {} }; | 
					
						
							|  |  |  |     bool disabled { false }; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-02 10:24:23 +02:00
										 |  |  | class CSSStyleSheet final : public StyleSheet { | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  |     WEB_PLATFORM_OBJECT(CSSStyleSheet, StyleSheet); | 
					
						
							| 
									
										
										
										
											2023-11-19 19:47:52 +01:00
										 |  |  |     JS_DECLARE_ALLOCATOR(CSSStyleSheet); | 
					
						
							| 
									
										
										
										
											2021-03-08 11:22:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-07 13:14:54 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2024-03-18 16:22:27 +13:00
										 |  |  |     [[nodiscard]] static JS::NonnullGCPtr<CSSStyleSheet> create(JS::Realm&, CSSRuleList&, MediaList&, Optional<URL::URL> location); | 
					
						
							| 
									
										
										
										
											2024-02-24 07:46:59 +00:00
										 |  |  |     static WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSStyleSheet>> construct_impl(JS::Realm&, Optional<CSSStyleSheetInit> const& options = {}); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-24 07:46:59 +00:00
										 |  |  |     JS::GCPtr<CSSRule const> owner_rule() const { return m_owner_css_rule; } | 
					
						
							|  |  |  |     JS::GCPtr<CSSRule> owner_rule() { return m_owner_css_rule; } | 
					
						
							| 
									
										
										
										
											2021-09-29 23:46:16 +02:00
										 |  |  |     void set_owner_css_rule(CSSRule* rule) { m_owner_css_rule = rule; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-03 14:19:49 +12:00
										 |  |  |     virtual String type() const override { return "text/css"_string; } | 
					
						
							| 
									
										
										
										
											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; } | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2024-02-24 07:46:59 +00:00
										 |  |  |     WebIDL::ExceptionOr<WebIDL::Long> add_rule(Optional<String> selector, Optional<String> style, Optional<WebIDL::UnsignedLong> index); | 
					
						
							| 
									
										
										
										
											2024-02-24 07:46:59 +00:00
										 |  |  |     WebIDL::ExceptionOr<void> remove_rule(Optional<WebIDL::UnsignedLong> index); | 
					
						
							| 
									
										
										
										
											2022-09-25 17:03:42 +01:00
										 |  |  |     WebIDL::ExceptionOr<void> delete_rule(unsigned index); | 
					
						
							| 
									
										
										
										
											2021-09-29 20:28:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-25 12:38:19 -06:00
										 |  |  |     JS::NonnullGCPtr<WebIDL::Promise> replace(String text); | 
					
						
							| 
									
										
										
										
											2024-02-24 07:46:59 +00:00
										 |  |  |     WebIDL::ExceptionOr<void> replace_sync(StringView text); | 
					
						
							| 
									
										
										
										
											2024-02-24 07:46:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-03 11:43:20 +01:00
										 |  |  |     void for_each_effective_rule(TraversalOrder, Function<void(CSSRule const&)> const& callback) const; | 
					
						
							| 
									
										
										
										
											2024-10-17 13:48:00 +01:00
										 |  |  |     void for_each_effective_style_producing_rule(Function<void(CSSRule 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-03-07 16:14:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-14 23:05:05 +01:00
										 |  |  |     JS::GCPtr<StyleSheetList> style_sheet_list() const { return m_style_sheet_list; } | 
					
						
							| 
									
										
										
										
											2022-03-09 19:57:15 +01:00
										 |  |  |     void set_style_sheet_list(Badge<StyleSheetList>, StyleSheetList*); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-24 19:14:24 +13:00
										 |  |  |     Optional<FlyString> default_namespace() const; | 
					
						
							| 
									
										
										
										
											2024-03-16 08:03:46 +01:00
										 |  |  |     JS::GCPtr<CSSNamespaceRule> default_namespace_rule() const { return m_default_namespace_rule; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-24 19:14:24 +13:00
										 |  |  |     Optional<FlyString> namespace_uri(StringView namespace_prefix) const; | 
					
						
							| 
									
										
										
										
											2023-07-29 11:51:15 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-23 16:46:33 +01:00
										 |  |  |     Vector<JS::NonnullGCPtr<CSSImportRule>> const& import_rules() const { return m_import_rules; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 16:22:27 +13:00
										 |  |  |     Optional<URL::URL> base_url() const { return m_base_url; } | 
					
						
							|  |  |  |     void set_base_url(Optional<URL::URL> base_url) { m_base_url = move(base_url); } | 
					
						
							| 
									
										
										
										
											2024-02-24 07:46:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bool constructed() const { return m_constructed; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     JS::GCPtr<DOM::Document const> constructor_document() const { return m_constructor_document; } | 
					
						
							|  |  |  |     void set_constructor_document(JS::GCPtr<DOM::Document const> constructor_document) { m_constructor_document = constructor_document; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-24 07:46:59 +00:00
										 |  |  |     bool disallow_modification() const { return m_disallow_modification; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-22 17:23:54 +01:00
										 |  |  |     void set_source_text(String); | 
					
						
							|  |  |  |     Optional<String> source_text(Badge<DOM::Document>) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-22 18:10:46 +02:00
										 |  |  |     void add_associated_font_loader(WeakPtr<FontLoader const> font_loader) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_associated_font_loaders.append(font_loader); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     bool has_associated_font_loader(FontLoader& font_loader) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-07 16:14:04 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2024-03-18 16:22:27 +13:00
										 |  |  |     CSSStyleSheet(JS::Realm&, CSSRuleList&, MediaList&, Optional<URL::URL> location); | 
					
						
							| 
									
										
										
										
											2022-09-24 16:34:04 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-07 08:41:28 +02:00
										 |  |  |     virtual void initialize(JS::Realm&) override; | 
					
						
							| 
									
										
										
										
											2022-08-07 13:29:49 +02:00
										 |  |  |     virtual void visit_edges(Cell::Visitor&) override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-23 16:46:33 +01:00
										 |  |  |     void recalculate_rule_caches(); | 
					
						
							| 
									
										
										
										
											2023-07-31 17:46:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-24 07:46:59 +00:00
										 |  |  |     void set_constructed(bool constructed) { m_constructed = constructed; } | 
					
						
							| 
									
										
										
										
											2024-02-24 07:46:59 +00:00
										 |  |  |     void set_disallow_modification(bool disallow_modification) { m_disallow_modification = disallow_modification; } | 
					
						
							| 
									
										
										
										
											2024-02-24 07:46:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-22 17:23:54 +01:00
										 |  |  |     Optional<String> m_source_text; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-26 16:09:02 -07:00
										 |  |  |     JS::GCPtr<CSSRuleList> m_rules; | 
					
						
							| 
									
										
										
										
											2023-07-31 17:46:57 +01:00
										 |  |  |     JS::GCPtr<CSSNamespaceRule> m_default_namespace_rule; | 
					
						
							| 
									
										
										
										
											2023-08-04 17:02:29 +01:00
										 |  |  |     HashMap<FlyString, JS::GCPtr<CSSNamespaceRule>> m_namespace_rules; | 
					
						
							| 
									
										
										
										
											2024-08-23 16:46:33 +01:00
										 |  |  |     Vector<JS::NonnullGCPtr<CSSImportRule>> m_import_rules; | 
					
						
							| 
									
										
										
										
											2021-09-29 23:46:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-07 13:29:49 +02:00
										 |  |  |     JS::GCPtr<StyleSheetList> m_style_sheet_list; | 
					
						
							| 
									
										
										
										
											2023-02-26 16:09:02 -07:00
										 |  |  |     JS::GCPtr<CSSRule> m_owner_css_rule; | 
					
						
							| 
									
										
										
										
											2024-02-24 07:46:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 16:22:27 +13:00
										 |  |  |     Optional<URL::URL> m_base_url; | 
					
						
							| 
									
										
										
										
											2024-02-24 07:46:59 +00:00
										 |  |  |     JS::GCPtr<DOM::Document const> m_constructor_document; | 
					
						
							|  |  |  |     bool m_constructed { false }; | 
					
						
							| 
									
										
										
										
											2024-02-24 07:46:59 +00:00
										 |  |  |     bool m_disallow_modification { false }; | 
					
						
							| 
									
										
										
										
											2024-08-11 09:34:37 -06:00
										 |  |  |     Optional<bool> m_did_match; | 
					
						
							| 
									
										
										
										
											2024-09-22 18:10:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Vector<WeakPtr<FontLoader const>> m_associated_font_loaders; | 
					
						
							| 
									
										
										
										
											2021-03-07 16:14:04 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |