freya_native_core/
attributes.rs

1use std::str::FromStr;
2
3#[derive(Clone, Copy, PartialEq, Debug, Hash, Eq)]
4pub enum AttributeName {
5    Width,
6    Height,
7    MinWidth,
8    MinHeight,
9    MaxWidth,
10    MaxHeight,
11    VisibleWidth,
12    VisibleHeight,
13    Padding,
14    Background,
15    BackgroundOpacity,
16    Border,
17    Direction,
18    Shadow,
19    CornerRadius,
20    CornerSmoothing,
21    Color,
22    Fill,
23    Stroke,
24    FontSize,
25    FontFamily,
26    FontStyle,
27    FontWeight,
28    FontWidth,
29    MainAlign,
30    CrossAlign,
31    TextAlign,
32    TextShadow,
33    MaxLines,
34    LineHeight,
35    LetterSpacing,
36    WordSpacing,
37    Decoration,
38    DecorationColor,
39    DecorationStyle,
40    TextOverflow,
41    TextHeight,
42    Rotate,
43    Overflow,
44    Margin,
45    Position,
46    PositionTop,
47    PositionRight,
48    PositionBottom,
49    PositionLeft,
50    Opacity,
51    Content,
52    CanvasReference,
53    Layer,
54    OffsetY,
55    OffsetX,
56    Reference,
57    CursorReference,
58    CursorIndex,
59    CursorColor,
60    CursorMode,
61    CursorId,
62    Highlights,
63    HighlightColor,
64    HighlightMode,
65    ImageReference,
66    ImageData,
67    SvgData,
68    SvgContent,
69    Spacing,
70    Scale,
71
72    // Image element
73    AspectRatio,
74    ImageCover,
75    ImageCacheKey,
76    Sampling,
77
78    // Focus
79    A11yId,
80    A11yFocusable,
81    A11yAutoFocus,
82
83    // Some internal notes about these accessibility attributes:
84    //
85    // - These are mostly derived from AccessKit's [`Node`] struct, with minor
86    //   modifications to fit Freya's needs. These modifications are documented.
87    //
88    // - Some properties are commented out, meaning they are yet to be implemented.
89    //   This is typically due to it being unclear how to represent these in Freya's
90    //   attribute system (such as the association types, which will likely need
91    //   some kind of ID system).
92    //
93    // - Any AccessKit properties that can be automatically calculated from style
94    //   attributes or measured from torin are not included here, and are instead
95    //   added in Freya's [`AccessibilityManager`] struct.
96
97    // Vec<NodeIdVec> associations
98    // A11yControls,
99    // A11yDetails,
100    // A11yDescribedBy,
101    // A11yFlowTo,
102    // A11yLabelledBy,
103    // A11yOwns,
104    // A11yRadioGroup,
105
106    // NodeId associations
107    // ActiveDescendant,
108    // A11yErrorMessage,
109    // A11yInPageLinkTarget,
110    A11yMemberOf,
111    // A11yNextOnLine,
112    // A11yPreviousOnLine,
113    // A11yPopupFor,
114
115    // String
116    A11yName,
117    A11yDescription,
118    A11yValue,
119    A11yAccessKey,
120    A11yAuthorId,
121    // These three attributes are intended for assistive tech that parse MathML,
122    // which we don't support at the moment anyways. Unlikely to be implemented.
123    // A11yClassName,
124    // A11yHtmlTag,
125    // A11yInnerHtml,
126    A11yKeyboardShortcut,
127    A11yLanguage,
128    A11yPlaceholder,
129    A11yRoleDescription,
130    A11yStateDescription,
131    A11yTooltip,
132    A11yUrl,
133    A11yRowIndexText,
134    A11yColumnIndexText,
135
136    // f64
137    A11yScrollX,
138    A11yScrollXMin,
139    A11yScrollXMax,
140    A11yScrollY,
141    A11yScrollYMin,
142    A11yScrollYMax,
143    A11yNumericValue,
144    A11yMinNumericValue,
145    A11yMaxNumericValue,
146    A11yNumericValueStep,
147    A11yNumericValueJump,
148
149    // usize
150    A11yRowCount,
151    A11yColumnCount,
152    A11yRowIndex,
153    A11yColumnIndex,
154    A11yRowSpan,
155    A11yColumnSpan,
156    A11yLevel,
157    A11ySizeOfSet,
158    A11yPositionInSet,
159
160    // Color
161    A11yColorValue,
162
163    // TODO: The following two categories are for inline text. They should be implemented
164    //       automatically in [`AccessibilityManager`] based on Skia text measurement on text.
165    //       spans. These really shouldn't be here (they should never have to be manually provided
166    //       as an attribute), but I've left them here as a reminder to implement inline text data.
167    //
168    // See AccessKit's documentation for inline text measurements here:
169    // - <https://docs.rs/accesskit/latest/accesskit/struct.Node.html#method.character_lengths>
170    //
171    // Chromium also has a good writeup on how it measures inline text spans:
172    // - <https://chromium.googlesource.com/chromium/src.git/+/HEAD/docs/accessibility/overview.md#text-bounding-boxes>
173
174    // LengthSlice
175    // A11yCharacterLengths,
176    // A11yWordLengths,
177
178    // CoordSlice
179    // A11yCharacterPositions,
180    // A11yCharacterWidths,
181
182    // bool
183    A11yExpanded,
184    A11ySelected,
185
186    // bitflag
187    // TODO: This might be able to be determined automatically,
188    //       but i'm not sure what ARIA property it corresponds to
189    //       or its actual purpose.
190    A11yHidden,
191    A11yMultiselectable,
192    A11yRequired,
193    A11yVisited,
194    A11yBusy,
195    A11yLiveAtomic,
196    A11yModal,
197    A11yTouchTransparent,
198    A11yReadOnly,
199    A11yDisabled,
200    A11yIsSpellingError,
201    A11yIsGrammarError,
202    A11yIsSearchMatch,
203    A11yIsSuggestion,
204
205    // Unique enums
206    A11yRole,
207    A11yInvalid,
208    A11yToggled,
209    A11yLive,
210    A11yDefaultActionVerb,
211    A11yOrientation,
212    A11ySortDirection,
213    A11yCurrent, // called AriaCurrent in accesskit, but that's a pretty poor name
214    A11yAutoComplete,
215    A11yHasPopup,
216    // This one is kind of weird to include, given it's reflecting a CSS property
217    // not in Freya for the HTML <ul>/<li> tags, but it can maybe be useful for
218    // language-specific semantics.
219    A11yListStyle,
220    A11yVerticalOffset,
221    // Other
222    // This could probably be inferred from Freya's text editing hook, but it's also
223    // a little strange in the data it expects.
224    // A11yTextSelection,
225    // A11yCustomActions, // Needs a special syntax or custom attribute value'
226
227    // TODO: Some way to specify builtin AccessKit actions, as well as a way to
228    //       handle actions in the form of an event.
229}
230
231impl FromStr for AttributeName {
232    type Err = String;
233
234    fn from_str(attr: &str) -> Result<Self, Self::Err> {
235        match attr {
236            "width" => Ok(AttributeName::Width),
237            "height" => Ok(AttributeName::Height),
238            "min_width" => Ok(AttributeName::MinWidth),
239            "min_height" => Ok(AttributeName::MinHeight),
240            "max_width" => Ok(AttributeName::MaxWidth),
241            "max_height" => Ok(AttributeName::MaxHeight),
242            "visible_width" => Ok(AttributeName::VisibleWidth),
243            "visible_height" => Ok(AttributeName::VisibleHeight),
244            "padding" => Ok(AttributeName::Padding),
245            "background" => Ok(AttributeName::Background),
246            "background_opacity" => Ok(AttributeName::BackgroundOpacity),
247            "border" => Ok(AttributeName::Border),
248            "direction" => Ok(AttributeName::Direction),
249            "shadow" => Ok(AttributeName::Shadow),
250            "corner_radius" => Ok(AttributeName::CornerRadius),
251            "corner_smoothing" => Ok(AttributeName::CornerSmoothing),
252            "color" => Ok(AttributeName::Color),
253            "fill" => Ok(AttributeName::Fill),
254            "stroke" => Ok(AttributeName::Stroke),
255            "font_size" => Ok(AttributeName::FontSize),
256            "font_family" => Ok(AttributeName::FontFamily),
257            "font_style" => Ok(AttributeName::FontStyle),
258            "font_weight" => Ok(AttributeName::FontWeight),
259            "font_width" => Ok(AttributeName::FontWidth),
260            "main_align" => Ok(AttributeName::MainAlign),
261            "cross_align" => Ok(AttributeName::CrossAlign),
262            "text_align" => Ok(AttributeName::TextAlign),
263            "text_shadow" => Ok(AttributeName::TextShadow),
264            "max_lines" => Ok(AttributeName::MaxLines),
265            "line_height" => Ok(AttributeName::LineHeight),
266            "letter_spacing" => Ok(AttributeName::LetterSpacing),
267            "word_spacing" => Ok(AttributeName::WordSpacing),
268            "decoration" => Ok(AttributeName::Decoration),
269            "decoration_color" => Ok(AttributeName::DecorationColor),
270            "decoration_style" => Ok(AttributeName::DecorationStyle),
271            "text_overflow" => Ok(AttributeName::TextOverflow),
272            "text_height" => Ok(AttributeName::TextHeight),
273            "rotate" => Ok(AttributeName::Rotate),
274            "overflow" => Ok(AttributeName::Overflow),
275            "margin" => Ok(AttributeName::Margin),
276            "position" => Ok(AttributeName::Position),
277            "position_top" => Ok(AttributeName::PositionTop),
278            "position_right" => Ok(AttributeName::PositionRight),
279            "position_bottom" => Ok(AttributeName::PositionBottom),
280            "position_left" => Ok(AttributeName::PositionLeft),
281            "opacity" => Ok(AttributeName::Opacity),
282            "content" => Ok(AttributeName::Content),
283            "canvas_reference" => Ok(AttributeName::CanvasReference),
284            "layer" => Ok(AttributeName::Layer),
285            "offset_y" => Ok(AttributeName::OffsetY),
286            "offset_x" => Ok(AttributeName::OffsetX),
287            "reference" => Ok(AttributeName::Reference),
288            "cursor_reference" => Ok(AttributeName::CursorReference),
289            "cursor_index" => Ok(AttributeName::CursorIndex),
290            "cursor_color" => Ok(AttributeName::CursorColor),
291            "cursor_mode" => Ok(AttributeName::CursorMode),
292            "cursor_id" => Ok(AttributeName::CursorId),
293            "highlights" => Ok(AttributeName::Highlights),
294            "highlight_color" => Ok(AttributeName::HighlightColor),
295            "highlight_mode" => Ok(AttributeName::HighlightMode),
296            "image_reference" => Ok(AttributeName::ImageReference),
297            "image_data" => Ok(AttributeName::ImageData),
298            "svg_data" => Ok(AttributeName::SvgData),
299            "svg_content" => Ok(AttributeName::SvgContent),
300            "spacing" => Ok(AttributeName::Spacing),
301            "scale" => Ok(AttributeName::Scale),
302            "aspect_ratio" => Ok(AttributeName::AspectRatio),
303            "cover" => Ok(AttributeName::ImageCover),
304            "cache_key" => Ok(AttributeName::ImageCacheKey),
305            "sampling" => Ok(AttributeName::Sampling),
306            "a11y_id" => Ok(AttributeName::A11yId),
307            "a11y_focusable" => Ok(AttributeName::A11yFocusable),
308            "a11y_auto_focus" => Ok(AttributeName::A11yAutoFocus),
309            "a11y_name" => Ok(AttributeName::A11yName),
310            "a11y_description" => Ok(AttributeName::A11yDescription),
311            "a11y_value" => Ok(AttributeName::A11yValue),
312            "a11y_access_key" => Ok(AttributeName::A11yAccessKey),
313            "a11y_author_id" => Ok(AttributeName::A11yAuthorId),
314            "a11y_keyboard_shortcut" => Ok(AttributeName::A11yKeyboardShortcut),
315            "a11y_language" => Ok(AttributeName::A11yLanguage),
316            "a11y_placeholder" => Ok(AttributeName::A11yPlaceholder),
317            "a11y_role_description" => Ok(AttributeName::A11yRoleDescription),
318            "a11y_state_description" => Ok(AttributeName::A11yStateDescription),
319            "a11y_tooltip" => Ok(AttributeName::A11yTooltip),
320            "a11y_url" => Ok(AttributeName::A11yUrl),
321            "a11y_row_index_text" => Ok(AttributeName::A11yRowIndexText),
322            "a11y_column_index_text" => Ok(AttributeName::A11yColumnIndexText),
323            "a11y_scroll_x" => Ok(AttributeName::A11yScrollX),
324            "a11y_scroll_x_min" => Ok(AttributeName::A11yScrollXMin),
325            "a11y_scroll_x_max" => Ok(AttributeName::A11yScrollXMax),
326            "a11y_scroll_y" => Ok(AttributeName::A11yScrollY),
327            "a11y_scroll_y_min" => Ok(AttributeName::A11yScrollYMin),
328            "a11y_scroll_y_max" => Ok(AttributeName::A11yScrollYMax),
329            "a11y_numeric_value" => Ok(AttributeName::A11yNumericValue),
330            "a11y_min_numeric_value" => Ok(AttributeName::A11yMinNumericValue),
331            "a11y_max_numeric_value" => Ok(AttributeName::A11yMaxNumericValue),
332            "a11y_numeric_value_step" => Ok(AttributeName::A11yNumericValueStep),
333            "a11y_numeric_value_jump" => Ok(AttributeName::A11yNumericValueJump),
334            "a11y_row_count" => Ok(AttributeName::A11yRowCount),
335            "a11y_column_count" => Ok(AttributeName::A11yColumnCount),
336            "a11y_row_index" => Ok(AttributeName::A11yRowIndex),
337            "a11y_column_index" => Ok(AttributeName::A11yColumnIndex),
338            "a11y_row_span" => Ok(AttributeName::A11yRowSpan),
339            "a11y_column_span" => Ok(AttributeName::A11yColumnSpan),
340            "a11y_level" => Ok(AttributeName::A11yLevel),
341            "a11y_size_of_set" => Ok(AttributeName::A11ySizeOfSet),
342            "a11y_position_in_set" => Ok(AttributeName::A11yPositionInSet),
343            "a11y_color_value" => Ok(AttributeName::A11yColorValue),
344            "a11y_expanded" => Ok(AttributeName::A11yExpanded),
345            "a11y_selected" => Ok(AttributeName::A11ySelected),
346            "a11y_hidden" => Ok(AttributeName::A11yHidden),
347            "a11y_multiselectable" => Ok(AttributeName::A11yMultiselectable),
348            "a11y_required" => Ok(AttributeName::A11yRequired),
349            "a11y_visited" => Ok(AttributeName::A11yVisited),
350            "a11y_busy" => Ok(AttributeName::A11yBusy),
351            "a11y_live_atomic" => Ok(AttributeName::A11yLiveAtomic),
352            "a11y_modal" => Ok(AttributeName::A11yModal),
353            "a11y_touch_transparent" => Ok(AttributeName::A11yTouchTransparent),
354            "a11y_read_only" => Ok(AttributeName::A11yReadOnly),
355            "a11y_disabled" => Ok(AttributeName::A11yDisabled),
356            "a11y_is_spelling_error" => Ok(AttributeName::A11yIsSpellingError),
357            "a11y_is_grammar_error" => Ok(AttributeName::A11yIsGrammarError),
358            "a11y_is_search_match" => Ok(AttributeName::A11yIsSearchMatch),
359            "a11y_is_suggestion" => Ok(AttributeName::A11yIsSuggestion),
360            "a11y_role" => Ok(AttributeName::A11yRole),
361            "a11y_invalid" => Ok(AttributeName::A11yInvalid),
362            "a11y_toggled" => Ok(AttributeName::A11yToggled),
363            "a11y_live" => Ok(AttributeName::A11yLive),
364            "a11y_default_action_verb" => Ok(AttributeName::A11yDefaultActionVerb),
365            "a11y_orientation" => Ok(AttributeName::A11yOrientation),
366            "a11y_sort_direction" => Ok(AttributeName::A11ySortDirection),
367            "a11y_current" => Ok(AttributeName::A11yCurrent),
368            "a11y_auto_complete" => Ok(AttributeName::A11yAutoComplete),
369            "a11y_has_popup" => Ok(AttributeName::A11yHasPopup),
370            "a11y_list_style" => Ok(AttributeName::A11yListStyle),
371            "a11y_vertical_offset" => Ok(AttributeName::A11yVerticalOffset),
372            "a11y_member_of" => Ok(AttributeName::A11yMemberOf),
373            _ => Err(format!("{attr} not supported.")),
374        }
375    }
376}