| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2023-02-20 18:56:08 +01:00
										 |  |  |  * Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org> | 
					
						
							| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  | #include <AK/DeprecatedString.h>
 | 
					
						
							| 
									
										
										
										
											2020-02-14 21:41:10 +01:00
										 |  |  | #include <AK/Vector.h>
 | 
					
						
							| 
									
										
										
										
											2022-08-07 16:21:26 +02:00
										 |  |  | #include <LibWeb/Bindings/PlatformObject.h>
 | 
					
						
							| 
									
										
										
										
											2023-05-08 06:57:55 +02:00
										 |  |  | #include <LibWeb/CSS/StyleProperty.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-07 10:32:51 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-26 20:01:35 +02:00
										 |  |  | namespace Web::CSS { | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-07 16:21:26 +02:00
										 |  |  | class CSSStyleDeclaration : public Bindings::PlatformObject { | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  |     WEB_PLATFORM_OBJECT(CSSStyleDeclaration, Bindings::PlatformObject); | 
					
						
							| 
									
										
										
										
											2023-11-19 19:47:52 +01:00
										 |  |  |     JS_DECLARE_ALLOCATOR(CSSStyleDeclaration); | 
					
						
							| 
									
										
										
										
											2021-03-13 22:39:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-07 16:21:26 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2022-03-14 13:21:51 -06:00
										 |  |  |     virtual ~CSSStyleDeclaration() = default; | 
					
						
							| 
									
										
										
										
											2023-08-07 08:41:28 +02:00
										 |  |  |     virtual void initialize(JS::Realm&) override; | 
					
						
							| 
									
										
										
										
											2021-09-12 19:24:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtual size_t length() const = 0; | 
					
						
							| 
									
										
										
										
											2023-09-06 19:07:24 +12:00
										 |  |  |     virtual String item(size_t index) const = 0; | 
					
						
							| 
									
										
										
										
											2021-09-12 19:24:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtual Optional<StyleProperty> property(PropertyID) const = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-25 17:03:42 +01:00
										 |  |  |     virtual WebIDL::ExceptionOr<void> set_property(PropertyID, StringView css_text, StringView priority = ""sv) = 0; | 
					
						
							| 
									
										
										
										
											2023-09-06 19:07:24 +12:00
										 |  |  |     virtual WebIDL::ExceptionOr<String> remove_property(PropertyID) = 0; | 
					
						
							| 
									
										
										
										
											2022-04-11 16:10:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-25 17:03:42 +01:00
										 |  |  |     WebIDL::ExceptionOr<void> set_property(StringView property_name, StringView css_text, StringView priority); | 
					
						
							| 
									
										
										
										
											2023-09-06 19:07:24 +12:00
										 |  |  |     WebIDL::ExceptionOr<String> remove_property(StringView property_name); | 
					
						
							| 
									
										
										
										
											2021-09-26 19:06:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-06 19:07:24 +12:00
										 |  |  |     String get_property_value(StringView property) const; | 
					
						
							|  |  |  |     StringView get_property_priority(StringView property) const; | 
					
						
							| 
									
										
										
										
											2021-09-12 20:44:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |     DeprecatedString css_text() const; | 
					
						
							| 
									
										
										
										
											2022-11-05 04:51:05 +00:00
										 |  |  |     virtual WebIDL::ExceptionOr<void> set_css_text(StringView) = 0; | 
					
						
							| 
									
										
										
										
											2021-10-01 19:57:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |     virtual DeprecatedString serialized() const = 0; | 
					
						
							| 
									
										
										
										
											2021-10-01 19:57:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-07 16:21:26 +02:00
										 |  |  |     virtual JS::ThrowCompletionOr<bool> internal_has_property(JS::PropertyKey const& name) const override; | 
					
						
							| 
									
										
										
										
											2023-07-08 17:39:18 +02:00
										 |  |  |     virtual JS::ThrowCompletionOr<JS::Value> internal_get(JS::PropertyKey const&, JS::Value receiver, JS::CacheablePropertyMetadata*) const override; | 
					
						
							| 
									
										
										
										
											2023-11-08 20:51:26 +01:00
										 |  |  |     virtual JS::ThrowCompletionOr<bool> internal_set(JS::PropertyKey const&, JS::Value value, JS::Value receiver, JS::CacheablePropertyMetadata*) override; | 
					
						
							| 
									
										
										
										
											2022-08-07 16:21:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-12 19:24:01 +02:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2022-09-24 16:34:04 -06:00
										 |  |  |     explicit CSSStyleDeclaration(JS::Realm&); | 
					
						
							| 
									
										
										
										
											2021-09-12 19:24:01 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class PropertyOwningCSSStyleDeclaration : public CSSStyleDeclaration { | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  |     WEB_PLATFORM_OBJECT(PropertyOwningCSSStyleDeclaration, CSSStyleDeclaration); | 
					
						
							| 
									
										
										
										
											2023-11-19 19:47:52 +01:00
										 |  |  |     JS_DECLARE_ALLOCATOR(PropertyOwningCSSStyleDeclaration); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-12 19:24:01 +02:00
										 |  |  |     friend class ElementInlineCSSStyleDeclaration; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2023-08-13 13:05:26 +02:00
										 |  |  |     [[nodiscard]] static JS::NonnullGCPtr<PropertyOwningCSSStyleDeclaration> | 
					
						
							| 
									
										
										
										
											2023-11-05 16:19:16 +13:00
										 |  |  |     create(JS::Realm&, Vector<StyleProperty>, HashMap<FlyString, StyleProperty> custom_properties); | 
					
						
							| 
									
										
										
										
											2019-06-21 19:19:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-14 13:21:51 -06:00
										 |  |  |     virtual ~PropertyOwningCSSStyleDeclaration() override = default; | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-12 19:24:01 +02:00
										 |  |  |     virtual size_t length() const override; | 
					
						
							| 
									
										
										
										
											2023-09-06 19:07:24 +12:00
										 |  |  |     virtual String item(size_t index) const override; | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-12 19:24:01 +02:00
										 |  |  |     virtual Optional<StyleProperty> property(PropertyID) const override; | 
					
						
							| 
									
										
										
										
											2022-04-11 16:10:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-25 17:03:42 +01:00
										 |  |  |     virtual WebIDL::ExceptionOr<void> set_property(PropertyID, StringView css_text, StringView priority) override; | 
					
						
							| 
									
										
										
										
											2023-09-06 19:07:24 +12:00
										 |  |  |     virtual WebIDL::ExceptionOr<String> remove_property(PropertyID) override; | 
					
						
							| 
									
										
										
										
											2021-09-12 19:24:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-01 20:58:27 +03:00
										 |  |  |     Vector<StyleProperty> const& properties() const { return m_properties; } | 
					
						
							| 
									
										
										
										
											2023-11-05 16:19:16 +13:00
										 |  |  |     HashMap<FlyString, StyleProperty> const& custom_properties() const { return m_custom_properties; } | 
					
						
							|  |  |  |     Optional<StyleProperty> custom_property(FlyString const& custom_property_name) const { return m_custom_properties.get(custom_property_name); } | 
					
						
							| 
									
										
										
										
											2021-09-12 19:24:01 +02:00
										 |  |  |     size_t custom_property_count() const { return m_custom_properties.size(); } | 
					
						
							| 
									
										
										
										
											2021-03-13 22:39:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |     virtual DeprecatedString serialized() const final override; | 
					
						
							| 
									
										
										
										
											2022-11-05 04:51:05 +00:00
										 |  |  |     virtual WebIDL::ExceptionOr<void> set_css_text(StringView) override; | 
					
						
							| 
									
										
										
										
											2021-10-01 19:57:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-16 18:55:53 +01:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2023-11-05 16:19:16 +13:00
										 |  |  |     PropertyOwningCSSStyleDeclaration(JS::Realm&, Vector<StyleProperty>, HashMap<FlyString, StyleProperty>); | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-11 16:10:55 +02:00
										 |  |  |     virtual void update_style_attribute() { } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-05 04:51:05 +00:00
										 |  |  |     void empty_the_declarations(); | 
					
						
							| 
									
										
										
										
											2023-11-05 16:19:16 +13:00
										 |  |  |     void set_the_declarations(Vector<StyleProperty> properties, HashMap<FlyString, StyleProperty> custom_properties); | 
					
						
							| 
									
										
										
										
											2022-11-05 04:51:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-19 17:28:16 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2023-02-20 18:56:08 +01:00
										 |  |  |     bool set_a_css_declaration(PropertyID, NonnullRefPtr<StyleValue const>, Important); | 
					
						
							| 
									
										
										
										
											2022-04-11 16:10:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-24 18:13:39 +02:00
										 |  |  |     virtual void visit_edges(Cell::Visitor&) override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-30 20:06:17 +02:00
										 |  |  |     Vector<StyleProperty> m_properties; | 
					
						
							| 
									
										
										
										
											2023-11-05 16:19:16 +13:00
										 |  |  |     HashMap<FlyString, StyleProperty> m_custom_properties; | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-12 19:24:01 +02:00
										 |  |  | class ElementInlineCSSStyleDeclaration final : public PropertyOwningCSSStyleDeclaration { | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  |     WEB_PLATFORM_OBJECT(ElementInlineCSSStyleDeclaration, PropertyOwningCSSStyleDeclaration); | 
					
						
							| 
									
										
										
										
											2023-11-19 19:47:52 +01:00
										 |  |  |     JS_DECLARE_ALLOCATOR(ElementInlineCSSStyleDeclaration); | 
					
						
							| 
									
										
										
										
											2022-08-07 16:21:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-16 18:55:53 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2023-11-05 16:19:16 +13:00
										 |  |  |     [[nodiscard]] static JS::NonnullGCPtr<ElementInlineCSSStyleDeclaration> create(DOM::Element&, Vector<StyleProperty>, HashMap<FlyString, StyleProperty> custom_properties); | 
					
						
							| 
									
										
										
										
											2022-08-07 16:21:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-14 13:21:51 -06:00
										 |  |  |     virtual ~ElementInlineCSSStyleDeclaration() override = default; | 
					
						
							| 
									
										
										
										
											2021-03-16 18:55:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     DOM::Element* element() { return m_element.ptr(); } | 
					
						
							|  |  |  |     const DOM::Element* element() const { return m_element.ptr(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-11 16:56:52 +02:00
										 |  |  |     bool is_updating() const { return m_updating; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-05 04:51:05 +00:00
										 |  |  |     virtual WebIDL::ExceptionOr<void> set_css_text(StringView) override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-16 18:55:53 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2023-11-05 16:19:16 +13:00
										 |  |  |     ElementInlineCSSStyleDeclaration(DOM::Element&, Vector<StyleProperty> properties, HashMap<FlyString, StyleProperty> custom_properties); | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtual void visit_edges(Cell::Visitor&) override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-11 16:10:55 +02:00
										 |  |  |     virtual void update_style_attribute() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  |     JS::GCPtr<DOM::Element> m_element; | 
					
						
							| 
									
										
										
										
											2022-04-11 16:56:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // https://drafts.csswg.org/cssom/#cssstyledeclaration-updating-flag
 | 
					
						
							|  |  |  |     bool m_updating { false }; | 
					
						
							| 
									
										
										
										
											2021-03-16 18:55:53 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | } |