diff --git a/src/qtdeclarative/src/quick/accessible/qaccessiblequickitem.cpp b/src/qtdeclarative/src/quick/accessible/qaccessiblequickitem.cpp index df99d43531..a5e67cb9c9 100644 --- a/src/qtdeclarative/src/quick/accessible/qaccessiblequickitem.cpp +++ b/src/qtdeclarative/src/quick/accessible/qaccessiblequickitem.cpp @@ -39,6 +39,7 @@ #include "QtQuick/private/qquicktext_p.h" #include "QtQuick/private/qquickaccessibleattached_p.h" #include "QtQuick/qquicktextdocument.h" +#include "QtQuick/QQuickRenderControl" QT_BEGIN_NAMESPACE #ifndef QT_NO_ACCESSIBILITY @@ -50,7 +51,17 @@ QAccessibleQuickItem::QAccessibleQuickItem(QQuickItem *item) QWindow *QAccessibleQuickItem::window() const { - return item()->window(); + QQuickWindow *wdw = item()->window(); + //Offscreen window inside QQuickWidget has no native window handle + if (wdw && !wdw->handle()) { + if (QQuickRenderControl* renderControl = QQuickWindowPrivate::get(wdw)->renderControl) { + if (QWindow* renderWindow = renderControl->renderWindow(Q_NULLPTR)) { + return renderWindow; + } + } + } + + return wdw; } int QAccessibleQuickItem::childCount() const diff --git a/src/qtdeclarative/src/quick/accessible/qaccessiblequickview_p.h b/src/qtdeclarative/src/quick/accessible/qaccessiblequickview_p.h index 049fa385ba..777e660dc6 100644 --- a/src/qtdeclarative/src/quick/accessible/qaccessiblequickview_p.h +++ b/src/qtdeclarative/src/quick/accessible/qaccessiblequickview_p.h @@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE #ifndef QT_NO_ACCESSIBILITY -class QAccessibleQuickWindow : public QAccessibleObject +class Q_QUICK_EXPORT QAccessibleQuickWindow : public QAccessibleObject { public: QAccessibleQuickWindow(QQuickWindow *object); diff --git a/src/qtdeclarative/src/quickwidgets/qaccessiblequickwidget.cpp b/src/qtdeclarative/src/quickwidgets/qaccessiblequickwidget.cpp new file mode 100644 index 0000000000..79187f1ad0 --- /dev/null +++ b/src/qtdeclarative/src/quickwidgets/qaccessiblequickwidget.cpp @@ -0,0 +1,39 @@ +#include "qaccessiblequickwidget.h" + +#include "qquickwidget_p.h" + +QT_BEGIN_NAMESPACE + +#ifndef QT_NO_ACCESSIBILITY + +QAccessibleQuickWidget::QAccessibleQuickWidget(QQuickWidget* widget) + : QAccessibleWidget(widget) + , m_widget(widget) + , m_accessibleWindow(QQuickWidgetPrivate::get(widget)->offscreenWindow) +{ + +} + +QAccessibleInterface *QAccessibleQuickWidget::child(int index) const +{ + return m_accessibleWindow.child(index); +} + +int QAccessibleQuickWidget::childCount() const +{ + return m_accessibleWindow.childCount(); +} + +int QAccessibleQuickWidget::indexOfChild(const QAccessibleInterface *iface) const +{ + return m_accessibleWindow.indexOfChild(iface); +} + +QAccessibleInterface *QAccessibleQuickWidget::childAt(int x, int y) const +{ + return m_accessibleWindow.childAt(x, y); +} + +#endif // QT_NO_ACCESSIBILITY + +QT_END_NAMESPACE diff --git a/src/qtdeclarative/src/quickwidgets/qaccessiblequickwidget.h b/src/qtdeclarative/src/quickwidgets/qaccessiblequickwidget.h new file mode 100644 index 0000000000..7fcfe59cef --- /dev/null +++ b/src/qtdeclarative/src/quickwidgets/qaccessiblequickwidget.h @@ -0,0 +1,35 @@ +#ifndef QACCESSIBLEQUICKWIDGET_H +#define QACCESSIBLEQUICKWIDGET_H + +#include +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +#ifndef QT_NO_ACCESSIBILITY + +class QAccessibleQuickWidget : public QAccessibleWidget +{ +public: + QAccessibleQuickWidget(QQuickWidget* widget); + + QAccessibleInterface *child(int index) const Q_DECL_OVERRIDE; + int childCount() const Q_DECL_OVERRIDE; + int indexOfChild(const QAccessibleInterface *iface) const Q_DECL_OVERRIDE; + QAccessibleInterface *childAt(int x, int y) const Q_DECL_OVERRIDE; + +private: + QPointer m_widget; + QAccessibleQuickWindow m_accessibleWindow; + Q_DISABLE_COPY(QAccessibleQuickWidget) +}; + +#endif // QT_NO_ACCESSIBILITY + +QT_END_NAMESPACE + +#endif + diff --git a/src/qtdeclarative/src/quickwidgets/qaccessiblequickwidgetfactory.cpp b/src/qtdeclarative/src/quickwidgets/qaccessiblequickwidgetfactory.cpp new file mode 100644 index 0000000000..241c88389d --- /dev/null +++ b/src/qtdeclarative/src/quickwidgets/qaccessiblequickwidgetfactory.cpp @@ -0,0 +1,19 @@ +#include "qaccessiblequickwidgetfactory_p.h" +#include "qaccessiblequickwidget.h" + +#ifndef QT_NO_ACCESSIBILITY + +QT_BEGIN_NAMESPACE + +QAccessibleInterface *qAccessibleQuickWidgetFactory(const QString &classname, QObject *object) +{ + if (classname == QLatin1String("QQuickWidget")) { + return new QAccessibleQuickWidget(qobject_cast(object)); + } + + return 0; +} + +QT_END_NAMESPACE + +#endif // QT_NO_ACCESSIBILITY diff --git a/src/qtdeclarative/src/quickwidgets/qaccessiblequickwidgetfactory_p.h b/src/qtdeclarative/src/quickwidgets/qaccessiblequickwidgetfactory_p.h new file mode 100644 index 0000000000..992563b314 --- /dev/null +++ b/src/qtdeclarative/src/quickwidgets/qaccessiblequickwidgetfactory_p.h @@ -0,0 +1,25 @@ +#include + +#ifndef QACCESSIBLEQUICKWIDGETFACTORY_H +#define QACCESSIBLEQUICKWIDGETFACTORY_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#ifndef QT_NO_ACCESSIBILITY +QT_BEGIN_NAMESPACE + +QAccessibleInterface *qAccessibleQuickWidgetFactory(const QString &classname, QObject *object); + +QT_END_NAMESPACE +#endif + +#endif diff --git a/src/qtdeclarative/src/quickwidgets/qquickwidget.cpp b/src/qtdeclarative/src/quickwidgets/qquickwidget.cpp index d0a518f02a..bc9a0f565e 100644 --- a/src/qtdeclarative/src/quickwidgets/qquickwidget.cpp +++ b/src/qtdeclarative/src/quickwidgets/qquickwidget.cpp @@ -33,6 +33,7 @@ #include "qquickwidget.h" #include "qquickwidget_p.h" +#include "qaccessiblequickwidgetfactory_p.h" #include "private/qquickwindow_p.h" #include "private/qquickitem_p.h" @@ -104,6 +105,10 @@ void QQuickWidgetPrivate::init(QQmlEngine* e) q->setAcceptDrops(true); #endif +#ifndef QT_NO_ACCESSIBILITY + QAccessible::installFactory(&qAccessibleQuickWidgetFactory); +#endif + QWidget::connect(offscreenWindow, SIGNAL(sceneGraphInitialized()), q, SLOT(createFramebufferObject())); QWidget::connect(offscreenWindow, SIGNAL(sceneGraphInvalidated()), q, SLOT(destroyFramebufferObject())); QObject::connect(renderControl, SIGNAL(renderRequested()), q, SLOT(triggerUpdate())); diff --git a/src/qtdeclarative/src/quickwidgets/quickwidgets.pro b/src/qtdeclarative/src/quickwidgets/quickwidgets.pro index 87409e31c5..411a32cc14 100644 --- a/src/qtdeclarative/src/quickwidgets/quickwidgets.pro +++ b/src/qtdeclarative/src/quickwidgets/quickwidgets.pro @@ -12,4 +12,14 @@ HEADERS += \ SOURCES += \ qquickwidget.cpp +contains(QT_CONFIG, accessibility) { +HEADERS += \ + qaccessiblequickwidgetfactory_p.h \ + qaccessiblequickwidget.h \ + +SOURCES += \ + qaccessiblequickwidgetfactory.cpp \ + qaccessiblequickwidget.cpp \ +} + load(qt_module)