Skip to content

Commit 56dad22

Browse files
committed
LibHTML: Implement the universal selector ("*")
1 parent 516708a commit 56dad22

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

Libraries/LibHTML/CSS/Selector.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Selector {
99
struct Component {
1010
enum class Type {
1111
Invalid,
12+
Universal,
1213
TagName,
1314
Id,
1415
Class,

Libraries/LibHTML/CSS/SelectorEngine.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ bool matches(const Selector::Component& component, const Element& element)
3030
}
3131

3232
switch (component.type) {
33+
case Selector::Component::Type::Universal:
34+
return true;
3335
case Selector::Component::Type::Id:
3436
return component.value == element.attribute("id");
3537
case Selector::Component::Type::Class:

Libraries/LibHTML/Dump.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ void dump_rule(const StyleRule& rule)
150150
case Selector::Component::Type::Invalid:
151151
type_description = "Invalid";
152152
break;
153+
case Selector::Component::Type::Universal:
154+
type_description = "Universal";
155+
break;
153156
case Selector::Component::Type::Id:
154157
type_description = "Id";
155158
break;

Libraries/LibHTML/Parser/CSSParser.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@ class CSSParser {
224224
consume_whitespace_or_comments();
225225
}
226226

227+
if (peek() == '*') {
228+
type = Selector::Component::Type::Universal;
229+
consume_one();
230+
return Selector::Component { type, Selector::Component::PseudoClass::None, relation, String() };
231+
}
232+
227233
if (peek() == '.') {
228234
type = Selector::Component::Type::Class;
229235
consume_one();

0 commit comments

Comments
 (0)