diff --git a/src/core/browser_accessibility_delegate_qt.cpp b/src/core/browser_accessibility_delegate_qt.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a692b2621f30b310978ad325dd9dad6b249afbaf --- /dev/null +++ b/src/core/browser_accessibility_delegate_qt.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "browser_accessibility_delegate_qt.h" + +#include <QtCore/qglobal.h> + +BrowserAccessibilityDelegateQt::BrowserAccessibilityDelegateQt(content::RenderWidgetHostViewBase *rwhv) + : m_rwhv(rwhv) +{ + Q_ASSERT(m_rwhv); +} + +bool BrowserAccessibilityDelegateQt::HasFocus() const +{ + return m_rwhv->HasFocus(); +} + +gfx::Rect BrowserAccessibilityDelegateQt::GetViewBounds() const +{ + return m_rwhv->GetViewBounds(); +} + +void BrowserAccessibilityDelegateQt::SetAccessibilityFocus(int acc_obj_id) +{ +} + +void BrowserAccessibilityDelegateQt::AccessibilityDoDefaultAction(int acc_obj_id) +{ +} + +void BrowserAccessibilityDelegateQt::AccessibilityScrollToMakeVisible( + int acc_obj_id, gfx::Rect subfocus) +{ +} + +void BrowserAccessibilityDelegateQt::AccessibilityScrollToPoint( + int acc_obj_id, gfx::Point point) +{ +} + +void BrowserAccessibilityDelegateQt::AccessibilitySetTextSelection( + int acc_obj_id, int start_offset, int end_offset) +{ +} + +gfx::Point BrowserAccessibilityDelegateQt::GetLastTouchEventLocation() const +{ + return gfx::Point(); +} + +void BrowserAccessibilityDelegateQt::FatalAccessibilityTreeError() +{ + qWarning("BrowserAccessibilityDelegateQt::FatalAccessibilityTreeError"); + m_rwhv->SetBrowserAccessibilityManager(0); +} diff --git a/src/core/browser_accessibility_delegate_qt.h b/src/core/browser_accessibility_delegate_qt.h new file mode 100644 index 0000000000000000000000000000000000000000..1174f2378c020519783ab556b1decf0f257cc18a --- /dev/null +++ b/src/core/browser_accessibility_delegate_qt.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BROWSER_ACCESSIBILITY_DELEGATE_QT_H +#define BROWSER_ACCESSIBILITY_DELEGATE_QT_H + +#include <QtCore/qglobal.h> + +#include "content/browser/accessibility/browser_accessibility_manager.h" +#include "content/browser/renderer_host/render_widget_host_view_base.h" + +class BrowserAccessibilityDelegateQt + : public content::BrowserAccessibilityDelegate +{ +public: + BrowserAccessibilityDelegateQt(content::RenderWidgetHostViewBase *rwhv); + + virtual bool HasFocus() const Q_DECL_OVERRIDE; + virtual void SetAccessibilityFocus(int acc_obj_id) Q_DECL_OVERRIDE; + + virtual void AccessibilityDoDefaultAction(int acc_obj_id) Q_DECL_OVERRIDE; + + virtual gfx::Rect GetViewBounds() const Q_DECL_OVERRIDE; + virtual void AccessibilityScrollToMakeVisible( + int acc_obj_id, gfx::Rect subfocus) Q_DECL_OVERRIDE; + virtual void AccessibilityScrollToPoint( + int acc_obj_id, gfx::Point point) Q_DECL_OVERRIDE; + + virtual void AccessibilitySetTextSelection( + int acc_obj_id, int start_offset, int end_offset) Q_DECL_OVERRIDE; + + virtual gfx::Point GetLastTouchEventLocation() const Q_DECL_OVERRIDE; + + virtual void FatalAccessibilityTreeError() Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(BrowserAccessibilityDelegateQt) + content::RenderWidgetHostViewBase *m_rwhv; +}; + +#endif diff --git a/src/core/browser_accessibility_manager_qt.cpp b/src/core/browser_accessibility_manager_qt.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8c2c3444a9c4095816574fb0575ae31dae464524 --- /dev/null +++ b/src/core/browser_accessibility_manager_qt.cpp @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "browser_accessibility_manager_qt.h" + +#include "third_party/WebKit/public/web/WebAXEnums.h" +#include "browser_accessibility_qt.h" + +using namespace blink; + +namespace content { + +BrowserAccessibility *BrowserAccessibilityFactoryQt::Create() +{ + return new BrowserAccessibilityQt(); +} + +BrowserAccessibilityManagerQt::BrowserAccessibilityManagerQt( + QObject* parentObject, + const AccessibilityNodeData& src, + BrowserAccessibilityDelegate* delegate, + BrowserAccessibilityFactory* factory) + : BrowserAccessibilityManager(delegate, factory) + , m_parentObject(parentObject) { + Initialize(src); +} + +QAccessibleInterface *BrowserAccessibilityManagerQt::rootParentAccessible() +{ + return QAccessible::queryAccessibleInterface(m_parentObject); +} + +void BrowserAccessibilityManagerQt::NotifyRootChanged() +{ +} + +void BrowserAccessibilityManagerQt::NotifyAccessibilityEvent(blink::WebAXEvent event_type, + BrowserAccessibility* node) +{ + BrowserAccessibilityQt *iface = static_cast<BrowserAccessibilityQt*>(node); + + switch (event_type) { + case WebAXEventFocus: { + QAccessibleEvent event(iface, QAccessible::Focus); + QAccessible::updateAccessibility(&event); + break; + } + case WebAXEventCheckedStateChanged: { + BrowserAccessibilityQt *iface = static_cast<BrowserAccessibilityQt*>(node); + QAccessible::State change; + change.checked = true; + QAccessibleStateChangeEvent event(iface, change); + QAccessible::updateAccessibility(&event); + break; + } + case WebAXEventValueChanged: { + QVariant value; + if (QAccessibleValueInterface *valueIface = iface->valueInterface()) + value = valueIface->currentValue(); + QAccessibleValueChangeEvent event(iface, value); + QAccessible::updateAccessibility(&event); + break; + } + case WebAXEventChildrenChanged: + break; + case WebAXEventLayoutComplete: + break; + case WebAXEventLoadComplete: + break; + case WebAXEventTextChanged: + break; + case WebAXEventTextInserted: + break; + case WebAXEventTextRemoved: + break; + default: + break; + } +} + +} diff --git a/src/core/browser_accessibility_manager_qt.h b/src/core/browser_accessibility_manager_qt.h new file mode 100644 index 0000000000000000000000000000000000000000..e3cca81cefd780a24c45c0c83e9f05cd141188bd --- /dev/null +++ b/src/core/browser_accessibility_manager_qt.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BROWSER_ACCESSIBILITY_MANAGER_QT_H +#define BROWSER_ACCESSIBILITY_MANAGER_QT_H + +#include "content/browser/accessibility/browser_accessibility_manager.h" +#include <QtCore/qobject.h> + +QT_BEGIN_NAMESPACE +class QAccessibleInterface; +QT_END_NAMESPACE + +namespace content { + +class BrowserAccessibilityFactoryQt : public BrowserAccessibilityFactory +{ +public: + BrowserAccessibility* Create() Q_DECL_OVERRIDE; +}; + +class BrowserAccessibilityManagerQt : public BrowserAccessibilityManager +{ +public: + BrowserAccessibilityManagerQt( + QObject* parentObject, + const AccessibilityNodeData& src, + BrowserAccessibilityDelegate* delegate, + BrowserAccessibilityFactory* factory = new BrowserAccessibilityFactoryQt()); + + void NotifyRootChanged() Q_DECL_OVERRIDE; + void NotifyAccessibilityEvent( + blink::WebAXEvent event_type, + BrowserAccessibility* node) Q_DECL_OVERRIDE; + + QAccessibleInterface *rootParentAccessible(); + +private: + Q_DISABLE_COPY(BrowserAccessibilityManagerQt) + QObject *m_parentObject; +}; + +} + +#endif diff --git a/src/core/browser_accessibility_qt.cpp b/src/core/browser_accessibility_qt.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bfbb3f69bea6cce80c72d0a542270e11b46cb912 --- /dev/null +++ b/src/core/browser_accessibility_qt.cpp @@ -0,0 +1,393 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "browser_accessibility_qt.h" + +#include "content/common/accessibility_node_data.h" +#include "third_party/WebKit/public/web/WebAXEnums.h" +#include "type_conversion.h" +#include "browser_accessibility_manager_qt.h" + +using namespace blink; + +namespace content { + +BrowserAccessibilityQt::BrowserAccessibilityQt() +{ + QAccessible::registerAccessibleInterface(this); +} + +bool BrowserAccessibilityQt::isValid() const +{ + return true; +} + +QObject *BrowserAccessibilityQt::object() const +{ + return 0; +} + +QAccessibleInterface *BrowserAccessibilityQt::childAt(int x, int y) const +{ + return 0; +} + +QAccessibleInterface *BrowserAccessibilityQt::parent() const +{ + BrowserAccessibility *p = BrowserAccessibility::parent(); + if (p) + return static_cast<BrowserAccessibilityQt*>(p); + return static_cast<BrowserAccessibilityManagerQt*>(manager())->rootParentAccessible(); +} + +QAccessibleInterface *BrowserAccessibilityQt::child(int index) const +{ + return static_cast<BrowserAccessibilityQt*>(BrowserAccessibility::PlatformGetChild(index)); +} + +int BrowserAccessibilityQt::childCount() const +{ + return child_count(); +} + +int BrowserAccessibilityQt::indexOfChild(const QAccessibleInterface *iface) const +{ + + const BrowserAccessibilityQt *child = static_cast<const BrowserAccessibilityQt*>(iface); + return child->index_in_parent(); +} + +QString BrowserAccessibilityQt::text(QAccessible::Text t) const +{ + std::string name_str = name(); + return toQt(name_str); +} + +void BrowserAccessibilityQt::setText(QAccessible::Text t, const QString &text) +{ +} + +QRect BrowserAccessibilityQt::rect() const +{ + gfx::Rect bounds = GetGlobalBoundsRect(); + return QRect(bounds.x(), bounds.y(), bounds.width(), bounds.height()); +} + +QAccessible::Role BrowserAccessibilityQt::role() const +{ + switch (BrowserAccessibility::role()) { + case WebAXRoleUnknown: + return QAccessible::NoRole; + + // Used by Chromium to distinguish between the root of the tree + // for this page, and a web area for a frame within this page. + case WebAXRoleWebArea: + case WebAXRoleRootWebArea: // not sure if we need to make a diff here, but this seems common + return QAccessible::Document; + + // These roles all directly correspond to blink accessibility roles, + // keep these alphabetical. + case WebAXRoleAlert: + return QAccessible::AlertMessage; + case WebAXRoleAnnotation: + return QAccessible::NoRole; // FIXME + case WebAXRoleApplication: + return QAccessible::Application; + case WebAXRoleArticle: + return QAccessible::Document; // FIXME + case WebAXRoleBrowser: + return QAccessible::Document; // FIXME + case WebAXRoleBusyIndicator: + return QAccessible::Animation; // FIXME + case WebAXRoleButton: + return QAccessible::Button; + case WebAXRoleCanvas: + return QAccessible::Canvas; + case WebAXRoleCell: + return QAccessible::Cell; + case WebAXRoleCheckBox: + return QAccessible::CheckBox; + case WebAXRoleColorWell: + return QAccessible::NoRole; // FIXME + case WebAXRoleColumn: + return QAccessible::Column; + case WebAXRoleColumnHeader: + return QAccessible::ColumnHeader; + case WebAXRoleComboBox: + return QAccessible::ComboBox; + case WebAXRoleDefinition: + return QAccessible::NoRole; // FIXME + case WebAXRoleDescriptionListDetail: + return QAccessible::NoRole; // FIXME + case WebAXRoleDescriptionListTerm: + return QAccessible::NoRole; // FIXME + case WebAXRoleDialog: + return QAccessible::Dialog; + case WebAXRoleDirectory: + return QAccessible::NoRole; // FIXME + case WebAXRoleDisclosureTriangle: + return QAccessible::NoRole; // FIXME + case WebAXRoleDiv: + return QAccessible::NoRole; // FIXME + case WebAXRoleDocument: + return QAccessible::Document; + case WebAXRoleDrawer: + return QAccessible::NoRole; // FIXME + case WebAXRoleEditableText: + return QAccessible::EditableText; + case WebAXRoleFooter: + return QAccessible::NoRole; // FIXME + case WebAXRoleForm: + return QAccessible::NoRole; // FIXME + case WebAXRoleGrid: + return QAccessible::NoRole; // FIXME + case WebAXRoleGroup: + return QAccessible::Grouping; + case WebAXRoleGrowArea: + return QAccessible::NoRole; // FIXME + case WebAXRoleHeading: + return QAccessible::StaticText; // FIXME + case WebAXRoleHelpTag: + return QAccessible::NoRole; // FIXME + case WebAXRoleHorizontalRule: + return QAccessible::NoRole; // FIXME + case WebAXRoleIgnored: + return QAccessible::NoRole; + case WebAXRoleImage: + return QAccessible::Graphic; + case WebAXRoleImageMap: + return QAccessible::NoRole; // FIXME + case WebAXRoleImageMapLink: + return QAccessible::NoRole; // FIXME + case WebAXRoleIncrementor: + return QAccessible::NoRole; // FIXME + case WebAXRoleLabel: + return QAccessible::StaticText; + case WebAXRoleLink: + return QAccessible::Link; + case WebAXRoleList: + return QAccessible::List; + case WebAXRoleListBox: + return QAccessible::NoRole; // FIXME + case WebAXRoleListBoxOption: + return QAccessible::NoRole; // FIXME + case WebAXRoleListItem: + return QAccessible::ListItem; + case WebAXRoleListMarker: + return QAccessible::NoRole; // FIXME + case WebAXRoleLog: + return QAccessible::NoRole; // FIXME + case WebAXRoleMarquee: + return QAccessible::NoRole; // FIXME + case WebAXRoleMath: + return QAccessible::NoRole; // FIXME + case WebAXRoleMatte: + return QAccessible::NoRole; // FIXME + case WebAXRoleMenu: + return QAccessible::PopupMenu; + case WebAXRoleMenuBar: + return QAccessible::MenuBar; + case WebAXRoleMenuItem: + return QAccessible::MenuItem; + case WebAXRoleMenuButton: + return QAccessible::MenuItem; + case WebAXRoleMenuListOption: + return QAccessible::NoRole; // FIXME + case WebAXRoleMenuListPopup: + return QAccessible::PopupMenu; + case WebAXRoleNote: + return QAccessible::NoRole; // FIXME + case WebAXRoleOutline: + return QAccessible::NoRole; // FIXME + case WebAXRoleParagraph: + return QAccessible::NoRole; // FIXME + case WebAXRolePopUpButton: + return QAccessible::NoRole; // FIXME + case WebAXRolePresentational: + return QAccessible::NoRole; // FIXME + case WebAXRoleProgressIndicator: + return QAccessible::NoRole; // FIXME + case WebAXRoleRadioButton: + return QAccessible::RadioButton; + case WebAXRoleRadioGroup: + return QAccessible::RadioButton; + case WebAXRoleRegion: + return QAccessible::NoRole; // FIXME + case WebAXRoleRow: + return QAccessible::Row; + case WebAXRoleRowHeader: + return QAccessible::RowHeader; + case WebAXRoleRuler: + return QAccessible::NoRole; // FIXME + case WebAXRoleRulerMarker: + return QAccessible::NoRole; // FIXME + case WebAXRoleScrollArea: + return QAccessible::NoRole; // FIXME + case WebAXRoleScrollBar: + return QAccessible::ScrollBar; + case WebAXRoleSheet: + return QAccessible::NoRole; // FIXME + case WebAXRoleSlider: + return QAccessible::Slider; + case WebAXRoleSliderThumb: + return QAccessible::NoRole; // FIXME + case WebAXRoleSpinButton: + return QAccessible::NoRole; // FIXME + case WebAXRoleSpinButtonPart: + return QAccessible::NoRole; // FIXME + case WebAXRoleSplitter: + return QAccessible::Splitter; + case WebAXRoleSplitGroup: + return QAccessible::NoRole; // FIXME + case WebAXRoleStaticText: + return QAccessible::StaticText; + case WebAXRoleStatus: + return QAccessible::NoRole; // FIXME + case WebAXRoleSVGRoot: + return QAccessible::NoRole; // FIXME + case WebAXRoleSystemWide: + return QAccessible::NoRole; // FIXME + case WebAXRoleTab: + return QAccessible::PageTab; + case WebAXRoleTable: + return QAccessible::Table; + case WebAXRoleTableHeaderContainer: + return QAccessible::NoRole; // FIXME + case WebAXRoleTabGroup: // blink doesn't use (uses ROLE_TAB_LIST) + return QAccessible::NoRole; // FIXME + case WebAXRoleTabList: + return QAccessible::PageTabList; + case WebAXRoleTabPanel: + return QAccessible::PageTab; + case WebAXRoleTextArea: + return QAccessible::EditableText; + case WebAXRoleTextField: + return QAccessible::EditableText; + case WebAXRoleTimer: + return QAccessible::NoRole; // FIXME + case WebAXRoleToggleButton: + return QAccessible::Button; // FIXME + case WebAXRoleToolbar: + return QAccessible::ToolBar; + case WebAXRoleUserInterfaceTooltip: + return QAccessible::ToolTip; + case WebAXRoleTree: + return QAccessible::Tree; + case WebAXRoleTreeGrid: + return QAccessible::NoRole; // FIXME + case WebAXRoleTreeItem: + return QAccessible::TreeItem; + case WebAXRoleValueIndicator: + return QAccessible::NoRole; // FIXME + case WebAXRoleWindow: + return QAccessible::Window; + } + return QAccessible::NoRole; +} + +QAccessible::State BrowserAccessibilityQt::state() const +{ + QAccessible::State state = QAccessible::State(); + int32 s = BrowserAccessibility::state(); + if (s & (1 << WebAXStateBusy)) + state.busy = true; + if (s & (1 << WebAXStateChecked)) + state.checked = true; + if (s & (1 << WebAXStateCollapsed)) + state.collapsed = true; + if (!(s & (1 << WebAXStateEnabled))) + state.disabled = true; + if (s & (1 << WebAXStateExpanded)) + state.expanded = true; + if (s & (1 << WebAXStateFocusable)) + state.focusable = true; + if (s & (1 << WebAXStateFocused)) + state.focused = true; + if (s & (1 << WebAXStateHaspopup)) + state.hasPopup = true; + if (s & (1 << WebAXStateHovered)) + state.hotTracked = true; + if (s & (1 << WebAXStateIndeterminate)) + {} // FIXME + if (s & (1 << WebAXStateInvisible)) + state.invisible = true; + if (s & (1 << WebAXStateLinked)) + state.linked = true; + if (s & (1 << WebAXStateMultiselectable)) + state.multiSelectable = true; + if (s & (1 << WebAXStateOffscreen)) + state.offscreen = true; + if (s & (1 << WebAXStatePressed)) + state.pressed = true; + if (s & (1 << WebAXStateProtected)) + {} // FIXME + if (s & (1 << WebAXStateReadonly)) + state.readOnly = true; + if (s & (1 << WebAXStateRequired)) + {} // FIXME + if (s & (1 << WebAXStateSelectable)) + state.selectable = true; + if (s & (1 << WebAXStateSelected)) + state.selected = true; + if (s & (1 << WebAXStateVertical)) + {} // FIXME + if (s & (1 << WebAXStateVisited)) + {} // FIXME + return state; +} + +// Qt does not reference count accessibles +void BrowserAccessibilityQt::NativeAddReference() +{ +} + +// there is no reference counting, but BrowserAccessibility::Destroy +// calls this (and that is the only place in the chromium sources, +// so we can safely use it to dispose of ourselves here +// (the default implementation of this function just contains a "delete this") +void BrowserAccessibilityQt::NativeReleaseReference() +{ + // delete this + QAccessible::Id interfaceId = QAccessible::uniqueId(this); + QAccessible::deleteAccessibleInterface(interfaceId); +} + +} // namespace content diff --git a/src/core/browser_accessibility_qt.h b/src/core/browser_accessibility_qt.h new file mode 100644 index 0000000000000000000000000000000000000000..839fedeb8270e66a474e13c360e0377336cdc430 --- /dev/null +++ b/src/core/browser_accessibility_qt.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BROWSER_ACCESSIBILITY_QT_H +#define BROWSER_ACCESSIBILITY_QT_H + +#include <QtGui/qaccessible.h> +#include "content/browser/accessibility/browser_accessibility.h" + +namespace content { + +class BrowserAccessibilityQt + : public BrowserAccessibility + , public QAccessibleInterface +{ +public: + BrowserAccessibilityQt(); + + // QAccessibleInterface + virtual bool isValid() const Q_DECL_OVERRIDE; + virtual QObject *object() const Q_DECL_OVERRIDE; + virtual QAccessibleInterface *childAt(int x, int y) const Q_DECL_OVERRIDE; + + // navigation, hierarchy + virtual QAccessibleInterface *parent() const Q_DECL_OVERRIDE; + virtual QAccessibleInterface *child(int index) const Q_DECL_OVERRIDE; + virtual int childCount() const Q_DECL_OVERRIDE; + virtual int indexOfChild(const QAccessibleInterface *) const Q_DECL_OVERRIDE; + + // properties and state + virtual QString text(QAccessible::Text t) const Q_DECL_OVERRIDE; + virtual void setText(QAccessible::Text t, const QString &text) Q_DECL_OVERRIDE; + virtual QRect rect() const Q_DECL_OVERRIDE; + virtual QAccessible::Role role() const Q_DECL_OVERRIDE; + virtual QAccessible::State state() const Q_DECL_OVERRIDE; + + // BrowserAccessible + void NativeAddReference() Q_DECL_OVERRIDE; + void NativeReleaseReference() Q_DECL_OVERRIDE; + bool IsNative() const Q_DECL_OVERRIDE { return true; } +}; + +} + +#endif diff --git a/src/core/core_gyp_generator.pro b/src/core/core_gyp_generator.pro index cab838849b83064bec9a72268297a14c3bd0c6d8..d86811ce3412785feae0b12bf3b2837b39681334 100644 --- a/src/core/core_gyp_generator.pro +++ b/src/core/core_gyp_generator.pro @@ -36,6 +36,9 @@ RESOURCES += devtools.qrc INCLUDEPATH += $$[QT_INSTALL_HEADERS] $$PWD SOURCES = \ + browser_accessibility_delegate_qt.cpp \ + browser_accessibility_manager_qt.cpp \ + browser_accessibility_qt.cpp \ browser_context_qt.cpp \ chromium_gpu_helper.cpp \ chromium_overrides.cpp \ @@ -77,6 +80,8 @@ SOURCES = \ HEADERS = \ + browser_accessibility_manager_qt.h \ + browser_accessibility_qt.h \ browser_context_qt.h \ chromium_overrides.h \ clipboard_qt.h \ diff --git a/src/core/qtwebengine_extras.gypi b/src/core/qtwebengine_extras.gypi index fe035a0b1dac1bd904a054fb29757a8e13dc5bd4..c0f4ce2319e8bc76d5fcaba86b00b509afe6b46a 100644 --- a/src/core/qtwebengine_extras.gypi +++ b/src/core/qtwebengine_extras.gypi @@ -33,6 +33,15 @@ ['exclude', 'browser/renderer_host/render_widget_host_view_mac\\.(mm|h)$'], ['exclude', 'browser/renderer_host/render_widget_host_view_win\\.(cc|h)$'], ['exclude', 'common/font_list_pango\\.cc$'], + ['exclude', 'browser/accessibility/browser_accessibility_android\\.(cc|h)$'], + ['exclude', 'browser/accessibility/browser_accessibility_cocoa\\.(cc|h)$'], + ['exclude', 'browser/accessibility/browser_accessibility_gtk\\.(cc|h)$'], + ['exclude', 'browser/accessibility/browser_accessibility_mac\\.(cc|h)$'], + ['exclude', 'browser/accessibility/browser_accessibility_win\\.(cc|h)$'], + ['exclude', 'browser/accessibility/browser_accessibility_manager_android\\.(cc|h)$'], + ['exclude', 'browser/accessibility/browser_accessibility_manager_gtk\\.(cc|h)$'], + ['exclude', 'browser/accessibility/browser_accessibility_manager_mac\\.(cc|h)$'], + ['exclude', 'browser/accessibility/browser_accessibility_manager_win\\.(cc|h)$'], ], 'defines': [ 'TOOLKIT_QT', diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index 386783f8874489ab823c5924dded25db1637b617..21de24d4519a499014bbfe03c0966718d9826a1c 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -41,20 +41,25 @@ #include "render_widget_host_view_qt.h" +#include "browser_accessibility_manager_qt.h" +#include "browser_accessibility_qt.h" #include "chromium_overrides.h" #include "delegated_frame_node.h" #include "render_widget_host_view_qt_delegate.h" #include "type_conversion.h" +#include "web_contents_adapter.h" #include "web_contents_adapter_client.h" #include "web_event_factory.h" #include "base/command_line.h" #include "cc/output/compositor_frame_ack.h" +#include "content/browser/accessibility/browser_accessibility_state_impl.h" #include "content/browser/renderer_host/render_view_host_impl.h" #include "content/browser/renderer_host/ui_events_helper.h" -#include "content/public/common/content_switches.h" #include "content/common/gpu/gpu_messages.h" #include "content/common/view_messages.h" +#include "content/public/common/content_switches.h" +#include "content/public/browser/browser_accessibility_state.h" #include "third_party/skia/include/core/SkColor.h" #include "third_party/WebKit/public/platform/WebColor.h" #include "third_party/WebKit/public/platform/WebCursorInfo.h" @@ -76,6 +81,7 @@ #include <QVariant> #include <QWheelEvent> #include <QWindow> +#include <QtGui/qaccessible.h> static inline ui::EventType toUIEventType(Qt::TouchPointState state) { @@ -258,9 +264,20 @@ gfx::NativeViewId RenderWidgetHostViewQt::GetNativeViewId() const gfx::NativeViewAccessible RenderWidgetHostViewQt::GetNativeViewAccessible() { - // We are not using accessibility features at this point. - QT_NOT_USED - return NULL; + CreateBrowserAccessibilityManagerIfNeeded(); + return GetBrowserAccessibilityManager()->GetRoot(); +} + +void RenderWidgetHostViewQt::CreateBrowserAccessibilityManagerIfNeeded() +{ + if (GetBrowserAccessibilityManager()) + return; + + m_accessibilityDelegate = scoped_ptr<BrowserAccessibilityDelegateQt>(new BrowserAccessibilityDelegateQt(this)); + SetBrowserAccessibilityManager(new content::BrowserAccessibilityManagerQt( + m_adapterClient->accessibilityParentObject(), + content::BrowserAccessibilityManagerQt::GetEmptyDocument(), + m_accessibilityDelegate.get())); } // Set focus to the associated View component. @@ -624,10 +641,10 @@ void RenderWidgetHostViewQt::SetHasHorizontalScrollbar(bool) { } void RenderWidgetHostViewQt::SetScrollOffsetPinning(bool, bool) { } -void RenderWidgetHostViewQt::OnAccessibilityEvents(const std::vector<AccessibilityHostMsg_EventParams>&) +void RenderWidgetHostViewQt::OnAccessibilityEvents(const std::vector<AccessibilityHostMsg_EventParams> ¬ifications) { - // We are not using accessibility features at this point. - QT_NOT_USED + CreateBrowserAccessibilityManagerIfNeeded(); + GetBrowserAccessibilityManager()->OnAccessibilityEvents(notifications); } void RenderWidgetHostViewQt::SelectionChanged(const base::string16 &text, size_t offset, const gfx::Range &range) @@ -1022,3 +1039,16 @@ void RenderWidgetHostViewQt::handleFocusEvent(QFocusEvent *ev) ev->accept(); } } + +QAccessibleInterface *RenderWidgetHostViewQt::GetQtAccessible() +{ + // Assume we have a screen reader doing stuff + CreateBrowserAccessibilityManagerIfNeeded(); + content::BrowserAccessibilityState::GetInstance()->OnScreenReaderDetected(); + content::BrowserAccessibilityStateImpl::GetInstance()->SetAccessibilityMode( + AccessibilityModeComplete); + + content::BrowserAccessibility *acc = GetBrowserAccessibilityManager()->GetRoot(); + content::BrowserAccessibilityQt *accQt = static_cast<content::BrowserAccessibilityQt*>(acc); + return accQt; +} diff --git a/src/core/render_widget_host_view_qt.h b/src/core/render_widget_host_view_qt.h index ff73b5734dcafbe93095175c056249147fb114ce..66cbef50156187d14424de0a3fe56abab29cd5a1 100644 --- a/src/core/render_widget_host_view_qt.h +++ b/src/core/render_widget_host_view_qt.h @@ -44,9 +44,11 @@ #include "render_widget_host_view_qt_delegate.h" +#include "browser_accessibility_delegate_qt.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "cc/resources/transferable_resource.h" +#include "content/browser/accessibility/browser_accessibility_manager.h" #include "content/browser/renderer_host/render_widget_host_view_base.h" #include "delegated_frame_node.h" #include "ui/events/gestures/gesture_recognizer.h" @@ -65,6 +67,7 @@ class QMouseEvent; class QTouchEvent; class QVariant; class QWheelEvent; +class QAccessibleInterface; QT_END_NAMESPACE class WebContentsAdapterClient; @@ -207,6 +210,8 @@ public: #endif // defined(USE_AURA) #endif // defined(OS_WIN) + QAccessibleInterface *GetQtAccessible(); + private: void sendDelegatedFrameAck(); void Paint(const gfx::Rect& damage_rect); @@ -217,6 +222,7 @@ private: float dpiScale() const; bool IsPopup() const; + void CreateBrowserAccessibilityManagerIfNeeded(); content::RenderWidgetHostImpl *m_host; scoped_ptr<ui::GestureRecognizer> m_gestureRecognizer; @@ -224,6 +230,7 @@ private: QMap<int, int> m_touchIdMapping; blink::WebTouchEvent m_accumTouchEvent; scoped_ptr<RenderWidgetHostViewQtDelegate> m_delegate; + scoped_ptr<BrowserAccessibilityDelegateQt> m_accessibilityDelegate; QExplicitlySharedDataPointer<DelegatedFrameNodeData> m_frameNodeData; cc::ReturnedResourceArray m_resourcesToRelease; diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index 8b0aafe21db76c8bb57ae0e757929bd12b755bb4..235534f18e6b209d3bef86139c94c328e2e28d57 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -74,6 +74,7 @@ #include <QStringList> #include <QStyleHints> #include <QVariant> +#include <QtGui/qaccessible.h> static const int kTestWindowWidth = 800; static const int kTestWindowHeight = 600; @@ -609,6 +610,13 @@ void WebContentsAdapter::enableInspector(bool enable) ContentBrowserClientQt::Get()->enableInspector(enable); } +QAccessibleInterface *WebContentsAdapter::browserAccessible() +{ + Q_D(const WebContentsAdapter); + RenderWidgetHostViewQt *rwhv = static_cast<RenderWidgetHostViewQt*>(d->webContents->GetRenderWidgetHostView()); + return rwhv ? rwhv->GetQtAccessible() : Q_NULLPTR; +} + void WebContentsAdapter::runJavaScript(const QString &javaScript) { Q_D(WebContentsAdapter); diff --git a/src/core/web_contents_adapter.h b/src/core/web_contents_adapter.h index d327de048164ea7afaf73d95d30b70bbb0a3c295..8e665ee2ccb96f528d105ed495eb3336bae44fd0 100644 --- a/src/core/web_contents_adapter.h +++ b/src/core/web_contents_adapter.h @@ -54,6 +54,8 @@ class WebContents; } class WebContentsAdapterPrivate; +QT_FORWARD_DECLARE_CLASS(QAccessibleInterface); + class QWEBENGINE_EXPORT WebContentsAdapter : public QSharedData { public: static QExplicitlySharedDataPointer<WebContentsAdapter> createFromSerializedNavigationHistory(QDataStream &input, WebContentsAdapterClient *adapterClient); @@ -109,6 +111,7 @@ public: void grantMediaAccessPermission(const QUrl &securityOrigin, WebContentsAdapterClient::MediaRequestFlags flags); void dpiScaleChanged(); + QAccessibleInterface *browserAccessible(); private: Q_DISABLE_COPY(WebContentsAdapter); diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h index 686b823798e2c35514a0a7eacec2e460afbc882b..b7836e4ca94a4a5ec2694ecf7cd65355fb9ac9d1 100644 --- a/src/core/web_contents_adapter_client.h +++ b/src/core/web_contents_adapter_client.h @@ -152,6 +152,9 @@ public: virtual void didFetchDocumentInnerText(quint64 requestId, const QString& result) = 0; virtual void didFindText(quint64 requestId, int matchCount) = 0; virtual void passOnFocus(bool reverse) = 0; + // returns the last QObject (QWidget/QQuickItem) based object in the accessibility + // hierarchy before going into the BrowserAccessibility tree + virtual QObject *accessibilityParentObject() = 0; virtual void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString& message, int lineNumber, const QString& sourceID) = 0; virtual void authenticationRequired(const QUrl &requestUrl, const QString &realm, bool isProxy, const QString &challengingHost, QString *outUser, QString *outPassword) = 0; virtual void runMediaAccessPermissionRequest(const QUrl &securityOrigin, MediaRequestFlags requestFlags) = 0; diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index ce41db7c14b2f14d8409b632e2d79592ce945931..897a592eb14185394a14d84278a75b4bce71f9ec 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -363,6 +363,12 @@ void QQuickWebEngineViewPrivate::runMediaAccessPermissionRequest(const QUrl &sec Q_EMIT e->featurePermissionRequested(securityOrigin, feature); } +QObject *QQuickWebEngineViewPrivate::accessibilityParentObject() +{ + Q_Q(QQuickWebEngineView); + return q; +} + void QQuickWebEngineViewPrivate::setDevicePixelRatio(qreal devicePixelRatio) { this->devicePixelRatio = devicePixelRatio; diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h index 6813b8a0e5df5090a8330719b93a612cb79d4dca..3bae23ceac3cc7aa9be2ba4475d8f1ebf8564774 100644 --- a/src/webengine/api/qquickwebengineview_p_p.h +++ b/src/webengine/api/qquickwebengineview_p_p.h @@ -167,6 +167,7 @@ public: virtual void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString& message, int lineNumber, const QString& sourceID) Q_DECL_OVERRIDE; virtual void authenticationRequired(const QUrl&, const QString&, bool, const QString&, QString*, QString*) Q_DECL_OVERRIDE { } virtual void runMediaAccessPermissionRequest(const QUrl &securityOrigin, MediaRequestFlags requestFlags) Q_DECL_OVERRIDE; + virtual QObject *accessibilityParentObject() Q_DECL_OVERRIDE; void setDevicePixelRatio(qreal); void adoptWebContents(WebContentsAdapter *webContents); diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index bbdcb25df0aa1f6a03fdf6241aba9cb8fa3bc753..8e87c1cf757250d16e4bb1b83b1f7aefe4c7ac33 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -333,6 +333,11 @@ void QWebEnginePagePrivate::runMediaAccessPermissionRequest(const QUrl &security Q_EMIT q->featurePermissionRequested(securityOrigin, requestedFeature); } +QObject *QWebEnginePagePrivate::accessibilityParentObject() +{ + return view; +} + void QWebEnginePagePrivate::updateAction(QWebEnginePage::WebAction action) const { #ifdef QT_NO_ACTION diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h index 894159366197ef1d96259d9c2d2069fe6e623cfb..a717b6ba827d701f55203f99aae1a53265174438 100644 --- a/src/webenginewidgets/api/qwebenginepage_p.h +++ b/src/webenginewidgets/api/qwebenginepage_p.h @@ -138,6 +138,7 @@ public: virtual void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString& message, int lineNumber, const QString& sourceID) Q_DECL_OVERRIDE; virtual void authenticationRequired(const QUrl &requestUrl, const QString &realm, bool isProxy, const QString &challengingHost, QString *outUser, QString *outPassword) Q_DECL_OVERRIDE; virtual void runMediaAccessPermissionRequest(const QUrl &securityOrigin, MediaRequestFlags requestFlags) Q_DECL_OVERRIDE; + virtual QObject *accessibilityParentObject() Q_DECL_OVERRIDE; void updateAction(QWebEnginePage::WebAction) const; void updateNavigationActions();