1 | use serde::{Deserialize, Serialize}; |
2 | use zvariant::Type; |
3 | |
4 | use crate::AtspiError; |
5 | |
6 | #[derive (Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type, Hash)] |
7 | /// An accessible object role. |
8 | /// To think of it in terms of HTML, any semantic element likely has a corollary in this enum. |
9 | /// For example: `<button>`, `<input>`, `<form>` or `<h4>`. |
10 | /// Non-semantic elements like `<span>`, `<div>` and `<b>` will not be represented here, and this information is not passed through via the atspi library. |
11 | /// TODO: add examples for GTK/Qt libraries in addition to HTML examples. |
12 | #[repr (u32)] |
13 | pub enum Role { |
14 | /// A role indicating an error condition, such as uninitialized Role data, or an error deserializing. |
15 | Invalid, |
16 | /// Object is a label indicating the keyboard accelerators for the parent. |
17 | AcceleratorLabel, |
18 | /// Object is used to alert the user about something. |
19 | Alert, |
20 | /// Object contains a dynamic or moving image of some kind. |
21 | Animation, |
22 | /// Object is a 2d directional indicator. |
23 | Arrow, |
24 | /// Object contains one or more dates, usually arranged into a 2d list. |
25 | Calendar, |
26 | /// Object that can be drawn into and is used to trap events. |
27 | Canvas, |
28 | /// A choice that can be checked or unchecked and provides a separate indicator for the current state. |
29 | CheckBox, |
30 | /// A menu item that behaves like a check box. See [`Self::CheckBox`]. |
31 | CheckMenuItem, |
32 | /// A specialized dialog that lets the user choose a color. |
33 | ColorChooser, |
34 | /// The header for a column of data. |
35 | ColumnHeader, |
36 | /// A list of choices the user can select from. |
37 | ComboBox, |
38 | /// An object which allows entry of a date. |
39 | DateEditor, |
40 | /// An inconifed internal frame within a [`Role::DesktopFrame`]. |
41 | DesktopIcon, |
42 | /// A pane that supports internal frames and iconified versions of those internal frames. |
43 | DesktopFrame, |
44 | /// An object that allows a value to be changed via rotating a visual element, or which displays a value via such a rotating element. |
45 | Dial, |
46 | /// A top level window with title bar and a border. |
47 | Dialog, |
48 | /// A pane that allows the user to navigate through and select the contents of a directory. |
49 | DirectoryPane, |
50 | /// An object used for drawing custom user interface elements. |
51 | DrawingArea, |
52 | /// A specialized dialog that displays the files in the directory and lets the user select a file, browse a different directory, or specify a filename. |
53 | FileChooser, |
54 | /// A object that fills up space in a user interface. |
55 | Filler, |
56 | /// Don't use, reserved for future use. |
57 | FocusTraversable, |
58 | /// Allows selection of a display font. |
59 | FontChooser, |
60 | /// A top level window with a title bar, border, menubar, etc. |
61 | Frame, |
62 | /// A pane that is guaranteed to be painted on top of all panes beneath it. |
63 | GlassPane, |
64 | /// A document container for HTML, whose children represent the document content. |
65 | HTMLContainer, |
66 | /// A small fixed size picture, typically used to decorate components. |
67 | Icon, |
68 | /// An image, typically static. |
69 | Image, |
70 | /// A frame-like object that is clipped by a desktop pane. |
71 | InternalFrame, |
72 | /// An object used to present an icon or short string in an interface. |
73 | Label, |
74 | /// A specialized pane that allows its children to be drawn in layers, providing a form of stacking order. |
75 | LayeredPane, |
76 | /// An object that presents a list of objects to the user and * allows the user to select one or more of them. |
77 | List, |
78 | /// An object that represents an element of a list. |
79 | ListItem, |
80 | /// An object usually found inside a menu bar that contains a list of actions the user can choose from. |
81 | Menu, |
82 | /// An object usually drawn at the top of the primary dialog box of an application that contains a list of menus the user can choose from. |
83 | MenuBar, |
84 | /// An object usually contained in a menu that presents an action the user can choose. |
85 | MenuItem, |
86 | /// A specialized pane whose primary use is inside a dialog. |
87 | OptionPane, |
88 | /// An object that is a child of a page tab list. |
89 | PageTab, |
90 | /// An object that presents a series of panels (or page tabs), one at a time,through some mechanism provided by the object. |
91 | PageTabList, |
92 | /// A generic container that is often used to group objects. |
93 | Panel, |
94 | /// A text object uses for passwords, or other places where the text content is not shown visibly to the user. |
95 | PasswordText, |
96 | /// A temporary window that is usually used to offer the user a list of choices, and then hides when the user selects one of those choices. |
97 | PopupMenu, |
98 | /// An object used to indicate how much of a task has been completed. |
99 | ProgressBar, |
100 | /// An object the user can manipulate to tell the application to do something. |
101 | PushButton, |
102 | /// A specialized check box that will cause other radio buttons in the same group to become unchecked when this one is checked. |
103 | RadioButton, |
104 | /// Object is both a menu item and a "radio button". See [`Self::RadioButton`]. |
105 | RadioMenuItem, |
106 | /// A specialized pane that has a glass pane and a layered pane as its children. |
107 | RootPane, |
108 | /// The header for a row of data. |
109 | RowHeader, |
110 | /// An object usually used to allow a user to incrementally view a large amount of data by moving the bounds of a viewport along a one-dimensional axis. |
111 | ScrollBar, |
112 | /// A scroll pane: the pane in which the scrollable content is contained within. |
113 | /// An object that allows a user to incrementally view a large amount of information. |
114 | /// [`Self::ScrollPane`] objects are usually accompanied by [`Self::ScrollBar`] controllers, |
115 | /// on which the [`crate::RelationType::ControllerFor`] and [`crate::RelationType::ControlledBy`] reciprocal relations are set. |
116 | ScrollPane, |
117 | /// An object usually contained in a menu to provide a visible and logical separation of the contents in a menu. |
118 | Separator, |
119 | /// An object that allows the user to select from a bounded range. |
120 | /// Unlike [`Self::ScrollBar`], [`Self::Slider`] objects need not control 'viewport'-like objects. |
121 | Slider, |
122 | /// An object which allows one of a set of choices to be selected, and which displays the current choice. |
123 | SpinButton, |
124 | /// A specialized panel that presents two other panels at the same time. |
125 | SplitPane, |
126 | /// Object displays non-quantitative status information (c.f. [`Self::ProgressBar`]) |
127 | StatusBar, |
128 | /// An object used to represent information in terms of rows and columns. |
129 | Table, |
130 | /// A 'cell' or discrete child within a Table. |
131 | /// Note: Table cells need not have [`Self::TableCell`], other [`crate::Role`] values are valid as well. |
132 | TableCell, |
133 | /// An object which labels a particular column in an [`Self::Table`]. |
134 | TableColumnHeader, |
135 | /// An object which labels a particular row in a [`Self::Table`]. |
136 | /// `TableProxy` rows and columns may also be labelled via the |
137 | /// [`crate::RelationType::LabelFor`]/[`crate::RelationType::LabelledBy`] relationships. |
138 | /// See: `AccessibleProxy::get_relation_type`. |
139 | TableRowHeader, |
140 | /// Object allows menu to be removed from menubar and shown in its own window. |
141 | TearoffMenuItem, |
142 | /// An object that emulates a terminal. |
143 | Terminal, |
144 | /// An interactive widget that supports multiple lines of text and optionally accepts user input, |
145 | /// but whose purpose is not to solicit user input. |
146 | /// Thus [`Self::Text`] is appropriate for the text view in a plain text editor but inappropriate for an input field in a dialog box or web form. |
147 | /// For widgets whose purpose is to solicit input from the user, see [`Self::Entry`] and [`Self::PasswordText`]. |
148 | /// For generic objects which display a brief amount of textual information, see [`Self::Static`]. |
149 | Text, |
150 | /// A specialized push button that can be checked or unchecked, but does not provide a separate indicator for the current state. |
151 | ToggleButton, |
152 | /// A bar or palette usually composed of push buttons or toggle buttons. |
153 | ToolBar, |
154 | /// An object that provides information about another object. |
155 | ToolTip, |
156 | /// An object used to repsent hierarchical information to the user. |
157 | Tree, |
158 | /// An object that presents both tabular and hierarchical info to the user. |
159 | TreeTable, |
160 | /// When the role cannot be accurately reported, this role will be set. |
161 | Unknown, |
162 | /// An object usually used in a scroll pane, or to otherwise clip a larger object or content renderer to a specific onscreen viewport. |
163 | Viewport, |
164 | /// A top level window with no title or border. |
165 | Window, |
166 | /// means that the role for this item is known, but not included in the core enumeration. |
167 | Extended, |
168 | /// An object that serves as a document header. |
169 | Header, |
170 | /// An object that serves as a document footer. |
171 | Footer, |
172 | /// An object which is contains a single paragraph of text content. See also [`Self::Text`]. |
173 | Paragraph, |
174 | /// An object which describes margins and tab stops, etc. for text objects which it controls (should have [`crate::RelationType::ControllerFor`] relation to such). |
175 | Ruler, |
176 | /// An object corresponding to the toplevel accessible of an application, which may contain [`Self::Frame`] objects or other accessible objects. |
177 | /// Children of objects with the [`Self::DesktopFrame`] role are generally [`Self::Application`] objects. |
178 | Application, |
179 | /// The object is a dialog or list containing items for insertion into an entry widget, for instance a list of words for completion of a text entry. |
180 | Autocomplete, |
181 | /// The object is an editable text object in a toolbar. |
182 | Editbar, |
183 | /// The object is an embedded component container. |
184 | /// This role is a "grouping" hint that the contained objects share a context which is different from the container in which this accessible is embedded. |
185 | /// In particular, it is used for some kinds of document embedding, and for embedding of out-of-process component, "panel applets", etc. |
186 | Embedded, |
187 | /// The object is a component whose textual content may be entered or modified by the user, provided [`crate::State::Editable`] is present. |
188 | /// A readonly [`Self::Entry`] object (i.e. where [`crate::State::Editable`] is not present) implies a read-only 'text field' in a form, as opposed to a title, label, or caption. |
189 | Entry, |
190 | /// The object is a graphical depiction of quantitative data. |
191 | /// It may contain multiple subelements whose attributes and/or description may be queried to obtain both the quantitative data and information about how the data is being presented. |
192 | /// The [`crate::RelationType::LabelledBy`] relation is particularly important in interpreting objects of this type, as is the accessible description property. |
193 | /// See [`Self::Caption`]. |
194 | CHART, |
195 | /// The object contains descriptive information, usually textual, about another user interface element such as a table, chart, or image. |
196 | Caption, |
197 | /// The object is a visual frame or container which |
198 | /// contains a view of document content. [`Self::DocumentFrame`]s may occur within |
199 | /// another `DocumentProxy` instance, in which case the second document may be |
200 | /// said to be embedded in the containing instance. |
201 | /// HTML frames are often [`Self::DocumentFrame`]: Either this object, or a singleton descendant, |
202 | /// should implement the [`crate::Interface::Document`] interface. |
203 | DocumentFrame, |
204 | /// Heading: this is a heading with a level (usually 1-6). This is represented by `<h1>` through `<h6>` in HTML. |
205 | /// The object serves as a heading for content which follows it in a document. |
206 | /// The 'heading level' of the heading, if available, may be obtained by querying the object's attributes. |
207 | Heading, |
208 | /// The object is a containing instance which encapsulates a page of information. |
209 | /// [`Self::Page`] is used in documents and content which support a paginated navigation model. |
210 | Page, |
211 | /// The object is a containing instance of document content which constitutes a particular 'logical' section of the document. |
212 | /// The type of content within a section, and the nature of the section division itself, may be obtained by querying the object's attributes. |
213 | /// Sections may be nested. |
214 | Section, |
215 | /// The object is redundant with another object in the hierarchy, and is exposed for purely technical reasons. |
216 | /// Objects of this role should be ignored by clients, if they are encountered at all. |
217 | RedundantObject, |
218 | /// The object is a containing instance of document content which has within it components with which the user can interact in order to input information; |
219 | /// i.e. the object is a container for pushbuttons, comboboxes, text input fields, and other 'GUI' components. |
220 | /// [`Self::Form`] should not, in general, be used for toplevel GUI containers or dialogs, but should be reserved for 'GUI' containers which occur within document content, for instance within Web documents, presentations, or text documents. |
221 | /// Unlike other GUI containers and dialogs which occur inside application instances, [`Self::Form`] containers' components are associated with the current document, rather than the current foreground application or viewer instance. |
222 | Form, |
223 | /// The object is a hypertext anchor, i.e. a "link" in a hypertext document. |
224 | /// Such objects are distinct from 'inline' content which may also use the [`crate::Interface::Hypertext`]/[`crate::Interface::Hyperlink`] interfaces to indicate the range/location within a text object where an inline or embedded object lies. |
225 | Link, |
226 | /// The object is a window or similar viewport which is used to allow composition or input of a 'complex character', in other words it is an "input method window". |
227 | InputMethodWindow, |
228 | /// A row in a table. |
229 | TableRow, |
230 | /// An object that represents an element of a tree. |
231 | TreeItem, |
232 | /// A document frame which contains a spreadsheet. |
233 | DocumentSpreadsheet, |
234 | /// A document frame which contains a presentation or slide content. |
235 | DocumentPresentation, |
236 | /// A document frame which contains textual content, such as found in a word processing application. |
237 | DocumentText, |
238 | /// A document frame which contains HTML or other markup suitable for display in a web browser. |
239 | DocumentWeb, |
240 | /// A document frame which contains email content to be displayed or composed either in plain text or HTML. |
241 | DocumentEmail, |
242 | /// An object found within a document and designed to present a comment, note, or other annotation. |
243 | /// In some cases, this object might not be visible until activated. |
244 | Comment, |
245 | /// A non-collapsible list of choices the user can select from. |
246 | ListBox, |
247 | /// A group of related widgets. This group typically has a label. |
248 | Grouping, |
249 | /// An image map object. Usually a graphic with multiple hotspots, where each hotspot can be activated resulting in the loading of another document or section of a document. |
250 | ImageMap, |
251 | /// A transitory object designed to present a message to the user, typically at the desktop level rather than inside a particular application. |
252 | Notification, |
253 | /// An object designed to present a message to the user within an existing window. |
254 | InfoBar, |
255 | /// A bar that serves as a level indicator to, for instance, show the strength of a password or the state of a battery. |
256 | LevelBar, |
257 | /// A bar that serves as the title of a window or a dialog. |
258 | TitleBar, |
259 | /// An object which contains a text section that is quoted from another source. |
260 | BlockQuote, |
261 | /// An object which represents an audio element. |
262 | Audio, |
263 | /// An object which represents a video element. |
264 | Video, |
265 | /// A definition of a term or concept. |
266 | Definition, |
267 | /// A section of a page that consists of a composition that forms an independent part of a document, page, or site. |
268 | /// Examples: A blog entry, a news story, a forum post. |
269 | Article, |
270 | /// A region of a web page intended as a navigational landmark. This is designed to allow Assistive Technologies to provide quick navigation among key regions within a document. |
271 | Landmark, |
272 | /// A text widget or container holding log content, such as chat history and error logs. In this role there is a relationship between the arrival of new items in the log and the reading order. |
273 | /// The log contains a meaningful sequence and new information is added only to the end of the log, not at arbitrary points. |
274 | Log, |
275 | /// A container where non-essential information changes frequently. |
276 | /// Common usages of marquee include stock tickers and ad banners. |
277 | /// The primary difference between a marquee and a log is that logs usually have a meaningful order or sequence of important content changes. |
278 | Marquee, |
279 | /// A text widget or container that holds a mathematical expression. |
280 | Math, |
281 | /// A rating system, generally out of five stars, but it does not need to be that way. There is no tag nor role for this in HTML, however. |
282 | /// A widget whose purpose is to display a rating, such as the number of stars associated with a song in a media player. |
283 | /// Objects of this role should also implement [`crate::Interface::Value`]. |
284 | Rating, |
285 | /// An object containing a numerical counter which indicates an amount of elapsed time from a start point, or the time remaining until an end point. |
286 | Timer, |
287 | /// A generic non-container object whose purpose is to display a brief amount of information to the user and whose role is known by the implementor but lacks semantic value for the user. |
288 | /// Examples in which [`Self::Static`] is appropriate include the message displayed in a message box and an image used as an alternative means to display text. |
289 | /// [`Self::Static`] should not be applied to widgets which are traditionally interactive, objects which display a significant amount of content, or any object which has an accessible relation pointing to another object. |
290 | /// The displayed information, as a general rule, should be exposed through the accessible name of the object. |
291 | /// For labels which describe another widget, see [`Self::Label`]. |
292 | /// For text views, see [`Self::Text`]. |
293 | /// For generic containers, see [`Self::Panel`]. For objects whose role is not known by the implementor, see [`Self::Unknown`]. |
294 | Static, |
295 | /// An object that represents a mathematical fraction. |
296 | MathFraction, |
297 | /// An object that represents a mathematical expression displayed with a radical. |
298 | MathRoot, |
299 | /// An object that contains text that is displayed as a subscript. |
300 | Subscript, |
301 | /// An object that contains text that is displayed as a superscript. |
302 | Superscript, |
303 | /// An object that represents a list of term-value groups. |
304 | /// A term-value group represents an individual description and consist of one or more names ([`Self::DescriptionTerm`]) followed by one or more values ([`Self::DescriptionValue`]). |
305 | /// For each list, there should not be more than one group with the same term name. |
306 | DescriptionList, |
307 | /// An object that represents a term or phrase with a corresponding definition. |
308 | DescriptionTerm, |
309 | /// An object that represents the description, definition, or value of a term. |
310 | DescriptionValue, |
311 | /// An object that contains the text of a footnote. |
312 | Footnote, |
313 | /// Content previously deleted or proposed to be deleted, e.g. in revision history or a content view providing suggestions from reviewers. |
314 | ContentDeletion, |
315 | /// Content previously inserted or proposed to be inserted, e.g. in revision history or a content view providing suggestions from reviewers. |
316 | ContentInsertion, |
317 | /// A run of content that is marked or highlighted, such as for reference purposes, or to call it out as having a special purpose. |
318 | /// If the marked content has an associated section in the document elaborating on the reason for the mark, then [`crate::RelationType::Details`] should be used on the mark to point to that associated section. |
319 | /// In addition, the reciprocal relation [`crate::RelationType::DetailsFor`] should be used on the associated content section to point back to the mark. |
320 | Mark, |
321 | /// A container for content that is called out as a proposed change from the current version of the document, such as by a reviewer of the content. |
322 | /// An object with this role should include children with [`Self::ContentDeletion`] and/or [`Self::ContentInsertion`], in any order, to indicate what the actual change is. |
323 | Suggestion, |
324 | /// A specialized push button to open a menu. |
325 | PushButtonMenu, |
326 | } |
327 | |
328 | impl TryFrom<u32> for Role { |
329 | type Error = AtspiError; |
330 | |
331 | #[allow (clippy::too_many_lines)] |
332 | fn try_from(value: u32) -> Result<Self, Self::Error> { |
333 | #[allow (clippy::enum_glob_use)] |
334 | use Role::*; |
335 | let res = match value { |
336 | 0 => Invalid, |
337 | 1 => AcceleratorLabel, |
338 | 2 => Alert, |
339 | 3 => Animation, |
340 | 4 => Arrow, |
341 | 5 => Calendar, |
342 | 6 => Canvas, |
343 | 7 => CheckBox, |
344 | 8 => CheckMenuItem, |
345 | 9 => ColorChooser, |
346 | 10 => ColumnHeader, |
347 | 11 => ComboBox, |
348 | 12 => DateEditor, |
349 | 13 => DesktopIcon, |
350 | 14 => DesktopFrame, |
351 | 15 => Dial, |
352 | 16 => Dialog, |
353 | 17 => DirectoryPane, |
354 | 18 => DrawingArea, |
355 | 19 => FileChooser, |
356 | 20 => Filler, |
357 | 21 => FocusTraversable, |
358 | 22 => FontChooser, |
359 | 23 => Frame, |
360 | 24 => GlassPane, |
361 | 25 => HTMLContainer, |
362 | 26 => Icon, |
363 | 27 => Image, |
364 | 28 => InternalFrame, |
365 | 29 => Label, |
366 | 30 => LayeredPane, |
367 | 31 => List, |
368 | 32 => ListItem, |
369 | 33 => Menu, |
370 | 34 => MenuBar, |
371 | 35 => MenuItem, |
372 | 36 => OptionPane, |
373 | 37 => PageTab, |
374 | 38 => PageTabList, |
375 | 39 => Panel, |
376 | 40 => PasswordText, |
377 | 41 => PopupMenu, |
378 | 42 => ProgressBar, |
379 | 43 => PushButton, |
380 | 44 => RadioButton, |
381 | 45 => RadioMenuItem, |
382 | 46 => RootPane, |
383 | 47 => RowHeader, |
384 | 48 => ScrollBar, |
385 | 49 => ScrollPane, |
386 | 50 => Separator, |
387 | 51 => Slider, |
388 | 52 => SpinButton, |
389 | 53 => SplitPane, |
390 | 54 => StatusBar, |
391 | 55 => Table, |
392 | 56 => TableCell, |
393 | 57 => TableColumnHeader, |
394 | 58 => TableRowHeader, |
395 | 59 => TearoffMenuItem, |
396 | 60 => Terminal, |
397 | 61 => Text, |
398 | 62 => ToggleButton, |
399 | 63 => ToolBar, |
400 | 64 => ToolTip, |
401 | 65 => Tree, |
402 | 66 => TreeTable, |
403 | 67 => Unknown, |
404 | 68 => Viewport, |
405 | 69 => Window, |
406 | 70 => Extended, |
407 | 71 => Header, |
408 | 72 => Footer, |
409 | 73 => Paragraph, |
410 | 74 => Ruler, |
411 | 75 => Application, |
412 | 76 => Autocomplete, |
413 | 77 => Editbar, |
414 | 78 => Embedded, |
415 | 79 => Entry, |
416 | 80 => CHART, |
417 | 81 => Caption, |
418 | 82 => DocumentFrame, |
419 | 83 => Heading, |
420 | 84 => Page, |
421 | 85 => Section, |
422 | 86 => RedundantObject, |
423 | 87 => Form, |
424 | 88 => Link, |
425 | 89 => InputMethodWindow, |
426 | 90 => TableRow, |
427 | 91 => TreeItem, |
428 | 92 => DocumentSpreadsheet, |
429 | 93 => DocumentPresentation, |
430 | 94 => DocumentText, |
431 | 95 => DocumentWeb, |
432 | 96 => DocumentEmail, |
433 | 97 => Comment, |
434 | 98 => ListBox, |
435 | 99 => Grouping, |
436 | 100 => ImageMap, |
437 | 101 => Notification, |
438 | 102 => InfoBar, |
439 | 103 => LevelBar, |
440 | 104 => TitleBar, |
441 | 105 => BlockQuote, |
442 | 106 => Audio, |
443 | 107 => Video, |
444 | 108 => Definition, |
445 | 109 => Article, |
446 | 110 => Landmark, |
447 | 111 => Log, |
448 | 112 => Marquee, |
449 | 113 => Math, |
450 | 114 => Rating, |
451 | 115 => Timer, |
452 | 116 => Static, |
453 | 117 => MathFraction, |
454 | 118 => MathRoot, |
455 | 119 => Subscript, |
456 | 120 => Superscript, |
457 | 121 => DescriptionList, |
458 | 122 => DescriptionTerm, |
459 | 123 => DescriptionValue, |
460 | 124 => Footnote, |
461 | 125 => ContentDeletion, |
462 | 126 => ContentInsertion, |
463 | 127 => Mark, |
464 | 128 => Suggestion, |
465 | 129 => PushButtonMenu, |
466 | _ => return Err(AtspiError::UnknownRole(value)), |
467 | }; |
468 | Ok(res) |
469 | } |
470 | } |
471 | |
472 | #[cfg (test)] |
473 | pub mod tests { |
474 | use super::Role; |
475 | use zvariant::{from_slice, to_bytes, EncodingContext}; |
476 | |
477 | const HIGHEST_ROLE_VALUE: u32 = 129; |
478 | |
479 | #[test ] |
480 | fn test_serialization_matches_from_impl() { |
481 | let ctxt = EncodingContext::<byteorder::LE>::new_dbus(0); |
482 | for role_num in 1..=HIGHEST_ROLE_VALUE { |
483 | let from_role = Role::try_from(role_num) |
484 | .unwrap_or_else(|_| panic!("Unable to convert {role_num} into Role" )); |
485 | let encoded = to_bytes(ctxt, &from_role).expect("Unable to encode {from_role}" ); |
486 | println!("ENCODED: {encoded:?}" ); |
487 | let zbus_role: Role = |
488 | from_slice(&encoded, ctxt).expect("Unable to convert {encoded} into Role" ); |
489 | assert_eq!(from_role, zbus_role, "The serde zvariant::from_slice(...) and From<u32> implementations have produced different results. The number used was {role_num}, it produced a Role of {from_role}, but the from_slice(...) implementation produced {zbus_role}" ); |
490 | assert_eq!( |
491 | from_role as u32, role_num, |
492 | "The role number {role_num} does not match the representation of the role {}" , |
493 | from_role as u32 |
494 | ); |
495 | } |
496 | } |
497 | } |
498 | |
499 | const ROLE_NAMES: &[&str] = &[ |
500 | "invalid" , |
501 | "accelerator label" , |
502 | "alert" , |
503 | "animation" , |
504 | "arrow" , |
505 | "calendar" , |
506 | "canvas" , |
507 | "check box" , |
508 | "check menu item" , |
509 | "color chooser" , |
510 | "column header" , |
511 | "combo box" , |
512 | "date editor" , |
513 | "desktop icon" , |
514 | "desktop frame" , |
515 | "dial" , |
516 | "dialog" , |
517 | "directory pane" , |
518 | "drawing area" , |
519 | "file chooser" , |
520 | "filler" , |
521 | "focus traversable" , |
522 | "font chooser" , |
523 | "frame" , |
524 | "glass pane" , |
525 | "html container" , |
526 | "icon" , |
527 | "image" , |
528 | "internal frame" , |
529 | "label" , |
530 | "layered pane" , |
531 | "list" , |
532 | "list item" , |
533 | "menu" , |
534 | "menu bar" , |
535 | "menu item" , |
536 | "option pane" , |
537 | "page tab" , |
538 | "page tab list" , |
539 | "panel" , |
540 | "password text" , |
541 | "popup menu" , |
542 | "progress bar" , |
543 | "push button" , |
544 | "radio button" , |
545 | "radio menu item" , |
546 | "root pane" , |
547 | "row header" , |
548 | "scroll bar" , |
549 | "scroll pane" , |
550 | "separator" , |
551 | "slider" , |
552 | "spin button" , |
553 | "split pane" , |
554 | "status bar" , |
555 | "table" , |
556 | "table cell" , |
557 | "table column header" , |
558 | "table row header" , |
559 | "tearoff menu item" , |
560 | "terminal" , |
561 | "text" , |
562 | "toggle button" , |
563 | "tool bar" , |
564 | "tool tip" , |
565 | "tree" , |
566 | "tree table" , |
567 | "unknown" , |
568 | "viewport" , |
569 | "window" , |
570 | "extended" , |
571 | "header" , |
572 | "footer" , |
573 | "paragraph" , |
574 | "ruler" , |
575 | "application" , |
576 | "autocomplete" , |
577 | "editbar" , |
578 | "embedded" , |
579 | "entry" , |
580 | "chart" , |
581 | "caption" , |
582 | "document frame" , |
583 | "heading" , |
584 | "page" , |
585 | "section" , |
586 | "redundant object" , |
587 | "form" , |
588 | "link" , |
589 | "input method window" , |
590 | "table row" , |
591 | "tree item" , |
592 | "document spreadsheet" , |
593 | "document presentation" , |
594 | "document text" , |
595 | "document web" , |
596 | "document email" , |
597 | "comment" , |
598 | "list box" , |
599 | "grouping" , |
600 | "image map" , |
601 | "notification" , |
602 | "info bar" , |
603 | "level bar" , |
604 | "title bar" , |
605 | "block quote" , |
606 | "audio" , |
607 | "video" , |
608 | "definition" , |
609 | "article" , |
610 | "landmark" , |
611 | "log" , |
612 | "marquee" , |
613 | "math" , |
614 | "rating" , |
615 | "timer" , |
616 | "static" , |
617 | "math fraction" , |
618 | "math root" , |
619 | "subscript" , |
620 | "superscript" , |
621 | "description list" , |
622 | "description term" , |
623 | "description value" , |
624 | "footnote" , |
625 | "content deletion" , |
626 | "content insertion" , |
627 | "mark" , |
628 | "suggestion" , |
629 | "push button menu" , |
630 | ]; |
631 | |
632 | impl Role { |
633 | /// Get a readable, English name from the role. |
634 | #[must_use ] |
635 | pub fn name(&self) -> &'static str { |
636 | ROLE_NAMES[*self as usize] |
637 | } |
638 | } |
639 | |
640 | impl std::fmt::Display for Role { |
641 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
642 | write!(f, " {}" , self.name()) |
643 | } |
644 | } |
645 | |