mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:27:45 +00:00
LibWeb: Remove now-unused null values from Selector enums
Now that we use a Variant for the SimpleSelector's data, we don't need to instantiate empty structs or variables for the types that aren't used, and so we can remove `PseudoElement::None`, `PsuedoClass::Type::None` and `Attribute::MatchType::None`. Also, we now always initialize a SimpleSelector with a type, so `SimpleSelector::Type::Invalid` can go too.
This commit is contained in:
parent
cbe2eaebab
commit
31b24c2b29
4 changed files with 3 additions and 30 deletions
|
@ -105,8 +105,6 @@ u32 Selector::specificity() const
|
|||
case SimpleSelector::Type::Universal:
|
||||
// ignore the universal selector
|
||||
break;
|
||||
case SimpleSelector::Type::Invalid:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ using SelectorList = NonnullRefPtrVector<class Selector>;
|
|||
class Selector : public RefCounted<Selector> {
|
||||
public:
|
||||
enum class PseudoElement {
|
||||
None,
|
||||
Before,
|
||||
After,
|
||||
FirstLine,
|
||||
|
@ -32,7 +31,6 @@ public:
|
|||
|
||||
struct SimpleSelector {
|
||||
enum class Type {
|
||||
Invalid,
|
||||
Universal,
|
||||
TagName,
|
||||
Id,
|
||||
|
@ -54,7 +52,6 @@ public:
|
|||
|
||||
struct PseudoClass {
|
||||
enum class Type {
|
||||
None,
|
||||
Link,
|
||||
Visited,
|
||||
Hover,
|
||||
|
@ -81,7 +78,7 @@ public:
|
|||
Active,
|
||||
Lang,
|
||||
};
|
||||
Type type { Type::None };
|
||||
Type type;
|
||||
|
||||
// FIXME: We don't need this field on every single SimpleSelector, but it's also annoying to malloc it somewhere.
|
||||
// Only used when "pseudo_class" is "NthChild" or "NthLastChild".
|
||||
|
@ -95,7 +92,6 @@ public:
|
|||
|
||||
struct Attribute {
|
||||
enum class MatchType {
|
||||
None,
|
||||
HasAttribute,
|
||||
ExactValueMatch,
|
||||
ContainsWord, // [att~=val]
|
||||
|
@ -104,12 +100,12 @@ public:
|
|||
StartsWithString, // [att^=val]
|
||||
EndsWithString, // [att$=val]
|
||||
};
|
||||
MatchType match_type { MatchType::None };
|
||||
MatchType match_type;
|
||||
FlyString name {};
|
||||
String value {};
|
||||
};
|
||||
|
||||
Type type { Type::Invalid };
|
||||
Type type;
|
||||
Variant<Empty, Attribute, PseudoClass, PseudoElement, FlyString> value {};
|
||||
|
||||
Attribute const& attribute() const { return value.get<Attribute>(); }
|
||||
|
@ -173,8 +169,6 @@ constexpr StringView pseudo_element_name(Selector::PseudoElement pseudo_element)
|
|||
return "first-letter"sv;
|
||||
case Selector::PseudoElement::Marker:
|
||||
return "marker"sv;
|
||||
case Selector::PseudoElement::None:
|
||||
break;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
@ -234,8 +228,6 @@ constexpr StringView pseudo_class_name(Selector::SimpleSelector::PseudoClass::Ty
|
|||
return "where"sv;
|
||||
case Selector::SimpleSelector::PseudoClass::Type::Lang:
|
||||
return "lang"sv;
|
||||
case Selector::SimpleSelector::PseudoClass::Type::None:
|
||||
break;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
|
|
@ -95,9 +95,6 @@ static inline bool matches_attribute(CSS::Selector::SimpleSelector::Attribute co
|
|||
return element.attribute(attribute.name).starts_with(attribute.value);
|
||||
case CSS::Selector::SimpleSelector::Attribute::MatchType::EndsWithString:
|
||||
return element.attribute(attribute.name).ends_with(attribute.value);
|
||||
case CSS::Selector::SimpleSelector::Attribute::MatchType::None:
|
||||
VERIFY_NOT_REACHED();
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -124,8 +121,6 @@ static inline DOM::Element const* next_sibling_with_same_tag_name(DOM::Element c
|
|||
static inline bool matches_pseudo_class(CSS::Selector::SimpleSelector::PseudoClass const& pseudo_class, DOM::Element const& element)
|
||||
{
|
||||
switch (pseudo_class.type) {
|
||||
case CSS::Selector::SimpleSelector::PseudoClass::Type::None:
|
||||
break;
|
||||
case CSS::Selector::SimpleSelector::PseudoClass::Type::Link:
|
||||
return element.is_link();
|
||||
case CSS::Selector::SimpleSelector::PseudoClass::Type::Visited:
|
||||
|
|
|
@ -333,9 +333,6 @@ void dump_selector(StringBuilder& builder, CSS::Selector const& selector)
|
|||
auto& simple_selector = relative_selector.simple_selectors[i];
|
||||
char const* type_description = "Unknown";
|
||||
switch (simple_selector.type) {
|
||||
case CSS::Selector::SimpleSelector::Type::Invalid:
|
||||
type_description = "Invalid";
|
||||
break;
|
||||
case CSS::Selector::SimpleSelector::Type::Universal:
|
||||
type_description = "Universal";
|
||||
break;
|
||||
|
@ -378,9 +375,6 @@ void dump_selector(StringBuilder& builder, CSS::Selector const& selector)
|
|||
case CSS::Selector::SimpleSelector::PseudoClass::Type::Active:
|
||||
pseudo_class_description = "Active";
|
||||
break;
|
||||
case CSS::Selector::SimpleSelector::PseudoClass::Type::None:
|
||||
pseudo_class_description = "None";
|
||||
break;
|
||||
case CSS::Selector::SimpleSelector::PseudoClass::Type::Root:
|
||||
pseudo_class_description = "Root";
|
||||
break;
|
||||
|
@ -479,9 +473,6 @@ void dump_selector(StringBuilder& builder, CSS::Selector const& selector)
|
|||
if (simple_selector.type == CSS::Selector::SimpleSelector::Type::PseudoElement) {
|
||||
char const* pseudo_element_description = "";
|
||||
switch (simple_selector.pseudo_element()) {
|
||||
case CSS::Selector::PseudoElement::None:
|
||||
pseudo_element_description = "NONE";
|
||||
break;
|
||||
case CSS::Selector::PseudoElement::Before:
|
||||
pseudo_element_description = "before";
|
||||
break;
|
||||
|
@ -507,9 +498,6 @@ void dump_selector(StringBuilder& builder, CSS::Selector const& selector)
|
|||
char const* attribute_match_type_description = "";
|
||||
|
||||
switch (attribute.match_type) {
|
||||
case CSS::Selector::SimpleSelector::Attribute::MatchType::None:
|
||||
attribute_match_type_description = "NONE";
|
||||
break;
|
||||
case CSS::Selector::SimpleSelector::Attribute::MatchType::HasAttribute:
|
||||
attribute_match_type_description = "HasAttribute";
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue