| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-22 19:10:43 +01:00
										 |  |  | #include <AK/FlyString.h>
 | 
					
						
							| 
									
										
										
										
											2021-05-23 20:59:26 +02:00
										 |  |  | #include <AK/String.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  | #include <AK/Vector.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-26 20:01:35 +02:00
										 |  |  | namespace Web::CSS { | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  | class Selector { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2019-11-27 20:37:36 +01:00
										 |  |  |     struct SimpleSelector { | 
					
						
							| 
									
										
										
										
											2019-06-29 17:32:32 +02:00
										 |  |  |         enum class Type { | 
					
						
							|  |  |  |             Invalid, | 
					
						
							| 
									
										
										
										
											2019-11-19 18:22:12 +01:00
										 |  |  |             Universal, | 
					
						
							| 
									
										
										
										
											2019-06-29 17:32:32 +02:00
										 |  |  |             TagName, | 
					
						
							|  |  |  |             Id, | 
					
						
							| 
									
										
										
										
											2019-10-06 09:28:10 +02:00
										 |  |  |             Class, | 
					
						
							| 
									
										
										
										
											2019-06-29 17:32:32 +02:00
										 |  |  |         }; | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  |         Type type { Type::Invalid }; | 
					
						
							| 
									
										
										
										
											2019-10-06 09:28:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-13 21:54:26 +02:00
										 |  |  |         enum class PseudoClass { | 
					
						
							|  |  |  |             None, | 
					
						
							|  |  |  |             Link, | 
					
						
							| 
									
										
										
										
											2020-06-13 00:21:42 +02:00
										 |  |  |             Visited, | 
					
						
							| 
									
										
										
										
											2019-10-13 21:54:26 +02:00
										 |  |  |             Hover, | 
					
						
							| 
									
										
										
										
											2020-05-05 11:48:13 +01:00
										 |  |  |             Focus, | 
					
						
							| 
									
										
										
										
											2019-12-16 19:34:52 +01:00
										 |  |  |             FirstChild, | 
					
						
							|  |  |  |             LastChild, | 
					
						
							| 
									
										
										
										
											2019-12-16 19:52:11 +01:00
										 |  |  |             OnlyChild, | 
					
						
							| 
									
										
										
										
											2019-12-16 19:45:50 +01:00
										 |  |  |             Empty, | 
					
						
							| 
									
										
										
										
											2020-05-13 22:38:12 +01:00
										 |  |  |             Root, | 
					
						
							| 
									
										
										
										
											2021-04-06 12:23:32 +02:00
										 |  |  |             FirstOfType, | 
					
						
							| 
									
										
										
										
											2021-04-06 13:06:25 +02:00
										 |  |  |             LastOfType, | 
					
						
							| 
									
										
										
										
											2021-05-08 23:19:25 +03:00
										 |  |  |             NthChild, | 
					
						
							| 
									
										
										
										
											2021-05-11 17:13:57 +03:00
										 |  |  |             NthLastChild, | 
					
						
							| 
									
										
										
										
											2021-05-23 22:36:36 +02:00
										 |  |  |             Disabled, | 
					
						
							|  |  |  |             Enabled, | 
					
						
							|  |  |  |             Checked, | 
					
						
							| 
									
										
										
										
											2021-05-23 20:59:26 +02:00
										 |  |  |             Not, | 
					
						
							| 
									
										
										
										
											2019-10-13 21:54:26 +02:00
										 |  |  |         }; | 
					
						
							|  |  |  |         PseudoClass pseudo_class { PseudoClass::None }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-01 15:40:20 +01:00
										 |  |  |         enum class PseudoElement { | 
					
						
							|  |  |  |             None, | 
					
						
							|  |  |  |             Before, | 
					
						
							|  |  |  |             After, | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         PseudoElement pseudo_element { PseudoElement::None }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-22 19:10:43 +01:00
										 |  |  |         FlyString value; | 
					
						
							| 
									
										
										
										
											2019-11-21 20:07:43 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         enum class AttributeMatchType { | 
					
						
							|  |  |  |             None, | 
					
						
							|  |  |  |             HasAttribute, | 
					
						
							|  |  |  |             ExactValueMatch, | 
					
						
							| 
									
										
										
										
											2020-06-10 15:43:41 +02:00
										 |  |  |             Contains, | 
					
						
							| 
									
										
										
										
											2021-04-29 21:16:28 +02:00
										 |  |  |             StartsWith, | 
					
						
							| 
									
										
										
										
											2019-11-21 20:07:43 +01:00
										 |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         AttributeMatchType attribute_match_type { AttributeMatchType::None }; | 
					
						
							| 
									
										
										
										
											2020-03-22 19:10:43 +01:00
										 |  |  |         FlyString attribute_name; | 
					
						
							| 
									
										
										
										
											2019-11-21 20:07:43 +01:00
										 |  |  |         String attribute_value; | 
					
						
							| 
									
										
										
										
											2021-05-08 23:19:25 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |         struct NthChildPattern { | 
					
						
							|  |  |  |             int step_size = 0; | 
					
						
							|  |  |  |             int offset = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             static NthChildPattern parse(const StringView& args); | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // FIXME: We don't need this field on every single SimpleSelector, but it's also annoying to malloc it somewhere.
 | 
					
						
							| 
									
										
										
										
											2021-05-11 17:13:57 +03:00
										 |  |  |         // Only used when "pseudo_class" is "NthChild" or "NthLastChild".
 | 
					
						
							| 
									
										
										
										
											2021-05-08 23:19:25 +03:00
										 |  |  |         NthChildPattern nth_child_pattern; | 
					
						
							| 
									
										
										
										
											2021-05-23 20:59:26 +02:00
										 |  |  |         String not_selector {}; | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-27 20:37:36 +01:00
										 |  |  |     struct ComplexSelector { | 
					
						
							|  |  |  |         enum class Relation { | 
					
						
							|  |  |  |             None, | 
					
						
							|  |  |  |             ImmediateChild, | 
					
						
							|  |  |  |             Descendant, | 
					
						
							|  |  |  |             AdjacentSibling, | 
					
						
							|  |  |  |             GeneralSibling, | 
					
						
							| 
									
										
										
										
											2021-04-29 21:16:28 +02:00
										 |  |  |             Column, | 
					
						
							| 
									
										
										
										
											2019-11-27 20:37:36 +01:00
										 |  |  |         }; | 
					
						
							|  |  |  |         Relation relation { Relation::None }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         using CompoundSelector = Vector<SimpleSelector>; | 
					
						
							|  |  |  |         CompoundSelector compound_selector; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     explicit Selector(Vector<ComplexSelector>&&); | 
					
						
							| 
									
										
										
										
											2019-06-22 09:27:39 +02:00
										 |  |  |     ~Selector(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-27 20:37:36 +01:00
										 |  |  |     const Vector<ComplexSelector>& complex_selectors() const { return m_complex_selectors; } | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-25 16:43:49 +02:00
										 |  |  |     u32 specificity() const; | 
					
						
							| 
									
										
										
										
											2019-06-29 17:32:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2019-11-27 20:37:36 +01:00
										 |  |  |     Vector<ComplexSelector> m_complex_selectors; | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |