From 890b4d79800f61450e903f1b6408431243a94793 Mon Sep 17 00:00:00 2001 From: MacDue Date: Sun, 29 Jan 2023 19:12:00 +0100 Subject: [PATCH] LibWeb: Replace ARIA role static FlyStrings with an enum This replaces the FlyStrings for ARIA roles that were constructed in a [[gnu::constructor]] with a single enum. I came across this as the DOM inspector was crashing due to a null FlyString for an ARIA role. After fixing that, I was confused as to why these roles were not an enum. Looking at the spec there's a fixed list of roles and switching from references to static strings to an enum was pretty much an exercise in find and replace :). No functional changes (outside of fixing the mentioned crash). --- Userland/Libraries/LibWeb/CMakeLists.txt | 2 +- Userland/Libraries/LibWeb/DOM/ARIAMixin.cpp | 13 +- Userland/Libraries/LibWeb/DOM/ARIAMixin.h | 5 +- .../Libraries/LibWeb/DOM/ARIARoleNames.cpp | 167 ----------------- Userland/Libraries/LibWeb/DOM/ARIARoles.cpp | 172 ++++++++++++++++++ .../DOM/{ARIARoleNames.h => ARIARoles.h} | 25 ++- .../LibWeb/DOM/AccessibilityTreeNode.cpp | 4 +- Userland/Libraries/LibWeb/DOM/Element.cpp | 6 +- Userland/Libraries/LibWeb/DOM/Node.h | 2 +- .../LibWeb/HTML/HTMLAnchorElement.cpp | 8 +- .../Libraries/LibWeb/HTML/HTMLAnchorElement.h | 2 +- .../Libraries/LibWeb/HTML/HTMLAreaElement.cpp | 8 +- .../Libraries/LibWeb/HTML/HTMLAreaElement.h | 2 +- .../Libraries/LibWeb/HTML/HTMLBodyElement.h | 4 +- .../Libraries/LibWeb/HTML/HTMLButtonElement.h | 4 +- .../Libraries/LibWeb/HTML/HTMLDataElement.h | 4 +- .../LibWeb/HTML/HTMLDataListElement.h | 4 +- .../LibWeb/HTML/HTMLDetailsElement.h | 4 +- .../Libraries/LibWeb/HTML/HTMLDialogElement.h | 4 +- .../Libraries/LibWeb/HTML/HTMLDivElement.h | 4 +- .../Libraries/LibWeb/HTML/HTMLElement.cpp | 50 ++--- Userland/Libraries/LibWeb/HTML/HTMLElement.h | 2 +- .../LibWeb/HTML/HTMLFieldSetElement.h | 4 +- .../Libraries/LibWeb/HTML/HTMLFormElement.h | 4 +- .../Libraries/LibWeb/HTML/HTMLHRElement.h | 4 +- .../LibWeb/HTML/HTMLHeadingElement.h | 5 +- .../Libraries/LibWeb/HTML/HTMLHtmlElement.h | 4 +- .../LibWeb/HTML/HTMLImageElement.cpp | 8 +- .../Libraries/LibWeb/HTML/HTMLImageElement.h | 2 +- .../LibWeb/HTML/HTMLInputElement.cpp | 30 +-- .../Libraries/LibWeb/HTML/HTMLInputElement.h | 2 +- .../Libraries/LibWeb/HTML/HTMLLIElement.h | 4 +- .../Libraries/LibWeb/HTML/HTMLMenuElement.h | 4 +- .../Libraries/LibWeb/HTML/HTMLMeterElement.h | 4 +- .../Libraries/LibWeb/HTML/HTMLModElement.cpp | 6 +- .../Libraries/LibWeb/HTML/HTMLModElement.h | 4 +- .../Libraries/LibWeb/HTML/HTMLOListElement.h | 4 +- .../LibWeb/HTML/HTMLOptGroupElement.h | 4 +- .../LibWeb/HTML/HTMLOptionElement.cpp | 6 +- .../Libraries/LibWeb/HTML/HTMLOptionElement.h | 2 +- .../Libraries/LibWeb/HTML/HTMLOutputElement.h | 4 +- .../LibWeb/HTML/HTMLParagraphElement.h | 4 +- .../Libraries/LibWeb/HTML/HTMLPreElement.h | 4 +- .../LibWeb/HTML/HTMLProgressElement.h | 4 +- .../LibWeb/HTML/HTMLQuoteElement.cpp | 8 +- .../Libraries/LibWeb/HTML/HTMLQuoteElement.h | 2 +- .../LibWeb/HTML/HTMLSelectElement.cpp | 8 +- .../Libraries/LibWeb/HTML/HTMLSelectElement.h | 2 +- .../Libraries/LibWeb/HTML/HTMLSpanElement.h | 4 +- .../LibWeb/HTML/HTMLTableCaptionElement.h | 4 +- .../LibWeb/HTML/HTMLTableCellElement.cpp | 2 +- .../LibWeb/HTML/HTMLTableCellElement.h | 2 +- .../Libraries/LibWeb/HTML/HTMLTableElement.h | 2 +- .../LibWeb/HTML/HTMLTableRowElement.h | 4 +- .../LibWeb/HTML/HTMLTableSectionElement.h | 4 +- .../LibWeb/HTML/HTMLTextAreaElement.h | 4 +- .../Libraries/LibWeb/HTML/HTMLTimeElement.h | 4 +- .../Libraries/LibWeb/HTML/HTMLUListElement.h | 4 +- .../WebContent/WebDriverConnection.cpp | 4 +- 59 files changed, 344 insertions(+), 327 deletions(-) delete mode 100644 Userland/Libraries/LibWeb/DOM/ARIARoleNames.cpp create mode 100644 Userland/Libraries/LibWeb/DOM/ARIARoles.cpp rename Userland/Libraries/LibWeb/DOM/{ARIARoleNames.h => ARIARoles.h} (89%) diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 7207a2071cd..7d731441a42 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -77,7 +77,7 @@ set(SOURCES DOM/Attr.idl DOM/ARIAMixin.cpp DOM/ARIAMixin.idl - DOM/ARIARoleNames.cpp + DOM/ARIARoles.cpp DOM/CDATASection.cpp DOM/CharacterData.cpp DOM/CharacterData.idl diff --git a/Userland/Libraries/LibWeb/DOM/ARIAMixin.cpp b/Userland/Libraries/LibWeb/DOM/ARIAMixin.cpp index 2ea332026b7..533ae17464b 100644 --- a/Userland/Libraries/LibWeb/DOM/ARIAMixin.cpp +++ b/Userland/Libraries/LibWeb/DOM/ARIAMixin.cpp @@ -5,13 +5,13 @@ */ #include -#include +#include #include namespace Web::DOM { // https://www.w3.org/TR/wai-aria-1.2/#introroles -DeprecatedFlyString ARIAMixin::role_or_default() const +Optional ARIAMixin::role_or_default() const { // 1. Use the rules of the host language to detect that an element has a role attribute and to identify the attribute value string for it. auto role_string = role(); @@ -20,10 +20,13 @@ DeprecatedFlyString ARIAMixin::role_or_default() const auto role_list = role_string.split_view(Infra::is_ascii_whitespace); // 3. Compare the substrings to all the names of the non-abstract WAI-ARIA roles. Case-sensitivity of the comparison inherits from the case-sensitivity of the host language. - for (auto const& role : role_list) { + for (auto const& role_name : role_list) { // 4. Use the first such substring in textual order that matches the name of a non-abstract WAI-ARIA role. - if (ARIARoleNames::is_non_abstract_aria_role(role)) - return role; + auto role = ARIARoles::from_string(role_name); + if (!role.has_value()) + continue; + if (ARIARoles::is_non_abstract_aria_role(*role)) + return *role; } // https://www.w3.org/TR/wai-aria-1.2/#document-handling_author-errors_roles diff --git a/Userland/Libraries/LibWeb/DOM/ARIAMixin.h b/Userland/Libraries/LibWeb/DOM/ARIAMixin.h index 4383af08482..f9c3934fdb5 100644 --- a/Userland/Libraries/LibWeb/DOM/ARIAMixin.h +++ b/Userland/Libraries/LibWeb/DOM/ARIAMixin.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include namespace Web::DOM { @@ -132,9 +133,9 @@ public: virtual WebIDL::ExceptionOr set_aria_value_text(DeprecatedString const&) = 0; // https://www.w3.org/TR/html-aria/#docconformance - virtual DeprecatedFlyString default_role() const { return {}; }; + virtual Optional default_role() const { return {}; }; - DeprecatedFlyString role_or_default() const; + Optional role_or_default() const; // https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion virtual bool exclude_from_accessibility_tree() const = 0; diff --git a/Userland/Libraries/LibWeb/DOM/ARIARoleNames.cpp b/Userland/Libraries/LibWeb/DOM/ARIARoleNames.cpp deleted file mode 100644 index 3d70ab243e7..00000000000 --- a/Userland/Libraries/LibWeb/DOM/ARIARoleNames.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2022, Jonah Shafran - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include - -namespace Web::DOM::ARIARoleNames { - -#define __ENUMERATE_ARIA_ROLE(name) DeprecatedFlyString name; -ENUMERATE_ARIA_ROLES -#undef __ENUMERATE_ARIA_ROLE - -[[gnu::constructor]] static void initialize() -{ - static bool s_initialized = false; - if (s_initialized) - return; - -#define __ENUMERATE_ARIA_ROLE(name) name = #name; - ENUMERATE_ARIA_ROLES -#undef __ENUMERATE_ARIA_ROLE - - // Special case for C++ keyword - switch_ = "switch"; - s_initialized = true; -} - -// https://www.w3.org/TR/wai-aria-1.2/#abstract_roles -bool is_abstract_aria_role(DeprecatedFlyString const& role) -{ - return role.is_one_of( - ARIARoleNames::command, - ARIARoleNames::composite, - ARIARoleNames::input, - ARIARoleNames::landmark, - ARIARoleNames::range, - ARIARoleNames::roletype, - ARIARoleNames::section, - ARIARoleNames::sectionhead, - ARIARoleNames::select, - ARIARoleNames::structure, - ARIARoleNames::widget, - ARIARoleNames::window); -} - -// https://www.w3.org/TR/wai-aria-1.2/#widget_roles -bool is_widget_aria_role(DeprecatedFlyString const& role) -{ - return role.to_lowercase().is_one_of( - ARIARoleNames::button, - ARIARoleNames::checkbox, - ARIARoleNames::gridcell, - ARIARoleNames::link, - ARIARoleNames::menuitem, - ARIARoleNames::menuitemcheckbox, - ARIARoleNames::option, - ARIARoleNames::progressbar, - ARIARoleNames::radio, - ARIARoleNames::scrollbar, - ARIARoleNames::searchbox, - ARIARoleNames::separator, // TODO: Only when focusable - ARIARoleNames::slider, - ARIARoleNames::spinbutton, - ARIARoleNames::switch_, - ARIARoleNames::tab, - ARIARoleNames::tabpanel, - ARIARoleNames::textbox, - ARIARoleNames::treeitem, - ARIARoleNames::combobox, - ARIARoleNames::grid, - ARIARoleNames::listbox, - ARIARoleNames::menu, - ARIARoleNames::menubar, - ARIARoleNames::radiogroup, - ARIARoleNames::tablist, - ARIARoleNames::tree, - ARIARoleNames::treegrid); -} - -// https://www.w3.org/TR/wai-aria-1.2/#document_structure_roles -bool is_document_structure_aria_role(DeprecatedFlyString const& role) -{ - return role.to_lowercase().is_one_of( - ARIARoleNames::application, - ARIARoleNames::article, - ARIARoleNames::blockquote, - ARIARoleNames::caption, - ARIARoleNames::cell, - ARIARoleNames::columnheader, - ARIARoleNames::definition, - ARIARoleNames::deletion, - ARIARoleNames::directory, - ARIARoleNames::document, - ARIARoleNames::emphasis, - ARIARoleNames::feed, - ARIARoleNames::figure, - ARIARoleNames::generic, - ARIARoleNames::group, - ARIARoleNames::heading, - ARIARoleNames::img, - ARIARoleNames::insertion, - ARIARoleNames::list, - ARIARoleNames::listitem, - ARIARoleNames::math, - ARIARoleNames::meter, - ARIARoleNames::none, - ARIARoleNames::note, - ARIARoleNames::paragraph, - ARIARoleNames::presentation, - ARIARoleNames::row, - ARIARoleNames::rowgroup, - ARIARoleNames::rowheader, - ARIARoleNames::separator, // TODO: Only when not focusable - ARIARoleNames::strong, - ARIARoleNames::subscript, - ARIARoleNames::table, - ARIARoleNames::term, - ARIARoleNames::time, - ARIARoleNames::toolbar, - ARIARoleNames::tooltip); -} - -// https://www.w3.org/TR/wai-aria-1.2/#landmark_roles -bool is_landmark_aria_role(DeprecatedFlyString const& role) -{ - return role.to_lowercase().is_one_of( - ARIARoleNames::banner, - ARIARoleNames::complementary, - ARIARoleNames::contentinfo, - ARIARoleNames::form, - ARIARoleNames::main, - ARIARoleNames::navigation, - ARIARoleNames::region, - ARIARoleNames::search); -} - -// https://www.w3.org/TR/wai-aria-1.2/#live_region_roles -bool is_live_region_aria_role(DeprecatedFlyString const& role) -{ - return role.to_lowercase().is_one_of( - ARIARoleNames::alert, - ARIARoleNames::log, - ARIARoleNames::marquee, - ARIARoleNames::status, - ARIARoleNames::timer); -} - -// https://www.w3.org/TR/wai-aria-1.2/#window_roles -bool is_windows_aria_role(DeprecatedFlyString const& role) -{ - return role.to_lowercase().is_one_of( - ARIARoleNames::alertdialog, - ARIARoleNames::dialog); -} - -bool is_non_abstract_aria_role(DeprecatedFlyString const& role) -{ - return is_widget_aria_role(role) - || is_document_structure_aria_role(role) - || is_landmark_aria_role(role) - || is_live_region_aria_role(role) - || is_windows_aria_role(role); -} - -} diff --git a/Userland/Libraries/LibWeb/DOM/ARIARoles.cpp b/Userland/Libraries/LibWeb/DOM/ARIARoles.cpp new file mode 100644 index 00000000000..01cc21c50a4 --- /dev/null +++ b/Userland/Libraries/LibWeb/DOM/ARIARoles.cpp @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2022, Jonah Shafran + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace Web::DOM::ARIARoles { + +StringView role_name(Role role) +{ + switch (role) { +#define __ENUMERATE_ARIA_ROLE(name) \ + case Role::name: \ + return #name##sv; + ENUMERATE_ARIA_ROLES +#undef __ENUMERATE_ARIA_ROLE + default: + VERIFY_NOT_REACHED(); + } +} + +Optional from_string(StringView role_name) +{ +#define __ENUMERATE_ARIA_ROLE(name) \ + if (role_name.equals_ignoring_case(#name##sv)) \ + return Role::name; + ENUMERATE_ARIA_ROLES +#undef __ENUMERATE_ARIA_ROLE + return {}; +} + +// https://www.w3.org/TR/wai-aria-1.2/#abstract_roles +bool is_abstract_aria_role(Role role) +{ + return first_is_one_of(role, + Role::command, + Role::composite, + Role::input, + Role::landmark, + Role::range, + Role::roletype, + Role::section, + Role::sectionhead, + Role::select, + Role::structure, + Role::widget, + Role::window); +} + +// https://www.w3.org/TR/wai-aria-1.2/#widget_roles +bool is_widget_aria_role(Role role) +{ + return first_is_one_of(role, + Role::button, + Role::checkbox, + Role::gridcell, + Role::link, + Role::menuitem, + Role::menuitemcheckbox, + Role::option, + Role::progressbar, + Role::radio, + Role::scrollbar, + Role::searchbox, + Role::separator, // TODO: Only when focusable + Role::slider, + Role::spinbutton, + Role::switch_, + Role::tab, + Role::tabpanel, + Role::textbox, + Role::treeitem, + Role::combobox, + Role::grid, + Role::listbox, + Role::menu, + Role::menubar, + Role::radiogroup, + Role::tablist, + Role::tree, + Role::treegrid); +} + +// https://www.w3.org/TR/wai-aria-1.2/#document_structure_roles +bool is_document_structure_aria_role(Role role) +{ + return first_is_one_of(role, + Role::application, + Role::article, + Role::blockquote, + Role::caption, + Role::cell, + Role::columnheader, + Role::definition, + Role::deletion, + Role::directory, + Role::document, + Role::emphasis, + Role::feed, + Role::figure, + Role::generic, + Role::group, + Role::heading, + Role::img, + Role::insertion, + Role::list, + Role::listitem, + Role::math, + Role::meter, + Role::none, + Role::note, + Role::paragraph, + Role::presentation, + Role::row, + Role::rowgroup, + Role::rowheader, + Role::separator, // TODO: Only when not focusable + Role::strong, + Role::subscript, + Role::table, + Role::term, + Role::time, + Role::toolbar, + Role::tooltip); +} + +// https://www.w3.org/TR/wai-aria-1.2/#landmark_roles +bool is_landmark_aria_role(Role role) +{ + return first_is_one_of(role, + Role::banner, + Role::complementary, + Role::contentinfo, + Role::form, + Role::main, + Role::navigation, + Role::region, + Role::search); +} + +// https://www.w3.org/TR/wai-aria-1.2/#live_region_roles +bool is_live_region_aria_role(Role role) +{ + return first_is_one_of(role, + Role::alert, + Role::log, + Role::marquee, + Role::status, + Role::timer); +} + +// https://www.w3.org/TR/wai-aria-1.2/#window_roles +bool is_windows_aria_role(Role role) +{ + return first_is_one_of(role, + Role::alertdialog, + Role::dialog); +} + +bool is_non_abstract_aria_role(Role role) +{ + return is_widget_aria_role(role) + || is_document_structure_aria_role(role) + || is_landmark_aria_role(role) + || is_live_region_aria_role(role) + || is_windows_aria_role(role); +} + +} diff --git a/Userland/Libraries/LibWeb/DOM/ARIARoleNames.h b/Userland/Libraries/LibWeb/DOM/ARIARoles.h similarity index 89% rename from Userland/Libraries/LibWeb/DOM/ARIARoleNames.h rename to Userland/Libraries/LibWeb/DOM/ARIARoles.h index 6bca60883d0..5efab6dd6c0 100644 --- a/Userland/Libraries/LibWeb/DOM/ARIARoleNames.h +++ b/Userland/Libraries/LibWeb/DOM/ARIARoles.h @@ -8,7 +8,7 @@ #include -namespace Web::DOM::ARIARoleNames { +namespace Web::DOM::ARIARoles { #define ENUMERATE_ARIA_ROLES \ __ENUMERATE_ARIA_ROLE(alert) \ @@ -106,17 +106,22 @@ namespace Web::DOM::ARIARoleNames { __ENUMERATE_ARIA_ROLE(widget) \ __ENUMERATE_ARIA_ROLE(window) -#define __ENUMERATE_ARIA_ROLE(name) extern DeprecatedFlyString name; -ENUMERATE_ARIA_ROLES +enum class Role { +#define __ENUMERATE_ARIA_ROLE(name) name, + ENUMERATE_ARIA_ROLES #undef __ENUMERATE_ARIA_ROLE +}; -bool is_abstract_aria_role(DeprecatedFlyString const&); -bool is_widget_aria_role(DeprecatedFlyString const&); -bool is_document_structure_aria_role(DeprecatedFlyString const&); -bool is_landmark_aria_role(DeprecatedFlyString const&); -bool is_live_region_aria_role(DeprecatedFlyString const&); -bool is_windows_aria_role(DeprecatedFlyString const&); +StringView role_name(Role); +Optional from_string(StringView role_name); -bool is_non_abstract_aria_role(DeprecatedFlyString const&); +bool is_abstract_aria_role(Role); +bool is_widget_aria_role(Role); +bool is_document_structure_aria_role(Role); +bool is_landmark_aria_role(Role); +bool is_live_region_aria_role(Role); +bool is_windows_aria_role(Role); + +bool is_non_abstract_aria_role(Role); } diff --git a/Userland/Libraries/LibWeb/DOM/AccessibilityTreeNode.cpp b/Userland/Libraries/LibWeb/DOM/AccessibilityTreeNode.cpp index c2a4674ebc6..3b891968a2d 100644 --- a/Userland/Libraries/LibWeb/DOM/AccessibilityTreeNode.cpp +++ b/Userland/Libraries/LibWeb/DOM/AccessibilityTreeNode.cpp @@ -35,10 +35,10 @@ void AccessibilityTreeNode::serialize_tree_as_json(JsonObjectSerializerrole_or_default(); - bool has_role = !role.is_null() && !role.is_empty() && !ARIARoleNames::is_abstract_aria_role(role); + bool has_role = role.has_value() && !ARIARoles::is_abstract_aria_role(*role); if (has_role) - MUST(object.add("role"sv, role.view())); + MUST(object.add("role"sv, ARIARoles::role_name(*role))); else MUST(object.add("role"sv, ""sv)); } else { diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 60ee3c634e8..f965b5241d3 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -1282,8 +1282,8 @@ bool Element::exclude_from_accessibility_tree() const // Elements with none or presentation as the first role in the role attribute. However, their exclusion is conditional. In addition, the element's descendants and text content are generally included. These exceptions and conditions are documented in the presentation (role) section. // FIXME: Handle exceptions to excluding presentation role - auto role = role_or_default().to_lowercase(); - if (role == ARIARoleNames::none || role == ARIARoleNames::presentation) + auto role = role_or_default(); + if (role == ARIARoles::Role::none || role == ARIARoles::Role::presentation) return true; // TODO: If not already excluded from the accessibility tree per the above rules, user agents SHOULD NOT include the following elements in the accessibility tree: @@ -1322,7 +1322,7 @@ bool Element::include_in_accessibility_tree() const // Elements that have an explicit role or a global WAI-ARIA attribute and do not have aria-hidden set to true. (See Excluding Elements in the Accessibility Tree for additional guidance on aria-hidden.) // NOTE: The spec says only explicit roles count, but playing around in other browsers, this does not seem to be true in practice (for example button elements are always exposed with their implicit role if none is set) // This issue https://github.com/w3c/aria/issues/1851 seeks clarification on this point - if ((!role_or_default().is_empty() || has_global_aria_attribute()) && aria_hidden() != "true") + if ((role_or_default().has_value() || has_global_aria_attribute()) && aria_hidden() != "true") return true; // TODO: Elements that are not hidden and have an ID that is referenced by another element via a WAI-ARIA property. diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h index 4c6f99ce9a2..8be743194d4 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.h +++ b/Userland/Libraries/LibWeb/DOM/Node.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp index 8a6956f3c61..3a62420849a 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include #include @@ -89,13 +89,13 @@ i32 HTMLAnchorElement::default_tab_index_value() const return 0; } -DeprecatedFlyString HTMLAnchorElement::default_role() const +Optional HTMLAnchorElement::default_role() const { // https://www.w3.org/TR/html-aria/#el-a-no-href if (!href().is_null()) - return DOM::ARIARoleNames::link; + return DOM::ARIARoles::Role::link; // https://www.w3.org/TR/html-aria/#el-a - return DOM::ARIARoleNames::generic; + return DOM::ARIARoles::Role::generic; } } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.h b/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.h index 3b0805a9abf..2f01af5187e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.h @@ -53,7 +53,7 @@ private: queue_an_element_task(source, move(steps)); } - virtual DeprecatedFlyString default_role() const override; + virtual Optional default_role() const override; }; } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.cpp index dea9e96b16b..9618a11f6f1 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include #include @@ -48,13 +48,13 @@ i32 HTMLAreaElement::default_tab_index_value() const return 0; } -DeprecatedFlyString HTMLAreaElement::default_role() const +Optional HTMLAreaElement::default_role() const { // https://www.w3.org/TR/html-aria/#el-area-no-href if (!href().is_null()) - return DOM::ARIARoleNames::link; + return DOM::ARIARoles::Role::link; // https://www.w3.org/TR/html-aria/#el-area - return DOM::ARIARoleNames::generic; + return DOM::ARIARoles::Role::generic; } } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.h b/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.h index f38a79f846d..b12b7df4049 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.h @@ -42,7 +42,7 @@ private: queue_an_element_task(source, move(steps)); } - virtual DeprecatedFlyString default_role() const override; + virtual Optional default_role() const override; }; } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.h b/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.h index fe5679114b5..4b437268fb5 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include #include @@ -24,7 +24,7 @@ public: virtual void apply_presentational_hints(CSS::StyleProperties&) const override; // https://www.w3.org/TR/html-aria/#el-body - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::generic; }; + virtual Optional default_role() const override { return DOM::ARIARoles::Role::generic; }; private: HTMLBodyElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.h b/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.h index 86d88e5e95c..8e49feba529 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include #include @@ -57,7 +57,7 @@ public: virtual bool is_labelable() const override { return true; } // https://www.w3.org/TR/html-aria/#el-button - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::button; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::button; } private: HTMLButtonElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLDataElement.h b/Userland/Libraries/LibWeb/HTML/HTMLDataElement.h index 6fd5497aa1c..57089632915 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLDataElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLDataElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -18,7 +18,7 @@ public: virtual ~HTMLDataElement() override; // https://www.w3.org/TR/html-aria/#el-data - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::generic; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::generic; } private: HTMLDataElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLDataListElement.h b/Userland/Libraries/LibWeb/HTML/HTMLDataListElement.h index df60c1b2c5f..d71383912e1 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLDataListElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLDataListElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -17,7 +17,7 @@ class HTMLDataListElement final : public HTMLElement { public: virtual ~HTMLDataListElement() override; - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::listbox; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::listbox; } private: HTMLDataListElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.h b/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.h index 46c2ce8236d..2a09a57b64b 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -18,7 +18,7 @@ public: virtual ~HTMLDetailsElement() override; // https://www.w3.org/TR/html-aria/#el-details - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::group; }; + virtual Optional default_role() const override { return DOM::ARIARoles::Role::group; }; private: HTMLDetailsElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLDialogElement.h b/Userland/Libraries/LibWeb/HTML/HTMLDialogElement.h index 89e42c47c72..d54332c8725 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLDialogElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLDialogElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -18,7 +18,7 @@ public: virtual ~HTMLDialogElement() override; // https://www.w3.org/TR/html-aria/#el-dialog - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::dialog; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::dialog; } private: HTMLDialogElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLDivElement.h b/Userland/Libraries/LibWeb/HTML/HTMLDivElement.h index 0d7c9172cdc..a94635fe1ad 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLDivElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLDivElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -18,7 +18,7 @@ public: virtual ~HTMLDivElement() override; // https://www.w3.org/TR/html-aria/#el-div - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::generic; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::generic; } private: HTMLDivElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp index 701699ddade..1fdc7a5e773 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include @@ -329,86 +329,86 @@ void HTMLElement::blur() // User agents may selectively or uniformly ignore calls to this method for usability reasons. } -DeprecatedFlyString HTMLElement::default_role() const +Optional HTMLElement::default_role() const { // https://www.w3.org/TR/html-aria/#el-article if (local_name() == TagNames::article) - return DOM::ARIARoleNames::article; + return DOM::ARIARoles::Role::article; // https://www.w3.org/TR/html-aria/#el-aside if (local_name() == TagNames::aside) - return DOM::ARIARoleNames::complementary; + return DOM::ARIARoles::Role::complementary; // https://www.w3.org/TR/html-aria/#el-b if (local_name() == TagNames::b) - return DOM::ARIARoleNames::generic; + return DOM::ARIARoles::Role::generic; // https://www.w3.org/TR/html-aria/#el-bdi if (local_name() == TagNames::bdi) - return DOM::ARIARoleNames::generic; + return DOM::ARIARoles::Role::generic; // https://www.w3.org/TR/html-aria/#el-bdo if (local_name() == TagNames::bdo) - return DOM::ARIARoleNames::generic; + return DOM::ARIARoles::Role::generic; // https://www.w3.org/TR/html-aria/#el-code if (local_name() == TagNames::code) - return DOM::ARIARoleNames::code; + return DOM::ARIARoles::Role::code; // https://www.w3.org/TR/html-aria/#el-dfn if (local_name() == TagNames::dfn) - return DOM::ARIARoleNames::term; + return DOM::ARIARoles::Role::term; // https://www.w3.org/TR/html-aria/#el-em if (local_name() == TagNames::em) - return DOM::ARIARoleNames::emphasis; + return DOM::ARIARoles::Role::emphasis; // https://www.w3.org/TR/html-aria/#el-figure if (local_name() == TagNames::figure) - return DOM::ARIARoleNames::figure; + return DOM::ARIARoles::Role::figure; // https://www.w3.org/TR/html-aria/#el-footer if (local_name() == TagNames::footer) { // TODO: If not a descendant of an article, aside, main, nav or section element, or an element with role=article, complementary, main, navigation or region then role=contentinfo // Otherwise, role=generic - return DOM::ARIARoleNames::generic; + return DOM::ARIARoles::Role::generic; } // https://www.w3.org/TR/html-aria/#el-header if (local_name() == TagNames::header) { // TODO: If not a descendant of an article, aside, main, nav or section element, or an element with role=article, complementary, main, navigation or region then role=banner // Otherwise, role=generic - return DOM::ARIARoleNames::generic; + return DOM::ARIARoles::Role::generic; } // https://www.w3.org/TR/html-aria/#el-hgroup if (local_name() == TagNames::hgroup) - return DOM::ARIARoleNames::generic; + return DOM::ARIARoles::Role::generic; // https://www.w3.org/TR/html-aria/#el-i if (local_name() == TagNames::i) - return DOM::ARIARoleNames::generic; + return DOM::ARIARoles::Role::generic; // https://www.w3.org/TR/html-aria/#el-main if (local_name() == TagNames::main) - return DOM::ARIARoleNames::main; + return DOM::ARIARoles::Role::main; // https://www.w3.org/TR/html-aria/#el-nav if (local_name() == TagNames::nav) - return DOM::ARIARoleNames::navigation; + return DOM::ARIARoles::Role::navigation; // https://www.w3.org/TR/html-aria/#el-samp if (local_name() == TagNames::samp) - return DOM::ARIARoleNames::generic; + return DOM::ARIARoles::Role::generic; // https://www.w3.org/TR/html-aria/#el-section if (local_name() == TagNames::section) { // TODO: role=region if the section element has an accessible name // Otherwise, no corresponding role - return DOM::ARIARoleNames::region; + return DOM::ARIARoles::Role::region; } // https://www.w3.org/TR/html-aria/#el-small if (local_name() == TagNames::small) - return DOM::ARIARoleNames::generic; + return DOM::ARIARoles::Role::generic; // https://www.w3.org/TR/html-aria/#el-strong if (local_name() == TagNames::strong) - return DOM::ARIARoleNames::strong; + return DOM::ARIARoles::Role::strong; // https://www.w3.org/TR/html-aria/#el-sub if (local_name() == TagNames::sub) - return DOM::ARIARoleNames::subscript; + return DOM::ARIARoles::Role::subscript; // https://www.w3.org/TR/html-aria/#el-summary if (local_name() == TagNames::summary) - return DOM::ARIARoleNames::button; + return DOM::ARIARoles::Role::button; // https://www.w3.org/TR/html-aria/#el-sup if (local_name() == TagNames::sup) - return DOM::ARIARoleNames::superscript; + return DOM::ARIARoles::Role::superscript; // https://www.w3.org/TR/html-aria/#el-u if (local_name() == TagNames::u) - return DOM::ARIARoleNames::generic; + return DOM::ARIARoles::Role::generic; return {}; } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.h b/Userland/Libraries/LibWeb/HTML/HTMLElement.h index a31d67f0b41..6f8e774f741 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.h @@ -59,7 +59,7 @@ public: // https://html.spec.whatwg.org/multipage/forms.html#category-label virtual bool is_labelable() const { return false; } - virtual DeprecatedFlyString default_role() const override; + virtual Optional default_role() const override; protected: HTMLElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.h b/Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.h index bf1e54c4ec1..ecb9eb522b9 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include #include @@ -36,7 +36,7 @@ public: // https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize virtual bool is_auto_capitalize_inheriting() const override { return true; } - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::group; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::group; } private: HTMLFieldSetElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h index df6bc49fe6e..41ec186c01e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include #include @@ -38,7 +38,7 @@ public: unsigned length() const; // https://www.w3.org/TR/html-aria/#el-form - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::form; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::form; } private: HTMLFormElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLHRElement.h b/Userland/Libraries/LibWeb/HTML/HTMLHRElement.h index 7176ba61b4e..97827985eab 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLHRElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLHRElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -18,7 +18,7 @@ public: virtual ~HTMLHRElement() override; // https://www.w3.org/TR/html-aria/#el-hr - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::separator; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::separator; } private: HTMLHRElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLHeadingElement.h b/Userland/Libraries/LibWeb/HTML/HTMLHeadingElement.h index 82896790772..599975c0463 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLHeadingElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLHeadingElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -20,7 +20,8 @@ public: virtual void apply_presentational_hints(CSS::StyleProperties&) const override; // https://www.w3.org/TR/html-aria/#el-h1-h6 - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::heading; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::heading; } + virtual DeprecatedString aria_level() const override { // TODO: aria-level = the number in the element's tag name diff --git a/Userland/Libraries/LibWeb/HTML/HTMLHtmlElement.h b/Userland/Libraries/LibWeb/HTML/HTMLHtmlElement.h index 6cc03a8f710..454d260a29a 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLHtmlElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLHtmlElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -20,7 +20,7 @@ public: bool should_use_body_background_properties() const; // https://www.w3.org/TR/html-aria/#el-html - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::document; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::document; } private: HTMLHtmlElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp index 13f6da07e2f..fd992c48eca 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include @@ -202,14 +202,14 @@ bool HTMLImageElement::complete() const return false; } -DeprecatedFlyString HTMLImageElement::default_role() const +Optional HTMLImageElement::default_role() const { // https://www.w3.org/TR/html-aria/#el-img // https://www.w3.org/TR/html-aria/#el-img-no-alt if (alt().is_null() || !alt().is_empty()) - return DOM::ARIARoleNames::img; + return DOM::ARIARoles::Role::img; // https://www.w3.org/TR/html-aria/#el-img-empty-alt - return DOM::ARIARoleNames::presentation; + return DOM::ARIARoles::Role::presentation; } } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h index 316d84e7472..9c79421a4d8 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h @@ -43,7 +43,7 @@ public: // https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-complete bool complete() const; - virtual DeprecatedFlyString default_role() const override; + virtual Optional default_role() const override; private: HTMLImageElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 242de50fc02..4592b97a293 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -870,32 +870,32 @@ WebIDL::ExceptionOr HTMLInputElement::set_selection_range(u32 start, u32 e return {}; } -DeprecatedFlyString HTMLInputElement::default_role() const +Optional HTMLInputElement::default_role() const { // https://www.w3.org/TR/html-aria/#el-input-button if (type_state() == TypeAttributeState::Button) - return DOM::ARIARoleNames::button; + return DOM::ARIARoles::Role::button; // https://www.w3.org/TR/html-aria/#el-input-checkbox if (type_state() == TypeAttributeState::Checkbox) - return DOM::ARIARoleNames::checkbox; + return DOM::ARIARoles::Role::checkbox; // https://www.w3.org/TR/html-aria/#el-input-email if (type_state() == TypeAttributeState::Email && attribute("list").is_null()) - return DOM::ARIARoleNames::textbox; + return DOM::ARIARoles::Role::textbox; // https://www.w3.org/TR/html-aria/#el-input-image if (type_state() == TypeAttributeState::ImageButton) - return DOM::ARIARoleNames::button; + return DOM::ARIARoles::Role::button; // https://www.w3.org/TR/html-aria/#el-input-number if (type_state() == TypeAttributeState::Number) - return DOM::ARIARoleNames::spinbutton; + return DOM::ARIARoles::Role::spinbutton; // https://www.w3.org/TR/html-aria/#el-input-radio if (type_state() == TypeAttributeState::RadioButton) - return DOM::ARIARoleNames::radio; + return DOM::ARIARoles::Role::radio; // https://www.w3.org/TR/html-aria/#el-input-range if (type_state() == TypeAttributeState::Range) - return DOM::ARIARoleNames::slider; + return DOM::ARIARoles::Role::slider; // https://www.w3.org/TR/html-aria/#el-input-reset if (type_state() == TypeAttributeState::ResetButton) - return DOM::ARIARoleNames::button; + return DOM::ARIARoles::Role::button; // https://www.w3.org/TR/html-aria/#el-input-text-list if ((type_state() == TypeAttributeState::Text || type_state() == TypeAttributeState::Search @@ -903,22 +903,22 @@ DeprecatedFlyString HTMLInputElement::default_role() const || type_state() == TypeAttributeState::URL || type_state() == TypeAttributeState::Email) && !attribute("list").is_null()) - return DOM::ARIARoleNames::combobox; + return DOM::ARIARoles::Role::combobox; // https://www.w3.org/TR/html-aria/#el-input-search if (type_state() == TypeAttributeState::Search && attribute("list").is_null()) - return DOM::ARIARoleNames::textbox; + return DOM::ARIARoles::Role::textbox; // https://www.w3.org/TR/html-aria/#el-input-submit if (type_state() == TypeAttributeState::SubmitButton) - return DOM::ARIARoleNames::button; + return DOM::ARIARoles::Role::button; // https://www.w3.org/TR/html-aria/#el-input-tel if (type_state() == TypeAttributeState::Telephone) - return DOM::ARIARoleNames::textbox; + return DOM::ARIARoles::Role::textbox; // https://www.w3.org/TR/html-aria/#el-input-text if (type_state() == TypeAttributeState::Text && attribute("list").is_null()) - return DOM::ARIARoleNames::textbox; + return DOM::ARIARoles::Role::textbox; // https://www.w3.org/TR/html-aria/#el-input-url if (type_state() == TypeAttributeState::URL && attribute("list").is_null()) - return DOM::ARIARoleNames::textbox; + return DOM::ARIARoles::Role::textbox; // https://www.w3.org/TR/html-aria/#el-input-color // https://www.w3.org/TR/html-aria/#el-input-date diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h index 3a6a863a14e..893696a0fb0 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h @@ -120,7 +120,7 @@ public: // https://html.spec.whatwg.org/multipage/forms.html#category-label virtual bool is_labelable() const override { return type_state() != TypeAttributeState::Hidden; } - virtual DeprecatedFlyString default_role() const override; + virtual Optional default_role() const override; private: HTMLInputElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLIElement.h b/Userland/Libraries/LibWeb/HTML/HTMLLIElement.h index 2e4c0baeca8..491001b714d 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLLIElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLLIElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -18,7 +18,7 @@ public: virtual ~HTMLLIElement() override; // https://www.w3.org/TR/html-aria/#el-li - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::listitem; }; + virtual Optional default_role() const override { return DOM::ARIARoles::Role::listitem; }; private: HTMLLIElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMenuElement.h b/Userland/Libraries/LibWeb/HTML/HTMLMenuElement.h index 1577bce29ff..2af2ebff78c 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMenuElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLMenuElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -18,7 +18,7 @@ public: virtual ~HTMLMenuElement() override; // https://www.w3.org/TR/html-aria/#el-menu - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::list; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::list; } private: HTMLMenuElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMeterElement.h b/Userland/Libraries/LibWeb/HTML/HTMLMeterElement.h index 0c2907461bf..5040a5589a8 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMeterElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLMeterElement.h @@ -7,7 +7,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -23,7 +23,7 @@ public: virtual bool is_labelable() const override { return true; } // https://www.w3.org/TR/html-aria/#el-meter - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::meter; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::meter; } private: HTMLMeterElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLModElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLModElement.cpp index bc5a40c4c75..a1a47788283 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLModElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLModElement.cpp @@ -23,14 +23,14 @@ void HTMLModElement::initialize(JS::Realm& realm) set_prototype(&Bindings::ensure_web_prototype(realm, "HTMLModElement")); } -DeprecatedFlyString HTMLModElement::default_role() const +Optional HTMLModElement::default_role() const { // https://www.w3.org/TR/html-aria/#el-del if (local_name() == TagNames::del) - return DOM::ARIARoleNames::deletion; + return DOM::ARIARoles::Role::deletion; // https://www.w3.org/TR/html-aria/#el-ins if (local_name() == TagNames::ins) - return DOM::ARIARoleNames::insertion; + return DOM::ARIARoles::Role::insertion; VERIFY_NOT_REACHED(); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLModElement.h b/Userland/Libraries/LibWeb/HTML/HTMLModElement.h index 710cf9a4718..47aa99d6415 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLModElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLModElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -17,7 +17,7 @@ class HTMLModElement final : public HTMLElement { public: virtual ~HTMLModElement() override; - virtual DeprecatedFlyString default_role() const override; + virtual Optional default_role() const override; private: HTMLModElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLOListElement.h b/Userland/Libraries/LibWeb/HTML/HTMLOListElement.h index 776fd1fb2bd..7df7b0b08b9 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLOListElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLOListElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -18,7 +18,7 @@ public: virtual ~HTMLOListElement() override; // https://www.w3.org/TR/html-aria/#el-ol - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::list; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::list; } private: HTMLOListElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLOptGroupElement.h b/Userland/Libraries/LibWeb/HTML/HTMLOptGroupElement.h index cef892b5c74..3b3971442da 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLOptGroupElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLOptGroupElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -18,7 +18,7 @@ public: virtual ~HTMLOptGroupElement() override; // https://www.w3.org/TR/html-aria/#el-optgroup - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::group; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::group; } private: HTMLOptGroupElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp index 17027c98b56..f70d7dffb97 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include #include @@ -146,11 +146,11 @@ bool HTMLOptionElement::disabled() const || (parent() && is(parent()) && static_cast(*parent()).has_attribute(AttributeNames::disabled)); } -DeprecatedFlyString HTMLOptionElement::default_role() const +Optional HTMLOptionElement::default_role() const { // https://www.w3.org/TR/html-aria/#el-option // TODO: Only an option element that is in a list of options or that represents a suggestion in a datalist should return option - return DOM::ARIARoleNames::option; + return DOM::ARIARoles::Role::option; } } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.h b/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.h index 9633a7c85bf..c6d8228c929 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.h @@ -30,7 +30,7 @@ public: bool disabled() const; - virtual DeprecatedFlyString default_role() const override; + virtual Optional default_role() const override; private: friend class Bindings::OptionConstructor; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLOutputElement.h b/Userland/Libraries/LibWeb/HTML/HTMLOutputElement.h index bc4a574b9e3..d8c22cb5c69 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLOutputElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLOutputElement.h @@ -7,7 +7,7 @@ #pragma once -#include +#include #include #include @@ -45,7 +45,7 @@ public: virtual void reset_algorithm() override; // https://www.w3.org/TR/html-aria/#el-output - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::status; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::status; } private: HTMLOutputElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLParagraphElement.h b/Userland/Libraries/LibWeb/HTML/HTMLParagraphElement.h index d124674decc..e0f41530473 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLParagraphElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLParagraphElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -20,7 +20,7 @@ public: virtual void apply_presentational_hints(CSS::StyleProperties&) const override; // https://www.w3.org/TR/html-aria/#el-p - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::paragraph; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::paragraph; } private: HTMLParagraphElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLPreElement.h b/Userland/Libraries/LibWeb/HTML/HTMLPreElement.h index d2fc64fa2fd..b1caeff7f69 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLPreElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLPreElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -18,7 +18,7 @@ public: virtual ~HTMLPreElement() override; // https://www.w3.org/TR/html-aria/#el-pre - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::generic; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::generic; } private: HTMLPreElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLProgressElement.h b/Userland/Libraries/LibWeb/HTML/HTMLProgressElement.h index aa39a9f9dbe..e8bac3b42d5 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLProgressElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLProgressElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -34,7 +34,7 @@ public: bool using_system_appearance() const; // https://www.w3.org/TR/html-aria/#el-progress - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::progressbar; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::progressbar; } private: HTMLProgressElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLQuoteElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLQuoteElement.cpp index 2547d64dd79..a1113a00a78 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLQuoteElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLQuoteElement.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include namespace Web::HTML { @@ -24,14 +24,14 @@ void HTMLQuoteElement::initialize(JS::Realm& realm) set_prototype(&Bindings::ensure_web_prototype(realm, "HTMLQuoteElement")); } -DeprecatedFlyString HTMLQuoteElement::default_role() const +Optional HTMLQuoteElement::default_role() const { // https://www.w3.org/TR/html-aria/#el-blockquote if (local_name() == TagNames::blockquote) - return DOM::ARIARoleNames::blockquote; + return DOM::ARIARoles::Role::blockquote; // https://www.w3.org/TR/html-aria/#el-q if (local_name() == TagNames::q) - return DOM::ARIARoleNames::generic; + return DOM::ARIARoles::Role::generic; VERIFY_NOT_REACHED(); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLQuoteElement.h b/Userland/Libraries/LibWeb/HTML/HTMLQuoteElement.h index f12877b04c0..9791dda4d75 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLQuoteElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLQuoteElement.h @@ -16,7 +16,7 @@ class HTMLQuoteElement final : public HTMLElement { public: virtual ~HTMLQuoteElement() override; - virtual DeprecatedFlyString default_role() const override; + virtual Optional default_role() const override; private: HTMLQuoteElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp index cc5ddb69067..bef90621152 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp @@ -161,18 +161,18 @@ DeprecatedString const& HTMLSelectElement::type() const return select_multiple; } -DeprecatedFlyString HTMLSelectElement::default_role() const +Optional HTMLSelectElement::default_role() const { // https://www.w3.org/TR/html-aria/#el-select-multiple-or-size-greater-1 if (has_attribute("multiple")) - return DOM::ARIARoleNames::listbox; + return DOM::ARIARoles::Role::listbox; if (has_attribute("size")) { auto size_attribute = attribute("size").to_int(); if (size_attribute.has_value() && size_attribute.value() > 1) - return DOM::ARIARoleNames::listbox; + return DOM::ARIARoles::Role::listbox; } // https://www.w3.org/TR/html-aria/#el-select - return DOM::ARIARoleNames::combobox; + return DOM::ARIARoles::Role::combobox; } } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h index 985edd49fc5..29996d74d4f 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h @@ -60,7 +60,7 @@ public: DeprecatedString const& type() const; - virtual DeprecatedFlyString default_role() const override; + virtual Optional default_role() const override; private: HTMLSelectElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSpanElement.h b/Userland/Libraries/LibWeb/HTML/HTMLSpanElement.h index 20d6a7d7bd8..493e2effe6b 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSpanElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLSpanElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -18,7 +18,7 @@ public: virtual ~HTMLSpanElement() override; // https://www.w3.org/TR/html-aria/#el-span - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::generic; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::generic; } private: HTMLSpanElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableCaptionElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTableCaptionElement.h index 94f44b41a8f..4de44131a4f 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableCaptionElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableCaptionElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -20,7 +20,7 @@ public: virtual void apply_presentational_hints(CSS::StyleProperties&) const override; // https://www.w3.org/TR/html-aria/#el-caption - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::caption; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::caption; } private: HTMLTableCaptionElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp index e554128132c..dbfbe9b62e2 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp @@ -74,7 +74,7 @@ void HTMLTableCellElement::set_row_span(unsigned int value) MUST(set_attribute(HTML::AttributeNames::rowspan, DeprecatedString::number(value))); } -DeprecatedFlyString HTMLTableCellElement::default_role() const +Optional HTMLTableCellElement::default_role() const { // TODO: For td: // role=cell if the ancestor table element is exposed as a role=table diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.h index 7eb0138762e..b30c0900f01 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.h @@ -22,7 +22,7 @@ public: void set_col_span(unsigned); void set_row_span(unsigned); - virtual DeprecatedFlyString default_role() const override; + virtual Optional default_role() const override; private: HTMLTableCellElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h index 5ed3f57edf3..6f897b41d46 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h @@ -43,7 +43,7 @@ public: WebIDL::ExceptionOr delete_row(long index); // https://www.w3.org/TR/html-aria/#el-table - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::table; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::table; } private: HTMLTableElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h index 9d404aed0e8..9332f86d388 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -25,7 +25,7 @@ public: WebIDL::ExceptionOr delete_cell(i32 index); // https://www.w3.org/TR/html-aria/#el-tr - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::row; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::row; } private: HTMLTableRowElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h index 83cfc5830e9..a09fb901233 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h @@ -7,7 +7,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -25,7 +25,7 @@ public: // https://www.w3.org/TR/html-aria/#el-tbody // https://www.w3.org/TR/html-aria/#el-tfoot // https://www.w3.org/TR/html-aria/#el-thead - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::rowgroup; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::rowgroup; } private: HTMLTableSectionElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.h index 86805985ab8..e7e323cfa7c 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.h @@ -7,7 +7,7 @@ #pragma once -#include +#include #include #include @@ -52,7 +52,7 @@ public: virtual void reset_algorithm() override; // https://www.w3.org/TR/html-aria/#el-textarea - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::textbox; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::textbox; } private: HTMLTextAreaElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTimeElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTimeElement.h index 02655140f46..f6e9fefc72f 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTimeElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLTimeElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -18,7 +18,7 @@ public: virtual ~HTMLTimeElement() override; // https://www.w3.org/TR/html-aria/#el-time - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::time; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::time; } private: HTMLTimeElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLUListElement.h b/Userland/Libraries/LibWeb/HTML/HTMLUListElement.h index 45e4af27541..f1f4585ad40 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLUListElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLUListElement.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace Web::HTML { @@ -18,7 +18,7 @@ public: virtual ~HTMLUListElement() override; // https://www.w3.org/TR/html-aria/#el-ul - virtual DeprecatedFlyString default_role() const override { return DOM::ARIARoleNames::list; } + virtual Optional default_role() const override { return DOM::ARIARoles::Role::list; } private: HTMLUListElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index 803015adc50..f45d9b26783 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -1253,7 +1253,9 @@ Messages::WebDriverClient::GetComputedRoleResponse WebDriverConnection::get_comp auto role = element->role_or_default(); // 5. Return success with data role. - return DeprecatedString { role }; + if (role.has_value()) + return Web::DOM::ARIARoles::role_name(*role); + return ""sv; } // 12.5.1 Element Click, https://w3c.github.io/webdriver/#element-click