1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 18:05:07 +00:00

LibWeb: Implement :enabled and :disabled pseudo classes to spec

Previously we only considered an element disabled if it was an <input>
element with the disabled attribute, but there's way more elements that
apply with more nuanced disabled/enabled rules.
This commit is contained in:
Luke Wilde 2022-09-30 16:21:34 +01:00 committed by Andreas Kling
parent c85fcd442f
commit 2133b7d58a
7 changed files with 82 additions and 10 deletions

View file

@ -222,17 +222,13 @@ static inline bool matches_pseudo_class(CSS::Selector::SimpleSelector::PseudoCla
case CSS::Selector::SimpleSelector::PseudoClass::Type::Lang:
return matches_lang_pseudo_class(element, pseudo_class.languages);
case CSS::Selector::SimpleSelector::PseudoClass::Type::Disabled:
if (!is<HTML::HTMLInputElement>(element))
return false;
if (!element.has_attribute(HTML::AttributeNames::disabled))
return false;
return true;
// https://html.spec.whatwg.org/multipage/semantics-other.html#selector-disabled
// The :disabled pseudo-class must match any element that is actually disabled.
return element.is_actually_disabled();
case CSS::Selector::SimpleSelector::PseudoClass::Type::Enabled:
if (!is<HTML::HTMLInputElement>(element))
return false;
if (element.has_attribute(HTML::AttributeNames::disabled))
return false;
return true;
// https://html.spec.whatwg.org/multipage/semantics-other.html#selector-enabled
// The :enabled pseudo-class must match any button, input, select, textarea, optgroup, option, fieldset element, or form-associated custom element that is not actually disabled.
return !element.is_actually_disabled();
case CSS::Selector::SimpleSelector::PseudoClass::Type::Checked:
return matches_checked_pseudo_class(element);
case CSS::Selector::SimpleSelector::PseudoClass::Type::Is: