diff options
Diffstat (limited to 'src/core/browser_accessibility_manager_qt.cpp')
-rw-r--r-- | src/core/browser_accessibility_manager_qt.cpp | 133 |
1 files changed, 74 insertions, 59 deletions
diff --git a/src/core/browser_accessibility_manager_qt.cpp b/src/core/browser_accessibility_manager_qt.cpp index 5968bfd30..077856266 100644 --- a/src/core/browser_accessibility_manager_qt.cpp +++ b/src/core/browser_accessibility_manager_qt.cpp @@ -1,79 +1,67 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +#include "qtwebenginecoreglobal.h" + +#include "content/browser/accessibility/browser_accessibility_manager.h" + +#include <QtGui/qtguiglobal.h> + +#if QT_CONFIG(accessibility) +#include "browser_accessibility_qt.h" #include "browser_accessibility_manager_qt.h" +#include "render_widget_host_view_qt.h" // WebContentsAccessibilityQt +#include "content/browser/accessibility/browser_accessibility.h" #include "ui/accessibility/ax_enums.mojom.h" -#include "browser_accessibility_qt.h" -using namespace blink; +#include <QtGui/qaccessible.h> +#endif // QT_CONFIG(accessibility) namespace content { -BrowserAccessibilityManager* BrowserAccessibilityManager::Create( - const ui::AXTreeUpdate& initialTree, - BrowserAccessibilityDelegate* delegate, - BrowserAccessibilityFactory* factory) +// static +BrowserAccessibilityManager *BrowserAccessibilityManager::Create( + const ui::AXTreeUpdate &initialTree, + WebAXPlatformTreeManagerDelegate *delegate) { #if QT_CONFIG(accessibility) - return new BrowserAccessibilityManagerQt(nullptr, initialTree, delegate, factory); + Q_ASSERT(delegate); + QtWebEngineCore::WebContentsAccessibilityQt *access = nullptr; + access = static_cast<QtWebEngineCore::WebContentsAccessibilityQt *>(delegate->AccessibilityGetWebContentsAccessibility()); + + // Accessibility is not supported for guest views and child frames. + if (!access) { + return nullptr; + } + + return new BrowserAccessibilityManagerQt(access, initialTree, delegate); #else - delete factory; + Q_UNUSED(initialTree); + Q_UNUSED(delegate); return nullptr; #endif // QT_CONFIG(accessibility) } -BrowserAccessibility *BrowserAccessibility::Create() +// static +BrowserAccessibilityManager *BrowserAccessibilityManager::Create( + WebAXPlatformTreeManagerDelegate *delegate) { #if QT_CONFIG(accessibility) - return new BrowserAccessibilityQt(); + return BrowserAccessibilityManager::Create(BrowserAccessibilityManagerQt::GetEmptyDocument(), delegate); #else + Q_UNUSED(delegate); return nullptr; -#endif // QT_CONFIG(accessibility) +#endif } #if QT_CONFIG(accessibility) BrowserAccessibilityManagerQt::BrowserAccessibilityManagerQt( - QObject *parentObject, const ui::AXTreeUpdate &initialTree, - BrowserAccessibilityDelegate* delegate, BrowserAccessibilityFactory* factory) - : BrowserAccessibilityManager(delegate, factory) - , m_parentObject(parentObject) + QtWebEngineCore::WebContentsAccessibilityQt *webContentsAccessibility, + const ui::AXTreeUpdate &initialTree, + WebAXPlatformTreeManagerDelegate* delegate) + : BrowserAccessibilityManager(delegate) + , m_webContentsAccessibility(webContentsAccessibility) { Initialize(initialTree); m_valid = true; // BrowserAccessibilityQt can start using the AXTree @@ -86,17 +74,28 @@ BrowserAccessibilityManagerQt::~BrowserAccessibilityManagerQt() QAccessibleInterface *BrowserAccessibilityManagerQt::rootParentAccessible() { - return QAccessible::queryAccessibleInterface(m_parentObject); + content::BrowserAccessibility *parent_node = GetParentNodeFromParentTreeAsBrowserAccessibility(); + if (!parent_node) { + Q_ASSERT(m_webContentsAccessibility); + return QAccessible::queryAccessibleInterface(m_webContentsAccessibility->accessibilityParentObject()); + } + + auto *parent_manager = + static_cast<BrowserAccessibilityManagerQt *>(parent_node->manager()); + return parent_manager->rootParentAccessible(); } void BrowserAccessibilityManagerQt::FireBlinkEvent(ax::mojom::Event event_type, - BrowserAccessibility* node) + BrowserAccessibility *node, + int action_request_id) { - BrowserAccessibilityQt *iface = static_cast<BrowserAccessibilityQt*>(node); + auto *iface = toQAccessibleInterface(node); switch (event_type) { case ax::mojom::Event::kFocus: { QAccessibleEvent event(iface, QAccessible::Focus); + if (event.object()) + event.setChild(-1); QAccessible::updateAccessibility(&event); break; } @@ -104,6 +103,8 @@ void BrowserAccessibilityManagerQt::FireBlinkEvent(ax::mojom::Event event_type, QAccessible::State change; change.checked = true; QAccessibleStateChangeEvent event(iface, change); + if (event.object()) + event.setChild(-1); QAccessible::updateAccessibility(&event); break; } @@ -112,6 +113,8 @@ void BrowserAccessibilityManagerQt::FireBlinkEvent(ax::mojom::Event event_type, if (QAccessibleValueInterface *valueIface = iface->valueInterface()) value = valueIface->currentValue(); QAccessibleValueChangeEvent event(iface, value); + if (event.object()) + event.setChild(-1); QAccessible::updateAccessibility(&event); break; } @@ -123,6 +126,8 @@ void BrowserAccessibilityManagerQt::FireBlinkEvent(ax::mojom::Event event_type, break; case ax::mojom::Event::kTextChanged: { QAccessibleTextUpdateEvent event(iface, -1, QString(), QString()); + if (event.object()) + event.setChild(-1); QAccessible::updateAccessibility(&event); break; } @@ -134,9 +139,13 @@ void BrowserAccessibilityManagerQt::FireBlinkEvent(ax::mojom::Event event_type, textIface->selection(0, &start, &end); if (start == end) { QAccessibleTextCursorEvent event(iface, start); + if (event.object()) + event.setChild(-1); QAccessible::updateAccessibility(&event); } else { QAccessibleTextSelectionEvent event(iface, start, end); + if (event.object()) + event.setChild(-1); QAccessible::updateAccessibility(&event); } } @@ -148,14 +157,20 @@ void BrowserAccessibilityManagerQt::FireBlinkEvent(ax::mojom::Event event_type, } void BrowserAccessibilityManagerQt::FireGeneratedEvent(ui::AXEventGenerator::Event event_type, - BrowserAccessibility* node) + const ui::AXNode *node) { - BrowserAccessibilityQt *iface = static_cast<BrowserAccessibilityQt*>(node); + BrowserAccessibilityManager::FireGeneratedEvent(event_type, node); + + BrowserAccessibility *wrapper = GetFromAXNode(node); + DCHECK(wrapper); + auto *iface = toQAccessibleInterface(wrapper); switch (event_type) { - case ui::AXEventGenerator::Event::VALUE_CHANGED: + case ui::AXEventGenerator::Event::VALUE_IN_TEXT_FIELD_CHANGED: if (iface->role() == QAccessible::EditableText) { QAccessibleTextUpdateEvent event(iface, -1, QString(), QString()); + if (event.object()) + event.setChild(-1); QAccessible::updateAccessibility(&event); } break; |