mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
LibWeb: Add support for more pseudoclasses
:disabled, :enabled and :checked are now parsed and matched. There surely are more nuances to consider.
This commit is contained in:
parent
4f4cde2379
commit
b53dac6e88
Notes:
sideshowbarker
2024-07-18 17:29:28 +09:00
Author: https://github.com/TobyAsE Commit: https://github.com/SerenityOS/serenity/commit/b53dac6e887 Pull-request: https://github.com/SerenityOS/serenity/pull/7430
4 changed files with 36 additions and 0 deletions
|
@ -573,6 +573,12 @@ public:
|
||||||
simple_selector.pseudo_element = CSS::Selector::SimpleSelector::PseudoElement::Before;
|
simple_selector.pseudo_element = CSS::Selector::SimpleSelector::PseudoElement::Before;
|
||||||
} else if (pseudo_name.equals_ignoring_case("after")) {
|
} else if (pseudo_name.equals_ignoring_case("after")) {
|
||||||
simple_selector.pseudo_element = CSS::Selector::SimpleSelector::PseudoElement::After;
|
simple_selector.pseudo_element = CSS::Selector::SimpleSelector::PseudoElement::After;
|
||||||
|
} else if (pseudo_name.equals_ignoring_case("disabled")) {
|
||||||
|
simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::Disabled;
|
||||||
|
} else if (pseudo_name.equals_ignoring_case("enabled")) {
|
||||||
|
simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::Enabled;
|
||||||
|
} else if (pseudo_name.equals_ignoring_case("checked")) {
|
||||||
|
simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::Checked;
|
||||||
} else {
|
} else {
|
||||||
dbgln("Unknown pseudo class: '{}'", pseudo_name);
|
dbgln("Unknown pseudo class: '{}'", pseudo_name);
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -38,6 +38,9 @@ public:
|
||||||
LastOfType,
|
LastOfType,
|
||||||
NthChild,
|
NthChild,
|
||||||
NthLastChild,
|
NthLastChild,
|
||||||
|
Disabled,
|
||||||
|
Enabled,
|
||||||
|
Checked,
|
||||||
};
|
};
|
||||||
PseudoClass pseudo_class { PseudoClass::None };
|
PseudoClass pseudo_class { PseudoClass::None };
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,24 @@ static bool matches(const CSS::Selector::SimpleSelector& component, const DOM::E
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case CSS::Selector::SimpleSelector::PseudoClass::Disabled:
|
||||||
|
if (!element.tag_name().equals_ignoring_case(HTML::TagNames::input))
|
||||||
|
return false;
|
||||||
|
if (!element.has_attribute("disabled"))
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
case CSS::Selector::SimpleSelector::PseudoClass::Enabled:
|
||||||
|
if (!element.tag_name().equals_ignoring_case(HTML::TagNames::input))
|
||||||
|
return false;
|
||||||
|
if (element.has_attribute("disabled"))
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
case CSS::Selector::SimpleSelector::PseudoClass::Checked:
|
||||||
|
if (!element.tag_name().equals_ignoring_case(HTML::TagNames::input))
|
||||||
|
return false;
|
||||||
|
if (!element.has_attribute("checked"))
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
case CSS::Selector::SimpleSelector::PseudoClass::NthChild:
|
case CSS::Selector::SimpleSelector::PseudoClass::NthChild:
|
||||||
case CSS::Selector::SimpleSelector::PseudoClass::NthLastChild:
|
case CSS::Selector::SimpleSelector::PseudoClass::NthLastChild:
|
||||||
const auto step_size = component.nth_child_pattern.step_size;
|
const auto step_size = component.nth_child_pattern.step_size;
|
||||||
|
|
|
@ -375,6 +375,15 @@ void dump_selector(StringBuilder& builder, const CSS::Selector& selector)
|
||||||
case CSS::Selector::SimpleSelector::PseudoClass::OnlyChild:
|
case CSS::Selector::SimpleSelector::PseudoClass::OnlyChild:
|
||||||
pseudo_class_description = "OnlyChild";
|
pseudo_class_description = "OnlyChild";
|
||||||
break;
|
break;
|
||||||
|
case CSS::Selector::SimpleSelector::PseudoClass::Disabled:
|
||||||
|
pseudo_class_description = "Disabled";
|
||||||
|
break;
|
||||||
|
case CSS::Selector::SimpleSelector::PseudoClass::Enabled:
|
||||||
|
pseudo_class_description = "Enabled";
|
||||||
|
break;
|
||||||
|
case CSS::Selector::SimpleSelector::PseudoClass::Checked:
|
||||||
|
pseudo_class_description = "Checked";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.appendff("{}:{}", type_description, simple_selector.value);
|
builder.appendff("{}:{}", type_description, simple_selector.value);
|
||||||
|
|
Loading…
Reference in a new issue