Qt Accessibility Client

accessibleobject.h
1/*
2 SPDX-FileCopyrightText: 2012 Frederik Gladhorn <gladhorn@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#ifndef QACCESSIBILITYCLIENT_ACCESSIBLEOBJECT_H
8#define QACCESSIBILITYCLIENT_ACCESSIBLEOBJECT_H
9
10
11namespace QAccessibleClient {
12 class AccessibleObject;
13}
14
15#include <QList>
16#include <QSharedPointer>
17#include <QAction>
18
19#include "qaccessibilityclient_export.h"
20
21namespace QAccessibleClient {
22
23class AccessibleObjectPrivate;
24class RegistryPrivate;
25
26
27#ifndef QT_NO_DEBUG_STREAM
28 QACCESSIBILITYCLIENT_EXPORT QDebug operator<<(QDebug, const AccessibleObject &);
29#endif
30
31/**
32 This class represents an accessible object.
33
34 An accessible object equals usually a visible widget or some kind
35 of other element the user can interact with but can also present
36 a not visible object that offers certain functionality like for
37 example actions which can be triggered.
38
39 It is implicitly shared and only created by the library.
40*/
41class QACCESSIBILITYCLIENT_EXPORT AccessibleObject
42{
43public:
44
45 /**
46 This enum describes the different interfaces that an
47 AccessibleObject can implement.
48
49 Each AccessibleObject must implement the AccessibleInterface, otherwise
50 it is invalid. All other interfaces are optional.
51
52 If the ActionInterface is implement the object
53 will have a list of actions that can be invoked.
54 */
55 enum Interface {
56 NoInterface = 0x0,
57 AccessibleInterface = 0x1,
58 CacheInterface = 0x2,
59 ActionInterface = 0x4,
60 ApplicationInterface = 0x8,
61 CollectionInterface = 0x10,
62 ComponentInterface = 0x20,
63 DocumentInterface = 0x40,
64 EditableTextInterface = 0x80,
65 EventKeyboardInterface = 0x100,
66 EventMouseInterface = 0x200,
67 EventObjectInterface = 0x400,
68 HyperlinkInterface = 0x800,
69 HypertextInterface = 0x1000,
70 ImageInterface = 0x2000,
71 SelectionInterface = 0x4000,
72 TableInterface = 0x8000,
73 TextInterface = 0x10000,
74 ValueInterface = 0x20000,
75 SocketInterface = 0x40000,
76 EventWindowInterface = 0x80000,
77 EventFocusInterface = 0x100000,
78
79 InvalidInterface = 0x80000000
80 };
81 Q_DECLARE_FLAGS(Interfaces, Interface)
82
83 /**
84 The role indicates the type of UI element that an AccessibleObject
85 represents.
86 */
87 enum Role {
88 NoRole, /*!< The object is invalid and has no role set. This is generally a bug. */
89 CheckBox,
90 CheckableMenuItem,
91 ColumnHeader,
92 ComboBox,
93 DesktopFrame,
94 Dial,
95 Dialog,
96 Filler,
97 Frame,
98 Icon,
99 Label,
100 ListView,
101 ListItem,
102 Menu,
103 MenuBar,
104 MenuItem,
105 Tab,
106 TabContainer,
107 PasswordText,
108 PopupMenu,
109 ProgressBar,
110 Button,
111 RadioButton,
112 RadioMenuItem,
113 RowHeader,
114 ScrollBar,
115 ScrollArea,
116 Separator,
117 Slider,
118 SpinButton,
119 StatusBar,
120 TableView,
121 TableCell,
122 TableColumnHeader,
123 TableColumn,
124 TableRowHeader,
125 TableRow,
126 Terminal,
127 Text,
128 ToggleButton,
129 ToolBar,
130 ToolTip,
131 TreeView,
132 Window,
133 TreeItem
134// Roles in Qt, I don't think we want those
135// TitleBar = 0x00000001,
136// Grip = 0x00000004,
137// Sound = 0x00000005,
138// Cursor = 0x00000006,
139// Caret = 0x00000007,
140// AlertMessage = 0x00000008,
141// Client = 0x0000000A,
142// Application = 0x0000000E,
143// Document = 0x0000000F,
144// Pane = 0x00000010,
145// Chart = 0x00000011,
146// Border = 0x00000013,
147// Grouping = 0x00000014,
148// Cell = 0x0000001D,
149// Link = 0x0000001E,
150// HelpBalloon = 0x0000001F,
151// Assistant = 0x00000020,
152// PageTab = 0x00000025,
153// PropertyPage = 0x00000026,
154// Indicator = 0x00000027,
155// Graphic = 0x00000028,
156// StaticText = 0x00000029,
157// EditableText = 0x0000002A, // Editable, selectable, etc.
158// HotkeyField = 0x00000032,
159// SpinBox = 0x00000034,
160// Canvas = 0x00000035,
161// Animation = 0x00000036,
162// Equation = 0x00000037,
163// ButtonDropDown = 0x00000038,
164// ButtonMenu = 0x00000039,
165// ButtonDropGrid = 0x0000003A,
166// Whitespace = 0x0000003B,
167// PageTabList = 0x0000003C,
168// Clock = 0x0000003D,
169// Splitter = 0x0000003E,
170// LayeredPane = 0x00000080,
171 };
172
173 /**
174 \brief The TextBoundaries enum represents the different boundaries when
175 asking for text at a certain offset.
176 */
178 CharBoundary,
179 WordStartBoundary,
180 WordEndBoundary,
181 SentenceStartBoundary,
182 SentenceEndBoundary,
183 LineStartBoundary,
184 LineEndBoundary
185 };
186
187 /**
188 \brief Construct an invalid AccessibleObject.
189 */
191
192 /**
193 \brief Copy constructor.
194 */
196
197 /**
198 Destroys the AccessibleObject
199 */
201
202 /**
203 Assignment operator
204 */
205 AccessibleObject &operator=(const AccessibleObject &other);
206 /**
207 Comparison operator
208 */
209 bool operator==(const AccessibleObject &other) const;
210 /**
211 Inequality operator
212 */
213 inline bool operator!=(const AccessibleObject &other) const {
214 return !operator==(other);
215 }
216
217 /**
218 \brief Returns a unique identifier for the object.
219 */
220 QString id() const;
221
222 /**
223 \brief Returns a QUrl that references the AccessibleObject.
224
225 This can be used to serialize/unserialize an AccessibleObject
226 to pass it around as string and restore the AccessibleObject
227 by using Registry::accessibleFromUrl later on.
228
229 The returned QUrl returns a scheme of "accessibleobject", the
230 dbus path as url path and the dbus service as url fragment.
231 */
232 QUrl url() const;
233
234 /**
235 \brief Returns true if this object is valid.
236
237 Invalid objects are for example returned when asking for the
238 parent of the top most item, or for a child that is out of range.
239 */
240 bool isValid() const;
241
242 /**
243 \brief Returns this object's parent.
244 \return The parent AccessibleObject
245 */
246 AccessibleObject parent() const;
247
248 /**
249 \brief Returns this accessible's index in it's parent's list of children.
250 \return index
251 */
252 int indexInParent() const;
253
254 /**
255 \brief Returns this accessible's children in a list.
256 \return children
257 */
258 QList<AccessibleObject> children() const;
259
260 /**
261 \brief Returns this accessible's children according to there roles.
262 \param roles The list of roles to query.
263 \return A vector that contains the children of this object according
264 to there roles. The number of vector-items equals to the number and
265 sorting of the roles items. Example code demonstrating usage:
266 \code
267 QList<Role> roles;
268 roles << Label << CheckBox;
269 QVector< QList<AccessibleObject> > c = children(roles);
270 Q_ASSERT(c.count() == roles.count());
271 Q_ASSERT(c[0].isEmpty() || c[0].first().role() == Label);
272 Q_ASSERT(c[1].isEmpty() || c[1].first().role() == CheckBox);
273 \endcode
274 */
275 QVector< QList<AccessibleObject> > children(const QList<Role> &roles) const;
276
277 /**
278 \brief Returns the number of children for this accessible.
279 \return number of children
280 */
281 int childCount() const;
282
283 /**
284 \brief Returns a specific child at position \a index.
285
286 The list of children is 0-based.
287 \return number of children
288 */
289 AccessibleObject child(int index) const;
290
291 /**
292 \brief Returns the accessible id of this accessible.
293
294 This is an id which is stable over application development.
295 It may be empty.
296 */
297 QString accessibleId() const;
298
299 /**
300 \brief Returns the name of this accessible.
301
302 The name is a short descriptive one or two words.
303 It is localized.
304 */
305 QString name() const;
306
307 /**
308 \brief Returns the description for this accessible.
309
310 The description is more of an explanation than the name.
311 This can be a sentence. The string is localized.
312 */
313 QString description() const;
314
315 /**
316 \brief Returns the role as integer value of this accessible.
317 */
318 Role role() const;
319
320 /**
321 \brief Returns the name of the role of this accessible.
322
323 This name is not localized to allow tools to work with the english string.
324 */
325 QString roleName() const;
326
327 /**
328 \brief Returns the name of the role of this accessible.
329
330 This name is localized and can be presented to the user.
331 */
332 QString localizedRoleName() const;
333
334 /**
335 \brief The ComponentLayer in which this object resides.
336 */
337 int layer() const;
338
339 /**
340 \brief Obtain the relative stacking order (i.e. 'Z' order) of an object.
341
342 Larger values indicate that an object is on "top" of the stack, therefore
343 objects with smaller MDIZOrder may be obscured by objects with a larger
344 MDIZOrder, but not vice-versa.
345 */
346 int mdiZOrder() const;
347
348 /**
349 \brief Obtain the alpha value of the component.
350
351 An alpha value of 1.0 or greater indicates that the object is fully opaque,
352 and an alpha value of 0.0 indicates that the object is fully transparent.
353 Negative alpha values have no defined meaning at this time.
354
355 Alpha values are used in conjunction with Z-order calculations to determine
356 whether an object wholly or partially obscures another object's visual
357 intersection, in the event that their bounds intersect.
358 */
359 double alpha() const;
360
361 /**
362 \brief Returns a bounding rectangle for the accessible.
363
364 It returns a QRect that bounds the accessible. This can be used to get the focus coordinates.
365
366 \return QRect that bounds the accessible.
367 */
368 QRect boundingRect() const;
369
370 /**
371 \brief Returns a bounding rectangle for the character at position \a offset.
372
373 This function is only supported for accessibles that implement the text interface.
374 It will return an empty rectangle for invalid offsets or accessibles.
375
376 \return QRect that bounds the character.
377 */
378 QRect characterRect(int offset) const;
379
380 /**
381 \brief Returns List of interfaces supported by the accessible.
382
383 This function provides a list of accessibile interfaces that are implemented
384 by an accessible object. This can be used to avoid calling functions that
385 are not supported by the accessible.
386
387 \return QStringList that contains list of supported interfaces
388 */
389 Interfaces supportedInterfaces() const;
390
391 /**
392 \brief Returns the offset of the caret from the beginning of the text.
393
394 This function provides the current offset of the caret from the beginning of
395 the text in an accessible that implements org.a11y.atspi.Text.
396
397 \return Caret Offset as an integer
398 */
399 int caretOffset() const;
400
401 /**
402 \brief Returns the number of characters.
403
404 \return Number of characters.
405 */
406 int characterCount() const;
407
408 /**
409 \brief Returns a list of selections the text has.
410
411 Code to demonstrate usage:
412 \code
413 QList< QPair<int,int> > sel = acc.textSelections();
414 int startOffset = sel[0].first;
415 int endOffset = sel[0].second;
416 QString allText = acc.text();
417 QString selText = allText.mid(startOffset, endOffset - startOffset);
418 \endcode
419
420 \return The list of selections where every item in that list
421 is a pair of integers representing startOffset and endOffset
422 of the selection.
423 */
424 QList< QPair<int,int> > textSelections() const;
425
426 /**
427 Set text \a selections, usually only one selection will be set,
428 use a list containing one QPair with the start and end offsets for that.
429 */
430 void setTextSelections(const QList< QPair<int,int> > &selections);
431
432 /**
433 \brief Returns the text of the TextInterface.
434
435 This function provides the current text as displayed by the
436 org.a11y.atspi.Text TextInterface component.
437
438 \param startOffset The start caret offset to return the text from.
439 \param endOffset The end caret offset to return the text from. If -1
440 then the endOffset is the end of the string what means all characters
441 are included.
442 \return The text as displayed by the TextInterface.
443 */
444 QString text(int startOffset = 0, int endOffset = -1) const;
445
446 /**
447 \brief Returns the text of the TextInterface by boundary.
448
449 Especially for larger text fields it may be more performant and easier to
450 query the text at a certain position instead of the full text.
451
452 For example the line where the cursor is currently can be retrieved with this function
453 in a convenient way.
454
455 \param offset is the position of the requested text.
456 \param startOffset returns the beginning of the offset, for example the start of the line when
457 asking for line boundaries.
458 \param endOffset returns the end of the text section
459 \return the text at the offset.
460 */
461 QString textWithBoundary(int offset, TextBoundary boundary, int *startOffset = nullptr, int *endOffset = nullptr) const;
462
463 /**
464 \brief Set the text of the EditableTextInterface.
465
466 \param text The text to set.
467 \return true on success and false on error.
468 */
469 bool setText(const QString &text);
470
471 /**
472 \brief Insert the text into the EditableTextInterface.
473
474 \param text The text to insert.
475 \param position The caret position at which to insert the text.
476 \param length The length of the text to insert.
477 \return true on success and false on error.
478 */
479 bool insertText(const QString &text, int position = 0, int length = -1);
480
481 /**
482 \brief Copy the text from the EditableTextInterface into the clipboard.
483
484 \param startPos The caret position from which to start to copy the text from.
485 \param endPos The caret position from which to end to copy the text from.
486 \return true on success and false on error.
487 */
488 bool copyText(int startPos, int endPos);
489
490 /**
491 \brief Cut the text from the EditableTextInterface into the clipboard.
492
493 \param startPos The caret position from which to start to cut the text from.
494 \param endPos The caret position from which to end to cut the text from.
495 \return true on success and false on error.
496 */
497 bool cutText(int startPos, int endPos);
498
499 /**
500 \brief Delete the text from the EditableTextInterface.
501
502 \param startPos The caret position from which to start to delete the text.
503 \param endPos The caret position from which to end to delete the text.
504 \return true on success and false on error.
505 */
506 bool deleteText(int startPos, int endPos);
507
508 /**
509 \brief Paste the text from the clipboard into the EditableTextInterface.
510
511 \param position The caret position at which to insert the text into.
512 \return true on success and false on error.
513 */
514 bool pasteText(int position);
515
516 /**
517 \brief Returns focus-point of the object
518
519 \return The Focus Point of the object
520 */
521 QPoint focusPoint() const;
522
523 /**
524 \brief Returns the application object.
525
526 \return The top-level application object that expose an
527 org.a11y.atspi.Application accessibility interface.
528 */
529 AccessibleObject application() const;
530
531 /**
532 \brief Returns the toolkit name.
533
534 \return The tookit name. This can be for example "Qt"
535 or "gtk".
536 */
537 QString appToolkitName() const;
538
539 /**
540 \brief Returns the toolkit version.
541
542 \return The tookit version. This can be for example "4.8.3"
543 for Qt 4.8.3.
544 */
545 QString appVersion() const;
546
547 /**
548 \brief Returns the unique application identifier.
549
550 \return The app id. The identifier will not last over session
551 and everytime the app quits and restarts it gets another
552 identifier that persists as long as the application is running.
553 */
554 int appId() const;
555
556 /**
557 The type of locale
558 */
560 LocaleTypeMessages,
561 LocaleTypeCollate,
562 LocaleTypeCType,
563 LocaleTypeMonetary,
564 LocaleTypeNumeric,
565 LocaleTypeTime
566 };
567
568 /**
569 \brief The application locale.
570
571 \param lctype The \a LocaleType for which the locale is queried.
572 \return A string compliant with the POSIX standard for locale description.
573 */
574 QString appLocale(LocaleType lctype = LocaleTypeMessages) const;
575
576 /**
577 \brief The application dbus address.
578 */
579 QString appBusAddress() const;
580
581 /**
582 \brief The minimum value allowed by this valuator.
583
584 If both, the \a minimumValue and \a maximumValue, are zero then
585 there is no minimum or maximum values. The \a currentValue has
586 no range restrictions.
587 */
588 double minimumValue() const;
589
590 /**
591 \brief The maximum value allowed by this valuator.
592
593 If both, the \a minimumValue and \a maximumValue, are zero then
594 there is no minimum or maximum values. The \a currentValue has
595 no range restrictions.
596 */
597 double maximumValue() const;
598
599 /**
600 \brief The smallest incremental change which this valuator allows.
601
602 This is a helper value to know in what steps the \a currentValue
603 is incremented or decremented.
604
605 If 0, the incremental changes to the valuator are limited only by
606 the precision of a double precision value on the platform.
607 */
608 double minimumValueIncrement() const;
609
610 /**
611 \brief The current value of the valuator.
612
613 This is the value the org.a11y.atspi.Value accessibility interface has.
614 */
615 double currentValue() const;
616
617 /**
618 \brief Set the value of the valuator.
619
620 \param value the value to set.
621 \return true on success and false on error.
622 */
623 bool setCurrentValue(const double value);
624
625 /**
626 \brief Returns the selection of accessible objects.
627 */
628 QList<AccessibleObject> selection() const;
629
630 /**
631 \brief A description text of the image.
632
633 It is recommended that imageDescription be the shorter of the available image
634 descriptions, for instance "alt text" in HTML images, and a longer description
635 be provided in Accessible::accessible-description, if available. A short, one
636 or two word label for the image should be provided in Accessible::accessible-name.
637
638 \return A UTF-8 string providing a textual description of what is visually
639 depicted in the image.
640 */
641 QString imageDescription() const;
642
643 /**
644 \brief The locale of the image.
645
646 \return A string corresponding to the POSIX LC_MESSAGES locale used by the
647 imageDescription.
648 */
649 QString imageLocale() const;
650
651 /**
652 \brief The image boundaries.
653
654 Obtain a bounding box which entirely contains the image contents, as
655 displayed on screen.
656
657 The bounds returned do not account for any viewport clipping or the fact that
658 the image may be partially or wholly obscured by other onscreen content.
659
660 This method returns the bounds of the current onscreen view, and not the
661 nominal size of the source data in the event that the original image has
662 been rescaled.\
663
664 \return A BoundingBox enclosing the image's onscreen representation.
665 */
666 QRect imageRect() const;
667
668 /**
669 \brief Returns a list of actions supported by this accessible.
670
671 Just trigger() the action to execute the underlying method at the accessible.
672 */
673 QVector< QSharedPointer<QAction> > actions() const;
674
675 // states
676 /// Returns if the AccessibleObject is currently active
677 bool isActive() const;
678 /// Returns if the AccessibleObject is checkable (often indicates a check action)
679 bool isCheckable() const;
680 /// Returns if the AccessibleObject is currently checked
681 bool isChecked() const;
682 /// Returns if the AccessibleObject is defunct - that means it does not properly respont to requests
683 /// and should be ignored for accessibility purposes
684 bool isDefunct() const;
685 /// Returns if the AccessibleObject is an editable text
686 bool isEditable() const;
687 /// Returns if the AccessibleObject is currently enabled
688 bool isEnabled() const;
689 /// Returns if the AccessibleObject can be expanded to show more information
690 bool isExpandable() const;
691 /// Returns if the AccessibleObject is currently expanded
692 bool isExpanded() const;
693 /// Returns if the AccessibleObject is focusable
694 bool isFocusable() const;
695 /// Returns if the AccessibleObject is currently focused
696 bool isFocused() const;
697 /// Returns if the AccessibleObject is a multi line text edit
698 bool isMultiLine() const;
699 /// Returns if the AccessibleObject is selectable
700 bool isSelectable() const;
701 /// Returns if the AccessibleObject is currently selected
702 bool isSelected() const;
703 /// Returns if the AccessibleObject reacts to input events
704 bool isSensitive() const;
705 /// Returns if the AccessibleObject is a single line text edit
706 bool isSingleLine() const;
707
708 /**
709 \brief Return a string representing states of this object.
710
711 This is useful for debugging applications.
712 */
713 QString stateString() const;
714
715 /*
716 * \internal
717 * \brief isTransient marks an object as being unreliable in that it can quickly disappear or change
718 *
719 * This is mostly a hint that the object should not be cached.
720 * \return true if the object is transient
721 */
722// bool isTransient() const;
723
724 /// Returns if the AccessibleObject is currently visible (it can still be off the screen,
725 /// but there is nothing preventing the user from seeing it in general)
726 bool isVisible() const;
727
728 /*
729 * \internal
730 * \brief managesDescendants marks an object as being responsible for its children
731 *
732 * This is to notify that this object handles signals for it's children.
733 * The property is typically used for tables and lists or other collection objects.
734 * \return true if the object is transient
735 */
736// bool managesDescendants() const;
737// bool isRequired() const;
738// bool isAnimated() const;
739// bool isInvalidEntry() const;
740 /// Returns if the AccessibleObject is the default widget (e.g. a button in a dialog)
741 bool isDefault() const;
742// bool isVisited() const;
743
744 /// Returns if the AccessibleObject allows text selections
745 bool hasSelectableText() const;
746 /// Returns if the AccessibleObject has a tool tip
747 bool hasToolTip() const;
748 /// Returns if the AccessibleObject supports automatic text completion
749 bool supportsAutocompletion() const;
750
751private:
752 AccessibleObject(RegistryPrivate *reg, const QString &service, const QString &path);
755
756 friend class Registry;
757 friend class RegistryPrivate;
758 friend class CacheWeakStrategy;
759 friend class CacheStrongStrategy;
760#ifndef QT_NO_DEBUG_STREAM
761 friend QDebug QAccessibleClient::operator<<(QDebug, const AccessibleObject &);
762#endif
763 friend uint qHash(const QAccessibleClient::AccessibleObject& object) {
764 return qHash(object.d);
765 }
766};
767
768}
769
770Q_DECLARE_METATYPE(QAccessibleClient::AccessibleObject)
771
772#endif
This class represents an accessible object.
Interface
This enum describes the different interfaces that an AccessibleObject can implement.
TextBoundary
The TextBoundaries enum represents the different boundaries when asking for text at a certain offset.
Role
The role indicates the type of UI element that an AccessibleObject represents.
bool operator!=(const AccessibleObject &other) const
Inequality operator.
This class represents the global accessibility registry.
Definition registry.h:30
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:52:18 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.