| 
									
										
										
										
											2024-07-24 14:56:16 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2024, Sam Atkins <sam@ladybird.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/FlyString.h>
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/StyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2024-07-24 14:56:16 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::CSS { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://drafts.csswg.org/css-lists-3/#counter-functions
 | 
					
						
							|  |  |  | class CounterStyleValue : public StyleValueWithDefaultOperators<CounterStyleValue> { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     enum class CounterFunction { | 
					
						
							|  |  |  |         Counter, | 
					
						
							|  |  |  |         Counters, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  |     static ValueComparingNonnullRefPtr<CounterStyleValue const> create_counter(FlyString counter_name, ValueComparingNonnullRefPtr<StyleValue const> counter_style) | 
					
						
							| 
									
										
										
										
											2024-07-24 14:56:16 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         return adopt_ref(*new (nothrow) CounterStyleValue(CounterFunction::Counter, move(counter_name), move(counter_style), {})); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  |     static ValueComparingNonnullRefPtr<CounterStyleValue const> create_counters(FlyString counter_name, FlyString join_string, ValueComparingNonnullRefPtr<StyleValue const> counter_style) | 
					
						
							| 
									
										
										
										
											2024-07-24 14:56:16 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         return adopt_ref(*new (nothrow) CounterStyleValue(CounterFunction::Counters, move(counter_name), move(counter_style), move(join_string))); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     virtual ~CounterStyleValue() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     CounterFunction function_type() const { return m_properties.function; } | 
					
						
							|  |  |  |     auto counter_name() const { return m_properties.counter_name; } | 
					
						
							|  |  |  |     auto counter_style() const { return m_properties.counter_style; } | 
					
						
							|  |  |  |     auto join_string() const { return m_properties.join_string; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-17 16:33:23 +01:00
										 |  |  |     String resolve(DOM::AbstractElement&) const; | 
					
						
							| 
									
										
										
										
											2024-07-24 14:56:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-07 00:59:49 +01:00
										 |  |  |     virtual String to_string(SerializationMode) const override; | 
					
						
							| 
									
										
										
										
											2024-07-24 14:56:16 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bool properties_equal(CounterStyleValue const& other) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  |     explicit CounterStyleValue(CounterFunction, FlyString counter_name, ValueComparingNonnullRefPtr<StyleValue const> counter_style, FlyString join_string); | 
					
						
							| 
									
										
										
										
											2024-07-24 14:56:16 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     struct Properties { | 
					
						
							|  |  |  |         CounterFunction function; | 
					
						
							|  |  |  |         FlyString counter_name; | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  |         ValueComparingNonnullRefPtr<StyleValue const> counter_style; | 
					
						
							| 
									
										
										
										
											2024-07-24 14:56:16 +01:00
										 |  |  |         FlyString join_string; | 
					
						
							|  |  |  |         bool operator==(Properties const&) const = default; | 
					
						
							|  |  |  |     } m_properties; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |