mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:27:43 +00:00
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).
This commit is contained in:
parent
f23eba1ba8
commit
890b4d7980
59 changed files with 344 additions and 327 deletions
|
@ -5,13 +5,13 @@
|
|||
*/
|
||||
|
||||
#include <LibWeb/DOM/ARIAMixin.h>
|
||||
#include <LibWeb/DOM/ARIARoleNames.h>
|
||||
#include <LibWeb/DOM/ARIARoles.h>
|
||||
#include <LibWeb/Infra/CharacterTypes.h>
|
||||
|
||||
namespace Web::DOM {
|
||||
|
||||
// https://www.w3.org/TR/wai-aria-1.2/#introroles
|
||||
DeprecatedFlyString ARIAMixin::role_or_default() const
|
||||
Optional<ARIARoles::Role> 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue