| 
									
										
										
										
											2021-03-09 17:36:21 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-04-28 22:46:44 +02:00
										 |  |  |  * Copyright (c) 2020-2021, the SerenityOS developers. | 
					
						
							| 
									
										
										
										
											2023-02-14 19:04:12 +00:00
										 |  |  |  * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org> | 
					
						
							| 
									
										
										
										
											2024-10-04 13:19:50 +02:00
										 |  |  |  * Copyright (c) 2023, Andreas Kling <andreas@ladybird.org> | 
					
						
							| 
									
										
										
										
											2021-03-09 17:36:21 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2021-03-09 17:36:21 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-01 14:13:48 +01:00
										 |  |  | #include <AK/NonnullRefPtr.h>
 | 
					
						
							|  |  |  | #include <AK/RefPtr.h>
 | 
					
						
							| 
									
										
										
										
											2021-03-09 20:06:52 +01:00
										 |  |  | #include <LibWeb/CSS/Parser/Token.h>
 | 
					
						
							| 
									
										
										
										
											2024-10-11 11:17:10 +01:00
										 |  |  | #include <LibWeb/CSS/Parser/Types.h>
 | 
					
						
							| 
									
										
										
										
											2021-03-09 17:36:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-12 12:13:10 +01:00
										 |  |  | namespace Web::CSS::Parser { | 
					
						
							| 
									
										
										
										
											2021-07-01 14:13:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-11 11:17:10 +01:00
										 |  |  | // https://drafts.csswg.org/css-syntax/#component-value
 | 
					
						
							| 
									
										
										
										
											2022-03-31 11:43:07 +01:00
										 |  |  | class ComponentValue { | 
					
						
							| 
									
										
										
										
											2021-03-09 17:36:21 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2022-03-31 11:43:07 +01:00
										 |  |  |     ComponentValue(Token); | 
					
						
							| 
									
										
										
										
											2024-10-11 11:17:10 +01:00
										 |  |  |     explicit ComponentValue(Function&&); | 
					
						
							|  |  |  |     explicit ComponentValue(SimpleBlock&&); | 
					
						
							| 
									
										
										
										
											2022-03-31 11:43:07 +01:00
										 |  |  |     ~ComponentValue(); | 
					
						
							| 
									
										
										
										
											2021-03-09 17:36:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-11 11:17:10 +01:00
										 |  |  |     bool is_block() const { return m_value.has<SimpleBlock>(); } | 
					
						
							|  |  |  |     SimpleBlock& block() { return m_value.get<SimpleBlock>(); } | 
					
						
							|  |  |  |     SimpleBlock const& block() const { return m_value.get<SimpleBlock>(); } | 
					
						
							| 
									
										
										
										
											2021-06-30 16:27:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-11 11:17:10 +01:00
										 |  |  |     bool is_function() const { return m_value.has<Function>(); } | 
					
						
							| 
									
										
										
										
											2023-09-05 19:42:28 +01:00
										 |  |  |     bool is_function(StringView name) const; | 
					
						
							| 
									
										
										
										
											2024-10-11 11:17:10 +01:00
										 |  |  |     Function& function() { return m_value.get<Function>(); } | 
					
						
							|  |  |  |     Function const& function() const { return m_value.get<Function>(); } | 
					
						
							| 
									
										
										
										
											2021-06-30 16:27:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-21 13:35:55 +00:00
										 |  |  |     bool is_token() const { return m_value.has<Token>(); } | 
					
						
							|  |  |  |     bool is(Token::Type type) const { return is_token() && token().is(type); } | 
					
						
							| 
									
										
										
										
											2023-06-06 14:28:42 +01:00
										 |  |  |     bool is_delim(u32 delim) const { return is(Token::Type::Delim) && token().delim() == delim; } | 
					
						
							| 
									
										
										
										
											2023-09-05 19:42:28 +01:00
										 |  |  |     bool is_ident(StringView ident) const; | 
					
						
							| 
									
										
										
										
											2022-03-21 13:35:55 +00:00
										 |  |  |     Token const& token() const { return m_value.get<Token>(); } | 
					
						
							|  |  |  |     operator Token() const { return m_value.get<Token>(); } | 
					
						
							| 
									
										
										
										
											2021-06-30 16:27:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-22 13:00:28 +01:00
										 |  |  |     String to_string() const; | 
					
						
							|  |  |  |     String to_debug_string() const; | 
					
						
							| 
									
										
										
										
											2021-03-09 17:36:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2024-10-11 11:17:10 +01:00
										 |  |  |     Variant<Token, Function, SimpleBlock> m_value; | 
					
						
							| 
									
										
										
										
											2021-03-09 17:36:21 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-04-12 12:30:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | template<> | 
					
						
							|  |  |  | struct AK::Formatter<Web::CSS::Parser::ComponentValue> : Formatter<StringView> { | 
					
						
							|  |  |  |     ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Parser::ComponentValue const& component_value) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-08-22 13:00:28 +01:00
										 |  |  |         return Formatter<StringView>::format(builder, component_value.to_string()); | 
					
						
							| 
									
										
										
										
											2022-04-12 12:30:48 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | }; |