mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 20:07:34 +00:00
LibWeb: Implement selector matching for :indeterminate pseudo-class
This commit is contained in:
parent
d177d83b44
commit
c3d6709a9e
4 changed files with 33 additions and 0 deletions
|
@ -447,6 +447,8 @@ Parser::ParseErrorOr<Selector::SimpleSelector> Parser::parse_pseudo_simple_selec
|
||||||
return make_pseudo_class_selector(Selector::SimpleSelector::PseudoClass::Type::Active);
|
return make_pseudo_class_selector(Selector::SimpleSelector::PseudoClass::Type::Active);
|
||||||
if (pseudo_name.equals_ignoring_ascii_case("checked"sv))
|
if (pseudo_name.equals_ignoring_ascii_case("checked"sv))
|
||||||
return make_pseudo_class_selector(Selector::SimpleSelector::PseudoClass::Type::Checked);
|
return make_pseudo_class_selector(Selector::SimpleSelector::PseudoClass::Type::Checked);
|
||||||
|
if (pseudo_name.equals_ignoring_ascii_case("indeterminate"sv))
|
||||||
|
return make_pseudo_class_selector(Selector::SimpleSelector::PseudoClass::Type::Indeterminate);
|
||||||
if (pseudo_name.equals_ignoring_ascii_case("disabled"sv))
|
if (pseudo_name.equals_ignoring_ascii_case("disabled"sv))
|
||||||
return make_pseudo_class_selector(Selector::SimpleSelector::PseudoClass::Type::Disabled);
|
return make_pseudo_class_selector(Selector::SimpleSelector::PseudoClass::Type::Disabled);
|
||||||
if (pseudo_name.equals_ignoring_ascii_case("empty"sv))
|
if (pseudo_name.equals_ignoring_ascii_case("empty"sv))
|
||||||
|
|
|
@ -105,6 +105,7 @@ public:
|
||||||
Disabled,
|
Disabled,
|
||||||
Enabled,
|
Enabled,
|
||||||
Checked,
|
Checked,
|
||||||
|
Indeterminate,
|
||||||
Is,
|
Is,
|
||||||
Not,
|
Not,
|
||||||
Where,
|
Where,
|
||||||
|
@ -275,6 +276,8 @@ constexpr StringView pseudo_class_name(Selector::SimpleSelector::PseudoClass::Ty
|
||||||
return "enabled"sv;
|
return "enabled"sv;
|
||||||
case Selector::SimpleSelector::PseudoClass::Type::Checked:
|
case Selector::SimpleSelector::PseudoClass::Type::Checked:
|
||||||
return "checked"sv;
|
return "checked"sv;
|
||||||
|
case Selector::SimpleSelector::PseudoClass::Type::Indeterminate:
|
||||||
|
return "indeterminate"sv;
|
||||||
case Selector::SimpleSelector::PseudoClass::Type::Active:
|
case Selector::SimpleSelector::PseudoClass::Type::Active:
|
||||||
return "active"sv;
|
return "active"sv;
|
||||||
case Selector::SimpleSelector::PseudoClass::Type::NthChild:
|
case Selector::SimpleSelector::PseudoClass::Type::NthChild:
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <LibWeb/HTML/HTMLInputElement.h>
|
#include <LibWeb/HTML/HTMLInputElement.h>
|
||||||
#include <LibWeb/HTML/HTMLOptGroupElement.h>
|
#include <LibWeb/HTML/HTMLOptGroupElement.h>
|
||||||
#include <LibWeb/HTML/HTMLOptionElement.h>
|
#include <LibWeb/HTML/HTMLOptionElement.h>
|
||||||
|
#include <LibWeb/HTML/HTMLProgressElement.h>
|
||||||
#include <LibWeb/HTML/HTMLSelectElement.h>
|
#include <LibWeb/HTML/HTMLSelectElement.h>
|
||||||
#include <LibWeb/HTML/HTMLTextAreaElement.h>
|
#include <LibWeb/HTML/HTMLTextAreaElement.h>
|
||||||
#include <LibWeb/Infra/Strings.h>
|
#include <LibWeb/Infra/Strings.h>
|
||||||
|
@ -96,6 +97,28 @@ static inline bool matches_checked_pseudo_class(DOM::Element const& element)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/semantics-other.html#selector-indeterminate
|
||||||
|
static inline bool matches_indeterminate_pseudo_class(DOM::Element const& element)
|
||||||
|
{
|
||||||
|
// The :indeterminate pseudo-class must match any element falling into one of the following categories:
|
||||||
|
// - input elements whose type attribute is in the Checkbox state and whose indeterminate IDL attribute is set to true
|
||||||
|
// FIXME: - input elements whose type attribute is in the Radio Button state and whose radio button group contains no input elements whose checkedness state is true.
|
||||||
|
if (is<HTML::HTMLInputElement>(element)) {
|
||||||
|
auto const& input_element = static_cast<HTML::HTMLInputElement const&>(element);
|
||||||
|
switch (input_element.type_state()) {
|
||||||
|
case HTML::HTMLInputElement::TypeAttributeState::Checkbox:
|
||||||
|
return input_element.indeterminate();
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// - progress elements with no value content attribute
|
||||||
|
if (is<HTML::HTMLProgressElement>(element)) {
|
||||||
|
return !element.has_attribute(HTML::AttributeNames::value);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool matches_attribute(CSS::Selector::SimpleSelector::Attribute const& attribute, DOM::Element const& element)
|
static inline bool matches_attribute(CSS::Selector::SimpleSelector::Attribute const& attribute, DOM::Element const& element)
|
||||||
{
|
{
|
||||||
if (attribute.match_type == CSS::Selector::SimpleSelector::Attribute::MatchType::HasAttribute) {
|
if (attribute.match_type == CSS::Selector::SimpleSelector::Attribute::MatchType::HasAttribute) {
|
||||||
|
@ -241,6 +264,8 @@ static inline bool matches_pseudo_class(CSS::Selector::SimpleSelector::PseudoCla
|
||||||
&& !element.is_actually_disabled();
|
&& !element.is_actually_disabled();
|
||||||
case CSS::Selector::SimpleSelector::PseudoClass::Type::Checked:
|
case CSS::Selector::SimpleSelector::PseudoClass::Type::Checked:
|
||||||
return matches_checked_pseudo_class(element);
|
return matches_checked_pseudo_class(element);
|
||||||
|
case CSS::Selector::SimpleSelector::PseudoClass::Type::Indeterminate:
|
||||||
|
return matches_indeterminate_pseudo_class(element);
|
||||||
case CSS::Selector::SimpleSelector::PseudoClass::Type::Is:
|
case CSS::Selector::SimpleSelector::PseudoClass::Type::Is:
|
||||||
case CSS::Selector::SimpleSelector::PseudoClass::Type::Where:
|
case CSS::Selector::SimpleSelector::PseudoClass::Type::Where:
|
||||||
for (auto& selector : pseudo_class.argument_selector_list) {
|
for (auto& selector : pseudo_class.argument_selector_list) {
|
||||||
|
|
|
@ -441,6 +441,9 @@ void dump_selector(StringBuilder& builder, CSS::Selector const& selector)
|
||||||
case CSS::Selector::SimpleSelector::PseudoClass::Type::Checked:
|
case CSS::Selector::SimpleSelector::PseudoClass::Type::Checked:
|
||||||
pseudo_class_description = "Checked";
|
pseudo_class_description = "Checked";
|
||||||
break;
|
break;
|
||||||
|
case CSS::Selector::SimpleSelector::PseudoClass::Type::Indeterminate:
|
||||||
|
pseudo_class_description = "Indeterminate";
|
||||||
|
break;
|
||||||
case CSS::Selector::SimpleSelector::PseudoClass::Type::Not:
|
case CSS::Selector::SimpleSelector::PseudoClass::Type::Not:
|
||||||
pseudo_class_description = "Not";
|
pseudo_class_description = "Not";
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue