LibWeb: Implement <input type=checkbox switch> experimentally

In conformance with the requirements of the spec PR at
https://github.com/whatwg/html/pull/9546, this change adds support for
the “switch” attribute for type=checkbox “input” elements — which is
shipping in Safari (since Safari 17.4). This change also implements
support for exposing it to AT users with role=switch.
This commit is contained in:
sideshowbarker 2024-12-11 11:34:41 +09:00 committed by Sam Atkins
commit 583ca6af89
Notes: github-actions[bot] 2024-12-13 11:32:27 +00:00
16 changed files with 268 additions and 3 deletions

View file

@ -28,6 +28,7 @@ void initialize_strings()
for_ = "for"_fly_string;
default_ = "default"_fly_string;
char_ = "char"_fly_string;
switch_ = "switch"_fly_string;
// NOTE: Special cases for attributes with dashes in them.
accept_charset = "accept-charset"_fly_string;
@ -81,6 +82,7 @@ bool is_boolean_attribute(FlyString const& attribute)
|| attribute.equals_ignoring_ascii_case(AttributeNames::reversed)
|| attribute.equals_ignoring_ascii_case(AttributeNames::seeking)
|| attribute.equals_ignoring_ascii_case(AttributeNames::selected)
|| attribute.equals_ignoring_ascii_case(AttributeNames::switch_)
|| attribute.equals_ignoring_ascii_case(AttributeNames::truespeed)
|| attribute.equals_ignoring_ascii_case(AttributeNames::willvalidate);
}

View file

@ -278,6 +278,7 @@ namespace AttributeNames {
__ENUMERATE_HTML_ATTRIBUTE(step) \
__ENUMERATE_HTML_ATTRIBUTE(style) \
__ENUMERATE_HTML_ATTRIBUTE(summary) \
__ENUMERATE_HTML_ATTRIBUTE(switch_) \
__ENUMERATE_HTML_ATTRIBUTE(tabindex) \
__ENUMERATE_HTML_ATTRIBUTE(target) \
__ENUMERATE_HTML_ATTRIBUTE(text) \

View file

@ -2343,13 +2343,16 @@ void HTMLInputElement::set_custom_validity(String const& error)
Optional<ARIA::Role> HTMLInputElement::default_role() const
{
// http://wpt.live/html-aam/roles-dynamic-switch.tentative.window.html "Disconnected <input type=checkbox switch>"
if (!is_connected())
return {};
// https://www.w3.org/TR/html-aria/#el-input-button
if (type_state() == TypeAttributeState::Button)
return ARIA::Role::button;
// https://www.w3.org/TR/html-aria/#el-input-checkbox
if (type_state() == TypeAttributeState::Checkbox) {
// https://github.com/w3c/html-aam/issues/496
if (has_attribute("switch"_string))
if (has_attribute(HTML::AttributeNames::switch_))
return ARIA::Role::switch_;
return ARIA::Role::checkbox;
}

View file

@ -38,6 +38,8 @@ interface HTMLInputElement : HTMLElement {
[CEReactions] attribute unsigned long size;
[CEReactions, Reflect, URL] attribute USVString src;
[CEReactions, Reflect] attribute DOMString step;
// https://whatpr.org/html-attr-input-switch/9546/input.html#the-input-element:dom-input-switch
[CEReactions, Reflect] attribute boolean switch;
[CEReactions] attribute DOMString type;
[CEReactions, Reflect=value] attribute DOMString defaultValue;
[CEReactions, LegacyNullToEmptyString] attribute DOMString value;