| 
									
										
										
										
											2021-03-09 17:36:21 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-04-28 22:46:44 +02:00
										 |  |  |  * Copyright (c) 2020-2021, the SerenityOS developers. | 
					
						
							| 
									
										
										
										
											2021-06-30 16:27:37 +01:00
										 |  |  |  * Copyright (c) 2021, Sam Atkins <atkinssj@gmail.com> | 
					
						
							| 
									
										
										
										
											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>
 | 
					
						
							| 
									
										
										
										
											2021-03-09 17:36:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::CSS { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-01 14:13:48 +01:00
										 |  |  | class StyleBlockRule; | 
					
						
							|  |  |  | class StyleFunctionRule; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-09 17:36:21 +01:00
										 |  |  | class StyleComponentValueRule { | 
					
						
							|  |  |  |     friend class Parser; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     enum class ComponentType { | 
					
						
							|  |  |  |         Token, | 
					
						
							|  |  |  |         Function, | 
					
						
							|  |  |  |         Block | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-03 14:54:19 +01:00
										 |  |  |     StyleComponentValueRule(Token); | 
					
						
							|  |  |  |     explicit StyleComponentValueRule(NonnullRefPtr<StyleFunctionRule>); | 
					
						
							|  |  |  |     explicit StyleComponentValueRule(NonnullRefPtr<StyleBlockRule>); | 
					
						
							| 
									
										
										
										
											2021-03-09 17:36:21 +01:00
										 |  |  |     ~StyleComponentValueRule(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-30 16:27:37 +01:00
										 |  |  |     bool is_block() const { return m_type == ComponentType::Block; } | 
					
						
							| 
									
										
										
										
											2021-07-01 14:13:48 +01:00
										 |  |  |     StyleBlockRule const& block() const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         VERIFY(is_block()); | 
					
						
							|  |  |  |         return *m_block; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-06-30 16:27:37 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bool is_function() const { return m_type == ComponentType::Function; } | 
					
						
							| 
									
										
										
										
											2021-07-01 14:13:48 +01:00
										 |  |  |     StyleFunctionRule const& function() const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         VERIFY(is_function()); | 
					
						
							|  |  |  |         return *m_function; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-06-30 16:27:37 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bool is(Token::TokenType type) const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return m_type == ComponentType::Token && m_token.is(type); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     Token const& token() const { return m_token; } | 
					
						
							|  |  |  |     operator Token() const { return m_token; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-09 17:36:21 +01:00
										 |  |  |     String to_string() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     ComponentType m_type; | 
					
						
							|  |  |  |     Token m_token; | 
					
						
							| 
									
										
										
										
											2021-07-01 14:13:48 +01:00
										 |  |  |     RefPtr<StyleFunctionRule> m_function; | 
					
						
							|  |  |  |     RefPtr<StyleBlockRule> m_block; | 
					
						
							| 
									
										
										
										
											2021-03-09 17:36:21 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | } |