| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Redistribution and use in source and binary forms, with or without | 
					
						
							|  |  |  |  * modification, are permitted provided that the following conditions are met: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 1. Redistributions of source code must retain the above copyright notice, this | 
					
						
							|  |  |  |  *    list of conditions and the following disclaimer. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 2. Redistributions in binary form must reproduce the above copyright notice, | 
					
						
							|  |  |  |  *    this list of conditions and the following disclaimer in the documentation | 
					
						
							|  |  |  |  *    and/or other materials provided with the distribution. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 
					
						
							|  |  |  |  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
					
						
							|  |  |  |  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 
					
						
							|  |  |  |  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | 
					
						
							|  |  |  |  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
					
						
							|  |  |  |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 
					
						
							|  |  |  |  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 
					
						
							|  |  |  |  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 
					
						
							|  |  |  |  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
					
						
							|  |  |  |  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-06 15:34:26 +02:00
										 |  |  | #include <AK/String.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  | #include <AK/Vector.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-29 17:32:32 +02:00
										 |  |  | #include <LibHTML/CSS/Specificity.h>
 | 
					
						
							| 
									
										
										
										
											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, | 
					
						
							|  |  |  |             Hover, | 
					
						
							| 
									
										
										
										
											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, | 
					
						
							| 
									
										
										
										
											2019-10-13 21:54:26 +02:00
										 |  |  |         }; | 
					
						
							|  |  |  |         PseudoClass pseudo_class { PseudoClass::None }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-20 23:25:25 +02:00
										 |  |  |         String value; | 
					
						
							| 
									
										
										
										
											2019-11-21 20:07:43 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         enum class AttributeMatchType { | 
					
						
							|  |  |  |             None, | 
					
						
							|  |  |  |             HasAttribute, | 
					
						
							|  |  |  |             ExactValueMatch, | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         AttributeMatchType attribute_match_type { AttributeMatchType::None }; | 
					
						
							|  |  |  |         String attribute_name; | 
					
						
							|  |  |  |         String attribute_value; | 
					
						
							| 
									
										
										
										
											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, | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-29 17:32:32 +02:00
										 |  |  |     Specificity specificity() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | }; |