mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 05:42:43 +00:00 
			
		
		
		
	 c449cabae3
			
		
	
	
		c449cabae3
		
	
	
	
	
		
			
			The goal here is to move the parser-internal classes into this namespace so they can have more convenient names without causing collisions. The Parser itself won't collide, and would be more convenient to just remain `CSS::Parser`, but having a namespace and a class with the same name makes C++ unhappy.
		
			
				
	
	
		
			76 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			76 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <LibWeb/CSS/Parser/Parser.h>
 | |
| #include <LibWeb/CSS/Supports.h>
 | |
| 
 | |
| namespace Web::CSS {
 | |
| 
 | |
| Supports::Supports(NonnullOwnPtr<Condition>&& condition)
 | |
|     : m_condition(move(condition))
 | |
| {
 | |
|     m_matches = m_condition->evaluate();
 | |
| }
 | |
| 
 | |
| bool Supports::Condition::evaluate() const
 | |
| {
 | |
|     switch (type) {
 | |
|     case Type::Not:
 | |
|         return !children.first().evaluate();
 | |
|     case Type::And:
 | |
|         for (auto& child : children) {
 | |
|             if (!child.evaluate())
 | |
|                 return false;
 | |
|         }
 | |
|         return true;
 | |
|     case Type::Or:
 | |
|         for (auto& child : children) {
 | |
|             if (child.evaluate())
 | |
|                 return true;
 | |
|         }
 | |
|         return false;
 | |
|     }
 | |
|     VERIFY_NOT_REACHED();
 | |
| }
 | |
| 
 | |
| bool Supports::InParens::evaluate() const
 | |
| {
 | |
|     return value.visit(
 | |
|         [&](NonnullOwnPtr<Condition> const& condition) {
 | |
|             return condition->evaluate();
 | |
|         },
 | |
|         [&](Feature const& feature) {
 | |
|             return feature.evaluate();
 | |
|         },
 | |
|         [&](GeneralEnclosed const&) {
 | |
|             return false;
 | |
|         });
 | |
| }
 | |
| 
 | |
| bool Supports::Declaration::evaluate() const
 | |
| {
 | |
|     auto style_property = Parser::Parser({}, declaration).parse_as_supports_condition();
 | |
|     return style_property.has_value();
 | |
| }
 | |
| 
 | |
| bool Supports::Selector::evaluate() const
 | |
| {
 | |
|     auto style_property = Parser::Parser({}, selector).parse_as_selector();
 | |
|     return style_property.has_value();
 | |
| }
 | |
| 
 | |
| bool Supports::Feature::evaluate() const
 | |
| {
 | |
|     return value.visit(
 | |
|         [&](Declaration const& declaration) {
 | |
|             return declaration.evaluate();
 | |
|         },
 | |
|         [&](Selector const& selector) {
 | |
|             return selector.evaluate();
 | |
|         });
 | |
| }
 | |
| 
 | |
| }
 |