/src/serenity/Userland/Libraries/LibWeb/ARIA/AriaData.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2023, Jonah Shafran <jonahshafran@gmail.com> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/NonnullOwnPtr.h> |
10 | | #include <AK/Vector.h> |
11 | | #include <LibWeb/ARIA/ARIAMixin.h> |
12 | | #include <LibWeb/Forward.h> |
13 | | |
14 | | namespace Web::ARIA { |
15 | | |
16 | | // https://www.w3.org/TR/wai-aria-1.2/#valuetype_tristate |
17 | | enum class Tristate { |
18 | | True, |
19 | | False, |
20 | | Mixed, |
21 | | Undefined |
22 | | }; |
23 | | |
24 | | // https://www.w3.org/TR/wai-aria-1.2/#aria-autocomplete |
25 | | enum class AriaAutocomplete { |
26 | | // When a user is providing input, text suggesting one way to complete the provided input may be dynamically inserted after the caret. |
27 | | Inline, |
28 | | // When a user is providing input, an element containing a collection of values that could complete the provided input may be displayed. |
29 | | List, |
30 | | // When a user is providing input, an element containing a collection of values that could complete the provided input may be displayed. |
31 | | // If displayed, one value in the collection is automatically selected, and the text needed to complete the automatically selected value appears after the caret in the input |
32 | | Both, |
33 | | // When a user is providing input, an automatic suggestion that attempts to predict how the user intends to complete the input is not displayed. |
34 | | None |
35 | | }; |
36 | | |
37 | | // https://www.w3.org/TR/wai-aria-1.2/#aria-current |
38 | | enum class AriaCurrent { |
39 | | // Represents the current page within a set of pages. |
40 | | Page, |
41 | | // Represents the current step within a process. |
42 | | Step, |
43 | | // Represents the current location within an environment or context. |
44 | | Location, |
45 | | // Represents the current date within a collection of dates. |
46 | | Date, |
47 | | // Represents the current time within a set of times. |
48 | | Time, |
49 | | // Represents the current item within a set. |
50 | | True, |
51 | | // Does not represent the current item within a set. |
52 | | False |
53 | | }; |
54 | | |
55 | | // https://www.w3.org/TR/wai-aria-1.2/#aria-dropeffect |
56 | | enum class AriaDropEffect { |
57 | | // A duplicate of the source object will be dropped into the target. |
58 | | Copy, |
59 | | // A function supported by the drop target is executed, using the drag source as an input. |
60 | | Execute, |
61 | | // A reference or shortcut to the dragged object will be created in the target object. |
62 | | Link, |
63 | | // The source object will be removed from its current location and dropped into the target. |
64 | | Move, |
65 | | // No operation can be performed; effectively cancels the drag operation if an attempt is made to drop on this object. |
66 | | // Ignored if combined with any other token value. e.g., 'none copy' is equivalent to a 'copy' value. |
67 | | None, |
68 | | // There is a popup menu or dialog that allows the user to choose one of the drag operations (copy, move, link, execute) and any other drag functionality, such as cancel. |
69 | | Popup |
70 | | }; |
71 | | |
72 | | // https://www.w3.org/TR/wai-aria-1.2/#aria-haspopup |
73 | | enum class AriaHasPopup { |
74 | | // Indicates the element does not have a popup. |
75 | | False, |
76 | | // Indicates the popup is a menu. |
77 | | True, |
78 | | // Indicates the popup is a menu. |
79 | | Menu, |
80 | | // Indicates the popup is a listbox. |
81 | | Listbox, |
82 | | // Indicates the popup is a tree. |
83 | | Tree, |
84 | | // Indicates the popup is a grid. |
85 | | Grid, |
86 | | // Indicates the popup is a dialog. |
87 | | Dialog |
88 | | }; |
89 | | |
90 | | // https://www.w3.org/TR/wai-aria-1.2/#aria-invalid |
91 | | enum class AriaInvalid { |
92 | | // A grammatical error was detected. |
93 | | Grammar, |
94 | | // There are no detected errors in the value. |
95 | | False, |
96 | | // A spelling error was detected. |
97 | | Spelling, |
98 | | // The value entered by the user has failed validation. |
99 | | True |
100 | | }; |
101 | | |
102 | | // https://www.w3.org/TR/wai-aria-1.2/#aria-live |
103 | | enum class AriaLive { |
104 | | // Indicates that updates to the region have the highest priority and should be presented the user immediately. |
105 | | Assertive, |
106 | | // Indicates that updates to the region should not be presented to the user unless the user is currently focused on that region. |
107 | | Off, |
108 | | // Indicates that updates to the region should be presented at the next graceful opportunity, such as at the end of speaking the current sentence or when the user pauses typing. |
109 | | Polite |
110 | | }; |
111 | | |
112 | | // https://www.w3.org/TR/wai-aria-1.2/#aria-orientation |
113 | | enum class AriaOrientation { |
114 | | // The element is oriented horizontally. |
115 | | Horizontal, |
116 | | // The element's orientation is unknown/ambiguous. |
117 | | Undefined, |
118 | | // The element is oriented vertically. |
119 | | Vertical |
120 | | }; |
121 | | |
122 | | // https://www.w3.org/TR/wai-aria-1.2/#aria-relevant |
123 | | enum class AriaRelevant { |
124 | | // Element nodes are added to the accessibility tree within the live region. |
125 | | Additions, |
126 | | // Equivalent to the combination of values, "additions text". |
127 | | AdditionsText, |
128 | | // Equivalent to the combination of all values, "additions removals text". |
129 | | All, |
130 | | // Text content, a text alternative, or an element node within the live region is removed from the accessibility tree. |
131 | | Removals, |
132 | | // Text content or a text alternative is added to any descendant in the accessibility tree of the live region. |
133 | | Text |
134 | | }; |
135 | | |
136 | | // https://www.w3.org/TR/wai-aria-1.2/#aria-sort |
137 | | enum class AriaSort { |
138 | | // Items are sorted in ascending order by this column. |
139 | | Ascending, |
140 | | // Items are sorted in descending order by this column. |
141 | | Descending, |
142 | | // There is no defined sort applied to the column. |
143 | | None, |
144 | | // A sort algorithm other than ascending or descending has been applied. |
145 | | Other |
146 | | }; |
147 | | |
148 | | class AriaData { |
149 | | public: |
150 | 0 | AriaData() { } |
151 | | |
152 | 0 | static ErrorOr<NonnullOwnPtr<AriaData>> build_data(ARIAMixin const& mixin) { return adopt_nonnull_own_or_enomem(new (nothrow) AriaData(mixin)); } |
153 | | |
154 | | Optional<String> aria_active_descendant_or_default() const; |
155 | | bool aria_atomic_or_default(bool default_value = false) const; |
156 | | AriaAutocomplete aria_auto_complete_or_default() const; |
157 | | String aria_braille_label_or_default() const; |
158 | | String aria_braille_role_description_or_default() const; |
159 | | bool aria_busy_or_default() const; |
160 | | Tristate aria_checked_or_default() const; |
161 | | Optional<i32> aria_col_count_or_default() const; |
162 | | Optional<i32> aria_col_index_or_default() const; |
163 | | String aria_col_index_text_or_default() const; |
164 | | Optional<i32> aria_col_span_or_default() const; |
165 | | Vector<String> aria_controls_or_default() const; |
166 | | AriaCurrent aria_current_or_default() const; |
167 | | Vector<String> aria_described_by_or_default() const; |
168 | | String aria_description_or_default() const; |
169 | | Optional<String> aria_details_or_default() const; |
170 | | bool aria_disabled_or_default() const; |
171 | | Vector<AriaDropEffect> aria_drop_effect_or_default() const; |
172 | | Optional<String> aria_error_message_or_default() const; |
173 | | Optional<bool> aria_expanded_or_default() const; |
174 | | Vector<String> aria_flow_to_or_default() const; |
175 | | Optional<bool> aria_grabbed_or_default() const; |
176 | | AriaHasPopup aria_has_popup_or_default() const; |
177 | | Optional<bool> aria_hidden_or_default() const; |
178 | | AriaInvalid aria_invalid_or_default() const; |
179 | | String aria_key_shortcuts_or_default() const; |
180 | | String aria_label_or_default() const; |
181 | | Vector<String> aria_labelled_by_or_default() const; |
182 | | Optional<i32> aria_level_or_default() const; |
183 | | AriaLive aria_live_or_default(AriaLive default_value = AriaLive::Off) const; |
184 | | bool aria_modal_or_default() const; |
185 | | bool aria_multi_line_or_default() const; |
186 | | bool aria_multi_selectable_or_default() const; |
187 | | AriaOrientation aria_orientation_or_default(AriaOrientation default_value = AriaOrientation::Undefined) const; |
188 | | Vector<String> aria_owns_or_default() const; |
189 | | String aria_placeholder_or_default() const; |
190 | | Optional<i32> aria_pos_in_set_or_default() const; |
191 | | Tristate aria_pressed_or_default() const; |
192 | | bool aria_read_only_or_default() const; |
193 | | Vector<AriaRelevant> aria_relevant_or_default() const; |
194 | | bool aria_required_or_default() const; |
195 | | String aria_role_description_or_default() const; |
196 | | Optional<i32> aria_row_count_or_default() const; |
197 | | Optional<i32> aria_row_index_or_default() const; |
198 | | String aria_row_index_text_or_default() const; |
199 | | Optional<i32> aria_row_span_or_default() const; |
200 | | Optional<bool> aria_selected_or_default() const; |
201 | | Optional<i32> aria_set_size_or_default() const; |
202 | | AriaSort aria_sort_or_default() const; |
203 | | Optional<f64> aria_value_max_or_default(Optional<f64> default_value = {}) const; |
204 | | Optional<f64> aria_value_min_or_default(Optional<f64> default_value = {}) const; |
205 | | Optional<f64> aria_value_now_or_default() const; |
206 | | String aria_value_text_or_default() const; |
207 | | |
208 | | private: |
209 | | explicit AriaData(ARIAMixin const&); |
210 | | |
211 | | // https://www.w3.org/TR/wai-aria-1.2/#valuetype_true-false |
212 | | // The default value for this value type is false unless otherwise specified. |
213 | | static bool parse_true_false(Optional<String> const&); |
214 | | |
215 | | // https://www.w3.org/TR/wai-aria-1.2/#valuetype_tristate |
216 | | // The default value for this value type is undefined unless otherwise specified. |
217 | | static Tristate parse_tristate(Optional<String> const&); |
218 | | |
219 | | // https://www.w3.org/TR/wai-aria-1.2/#valuetype_true-false-undefined |
220 | | // The default value for this value type is undefined unless otherwise specified. |
221 | | static Optional<bool> parse_true_false_undefined(Optional<String> const&); |
222 | | |
223 | | // https://www.w3.org/TR/wai-aria-1.2/#valuetype_integer |
224 | | static Optional<i32> parse_integer(Optional<String> const&); |
225 | | |
226 | | // https://www.w3.org/TR/wai-aria-1.2/#valuetype_number |
227 | | static Optional<f64> parse_number(Optional<String> const&); |
228 | | |
229 | | static AriaAutocomplete parse_aria_autocomplete(Optional<String> const&); |
230 | | static AriaCurrent parse_aria_current(Optional<String> const&); |
231 | | static Vector<AriaDropEffect> parse_aria_drop_effect(Optional<String> const&); |
232 | | static AriaHasPopup parse_aria_has_popup(Optional<String> const&); |
233 | | static AriaInvalid parse_aria_invalid(Optional<String> const&); |
234 | | static Optional<AriaLive> parse_aria_live(Optional<String> const&); |
235 | | static Optional<AriaOrientation> parse_aria_orientation(Optional<String> const&); |
236 | | static Vector<AriaRelevant> parse_aria_relevant(Optional<String> const&); |
237 | | static AriaSort parse_aria_sort(Optional<String> const&); |
238 | | static Optional<bool> parse_optional_true_false(Optional<String> const&); |
239 | | |
240 | | Optional<String> m_aria_active_descendant; |
241 | | Optional<bool> m_aria_atomic; |
242 | | AriaAutocomplete m_aria_auto_complete; |
243 | | String m_aria_braille_label; |
244 | | String m_aria_braille_role_description; |
245 | | bool m_aria_busy; |
246 | | Tristate m_aria_checked; |
247 | | Optional<i32> m_aria_col_count; |
248 | | Optional<i32> m_aria_col_index; |
249 | | String m_aria_col_index_text; |
250 | | Optional<i32> m_aria_col_span; |
251 | | Vector<String> m_aria_controls; |
252 | | AriaCurrent m_aria_current; |
253 | | Vector<String> m_aria_described_by; |
254 | | String m_aria_description; |
255 | | Optional<String> m_aria_details; |
256 | | bool m_aria_disabled; |
257 | | Vector<AriaDropEffect> m_aria_drop_effect; |
258 | | Optional<String> m_aria_error_message; |
259 | | Optional<bool> m_aria_expanded; |
260 | | Vector<String> m_aria_flow_to; |
261 | | Optional<bool> m_aria_grabbed; |
262 | | AriaHasPopup m_aria_has_popup; |
263 | | Optional<bool> m_aria_hidden; |
264 | | AriaInvalid m_aria_invalid; |
265 | | String m_aria_key_shortcuts; |
266 | | String m_aria_label; |
267 | | Vector<String> m_aria_labelled_by; |
268 | | Optional<i32> m_aria_level; |
269 | | Optional<AriaLive> m_aria_live; |
270 | | bool m_aria_modal; |
271 | | bool m_aria_multi_line; |
272 | | bool m_aria_multi_selectable; |
273 | | Optional<AriaOrientation> m_aria_orientation; |
274 | | Vector<String> m_aria_owns; |
275 | | String m_aria_placeholder; |
276 | | Optional<i32> m_aria_pos_in_set; |
277 | | Tristate m_aria_pressed; |
278 | | bool m_aria_read_only; |
279 | | Vector<AriaRelevant> m_aria_relevant; |
280 | | bool m_aria_required; |
281 | | String m_aria_role_description; |
282 | | Optional<i32> m_aria_row_count; |
283 | | Optional<i32> m_aria_row_index; |
284 | | String m_aria_row_index_text; |
285 | | Optional<i32> m_aria_row_span; |
286 | | Optional<bool> m_aria_selected; |
287 | | Optional<i32> m_aria_set_size; |
288 | | AriaSort m_aria_sort; |
289 | | Optional<f64> m_aria_value_max; |
290 | | Optional<f64> m_aria_value_min; |
291 | | Optional<f64> m_aria_value_now; |
292 | | String m_aria_value_text; |
293 | | }; |
294 | | |
295 | | } |