| 
									
										
										
										
											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>
 | 
					
						
							| 
									
										
										
										
											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-02-12 14:53:59 +00:00
										 |  |  | enum class Important { | 
					
						
							|  |  |  |     No, | 
					
						
							|  |  |  |     Yes, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-30 20:06:17 +02:00
										 |  |  | struct StyleProperty { | 
					
						
							| 
									
										
										
										
											2022-02-12 14:53:59 +00:00
										 |  |  |     Important important { Important::No }; | 
					
						
							| 
									
										
										
										
											2019-10-08 15:34:19 +02:00
										 |  |  |     CSS::PropertyID property_id; | 
					
						
							| 
									
										
										
										
											2023-02-20 18:56:08 +01:00
										 |  |  |     NonnullRefPtr<StyleValue const> value; | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |     DeprecatedString custom_name {}; | 
					
						
							| 
									
										
										
										
											2019-09-30 20:06:17 +02: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); | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2021-09-12 19:24:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtual size_t length() const = 0; | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |     virtual DeprecatedString 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; | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |     virtual WebIDL::ExceptionOr<DeprecatedString> 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); | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |     WebIDL::ExceptionOr<DeprecatedString> remove_property(StringView property_name); | 
					
						
							| 
									
										
										
										
											2021-09-26 19:06:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |     DeprecatedString get_property_value(StringView property) const; | 
					
						
							|  |  |  |     DeprecatedString 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; | 
					
						
							|  |  |  |     virtual JS::ThrowCompletionOr<JS::Value> internal_get(JS::PropertyKey const&, JS::Value receiver) const override; | 
					
						
							|  |  |  |     virtual JS::ThrowCompletionOr<bool> internal_set(JS::PropertyKey const&, JS::Value value, JS::Value receiver) override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2021-09-12 19:24:01 +02:00
										 |  |  |     friend class ElementInlineCSSStyleDeclaration; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2023-02-12 23:22:53 +01:00
										 |  |  |     static WebIDL::ExceptionOr<JS::NonnullGCPtr<PropertyOwningCSSStyleDeclaration>> create(JS::Realm&, Vector<StyleProperty>, HashMap<DeprecatedString, 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; | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |     virtual DeprecatedString 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; | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |     virtual WebIDL::ExceptionOr<DeprecatedString> 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; } | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |     HashMap<DeprecatedString, StyleProperty> const& custom_properties() const { return m_custom_properties; } | 
					
						
							|  |  |  |     Optional<StyleProperty> custom_property(DeprecatedString 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: | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |     PropertyOwningCSSStyleDeclaration(JS::Realm&, Vector<StyleProperty>, HashMap<DeprecatedString, 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(); | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |     void set_the_declarations(Vector<StyleProperty> properties, HashMap<DeprecatedString, 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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-30 20:06:17 +02:00
										 |  |  |     Vector<StyleProperty> m_properties; | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |     HashMap<DeprecatedString, 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); | 
					
						
							| 
									
										
										
										
											2022-08-07 16:21:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-16 18:55:53 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2023-02-12 23:22:53 +01:00
										 |  |  |     static WebIDL::ExceptionOr<JS::NonnullGCPtr<ElementInlineCSSStyleDeclaration>> create(DOM::Element&, Vector<StyleProperty> properties, HashMap<DeprecatedString, 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: | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |     ElementInlineCSSStyleDeclaration(DOM::Element&, Vector<StyleProperty> properties, HashMap<DeprecatedString, 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
										 |  |  | } |