From 463898f0765b83f6c391f6802a0ee06796f9f6d2 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 5 Nov 2019 12:51:02 +0100 Subject: Respect user-set Accessible.name Check if the user has set Accessible.name before setting it to the control's text/title/etc. Fixes: QTBUG-66583 Change-Id: I8b2c8ab3f8a8ae8e76c8e6a241260b7f90eca254 Reviewed-by: Liang Qi --- src/quicktemplates2/qquickpopupitem.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/quicktemplates2/qquickpopupitem.cpp') diff --git a/src/quicktemplates2/qquickpopupitem.cpp b/src/quicktemplates2/qquickpopupitem.cpp index 16d8c4f6..fcf23db5 100644 --- a/src/quicktemplates2/qquickpopupitem.cpp +++ b/src/quicktemplates2/qquickpopupitem.cpp @@ -45,6 +45,10 @@ #include #include +#if QT_CONFIG(accessibility) +#include +#endif + QT_BEGIN_NAMESPACE class QQuickPopupItemPrivate : public QQuickPagePrivate @@ -401,7 +405,28 @@ QAccessible::Role QQuickPopupItem::accessibleRole() const void QQuickPopupItem::accessibilityActiveChanged(bool active) { Q_D(const QQuickPopupItem); + // Can't just use d->popup->accessibleName() here, because that refers to the accessible + // name of us, the popup item, which is not what we want. + const QQuickAccessibleAttached *popupAccessibleAttached = QQuickControlPrivate::accessibleAttached(d->popup); + const QString oldPopupName = popupAccessibleAttached ? popupAccessibleAttached->name() : QString(); + const bool wasNameExplicitlySetOnPopup = popupAccessibleAttached && popupAccessibleAttached->wasNameExplicitlySet(); + QQuickPage::accessibilityActiveChanged(active); + + QQuickAccessibleAttached *accessibleAttached = QQuickControlPrivate::accessibleAttached(this); + const QString ourName = accessibleAttached ? accessibleAttached->name() : QString(); + if (wasNameExplicitlySetOnPopup && accessibleAttached && ourName != oldPopupName) { + // The user set Accessible.name on the Popup. Since the Popup and its popup item + // have different accessible attached properties, the popup item doesn't know that + // a name was set on the Popup by the user, and that it should use that, rather than + // whatever QQuickPage sets. That's why we need to do it here. + // To avoid it being overridden by the call to accessibilityActiveChanged() below, + // we set it explicitly. It's safe to do this as the popup item is an internal implementation detail. + accessibleAttached->setName(oldPopupName); + } + + // This allows the different popup types to set a name on their popup item accordingly. + // For example: Dialog uses its title and ToolTip uses its text. d->popup->accessibilityActiveChanged(active); } #endif -- cgit v1.2.3