| 
									
										
										
										
											2022-08-24 12:21:58 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2023-08-25 23:29:13 +02:00
										 |  |  |  * Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com> | 
					
						
							| 
									
										
										
										
											2022-08-24 12:21:58 +02:00
										 |  |  |  * Copyright (c) 2022, Martin Falisse <mfalisse@outlook.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-06 19:02:26 +01:00
										 |  |  | #include <AK/String.h>
 | 
					
						
							| 
									
										
										
										
											2025-07-08 14:31:40 +12:00
										 |  |  | #include <LibWeb/CSS/CalculatedOr.h>
 | 
					
						
							| 
									
										
										
										
											2022-08-24 12:21:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::CSS { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class GridTrackPlacement { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2023-08-25 23:29:13 +02:00
										 |  |  |     static GridTrackPlacement make_auto() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return GridTrackPlacement(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-17 18:09:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-08 14:31:40 +12:00
										 |  |  |     static GridTrackPlacement make_line(Optional<IntegerOrCalculated> line_number, Optional<String> name) | 
					
						
							| 
									
										
										
										
											2023-08-25 23:29:13 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2025-09-24 22:46:30 +01:00
										 |  |  |         return GridTrackPlacement(AreaOrLine { .line_number = move(line_number), .name = move(name) }); | 
					
						
							| 
									
										
										
										
											2023-08-25 23:29:13 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-08-24 12:21:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-08 14:31:40 +12:00
										 |  |  |     static GridTrackPlacement make_span(IntegerOrCalculated value, Optional<String> name) | 
					
						
							| 
									
										
										
										
											2023-08-25 23:29:13 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2025-09-24 22:46:30 +01:00
										 |  |  |         return GridTrackPlacement(Span { .value = move(value), .name = move(name) }); | 
					
						
							| 
									
										
										
										
											2023-08-25 23:29:13 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-10-30 13:46:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-25 23:29:13 +02:00
										 |  |  |     bool is_auto() const { return m_value.has<Auto>(); } | 
					
						
							|  |  |  |     bool is_span() const { return m_value.has<Span>(); } | 
					
						
							| 
									
										
										
										
											2023-08-27 16:27:35 +02:00
										 |  |  |     bool is_area_or_line() const { return m_value.has<AreaOrLine>(); } | 
					
						
							| 
									
										
										
										
											2022-08-24 12:21:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-25 23:29:13 +02:00
										 |  |  |     bool is_auto_positioned() const { return is_auto() || is_span(); } | 
					
						
							|  |  |  |     bool is_positioned() const { return !is_auto_positioned(); } | 
					
						
							| 
									
										
										
										
											2022-09-07 15:03:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-08 14:31:40 +12:00
										 |  |  |     bool is_custom_ident() const { return is_area_or_line() && !m_value.get<AreaOrLine>().line_number.has_value(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-27 16:27:35 +02:00
										 |  |  |     bool has_identifier() const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return is_area_or_line() && m_value.get<AreaOrLine>().name.has_value(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool has_line_number() const | 
					
						
							| 
									
										
										
										
											2022-08-24 12:21:58 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-08-27 16:27:35 +02:00
										 |  |  |         return is_area_or_line() && m_value.get<AreaOrLine>().line_number.has_value(); | 
					
						
							| 
									
										
										
										
											2022-08-24 12:21:58 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-27 16:27:35 +02:00
										 |  |  |     String identifier() const { return *m_value.get<AreaOrLine>().name; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-08 14:31:40 +12:00
										 |  |  |     IntegerOrCalculated line_number() const { return *m_value.get<AreaOrLine>().line_number; } | 
					
						
							|  |  |  |     IntegerOrCalculated span() const { return m_value.get<Span>().value; } | 
					
						
							| 
									
										
										
										
											2023-08-25 23:29:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-04 22:04:18 +12:00
										 |  |  |     String to_string(SerializationMode mode) const; | 
					
						
							| 
									
										
										
										
											2023-08-25 23:29:13 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bool operator==(GridTrackPlacement const& other) const = default; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-24 12:21:58 +02:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2023-08-25 23:29:13 +02:00
										 |  |  |     struct Auto { | 
					
						
							|  |  |  |         bool operator==(Auto const&) const = default; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-27 16:27:35 +02:00
										 |  |  |     struct AreaOrLine { | 
					
						
							| 
									
										
										
										
											2025-07-08 14:31:40 +12:00
										 |  |  |         Optional<IntegerOrCalculated> line_number; | 
					
						
							| 
									
										
										
										
											2023-08-25 23:29:13 +02:00
										 |  |  |         Optional<String> name; | 
					
						
							| 
									
										
										
										
											2023-08-27 16:27:35 +02:00
										 |  |  |         bool operator==(AreaOrLine const& other) const = default; | 
					
						
							| 
									
										
										
										
											2023-08-25 23:29:13 +02:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     struct Span { | 
					
						
							| 
									
										
										
										
											2025-07-08 14:31:40 +12:00
										 |  |  |         IntegerOrCalculated value; | 
					
						
							|  |  |  |         Optional<String> name; | 
					
						
							| 
									
										
										
										
											2023-08-25 23:29:13 +02:00
										 |  |  |         bool operator==(Span const& other) const = default; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     GridTrackPlacement() | 
					
						
							| 
									
										
										
										
											2024-12-27 18:47:33 -05:00
										 |  |  |         : m_value(Auto {}) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-08-27 16:27:35 +02:00
										 |  |  |     GridTrackPlacement(AreaOrLine value) | 
					
						
							| 
									
										
										
										
											2025-09-24 22:46:30 +01:00
										 |  |  |         : m_value(move(value)) | 
					
						
							| 
									
										
										
										
											2024-12-27 18:47:33 -05:00
										 |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-08-25 23:29:13 +02:00
										 |  |  |     GridTrackPlacement(Span value) | 
					
						
							| 
									
										
										
										
											2025-09-24 22:46:30 +01:00
										 |  |  |         : m_value(move(value)) | 
					
						
							| 
									
										
										
										
											2024-12-27 18:47:33 -05:00
										 |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-08-25 23:29:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-27 16:27:35 +02:00
										 |  |  |     Variant<Auto, AreaOrLine, Span> m_value; | 
					
						
							| 
									
										
										
										
											2022-08-24 12:21:58 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |