| 
									
										
										
										
											2025-04-14 17:10:20 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2025, Sam Atkins <sam@ladybird.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-15 11:48:56 +01:00
										 |  |  | #include <LibWeb/CSS/CSSMarginRule.h>
 | 
					
						
							| 
									
										
										
										
											2025-04-14 17:10:20 +01:00
										 |  |  | #include <LibWeb/CSS/Parser/RuleContext.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Web::CSS::Parser { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RuleContext rule_context_type_for_rule(CSSRule::Type rule_type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     switch (rule_type) { | 
					
						
							|  |  |  |     case CSSRule::Type::Style: | 
					
						
							|  |  |  |         return RuleContext::Style; | 
					
						
							|  |  |  |     case CSSRule::Type::Media: | 
					
						
							|  |  |  |         return RuleContext::AtMedia; | 
					
						
							|  |  |  |     case CSSRule::Type::FontFace: | 
					
						
							|  |  |  |         return RuleContext::AtFontFace; | 
					
						
							|  |  |  |     case CSSRule::Type::Keyframes: | 
					
						
							|  |  |  |         return RuleContext::AtKeyframes; | 
					
						
							|  |  |  |     case CSSRule::Type::Keyframe: | 
					
						
							|  |  |  |         return RuleContext::Keyframe; | 
					
						
							|  |  |  |     case CSSRule::Type::Supports: | 
					
						
							|  |  |  |         return RuleContext::AtSupports; | 
					
						
							|  |  |  |     case CSSRule::Type::LayerBlock: | 
					
						
							|  |  |  |         return RuleContext::AtLayer; | 
					
						
							| 
									
										
										
										
											2025-05-15 11:48:56 +01:00
										 |  |  |     case CSSRule::Type::Margin: | 
					
						
							|  |  |  |         return RuleContext::Margin; | 
					
						
							| 
									
										
										
										
											2025-04-14 17:10:20 +01:00
										 |  |  |     case CSSRule::Type::NestedDeclarations: | 
					
						
							|  |  |  |         return RuleContext::Style; | 
					
						
							| 
									
										
										
										
											2025-05-13 12:17:41 +01:00
										 |  |  |     case CSSRule::Type::Page: | 
					
						
							|  |  |  |         return RuleContext::AtPage; | 
					
						
							| 
									
										
										
										
											2025-04-14 17:10:20 +01:00
										 |  |  |     case CSSRule::Type::Property: | 
					
						
							|  |  |  |         return RuleContext::AtProperty; | 
					
						
							|  |  |  |         // Other types shouldn't be trying to create a context.
 | 
					
						
							|  |  |  |     case CSSRule::Type::Import: | 
					
						
							|  |  |  |     case CSSRule::Type::LayerStatement: | 
					
						
							|  |  |  |     case CSSRule::Type::Namespace: | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     VERIFY_NOT_REACHED(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RuleContext rule_context_type_for_at_rule(FlyString const& name) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2025-05-15 10:58:21 +01:00
										 |  |  |     if (name.equals_ignoring_ascii_case("media"sv)) | 
					
						
							| 
									
										
										
										
											2025-04-14 17:10:20 +01:00
										 |  |  |         return RuleContext::AtMedia; | 
					
						
							| 
									
										
										
										
											2025-05-15 10:58:21 +01:00
										 |  |  |     if (name.equals_ignoring_ascii_case("font-face"sv)) | 
					
						
							| 
									
										
										
										
											2025-04-14 17:10:20 +01:00
										 |  |  |         return RuleContext::AtFontFace; | 
					
						
							| 
									
										
										
										
											2025-05-15 10:58:21 +01:00
										 |  |  |     if (name.equals_ignoring_ascii_case("keyframes"sv)) | 
					
						
							| 
									
										
										
										
											2025-04-14 17:10:20 +01:00
										 |  |  |         return RuleContext::AtKeyframes; | 
					
						
							| 
									
										
										
										
											2025-05-15 10:58:21 +01:00
										 |  |  |     if (name.equals_ignoring_ascii_case("supports"sv)) | 
					
						
							| 
									
										
										
										
											2025-04-14 17:10:20 +01:00
										 |  |  |         return RuleContext::AtSupports; | 
					
						
							| 
									
										
										
										
											2025-05-15 10:58:21 +01:00
										 |  |  |     if (name.equals_ignoring_ascii_case("layer"sv)) | 
					
						
							| 
									
										
										
										
											2025-04-14 17:10:20 +01:00
										 |  |  |         return RuleContext::AtLayer; | 
					
						
							| 
									
										
										
										
											2025-05-15 10:58:21 +01:00
										 |  |  |     if (name.equals_ignoring_ascii_case("property"sv)) | 
					
						
							| 
									
										
										
										
											2025-04-14 17:10:20 +01:00
										 |  |  |         return RuleContext::AtProperty; | 
					
						
							| 
									
										
										
										
											2025-05-15 10:58:21 +01:00
										 |  |  |     if (name.equals_ignoring_ascii_case("page"sv)) | 
					
						
							| 
									
										
										
										
											2025-05-13 12:17:41 +01:00
										 |  |  |         return RuleContext::AtPage; | 
					
						
							| 
									
										
										
										
											2025-05-15 11:48:56 +01:00
										 |  |  |     if (is_margin_rule_name(name)) | 
					
						
							|  |  |  |         return RuleContext::Margin; | 
					
						
							| 
									
										
										
										
											2025-04-14 17:10:20 +01:00
										 |  |  |     return RuleContext::Unknown; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |