diff options
Diffstat (limited to 'src/gui/accessible/qaccessible.cpp')
-rw-r--r-- | src/gui/accessible/qaccessible.cpp | 404 |
1 files changed, 352 insertions, 52 deletions
diff --git a/src/gui/accessible/qaccessible.cpp b/src/gui/accessible/qaccessible.cpp index 0ccdb97e3c..b75712c3e8 100644 --- a/src/gui/accessible/qaccessible.cpp +++ b/src/gui/accessible/qaccessible.cpp @@ -173,6 +173,7 @@ Q_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core"); \value ActionChanged An action has been changed. \value ActiveDescendantChanged \value Alert A system alert (e.g., a message from a QMessageBox) + \value [since 6.8] Announcement The announcement of a message is requested. \value AttributeChanged \value ContextHelpEnd Context help (QWhatsThis) for an object is finished. \value ContextHelpStart Context help (QWhatsThis) for an object is initiated. @@ -205,6 +206,7 @@ Q_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core"); clicked or via a key press. \value HypertextLinkSelected A hypertext link has been selected. \value HypertextNLinksChanged + \value [since 6.8] IdentifierChanged The identifier of an object has changed. \value LocationChanged An object's location on the screen has changed. \value MenuCommand A menu item is triggered. \value MenuEnd A menu has been closed (Qt uses PopupMenuEnd for all @@ -218,7 +220,7 @@ Q_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core"); \value ObjectHide An object is hidden; for example, with QWidget::hide(). Any children the object that is hidden has do not send this event. It is not sent when an object is hidden as - it is being obcured by others. + it is being obscured by others. \value ObjectReorder A layout or item view has added, removed, or moved an object (Qt does not use this event). \value ObjectShow An object is displayed; for example, with @@ -275,7 +277,7 @@ Q_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core"); \value AlertMessage An object that is used to alert the user. \value Animation An object that displays an animation. \value Application The application's main window. - \value Assistant An object that provids interactive help. + \value Assistant An object that provides interactive help. \value Border An object that represents a border. \value ButtonDropDown A button that drops down a list of items. \value ButtonDropGrid A button that drops down a grid. @@ -354,14 +356,29 @@ Q_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core"); \enum QAccessible::RelationFlag This enum type defines bit flags that can be combined to indicate - the relationship between two accessible objects. - - \value Label The first object is the label of the second object. - \value Labelled The first object is labelled by the second object. - \value Controller The first object controls the second object. - \value Controlled The first object is controlled by the second object. - \value AllRelations Used as a mask to specify that we are interesting in information - about all relations + the relationship between two accessible objects. It is used by + the relations() function, which returns a list of all the related + interfaces of the calling object, together with the relations + for each object. + + Each entry in the list is a QPair where the \c second member stores + the relation type(s) between the \c returned object represented by the + \c first member and the \c origin (the caller) interface/object. + + In the table below, the \c returned object refers to the object in + the returned list, and the \c origin object is the one represented + by the calling interface. + + \value Label The \c returned object is the label for the \c origin object. + \value Labelled The \c returned object is labelled by the \c origin object. + \value Controller The \c returned object controls the \c origin object. + \value Controlled The \c returned object is controlled by the \c origin object. + \value [since 6.6] DescriptionFor The \c returned object provides a description for the \c origin object. + \value [since 6.6] Described The \c returned object is described by the \c origin object. + \value [since 6.6] FlowsFrom Content logically flows from the \c returned object to the \c origin object. + \value [since 6.6] FlowsTo Content logically flows to the \c returned object from the \c origin object. + \value AllRelations Used as a mask to specify that we are interesting in information + about all relations Implementations of relations() return a combination of these flags. Some values are mutually exclusive. @@ -373,14 +390,15 @@ Q_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core"); This enum specifies string information that an accessible object returns. - \value Name The name of the object. This can be used both - as an identifier or a short description by - accessible clients. - \value Description A short text describing the object. - \value Value The value of the object. - \value Help A longer text giving information about how to use the object. - \value Accelerator The keyboard shortcut that executes the object's default action. - \value UserText The first value to be used for user defined text. + \value Name The name of the object. This can be used both + as an identifier or a short description by + accessible clients. + \value Description A short text describing the object. + \value Value The value of the object. + \value Help A longer text giving information about how to use the object. + \value Accelerator The keyboard shortcut that executes the object's default action. + \value UserText The first value to be used for user defined text. + \value [since 6.8] Identifier An identifier for the object for e.g. UI tests. \omitvalue DebugDescription */ @@ -397,6 +415,67 @@ Q_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core"); \sa QAccessibleTextInterface */ +/*! \enum QAccessible::Attribute + This enum describes different types of attributes used by the + \l QAccessibleAttributesInterface. + \since 6.8 + + These attributes are comparable to the concept of properties/(object) + attributes found in ARIA, AT-SPI2, IAccessible, UIA and NSAccessibility + and are mapped to their platform counterpart where applicable. + + Each attribute is handled as a key-value pair, with the values of this + enumeration being used as keys. + + Attribute values are represented in a \l QVariant. The type of the value + stored in the \l QVariant is fixed and specified below for each of the + attribute types. + + \value Custom value type: \a QHash<QString, QString> + The \a Custom attribute is special in that + it can effectively represent multiple attributes at + once, since it itself is a \l QHash used to represent + key-value pairs. + For platforms supporting custom key-value pairs for + attributes, those set in the \a Custom attribute + are bridged to the platform layer without applying any + translation to platform-specific attributes. In general, + the other, more strongly typed attributes should be used. + This attribute can e.g. be used for prototyping + before officially adding an official new enumeration value + for a specific feature. + \value Level value type: \a int + Defines the hierarchical level of an element within a structure, + e.g. the heading level of a heading. This attribute conceptually + matches the "aria-level" property in ARIA. + + \sa QAccessibleAttributesInterface +*/ + +/*! \enum QAccessible::AnnouncementPriority + This enum describes the priority for announcements used by the + \l QAccessibleAnnouncementEvent. + \since 6.8 + + With \a QAccessible::AnouncementPriority::Polite, assistive technologies + should announce the message at the next graceful opportunity such as at the + end of speaking the current sentence or when the user pauses typing. + + When specifying \a QAccessible::AnouncementPriority::Assertive, assistive + technologies should notify the user immediately. + + Because an interruption might disorient users or cause them to not complete + their current task, \a QAccessible::AnouncementPriority::Assertive should + not be used unless the interruption is imperative. + + \value Polite The announcement has normal priority. + \value Assertive The announcement has high priority and should notify + the user immediately, even if that means interrupting the user's + current task. + + \sa QAccessibleAnnouncementEvent +*/ + /*! \enum QAccessible::InterfaceType @@ -415,11 +494,13 @@ Q_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core"); \value TableInterface For lists, tables and trees. \value TableCellInterface For cells in a TableInterface object. \value HyperlinkInterface For hyperlink nodes (usually embedded as children of text nodes) + \value [since 6.5] SelectionInterface For non-text objects that support selection of child objects. + \value [since 6.8] AttributesInterface For objects that support object-specific attributes. - \sa QAccessibleInterface::interface_cast(), QAccessibleTextInterface, QAccessibleValueInterface, QAccessibleActionInterface, QAccessibleTableInterface, QAccessibleTableCellInterface + \sa QAccessibleInterface::interface_cast(), QAccessibleTextInterface, QAccessibleValueInterface, QAccessibleActionInterface, QAccessibleTableInterface, QAccessibleTableCellInterface, QAccessibleSelectionInterface, QAccessibleAttributesInterface */ -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) /*! Destroys the QAccessibleInterface. @@ -436,7 +517,7 @@ QAccessibleInterface::~QAccessibleInterface() /* accessible widgets plugin discovery stuff */ -Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, +Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, acLoader, (QAccessibleFactoryInterface_iid, "/accessible"_L1)) typedef QHash<QString, QAccessiblePlugin*> QAccessiblePluginsHash; Q_GLOBAL_STATIC(QAccessiblePluginsHash, qAccessiblePlugins) @@ -670,7 +751,7 @@ QAccessibleInterface *QAccessible::queryAccessibleInterface(QObject *object) const QString cn = QLatin1StringView(mo->className()); // Check if the class has a InterfaceFactory installed. - for (int i = qAccessibleFactories()->count(); i > 0; --i) { + for (int i = qAccessibleFactories()->size(); i > 0; --i) { InterfaceFactory factory = qAccessibleFactories()->at(i - 1); if (QAccessibleInterface *iface = factory(cn, object)) { QAccessibleCache::instance()->insert(object, iface); @@ -682,9 +763,9 @@ QAccessibleInterface *QAccessible::queryAccessibleInterface(QObject *object) // no entry in the cache try to create it using the plugin loader. if (!qAccessiblePlugins()->contains(cn)) { QAccessiblePlugin *factory = nullptr; // 0 means "no plugin found". This is cached as well. - const int index = loader()->indexOf(cn); + const int index = acLoader()->indexOf(cn); if (index != -1) - factory = qobject_cast<QAccessiblePlugin *>(loader()->instance(index)); + factory = qobject_cast<QAccessiblePlugin *>(acLoader()->instance(index)); qAccessiblePlugins()->insert(cn, factory); } @@ -787,7 +868,7 @@ bool QAccessible::isActive() */ void QAccessible::setActive(bool active) { - for (int i = 0; i < qAccessibleActivationObservers()->count() ;++i) + for (int i = 0; i < qAccessibleActivationObservers()->size() ;++i) qAccessibleActivationObservers()->at(i)->accessibilityActiveChanged(active); } @@ -850,11 +931,11 @@ void QAccessible::updateAccessibility(QAccessibleEvent *event) if (iface->tableInterface()) iface->tableInterface()->modelChange(static_cast<QAccessibleTableModelChangeEvent*>(event)); } + } - if (updateHandler) { - updateHandler(event); - return; - } + if (updateHandler) { + updateHandler(event); + return; } if (QPlatformAccessibility *pfAccessibility = platformAccessibility()) @@ -1170,6 +1251,13 @@ QAccessibleInterface *QAccessibleInterface::focusChild() const tool buttons also have shortcut keys and usually display them in their tooltip. + The \l QAccessible::Identifier can be explicitly set to provide an + ID to assistive technologies. This can be especially useful for UI tests. + If no identifier has been explicitly set, the identifier is set by the + respective interface to an ID based on \l QObject::objectName or its + class name and \l QObject::objectName or class name of the parents + in its parents chain. + All objects provide a string for \l QAccessible::Name. \sa role(), state() @@ -1273,6 +1361,11 @@ QColor QAccessibleInterface::backgroundColor() const */ /*! + \fn QAccessibleSelectionInterface *QAccessibleInterface::selectionInterface() + \since 6.5 +*/ + +/*! \class QAccessibleEvent \ingroup accessibility \inmodule QtGui @@ -1634,8 +1727,8 @@ QAccessibleTextRemoveEvent::~QAccessibleTextRemoveEvent() /*! \fn QAccessibleTextInsertEvent::QAccessibleTextInsertEvent(QAccessibleInterface *iface, int position, const QString &text) - Constructs a new QAccessibleTextInsertEvent event for \a iface. The text has been inserted at - \a position. + Constructs a new QAccessibleTextInsertEvent event for \a iface. The \a text has been inserted + at \a position. */ /*! @@ -1719,9 +1812,58 @@ QAccessibleTextSelectionEvent::~QAccessibleTextSelectionEvent() { } +/*! + \since 6.8 + \class QAccessibleAnnouncementEvent + \ingroup accessibility + \inmodule QtGui + + \brief The QAccessibleAnnouncementEvent is used to request the announcement + of a given message by assistive technologies. + + This class is used with \l QAccessible::updateAccessibility(). +*/ + +/*! \fn QAccessibleAnnouncementEvent::QAccessibleAnnouncementEvent(QObject *object, const QString &message) + + Constructs a new QAccessibleAnnouncementEvent event for \a object + to request the announcement of \a message with priority \l QAccessible::AnnouncementPriority::Polite. + + \l QAccessibleAnnouncementEvent::setPriority can be used to adjust the priority. +*/ + +/*! \fn QAccessibleAnnouncementEvent::QAccessibleAnnouncementEvent(QAccessibleInterface *iface, const QString &message) + + Constructs a new QAccessibleAnnouncementEvent event for \a iface + to request the announcement of \a message with priority \l QAccessible::AnnouncementPriority::Polite. + + \l QAccessibleAnnouncementEvent::setPriority can be used to adjust the priority. +*/ + +/*! \fn QString QAccessibleAnnouncementEvent::message() const + + Returns the message. +*/ + +/*! \fn QAccessible::AnnouncementPriority QAccessibleAnnouncementEvent::priority() const + + Returns the priority. +*/ + +/*! \fn void QAccessibleAnnouncementEvent::setPriority(QAccessible::AnnouncementPriority priority) + + Sets the priority with which the announcement will be requested to \a priority. +*/ /*! + \internal +*/ +QAccessibleAnnouncementEvent::~QAccessibleAnnouncementEvent() +{ +} + +/*! Returns the QAccessibleInterface associated with the event. */ QAccessibleInterface *QAccessibleEvent::accessibleInterface() const @@ -1828,13 +1970,13 @@ Q_GUI_EXPORT QDebug operator<<(QDebug d, const QAccessibleInterface *iface) QStringList stateStrings; QAccessible::State st = iface->state(); if (st.focusable) - stateStrings << "focusable"_L1; + stateStrings << u"focusable"_s; if (st.focused) - stateStrings << "focused"_L1; + stateStrings << u"focused"_s; if (st.selected) - stateStrings << "selected"_L1; + stateStrings << u"selected"_s; if (st.invisible) - stateStrings << "invisible"_L1; + stateStrings << u"invisible"_s; if (!stateStrings.isEmpty()) d << stateStrings.join(u'|'); @@ -2008,7 +2150,7 @@ static QString textLineBoundary(int beforeAtAfter, const QString &text, int offs { Q_ASSERT(beforeAtAfter >= -1 && beforeAtAfter <= 1); Q_ASSERT(*startOffset == -1 && *endOffset == -1); - int length = text.length(); + int length = text.size(); Q_ASSERT(offset >= 0 && offset <= length); // move offset into the right range (if asking for line before or after @@ -2057,10 +2199,10 @@ QString QAccessibleTextInterface::textBeforeOffset(int offset, QAccessible::Text const QString txt = text(0, characterCount()); if (offset == -1) - offset = txt.length(); + offset = txt.size(); *startOffset = *endOffset = -1; - if (txt.isEmpty() || offset <= 0 || offset > txt.length()) + if (txt.isEmpty() || offset <= 0 || offset > txt.size()) return QString(); // type initialized just to silence a compiler warning [-Werror=maybe-uninitialized] @@ -2131,10 +2273,10 @@ QString QAccessibleTextInterface::textAfterOffset(int offset, QAccessible::TextB const QString txt = text(0, characterCount()); if (offset == -1) - offset = txt.length(); + offset = txt.size(); *startOffset = *endOffset = -1; - if (txt.isEmpty() || offset < 0 || offset >= txt.length()) + if (txt.isEmpty() || offset < 0 || offset >= txt.size()) return QString(); // type initialized just to silence a compiler warning [-Werror=maybe-uninitialized] @@ -2169,20 +2311,20 @@ QString QAccessibleTextInterface::textAfterOffset(int offset, QAccessible::TextB int toNext = boundary.toNextBoundary(); if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem))) break; - if (toNext < 0 || toNext >= txt.length()) + if (toNext < 0 || toNext >= txt.size()) break; // not found, the boundary might not exist } - Q_ASSERT(boundary.position() <= txt.length()); + Q_ASSERT(boundary.position() <= txt.size()); *startOffset = boundary.position(); while (true) { int toNext = boundary.toNextBoundary(); if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem))) break; - if (toNext < 0 || toNext >= txt.length()) + if (toNext < 0 || toNext >= txt.size()) break; // not found, the boundary might not exist } - Q_ASSERT(boundary.position() <= txt.length()); + Q_ASSERT(boundary.position() <= txt.size()); *endOffset = boundary.position(); if ((*startOffset == -1) || (*endOffset == -1) || (*startOffset == *endOffset)) { @@ -2216,13 +2358,13 @@ QString QAccessibleTextInterface::textAtOffset(int offset, QAccessible::TextBoun const QString txt = text(0, characterCount()); if (offset == -1) - offset = txt.length(); + offset = txt.size(); *startOffset = *endOffset = -1; - if (txt.isEmpty() || offset < 0 || offset > txt.length()) + if (txt.isEmpty() || offset < 0 || offset > txt.size()) return QString(); - if (offset == txt.length() && boundaryType == QAccessible::CharBoundary) + if (offset == txt.size() && boundaryType == QAccessible::CharBoundary) return QString(); // type initialized just to silence a compiler warning [-Werror=maybe-uninitialized] @@ -2243,7 +2385,7 @@ QString QAccessibleTextInterface::textAtOffset(int offset, QAccessible::TextBoun return textLineBoundary(0, txt, offset, startOffset, endOffset); case QAccessible::NoBoundary: *startOffset = 0; - *endOffset = txt.length(); + *endOffset = txt.size(); return txt; default: Q_UNREACHABLE(); @@ -2261,11 +2403,11 @@ QString QAccessibleTextInterface::textAtOffset(int offset, QAccessible::TextBoun Q_ASSERT(boundary.position() >= 0); *startOffset = boundary.position(); - while (boundary.toNextBoundary() < txt.length()) { + while (boundary.toNextBoundary() < txt.size()) { if ((boundary.boundaryReasons() & (QTextBoundaryFinder::StartOfItem | QTextBoundaryFinder::EndOfItem))) break; } - Q_ASSERT(boundary.position() <= txt.length()); + Q_ASSERT(boundary.position() <= txt.size()); *endOffset = boundary.position(); return txt.mid(*startOffset, *endOffset - *startOffset); @@ -2588,7 +2730,7 @@ QAccessibleTableInterface::~QAccessibleTableInterface() /*! \fn virtual QList<int> QAccessibleTableInterface::selectedRows() const - Returns the list of currently selected columns. + Returns the list of currently selected rows. */ /*! @@ -2941,6 +3083,164 @@ QString QAccessibleActionInterface::nextPageAction() return accessibleActionStrings()->nextPageAction; } + +/*! + \since 6.5 + \class QAccessibleSelectionInterface + \inmodule QtGui + \ingroup accessibility + + \brief The QAccessibleSelectionInterface class implements support for + selection handling. + + It provides methods for both, retrieving the current selection + as well as modifying the selection. + + Only selections of direct children are supported. +*/ + +/*! + + Destroys the QAccessibleSelectionInterface. +*/ +QAccessibleSelectionInterface::~QAccessibleSelectionInterface() +{ +} + +/*! + \fn virtual int QAccessibleSelectionInterface::selectedItemCount() const + + Returns the total number of selected accessible items. +*/ + +/*! + \fn virtual QList<QAccessibleInterface *> QAccessibleSelectionInterface::selectedItems() const + + Returns the list of selected accessible items. +*/ + +/*! + Returns the selected accessible item at index \a selectionIndex in the selection. + + Note that the index refers to the n-th selected accessible item (i.e. the index in the current selection), + which generally differs from the index that would be passed to \l QAccessibleInterface::child() + in order to retrieve the same item. + + The default implementation uses \a selectionIndex to retrieve the item from the list + of selected items retrieved by \l QAccessibleSelectionInterface::selectedItems(). + + In particular for implementations dealing with many selected items, reimplementing + this method in a more efficient way may be desirable for performance reasons. +*/ +QAccessibleInterface* QAccessibleSelectionInterface::selectedItem(int selectionIndex) const +{ + QList<QAccessibleInterface*> items = selectedItems(); + if (selectionIndex < 0 || selectionIndex > items.length() -1) { + qCWarning(lcAccessibilityCore) << "Selection index" << selectionIndex << "out of range."; + return nullptr; + } + + return items.at(selectionIndex); +} + +/*! + Returns whether \a childItem is part of the current selection. + + The default implementation checks whether \a childItem is contained + in the list of items retrieved by \l QAccessibleSelectionInterface::selectedItems. +*/ +bool QAccessibleSelectionInterface::isSelected(QAccessibleInterface *childItem) const +{ + return selectedItems().contains(childItem); +} + +/*! + \fn virtual bool QAccessibleSelectionInterface::select(QAccessibleInterface *childItem) + + Adds \a childItem to the selection. + Returns whether \a childItem has actually been added to the selection. + + For implementations that only allow single selections, + this may replace the current selection. +*/ + +/*! + \fn virtual bool QAccessibleSelectionInterface::unselect(QAccessibleInterface *childItem) + + Removes \a childItem from the selection. + + Returns whether the accessible item has actually been removed from the selection. +*/ + +/*! + \fn virtual bool QAccessibleSelectionInterface::selectAll() + + Selects all accessible child items. + + Returns whether all accessible child items have actually been added to the selection. +*/ + +/*! + \fn virtual bool QAccessibleSelectionInterface::clear() + + Unselects all accessible child items. + + Returns whether all accessible child items have actually been removed from the selection, + i.e. whether the selection is empty after this method has been called. +*/ + + +/*! + \since 6.8 + \class QAccessibleAttributesInterface + \inmodule QtGui + \ingroup accessibility + + \brief The QAccessibleAttributesInterface class implements support for + reporting attributes for an accessible object. + + Attributes are key-value pairs. Values are stored in \l QVariant. + + The \l QAccessible::Attribute enumeration describes the available keys and + documents which type to use for the value of each key. + + While the text-specific attributes handled by \l QAccessibleTextInterface::attributes + are specific to objects implementing text and are specific to a specific text + position/offset, the attributes handled by the \l QAccessibleAttributesInterface + can be used for objects of any role and apply for the whole object. + + Classes already implementing \l QAccessibleTextInterface for text-specific attrtibutes + may want to implement \l QAccessibleAttributesInterface in addition for object-specific + attributes. +*/ + +/*! + + Destroys the QAccessibleAttributesInterface. +*/ +QAccessibleAttributesInterface::~QAccessibleAttributesInterface() +{ +} + +/*! + \fn QList<QAccessible::Attribute> QAccessibleAttributesInterface::attributeKeys() const + + Returns the keys of all attributes the object supports. The \l QAccessible::Attribute + enumeration describes available keys. +*/ + +/*! + \fn QVariant QAccessibleAttributesInterface::attributeValue(QAccessible::Attribute key) const + + Returns the value of the attribute \a key of this object. + + If the attribute is set for this object, a value of the type documented for the + given key in the documentation of the \l QAccessible::Attribute enumeration is + returned in the \l QVariant. + + Otherwise, an invalid \l QVariant is returned. +*/ + /*! \internal */ QString qAccessibleLocalizedActionDescription(const QString &actionName) { @@ -2985,7 +3285,7 @@ QAccessibleHyperlinkInterface::~QAccessibleHyperlinkInterface() } -#endif // QT_NO_ACCESSIBILITY +#endif // QT_CONFIG(accessibility) QT_END_NAMESPACE |