diff options
Diffstat (limited to 'src/core/accessibility_tree_formatter_qt.cpp')
-rw-r--r-- | src/core/accessibility_tree_formatter_qt.cpp | 193 |
1 files changed, 78 insertions, 115 deletions
diff --git a/src/core/accessibility_tree_formatter_qt.cpp b/src/core/accessibility_tree_formatter_qt.cpp index cb13f842d..3a3b30cb4 100644 --- a/src/core/accessibility_tree_formatter_qt.cpp +++ b/src/core/accessibility_tree_formatter_qt.cpp @@ -1,60 +1,27 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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) 2018 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 "ui/accessibility/platform/inspect/ax_tree_formatter_base.h" +#include "content/browser/accessibility/browser_accessibility_manager.h" +#include "content/browser/accessibility/accessibility_tree_formatter_blink.h" +#include "content/public/browser/ax_inspect_factory.h" +#include "ui/accessibility/platform/inspect/ax_event_recorder.h" + +#include <QtGui/qtguiglobal.h> +#include <memory> +#include <string> #include <utility> -#include "base/logging.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/string_util.h" +#if QT_CONFIG(accessibility) +#include "browser_accessibility_qt.h" + #include "base/strings/stringprintf.h" -#include "base/strings/utf_string_conversions.h" #include "base/values.h" -#include "content/browser/accessibility/accessibility_event_recorder.h" -#include "content/browser/accessibility/accessibility_tree_formatter_blink.h" #include "content/browser/accessibility/browser_accessibility.h" -#include "content/public/browser/ax_inspect_factory.h" - -#include "browser_accessibility_qt.h" +#include "ui/accessibility/platform/inspect/ax_tree_formatter_base.h" #include <QtGui/qaccessible.h> +#endif namespace content { @@ -64,16 +31,16 @@ public: explicit AccessibilityTreeFormatterQt(); ~AccessibilityTreeFormatterQt() override; - base::Value BuildTree(ui::AXPlatformNodeDelegate *start) const override; - base::Value BuildTreeForSelector(const AXTreeSelector &selector) const override + base::Value::Dict BuildTree(ui::AXPlatformNodeDelegate *start) const override; + base::Value::Dict BuildTreeForSelector(const AXTreeSelector &selector) const override { - return base::Value{}; + return base::Value::Dict{}; } private: - void RecursiveBuildAccessibilityTree(const BrowserAccessibility &node, base::DictionaryValue *dict) const; - void AddProperties(const BrowserAccessibility &node, base::DictionaryValue *dict) const; - std::string ProcessTreeForOutput(const base::DictionaryValue &node) const override; + void RecursiveBuildAccessibilityTree(const BrowserAccessibility &node, base::Value::Dict *dict) const; + void AddProperties(const BrowserAccessibility &node, base::Value::Dict *dict) const; + std::string ProcessTreeForOutput(const base::Value::Dict &node) const override; }; AccessibilityTreeFormatterQt::AccessibilityTreeFormatterQt() @@ -84,128 +51,124 @@ AccessibilityTreeFormatterQt::~AccessibilityTreeFormatterQt() { } -base::Value AccessibilityTreeFormatterQt::BuildTree(ui::AXPlatformNodeDelegate *start) const +base::Value::Dict AccessibilityTreeFormatterQt::BuildTree(ui::AXPlatformNodeDelegate *start) const { BrowserAccessibility *root_internal = BrowserAccessibility::FromAXPlatformNodeDelegate(start); - base::Value dict(base::Value::Type::DICTIONARY); - RecursiveBuildAccessibilityTree(*root_internal, static_cast<base::DictionaryValue *>(&dict)); + base::Value::Dict dict; + RecursiveBuildAccessibilityTree(*root_internal, &dict); return dict; } -void AccessibilityTreeFormatterQt::RecursiveBuildAccessibilityTree(const BrowserAccessibility &node, base::DictionaryValue *dict) const +void AccessibilityTreeFormatterQt::RecursiveBuildAccessibilityTree(const BrowserAccessibility &node, base::Value::Dict *dict) const { AddProperties(node, dict); - auto children = std::make_unique<base::ListValue>(); + base::Value::List children; for (size_t i = 0; i < node.PlatformChildCount(); ++i) { - std::unique_ptr<base::DictionaryValue> child_dict(new base::DictionaryValue); + base::Value::Dict child_dict; content::BrowserAccessibility *child_node = node.PlatformGetChild(i); - RecursiveBuildAccessibilityTree(*child_node, child_dict.get()); - children->Append(std::move(child_dict)); + RecursiveBuildAccessibilityTree(*child_node, &child_dict); + children.Append(std::move(child_dict)); } dict->Set(kChildrenDictAttr, std::move(children)); } -void AccessibilityTreeFormatterQt::AddProperties(const BrowserAccessibility &node, base::DictionaryValue *dict) const +void AccessibilityTreeFormatterQt::AddProperties(const BrowserAccessibility &node, base::Value::Dict *dict) const { - dict->SetInteger("id", node.GetId()); + dict->Set("id", node.GetId()); const QAccessibleInterface *iface = toQAccessibleInterface(&node); - dict->SetString("role", qAccessibleRoleString(iface->role())); + dict->Set("role", qAccessibleRoleString(iface->role())); QAccessible::State state = iface->state(); - std::vector<base::Value> states; + base::Value::List states; if (state.busy) - states.push_back(base::Value("busy")); + states.Append(base::Value("busy")); if (state.checkable) - states.push_back(base::Value("checkable")); + states.Append(base::Value("checkable")); if (state.checked) - states.push_back(base::Value("checked")); + states.Append(base::Value("checked")); if (node.IsClickable()) - states.push_back(base::Value("clickable")); + states.Append(base::Value("clickable")); if (state.collapsed) - states.push_back(base::Value("collapsed")); + states.Append(base::Value("collapsed")); if (state.disabled) - states.push_back(base::Value("disabled")); + states.Append(base::Value("disabled")); if (state.editable) - states.push_back(base::Value("editable")); + states.Append(base::Value("editable")); if (state.expandable) - states.push_back(base::Value("expandable")); + states.Append(base::Value("expandable")); if (state.expanded) - states.push_back(base::Value("expanded")); + states.Append(base::Value("expanded")); if (state.focusable) - states.push_back(base::Value("focusable")); + states.Append(base::Value("focusable")); if (state.focused) - states.push_back(base::Value("focused")); + states.Append(base::Value("focused")); if (state.hasPopup) - states.push_back(base::Value("hasPopup")); + states.Append(base::Value("hasPopup")); if (state.hotTracked) - states.push_back(base::Value("hotTracked")); + states.Append(base::Value("hotTracked")); if (state.invisible) - states.push_back(base::Value("invisible")); + states.Append(base::Value("invisible")); if (state.linked) - states.push_back(base::Value("linked")); + states.Append(base::Value("linked")); if (state.multiLine) - states.push_back(base::Value("multiLine")); + states.Append(base::Value("multiLine")); if (state.multiSelectable) - states.push_back(base::Value("multiSelectable")); + states.Append(base::Value("multiSelectable")); if (state.modal) - states.push_back(base::Value("modal")); + states.Append(base::Value("modal")); if (state.offscreen) - states.push_back(base::Value("offscreen")); + states.Append(base::Value("offscreen")); if (state.passwordEdit) - states.push_back(base::Value("password")); + states.Append(base::Value("password")); if (state.pressed) - states.push_back(base::Value("pressed")); + states.Append(base::Value("pressed")); if (state.readOnly) - states.push_back(base::Value("readOnly")); + states.Append(base::Value("readOnly")); if (state.selectable) - states.push_back(base::Value("selectable")); + states.Append(base::Value("selectable")); if (state.selected) - states.push_back(base::Value("selected")); + states.Append(base::Value("selected")); if (state.traversed) - states.push_back(base::Value("traversed")); - dict->SetKey("states", base::Value(states)); + states.Append(base::Value("traversed")); + dict->Set("states", std::move(states)); - dict->SetString("name", iface->text(QAccessible::Name).toStdString()); - dict->SetString("description", iface->text(QAccessible::Description).toStdString()); + dict->Set("name", iface->text(QAccessible::Name).toStdString()); + dict->Set("description", iface->text(QAccessible::Description).toStdString()); } -std::string AccessibilityTreeFormatterQt::ProcessTreeForOutput(const base::DictionaryValue &node) const +std::string AccessibilityTreeFormatterQt::ProcessTreeForOutput(const base::Value::Dict &node) const { std::string error_value; - if (node.GetString("error", &error_value)) - return error_value; + if (auto error_value = node.FindString("error")) + return *error_value; std::string line; std::string role_value; - node.GetString("role", &role_value); - if (!role_value.empty()) - WriteAttribute(true, base::StringPrintf("%s", role_value.c_str()), &line); - - const base::ListValue *states_value = nullptr; - if (node.GetList("states", &states_value)) { - for (const auto &state : states_value->GetList()) { - std::string state_value; - if (state.GetAsString(&state_value)) - WriteAttribute(false, state_value, &line); + if (auto role_value = node.FindString("role")) + WriteAttribute(true, base::StringPrintf("%s", role_value->c_str()), &line); + + if (const auto states_value = node.FindList("states")) { + for (const auto &state : *states_value) { + if (auto *state_value = state.GetIfString()) + WriteAttribute(false, *state_value, &line); } } - std::string name_value; - if (node.GetString("name", &name_value)) - WriteAttribute(true, base::StringPrintf("name='%s'", name_value.c_str()), &line); + if (auto name_value = node.FindString("name")) + WriteAttribute(true, base::StringPrintf("name='%s'", name_value->c_str()), &line); - std::string description_value; - if (node.GetString("description", &description_value)) - WriteAttribute(false, base::StringPrintf("description='%s'", description_value.c_str()), &line); + if (auto description_value = node.FindString("description")) + WriteAttribute(false, base::StringPrintf("description='%s'", description_value->c_str()), &line); int id_value; - node.GetInteger("id", &id_value); + if (auto maybe_id = node.FindInt("id")) + id_value = *maybe_id; WriteAttribute(false, base::StringPrintf("id=%d", id_value), &line); return line + "\n"; @@ -254,7 +217,7 @@ std::unique_ptr<ui::AXEventRecorder> AXInspectFactory::CreateRecorder(ui::AXApiT { switch (type) { case ui::AXApiType::kQt: - return std::make_unique<AccessibilityEventRecorder>(manager); + return std::make_unique<ui::AXEventRecorder>(); default: NOTREACHED() << "Unsupported inspect type " << type; } |