summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/DOM/ARIARoleNames.cpp
blob: 3d70ab243e70eeab0f5a4cb3cdcca46066200c47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
 * Copyright (c) 2022, Jonah Shafran <jonahshafran@gmail.com>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <LibWeb/DOM/ARIARoleNames.h>

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);
}

}