diff options
author | Peter Varga <pvarga@inf.u-szeged.hu> | 2019-11-12 10:57:12 +0100 |
---|---|---|
committer | Peter Varga <pvarga@inf.u-szeged.hu> | 2020-01-24 12:31:50 +0100 |
commit | ffdf7eceed26c99c81accaf1529024bd0bf40f44 (patch) | |
tree | a25914e8fa450622d31d146e00cbf8803085ff73 /src/webenginewidgets/api/qwebengineview.cpp | |
parent | 08cad56d16ce56a89ae98f6f8a6589d3cc369e6b (diff) | |
download | qtwebengine-ffdf7eceed26c99c81accaf1529024bd0bf40f44.tar.gz |
Fix widget accessibility on macOS
macOS Accessibility queries the window for the focused accessibility
element. The window forwards the query to the widget with active focus.
This widget is the RWHVQtDelegateWidget if a web element is focused
in QWebEngineView. Therefore, a QAccessibleWidget interface has been
implemented for the RWHVQtDelegateWidget to forward the request to the
QWebEngineView.
The focused accessibility element expected to be returned by the
QAccessibleInterface::focusChild() method. In case of the macOS accessibility
backend, it is called by the accessibilityFocusedUIElement() NSAccessibility
API function. It expects the focused web accessibility element otherwise
VoiceOver won't focus properly.
The focused web accessiblity element is looked up by the new
BrowserAccessibilityQt::focusChild() method.
RenderWidgetHostviewQtDelegateWidget::focusChild() and
QWebengineViewAccessible::focusChild() methods have been also implemented
to forward it.
This patch depends on a focusChild() fix in qtbase:
a132e02540 Fix QAccessibleWidget::focusChild() to return focused descendant
Microsoft Narrator also uses focusChild() to query the current focused
element when it starts but it is still functional without this fix.
Task-number: QTBUG-78284
Task-number: QTBUG-81539
Change-Id: I3c4861e58622ccbb5046c60c4efcc19842400a88
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'src/webenginewidgets/api/qwebengineview.cpp')
-rw-r--r-- | src/webenginewidgets/api/qwebengineview.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/webenginewidgets/api/qwebengineview.cpp b/src/webenginewidgets/api/qwebengineview.cpp index de81448a9..a51f9b7a5 100644 --- a/src/webenginewidgets/api/qwebengineview.cpp +++ b/src/webenginewidgets/api/qwebengineview.cpp @@ -107,9 +107,18 @@ void QWebEngineViewPrivate::widgetChanged(QtWebEngineCore::RenderWidgetHostViewQ if (oldWidget) { q->layout()->removeWidget(oldWidget); oldWidget->hide(); +#if QT_CONFIG(accessibility) + QAccessible::deleteAccessibleInterface(QAccessible::uniqueId(QAccessible::queryAccessibleInterface(oldWidget))); +#endif } if (newWidget) { +#if QT_CONFIG(accessibility) + // An earlier QAccessible::queryAccessibleInterface() call may have already registered a default + // QAccessibleInterface for newWidget: remove it first to avoid assert in QAccessibleCache::insert(). + QAccessible::deleteAccessibleInterface(QAccessible::uniqueId(QAccessible::queryAccessibleInterface(newWidget))); + QAccessible::registerAccessibleInterface(new QtWebEngineCore::RenderWidgetHostViewQtDelegateWidgetAccessible(newWidget, q)); +#endif q->layout()->addWidget(newWidget); q->setFocusProxy(newWidget); newWidget->show(); @@ -462,11 +471,16 @@ void QWebEngineView::dropEvent(QDropEvent *e) #endif // QT_CONFIG(draganddrop) #ifndef QT_NO_ACCESSIBILITY +QAccessibleInterface *QWebEngineViewAccessible::focusChild() const +{ + if (child(0) && child(0)->focusChild()) + return child(0)->focusChild(); + return const_cast<QWebEngineViewAccessible *>(this); +} + int QWebEngineViewAccessible::childCount() const { - if (view() && child(0)) - return 1; - return 0; + return child(0) ? 1 : 0; } QAccessibleInterface *QWebEngineViewAccessible::child(int index) const @@ -478,7 +492,7 @@ QAccessibleInterface *QWebEngineViewAccessible::child(int index) const int QWebEngineViewAccessible::indexOfChild(const QAccessibleInterface *c) const { - if (c == child(0)) + if (child(0) && c == child(0)) return 0; return -1; } |