Bläddra i källkod

LibHTML: Parse the :link and :hover CSS pseudo-classes

We don't actually do anything with these yet, but now the values will
be there for the selector engine to look at when it feels ready. :^)
Andreas Kling 5 år sedan
förälder
incheckning
605a225b53
2 ändrade filer med 22 tillägg och 4 borttagningar
  1. 7 0
      Libraries/LibHTML/CSS/Selector.h
  2. 15 4
      Libraries/LibHTML/Parser/CSSParser.cpp

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

@@ -15,6 +15,13 @@ public:
         };
         Type type { Type::Invalid };
 
+        enum class PseudoClass {
+            None,
+            Link,
+            Hover,
+        };
+        PseudoClass pseudo_class { PseudoClass::None };
+
         enum class Relation {
             None,
             ImmediateChild,

+ 15 - 4
Libraries/LibHTML/Parser/CSSParser.cpp

@@ -197,7 +197,7 @@ public:
             buffer.append(consume_one());
 
         PARSE_ASSERT(!buffer.is_null());
-        Selector::Component component { type, relation, String::copy(buffer) };
+        Selector::Component component { type, Selector::Component::PseudoClass::None, relation, String::copy(buffer) };
         buffer.clear();
 
         if (peek() == '[') {
@@ -209,12 +209,23 @@ public:
         }
 
         if (peek() == ':') {
-            // FIXME: Implement pseudo stuff.
+            // FIXME: Implement pseudo elements.
+            [[maybe_unused]] bool is_pseudo_element = false;
             consume_one();
-            if (peek() == ':')
+            if (peek() == ':') {
+                is_pseudo_element = true;
                 consume_one();
+            }
             while (is_valid_selector_char(peek()))
-                consume_one();
+                buffer.append(consume_one());
+
+            auto pseudo_name = String::copy(buffer);
+            buffer.clear();
+
+            if (pseudo_name == "link")
+                component.pseudo_class = Selector::Component::PseudoClass::Link;
+            else if (pseudo_name == "hover")
+                component.pseudo_class = Selector::Component::PseudoClass::Hover;
         }
 
         return component;