| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-03-13 22:39:55 +01:00
										 |  |  |  * Copyright (c) 2018-2021, 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
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-06 15:34:26 +02:00
										 |  |  | #include <AK/String.h>
 | 
					
						
							| 
									
										
										
										
											2020-02-14 21:41:10 +01:00
										 |  |  | #include <AK/Vector.h>
 | 
					
						
							| 
									
										
										
										
											2021-03-13 22:39:55 +01:00
										 |  |  | #include <LibWeb/Bindings/Wrappable.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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-30 20:06:17 +02:00
										 |  |  | struct StyleProperty { | 
					
						
							| 
									
										
										
										
											2019-10-08 15:34:19 +02:00
										 |  |  |     CSS::PropertyID property_id; | 
					
						
							| 
									
										
										
										
											2019-09-30 20:06:17 +02:00
										 |  |  |     NonnullRefPtr<StyleValue> value; | 
					
						
							| 
									
										
										
										
											2021-05-24 22:54:41 +02:00
										 |  |  |     String custom_name {}; | 
					
						
							| 
									
										
										
										
											2019-10-06 09:28:10 +02:00
										 |  |  |     bool important { false }; | 
					
						
							| 
									
										
										
										
											2019-09-30 20:06:17 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-13 22:39:55 +01:00
										 |  |  | class CSSStyleDeclaration | 
					
						
							|  |  |  |     : public RefCounted<CSSStyleDeclaration> | 
					
						
							|  |  |  |     , public Bindings::Wrappable { | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2021-03-13 22:39:55 +01:00
										 |  |  |     using WrapperType = Bindings::CSSStyleDeclarationWrapper; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-24 22:54:41 +02:00
										 |  |  |     static NonnullRefPtr<CSSStyleDeclaration> create(Vector<StyleProperty>&& properties, HashMap<String, StyleProperty>&& custom_properties) | 
					
						
							| 
									
										
										
										
											2019-06-21 19:19:49 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-05-24 22:54:41 +02:00
										 |  |  |         return adopt_ref(*new CSSStyleDeclaration(move(properties), move(custom_properties))); | 
					
						
							| 
									
										
										
										
											2019-06-21 19:19:49 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-16 18:55:53 +01:00
										 |  |  |     virtual ~CSSStyleDeclaration(); | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-30 20:06:17 +02:00
										 |  |  |     const Vector<StyleProperty>& properties() const { return m_properties; } | 
					
						
							| 
									
										
										
										
											2021-05-24 22:54:41 +02:00
										 |  |  |     const Optional<StyleProperty> custom_property(const String& custom_property_name) const { return m_custom_properties.get(custom_property_name); } | 
					
						
							|  |  |  |     size_t custom_property_count() const { return m_custom_properties.size(); }; | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-13 22:39:55 +01:00
										 |  |  |     size_t length() const { return m_properties.size(); } | 
					
						
							|  |  |  |     String item(size_t index) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-16 18:55:53 +01:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2021-05-24 22:54:41 +02:00
										 |  |  |     explicit CSSStyleDeclaration(Vector<StyleProperty>&&, HashMap<String, StyleProperty>&&); | 
					
						
							| 
									
										
										
										
											2021-03-16 18:55:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-19 17:28:16 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2021-03-14 17:05:02 +01:00
										 |  |  |     friend class Bindings::CSSStyleDeclarationWrapper; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-30 20:06:17 +02:00
										 |  |  |     Vector<StyleProperty> m_properties; | 
					
						
							| 
									
										
										
										
											2021-05-24 22:54:41 +02:00
										 |  |  |     HashMap<String, StyleProperty> m_custom_properties; | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-16 18:55:53 +01:00
										 |  |  | class ElementInlineCSSStyleDeclaration final : public CSSStyleDeclaration { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2021-04-23 16:46:57 +02:00
										 |  |  |     static NonnullRefPtr<ElementInlineCSSStyleDeclaration> create(DOM::Element& element) { return adopt_ref(*new ElementInlineCSSStyleDeclaration(element)); } | 
					
						
							| 
									
										
										
										
											2021-03-16 18:55:53 +01:00
										 |  |  |     virtual ~ElementInlineCSSStyleDeclaration() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     DOM::Element* element() { return m_element.ptr(); } | 
					
						
							|  |  |  |     const DOM::Element* element() const { return m_element.ptr(); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     explicit ElementInlineCSSStyleDeclaration(DOM::Element&); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     WeakPtr<DOM::Element> m_element; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-03-13 22:39:55 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::Bindings { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CSSStyleDeclarationWrapper* wrap(JS::GlobalObject&, CSS::CSSStyleDeclaration&); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |