瀏覽代碼

LibHTML: Parse descendant relations in CSS selectors

"div p" now generates a Selector with two components where the second
component is a type=TagName, value="p", relation=Descendant.

We still don't handle matching of these, but at least we parse them.
Andreas Kling 5 年之前
父節點
當前提交
2a266db05b
共有 3 個文件被更改,包括 9 次插入1 次删除
  1. 1 0
      Libraries/LibHTML/CSS/Selector.h
  2. 3 0
      Libraries/LibHTML/Dump.cpp
  3. 5 1
      Libraries/LibHTML/Parser/CSSParser.cpp

+ 1 - 0
Libraries/LibHTML/CSS/Selector.h

@@ -18,6 +18,7 @@ public:
         enum class Relation {
         enum class Relation {
             None,
             None,
             ImmediateChild,
             ImmediateChild,
+            Descendant,
         };
         };
         Relation relation { Relation::None };
         Relation relation { Relation::None };
 
 

+ 3 - 0
Libraries/LibHTML/Dump.cpp

@@ -155,6 +155,9 @@ void dump_rule(const StyleRule& rule)
             case Selector::Component::Relation::ImmediateChild:
             case Selector::Component::Relation::ImmediateChild:
                 relation_description = "{ImmediateChild}";
                 relation_description = "{ImmediateChild}";
                 break;
                 break;
+            case Selector::Component::Relation::Descendant:
+                relation_description = "{Descendant}";
+                break;
             }
             }
             dbgprintf("    %s:%s %s\n", type_description, component.value.characters(), relation_description);
             dbgprintf("    %s:%s %s\n", type_description, component.value.characters(), relation_description);
         }
         }

+ 5 - 1
Libraries/LibHTML/Parser/CSSParser.cpp

@@ -88,7 +88,7 @@ public:
     {
     {
         consume_whitespace();
         consume_whitespace();
         Selector::Component::Type type;
         Selector::Component::Type type;
-        Selector::Component::Relation relation = Selector::Component::Relation::None;
+        Selector::Component::Relation relation = Selector::Component::Relation::Descendant;
 
 
         if (peek() == '{')
         if (peek() == '{')
             return {};
             return {};
@@ -149,6 +149,10 @@ public:
                 break;
                 break;
         }
         }
 
 
+        if (components.is_empty())
+            return;
+        components.first().relation = Selector::Component::Relation::None;
+
         current_rule.selectors.append(Selector(move(components)));
         current_rule.selectors.append(Selector(move(components)));
     };
     };