| 
									
										
										
										
											2022-02-21 17:43:30 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2025-05-16 20:02:16 +01:00
										 |  |  |  * Copyright (c) 2022-2025, Sam Atkins <sam@ladybird.org> | 
					
						
							| 
									
										
										
										
											2022-02-21 17:43:30 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-06 19:02:26 +01:00
										 |  |  | #include <AK/String.h>
 | 
					
						
							| 
									
										
										
										
											2025-05-16 20:02:16 +01:00
										 |  |  | #include <LibWeb/CSS/SerializationMode.h>
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:26:21 +01:00
										 |  |  | #include <LibWeb/CSS/Units.h>
 | 
					
						
							| 
									
										
										
										
											2022-02-21 17:43:30 +00:00
										 |  |  | #include <LibWeb/Forward.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Web::CSS { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Angle { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     Angle(double value, AngleUnit unit); | 
					
						
							| 
									
										
										
										
											2023-05-27 21:10:21 +02:00
										 |  |  |     static Angle make_degrees(double); | 
					
						
							| 
									
										
										
										
											2022-02-21 17:43:30 +00:00
										 |  |  |     Angle percentage_of(Percentage const&) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-16 20:02:16 +01:00
										 |  |  |     String to_string(SerializationMode = SerializationMode::Normal) const; | 
					
						
							| 
									
										
										
										
											2023-05-27 23:50:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-27 21:10:21 +02:00
										 |  |  |     double to_degrees() const; | 
					
						
							| 
									
										
										
										
											2023-05-27 23:50:33 +02:00
										 |  |  |     double to_radians() const; | 
					
						
							| 
									
										
										
										
											2022-02-21 17:43:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-27 21:10:21 +02:00
										 |  |  |     double raw_value() const { return m_value; } | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     AngleUnit unit() const { return m_unit; } | 
					
						
							| 
									
										
										
										
											2025-09-11 11:50:59 +01:00
										 |  |  |     FlyString unit_name() const { return CSS::to_string(m_unit); } | 
					
						
							| 
									
										
										
										
											2023-04-11 12:57:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-21 17:43:30 +00:00
										 |  |  |     bool operator==(Angle const& other) const | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |         return m_unit == other.m_unit && m_value == other.m_value; | 
					
						
							| 
									
										
										
										
											2022-02-21 17:43:30 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-31 14:55:18 +01:00
										 |  |  |     int operator<=>(Angle const& other) const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         auto this_degrees = to_degrees(); | 
					
						
							|  |  |  |         auto other_degrees = other.to_degrees(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (this_degrees < other_degrees) | 
					
						
							|  |  |  |             return -1; | 
					
						
							|  |  |  |         if (this_degrees > other_degrees) | 
					
						
							|  |  |  |             return 1; | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-15 15:18:27 -06:00
										 |  |  |     static Angle resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const&, Layout::Node const&, Angle const& reference_value); | 
					
						
							| 
									
										
										
										
											2024-08-02 14:28:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-21 17:43:30 +00:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     AngleUnit m_unit; | 
					
						
							| 
									
										
										
										
											2023-05-27 21:10:21 +02:00
										 |  |  |     double m_value { 0 }; | 
					
						
							| 
									
										
										
										
											2022-02-21 17:43:30 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-07-27 11:41:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | template<> | 
					
						
							|  |  |  | struct AK::Formatter<Web::CSS::Angle> : Formatter<StringView> { | 
					
						
							|  |  |  |     ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Angle const& angle) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-08-22 12:25:30 +01:00
										 |  |  |         return Formatter<StringView>::format(builder, angle.to_string()); | 
					
						
							| 
									
										
										
										
											2022-07-27 11:41:31 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | }; |