| 
									
										
										
										
											2025-02-26 18:16:36 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2025, Andreas Kling <andreas@ladybird.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <LibWeb/CSS/PercentageOr.h>
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  | #include <LibWeb/CSS/StyleValues/StyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2025-02-26 18:16:36 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::CSS { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  | class FitContentStyleValue final : public StyleValue { | 
					
						
							| 
									
										
										
										
											2025-02-26 18:16:36 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2025-04-15 15:18:27 -06:00
										 |  |  |     static ValueComparingNonnullRefPtr<FitContentStyleValue const> create() | 
					
						
							| 
									
										
										
										
											2025-02-26 18:16:36 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         return adopt_ref(*new (nothrow) FitContentStyleValue(LengthPercentage { Length::make_auto() })); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-04-15 15:18:27 -06:00
										 |  |  |     static ValueComparingNonnullRefPtr<FitContentStyleValue const> create(LengthPercentage length_percentage) | 
					
						
							| 
									
										
										
										
											2025-02-26 18:16:36 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         return adopt_ref(*new (nothrow) FitContentStyleValue(move(length_percentage))); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     virtual ~FitContentStyleValue() override = default; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-03 15:37:42 +12:00
										 |  |  |     virtual String to_string(SerializationMode mode) const override | 
					
						
							| 
									
										
										
										
											2025-02-26 18:16:36 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         if (m_length_percentage.is_auto()) | 
					
						
							|  |  |  |             return "fit-content"_string; | 
					
						
							| 
									
										
										
										
											2025-08-03 15:37:42 +12:00
										 |  |  |         return MUST(String::formatted("fit-content({})", m_length_percentage.to_string(mode))); | 
					
						
							| 
									
										
										
										
											2025-02-26 18:16:36 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  |     bool equals(StyleValue const& other) const override | 
					
						
							| 
									
										
										
										
											2025-02-26 18:16:36 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         if (type() != other.type()) | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         return m_length_percentage == other.as_fit_content().m_length_percentage; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     [[nodiscard]] LengthPercentage const& length_percentage() const { return m_length_percentage; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     FitContentStyleValue(LengthPercentage length_percentage) | 
					
						
							| 
									
										
										
										
											2025-08-08 10:11:51 +01:00
										 |  |  |         : StyleValue(Type::FitContent) | 
					
						
							| 
									
										
										
										
											2025-02-26 18:16:36 +01:00
										 |  |  |         , m_length_percentage(move(length_percentage)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     LengthPercentage m_length_percentage; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |