diff options
Diffstat (limited to 'src/plugins/platforms/windows/uiautomation')
6 files changed, 304 insertions, 10 deletions
diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiaaccessibility.cpp b/src/plugins/platforms/windows/uiautomation/qwindowsuiaaccessibility.cpp index 85a931e015..c7c0deab3f 100644 --- a/src/plugins/platforms/windows/uiautomation/qwindowsuiaaccessibility.cpp +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiaaccessibility.cpp @@ -113,6 +113,9 @@ void QWindowsUiaAccessibility::notifyAccessibilityUpdate(QAccessibleEvent *event case QAccessible::ValueChanged: QWindowsUiaMainProvider::notifyValueChange(static_cast<QAccessibleValueChangeEvent *>(event)); break; + case QAccessible::SelectionAdd: + QWindowsUiaMainProvider::notifySelectionChange(event); + break; case QAccessible::TextAttributeChanged: case QAccessible::TextColumnChanged: case QAccessible::TextInserted: diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp b/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp index fad83fb165..a427e553f0 100644 --- a/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp @@ -52,6 +52,7 @@ #include "qwindowsuiatableitemprovider.h" #include "qwindowsuiagridprovider.h" #include "qwindowsuiagriditemprovider.h" +#include "qwindowsuiawindowprovider.h" #include "qwindowscombase.h" #include "qwindowscontext.h" #include "qwindowsuiautils.h" @@ -146,9 +147,33 @@ void QWindowsUiaMainProvider::notifyStateChange(QAccessibleStateChangeEvent *eve void QWindowsUiaMainProvider::notifyValueChange(QAccessibleValueChangeEvent *event) { if (QAccessibleInterface *accessible = event->accessibleInterface()) { - if (QAccessibleValueInterface *valueInterface = accessible->valueInterface()) { - // Notifies changes in values of controls supporting the value interface. + if (accessible->role() == QAccessible::ComboBox && accessible->childCount() > 0) { + QAccessibleInterface *listacc = accessible->child(0); + if (listacc && listacc->role() == QAccessible::List) { + int count = listacc->childCount(); + for (int i = 0; i < count; ++i) { + QAccessibleInterface *item = listacc->child(i); + if (item && item->text(QAccessible::Name) == event->value()) { + if (!item->state().selected) { + if (QAccessibleActionInterface *actionInterface = item->actionInterface()) + actionInterface->doAction(QAccessibleActionInterface::toggleAction()); + } + break; + } + } + } + } + if (event->value().type() == QVariant::String) { if (QWindowsUiaMainProvider *provider = providerForAccessible(accessible)) { + // Notifies changes in string values. + VARIANT oldVal, newVal; + clearVariant(&oldVal); + setVariantString(event->value().toString(), &newVal); + QWindowsUiaWrapper::instance()->raiseAutomationPropertyChangedEvent(provider, UIA_ValueValuePropertyId, oldVal, newVal); + } + } else if (QAccessibleValueInterface *valueInterface = accessible->valueInterface()) { + if (QWindowsUiaMainProvider *provider = providerForAccessible(accessible)) { + // Notifies changes in values of controls supporting the value interface. VARIANT oldVal, newVal; clearVariant(&oldVal); setVariantDouble(valueInterface->currentValue().toDouble(), &newVal); @@ -158,6 +183,15 @@ void QWindowsUiaMainProvider::notifyValueChange(QAccessibleValueChangeEvent *eve } } +void QWindowsUiaMainProvider::notifySelectionChange(QAccessibleEvent *event) +{ + if (QAccessibleInterface *accessible = event->accessibleInterface()) { + if (QWindowsUiaMainProvider *provider = providerForAccessible(accessible)) { + QWindowsUiaWrapper::instance()->raiseAutomationEvent(provider, UIA_SelectionItem_ElementSelectedEventId); + } + } +} + // Notifies changes in text content and selection state of text controls. void QWindowsUiaMainProvider::notifyTextChange(QAccessibleEvent *event) { @@ -230,6 +264,11 @@ HRESULT QWindowsUiaMainProvider::GetPatternProvider(PATTERNID idPattern, IUnknow return UIA_E_ELEMENTNOTAVAILABLE; switch (idPattern) { + case UIA_WindowPatternId: + if (accessible->parent() && (accessible->parent()->role() == QAccessible::Application)) { + *pRetVal = new QWindowsUiaWindowProvider(id()); + } + break; case UIA_TextPatternId: case UIA_TextPattern2Id: // All text controls. @@ -319,8 +358,7 @@ HRESULT QWindowsUiaMainProvider::GetPropertyValue(PROPERTYID idProp, VARIANT *pR if (!accessible) return UIA_E_ELEMENTNOTAVAILABLE; - bool clientTopLevel = (accessible->role() == QAccessible::Client) - && accessible->parent() && (accessible->parent()->role() == QAccessible::Application); + bool topLevelWindow = accessible->parent() && (accessible->parent()->role() == QAccessible::Application); switch (idProp) { case UIA_ProcessIdPropertyId: @@ -346,7 +384,7 @@ HRESULT QWindowsUiaMainProvider::GetPropertyValue(PROPERTYID idProp, VARIANT *pR setVariantString(QStringLiteral("Qt"), pRetVal); break; case UIA_ControlTypePropertyId: - if (clientTopLevel) { + if (topLevelWindow) { // Reports a top-level widget as a window, instead of "custom". setVariantI4(UIA_WindowControlTypeId, pRetVal); } else { @@ -358,10 +396,20 @@ HRESULT QWindowsUiaMainProvider::GetPropertyValue(PROPERTYID idProp, VARIANT *pR setVariantString(accessible->text(QAccessible::Help), pRetVal); break; case UIA_HasKeyboardFocusPropertyId: - setVariantBool(accessible->state().focused, pRetVal); + if (topLevelWindow) { + // Windows set the active state to true when they are focused + setVariantBool(accessible->state().active, pRetVal); + } else { + setVariantBool(accessible->state().focused, pRetVal); + } break; case UIA_IsKeyboardFocusablePropertyId: - setVariantBool(accessible->state().focusable, pRetVal); + if (topLevelWindow) { + // Windows should always be focusable + setVariantBool(true, pRetVal); + } else { + setVariantBool(accessible->state().focusable, pRetVal); + } break; case UIA_IsOffscreenPropertyId: setVariantBool(accessible->state().offscreen, pRetVal); @@ -391,7 +439,7 @@ HRESULT QWindowsUiaMainProvider::GetPropertyValue(PROPERTYID idProp, VARIANT *pR break; case UIA_NamePropertyId: { QString name = accessible->text(QAccessible::Name); - if (name.isEmpty() && clientTopLevel) + if (name.isEmpty() && topLevelWindow) name = QCoreApplication::applicationName(); setVariantString(name, pRetVal); break; diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.h b/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.h index 325d5b3de4..df0d60f9c9 100644 --- a/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.h +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.h @@ -68,6 +68,7 @@ public: static void notifyFocusChange(QAccessibleEvent *event); static void notifyStateChange(QAccessibleStateChangeEvent *event); static void notifyValueChange(QAccessibleValueChangeEvent *event); + static void notifySelectionChange(QAccessibleEvent *event); static void notifyTextChange(QAccessibleEvent *event); // IUnknown diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiawindowprovider.cpp b/src/plugins/platforms/windows/uiautomation/qwindowsuiawindowprovider.cpp new file mode 100644 index 0000000000..3738aa72ff --- /dev/null +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiawindowprovider.cpp @@ -0,0 +1,168 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui/qtguiglobal.h> +#if QT_CONFIG(accessibility) + +#include "qwindowsuiawindowprovider.h" +#include "qwindowsuiautils.h" +#include "qwindowscontext.h" + +#include <QtGui/qaccessible.h> +#include <QtGui/private/qwindow_p.h> +#include <QtCore/qloggingcategory.h> +#include <QtCore/qstring.h> + +QT_BEGIN_NAMESPACE + +using namespace QWindowsUiAutomation; + + +QWindowsUiaWindowProvider::QWindowsUiaWindowProvider(QAccessible::Id id) : + QWindowsUiaBaseProvider(id) +{ +} + +QWindowsUiaWindowProvider::~QWindowsUiaWindowProvider() +{ +} + +HRESULT STDMETHODCALLTYPE QWindowsUiaWindowProvider::SetVisualState(WindowVisualState state) { + qCDebug(lcQpaUiAutomation) << __FUNCTION__; + QAccessibleInterface *accessible = accessibleInterface(); + if (!accessible || !accessible->window()) + return UIA_E_ELEMENTNOTAVAILABLE; + auto window = accessible->window(); + switch (state) { + case WindowVisualState_Normal: + window->showNormal(); + break; + case WindowVisualState_Maximized: + window->showMaximized(); + break; + case WindowVisualState_Minimized: + window->showMinimized(); + break; + } + return S_OK; +} + +HRESULT STDMETHODCALLTYPE QWindowsUiaWindowProvider::Close() { + qCDebug(lcQpaUiAutomation) << __FUNCTION__; + QAccessibleInterface *accessible = accessibleInterface(); + if (!accessible || !accessible->window()) + return UIA_E_ELEMENTNOTAVAILABLE; + accessible->window()->close(); + return S_OK; +} + +HRESULT STDMETHODCALLTYPE QWindowsUiaWindowProvider::WaitForInputIdle(int milliseconds, __RPC__out BOOL *pRetVal) { + Q_UNUSED(milliseconds); + Q_UNUSED(pRetVal); + return UIA_E_NOTSUPPORTED; +} + +HRESULT STDMETHODCALLTYPE QWindowsUiaWindowProvider::get_CanMaximize(__RPC__out BOOL *pRetVal) { + qCDebug(lcQpaUiAutomation) << __FUNCTION__; + QAccessibleInterface *accessible = accessibleInterface(); + if (!accessible || !accessible->window()) + return UIA_E_ELEMENTNOTAVAILABLE; + + auto window = accessible->window(); + auto flags = window->flags(); + + *pRetVal = (!(flags & Qt::MSWindowsFixedSizeDialogHint) + && (flags & Qt::WindowMaximizeButtonHint) + && ((flags & Qt::CustomizeWindowHint) + || window->maximumSize() == QSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX))); + return S_OK; +} + +HRESULT STDMETHODCALLTYPE QWindowsUiaWindowProvider::get_CanMinimize(__RPC__out BOOL *pRetVal) { + qCDebug(lcQpaUiAutomation) << __FUNCTION__; + QAccessibleInterface *accessible = accessibleInterface(); + if (!accessible || !accessible->window()) + return UIA_E_ELEMENTNOTAVAILABLE; + *pRetVal = accessible->window()->flags() & Qt::WindowMinimizeButtonHint; + return S_OK; +} + +HRESULT STDMETHODCALLTYPE QWindowsUiaWindowProvider::get_IsModal(__RPC__out BOOL *pRetVal) { + qCDebug(lcQpaUiAutomation) << __FUNCTION__; + QAccessibleInterface *accessible = accessibleInterface(); + if (!accessible || !accessible->window()) + return UIA_E_ELEMENTNOTAVAILABLE; + *pRetVal = accessible->window()->isModal(); + return S_OK; +} + +HRESULT STDMETHODCALLTYPE QWindowsUiaWindowProvider::get_WindowVisualState(__RPC__out enum WindowVisualState *pRetVal) { + qCDebug(lcQpaUiAutomation) << __FUNCTION__; + QAccessibleInterface *accessible = accessibleInterface(); + if (!accessible || !accessible->window()) + return UIA_E_ELEMENTNOTAVAILABLE; + auto visibility = accessible->window()->visibility(); + switch (visibility) { + case QWindow::FullScreen: + case QWindow::Maximized: + *pRetVal = WindowVisualState_Maximized; + break; + case QWindow::Minimized: + *pRetVal = WindowVisualState_Minimized; + break; + default: + *pRetVal = WindowVisualState_Normal; + break; + } + return S_OK; +} + +HRESULT STDMETHODCALLTYPE QWindowsUiaWindowProvider::get_WindowInteractionState(__RPC__out enum WindowInteractionState *pRetVal) { + Q_UNUSED(pRetVal); + return UIA_E_NOTSUPPORTED; +} + +HRESULT STDMETHODCALLTYPE QWindowsUiaWindowProvider::get_IsTopmost(__RPC__out BOOL *pRetVal) { + Q_UNUSED(pRetVal); + return UIA_E_NOTSUPPORTED; +} + +QT_END_NAMESPACE + +#endif // QT_CONFIG(accessibility) diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiawindowprovider.h b/src/plugins/platforms/windows/uiautomation/qwindowsuiawindowprovider.h new file mode 100644 index 0000000000..343fb275f7 --- /dev/null +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiawindowprovider.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWINDOWSUIAWINDOWPROVIDER_H +#define QWINDOWSUIAWINDOWPROVIDER_H + +#include <QtGui/qtguiglobal.h> +#if QT_CONFIG(accessibility) + +#include "qwindowsuiabaseprovider.h" + +QT_BEGIN_NAMESPACE + +class QWindowsUiaWindowProvider : public QWindowsUiaBaseProvider, + public QWindowsComBase<IWindowProvider> +{ + Q_DISABLE_COPY(QWindowsUiaWindowProvider) +public: + explicit QWindowsUiaWindowProvider(QAccessible::Id id); + ~QWindowsUiaWindowProvider() override; + + HRESULT STDMETHODCALLTYPE SetVisualState(WindowVisualState state) override; + HRESULT STDMETHODCALLTYPE Close( void) override; + HRESULT STDMETHODCALLTYPE WaitForInputIdle(int milliseconds, __RPC__out BOOL *pRetVal) override; + HRESULT STDMETHODCALLTYPE get_CanMaximize(__RPC__out BOOL *pRetVal) override; + HRESULT STDMETHODCALLTYPE get_CanMinimize(__RPC__out BOOL *pRetVal) override; + HRESULT STDMETHODCALLTYPE get_IsModal(__RPC__out BOOL *pRetVal) override; + HRESULT STDMETHODCALLTYPE get_WindowVisualState(__RPC__out WindowVisualState *pRetVal) override; + HRESULT STDMETHODCALLTYPE get_WindowInteractionState(__RPC__out WindowInteractionState *pRetVal) override; + HRESULT STDMETHODCALLTYPE get_IsTopmost(__RPC__out BOOL *pRetVal) override; +}; + +QT_END_NAMESPACE + +#endif // QT_CONFIG(accessibility) + +#endif // QWINDOWSUIAWINDOWPROVIDER_H diff --git a/src/plugins/platforms/windows/uiautomation/uiautomation.pri b/src/plugins/platforms/windows/uiautomation/uiautomation.pri index e3071766d9..ee9332e7ea 100644 --- a/src/plugins/platforms/windows/uiautomation/uiautomation.pri +++ b/src/plugins/platforms/windows/uiautomation/uiautomation.pri @@ -18,6 +18,7 @@ SOURCES += \ $$PWD/qwindowsuiatableitemprovider.cpp \ $$PWD/qwindowsuiagridprovider.cpp \ $$PWD/qwindowsuiagriditemprovider.cpp \ + $$PWD/qwindowsuiawindowprovider.cpp \ $$PWD/qwindowsuiautils.cpp HEADERS += \ @@ -37,7 +38,7 @@ HEADERS += \ $$PWD/qwindowsuiatableitemprovider.h \ $$PWD/qwindowsuiagridprovider.h \ $$PWD/qwindowsuiagriditemprovider.h \ + $$PWD/qwindowsuiawindowprovider.h \ $$PWD/qwindowsuiautils.h -mingw: LIBS *= -luuid - +mingw: QMAKE_USE *= uuid |