From 73e72f7b5f3dc9b08a18a2afc286576951b424b9 Mon Sep 17 00:00:00 2001
From: Alexandru Croitor <alexandru.croitor@qt.io>
Date: Wed, 7 Feb 2018 17:56:25 +0100
Subject: [PATCH] Replace accessibility private API usage with QQmlProperty

Previously enabling accessibility for the QtQuick WebEngineView was
done by calling QuickAccessibleAttached::qmlAttachedProperties()
which is a private API call.
Instead of that, set the Accessibility attached properties by using
QQmlProperty.

Task-number: QTBUG-63098
Change-Id: Ibc927c1fce121dee56d8a21af412056d98c82c4d
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
---
 src/webengine/api/qquickwebengineview.cpp | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp
index 85681bfef..42121ceb2 100644
--- a/src/webengine/api/qquickwebengineview.cpp
+++ b/src/webengine/api/qquickwebengineview.cpp
@@ -89,9 +89,6 @@
 #include <QTimer>
 #include <private/qguiapplication_p.h>
 #include <qpa/qplatformintegration.h>
-#ifndef QT_NO_ACCESSIBILITY
-#include <private/qquickaccessibleattached_p.h>
-#endif // QT_NO_ACCESSIBILITY
 
 QT_BEGIN_NAMESPACE
 using namespace QtWebEngineCore;
@@ -768,11 +765,6 @@ QQuickWebEngineView::QQuickWebEngineView(QQuickItem *parent)
     d->q_ptr = this;
     this->setActiveFocusOnTab(true);
     this->setFlags(QQuickItem::ItemIsFocusScope | QQuickItem::ItemAcceptsDrops);
-
-#ifndef QT_NO_ACCESSIBILITY
-    QQuickAccessibleAttached *accessible = QQuickAccessibleAttached::qmlAttachedProperties(this);
-    accessible->setRole(QAccessible::Grouping);
-#endif // QT_NO_ACCESSIBILITY
 }
 
 QQuickWebEngineView::~QQuickWebEngineView()
@@ -1777,6 +1769,16 @@ void QQuickWebEngineViewPrivate::userScripts_clear(QQmlListProperty<QQuickWebEng
 void QQuickWebEngineView::componentComplete()
 {
     QQuickItem::componentComplete();
+
+#ifndef QT_NO_ACCESSIBILITY
+    // Enable accessibility via a dynamic QQmlProperty, instead of using private API call
+    // QQuickAccessibleAttached::qmlAttachedProperties(this). The qmlContext is required, otherwise
+    // it is not possible to reference attached properties.
+    QQmlContext *qmlContext = QQmlEngine::contextForObject(this);
+    QQmlProperty role(this, QStringLiteral("Accessible.role"), qmlContext);
+    role.write(QAccessible::Grouping);
+#endif // QT_NO_ACCESSIBILITY
+
     QTimer::singleShot(0, this, &QQuickWebEngineView::lazyInitialize);
 }
 
-- 
GitLab