| 
									
										
										
										
											2025-01-05 09:51:58 +11:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2025, Ladybird contributors | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 11:41:12 +01:00
										 |  |  | #include "LightDarkStyleValue.h"
 | 
					
						
							| 
									
										
										
										
											2025-01-05 09:51:58 +11:00
										 |  |  | #include <LibWeb/Layout/Node.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Web::CSS { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 11:41:12 +01:00
										 |  |  | Optional<Color> LightDarkStyleValue::to_color(ColorResolutionContext color_resolution_context) const | 
					
						
							| 
									
										
										
										
											2025-01-05 09:51:58 +11:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-07-19 11:31:07 +12:00
										 |  |  |     if (color_resolution_context.color_scheme == PreferredColorScheme::Dark) | 
					
						
							|  |  |  |         return m_properties.dark->to_color(color_resolution_context); | 
					
						
							| 
									
										
										
										
											2025-01-05 09:51:58 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-19 11:31:07 +12:00
										 |  |  |     return m_properties.light->to_color(color_resolution_context); | 
					
						
							| 
									
										
										
										
											2025-01-05 09:51:58 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 11:41:12 +01:00
										 |  |  | bool LightDarkStyleValue::equals(StyleValue const& other) const | 
					
						
							| 
									
										
										
										
											2025-01-05 09:51:58 +11:00
										 |  |  | { | 
					
						
							|  |  |  |     if (type() != other.type()) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     auto const& other_color = other.as_color(); | 
					
						
							|  |  |  |     if (color_type() != other_color.color_type()) | 
					
						
							|  |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2025-08-08 11:41:12 +01:00
										 |  |  |     auto const& other_light_dark = as<LightDarkStyleValue>(other_color); | 
					
						
							| 
									
										
										
										
											2025-01-05 09:51:58 +11:00
										 |  |  |     return m_properties == other_light_dark.m_properties; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 11:41:12 +01:00
										 |  |  | String LightDarkStyleValue::to_string(SerializationMode mode) const | 
					
						
							| 
									
										
										
										
											2025-01-05 09:51:58 +11:00
										 |  |  | { | 
					
						
							|  |  |  |     // FIXME: We don't have enough information to determine the computed value here.
 | 
					
						
							|  |  |  |     return MUST(String::formatted("light-dark({}, {})", m_properties.light->to_string(mode), m_properties.dark->to_string(mode))); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |