2017-05-12 20:28:25 +02:00
|
|
|
// Copyright 2017 The Chromium Embedded Framework Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be found
|
|
|
|
// in the LICENSE file.
|
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/osr/osr_accessibility_util.h"
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include "base/json/string_escape.h"
|
2019-02-01 17:42:40 +01:00
|
|
|
#include "base/stl_util.h"
|
2017-05-12 20:28:25 +02:00
|
|
|
#include "base/strings/string_number_conversions.h"
|
|
|
|
#include "base/strings/stringprintf.h"
|
2018-03-20 21:15:08 +01:00
|
|
|
#include "ui/accessibility/ax_enum_util.h"
|
|
|
|
#include "ui/accessibility/ax_enums.mojom.h"
|
2017-05-12 20:28:25 +02:00
|
|
|
#include "ui/accessibility/ax_text_utils.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "ui/accessibility/ax_tree_update.h"
|
2024-05-23 03:52:35 +02:00
|
|
|
#include "ui/accessibility/ax_updates_and_events.h"
|
2021-10-19 00:17:16 +02:00
|
|
|
#include "ui/gfx/geometry/transform.h"
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
using ui::ToString;
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
template <typename T>
|
2017-05-12 20:28:25 +02:00
|
|
|
CefRefPtr<CefListValue> ToCefValue(const std::vector<T>& vecData);
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
template <>
|
2017-05-12 20:28:25 +02:00
|
|
|
CefRefPtr<CefListValue> ToCefValue<int>(const std::vector<int>& vecData) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefListValue> value = CefListValue::Create();
|
2023-01-02 23:59:03 +01:00
|
|
|
for (size_t i = 0; i < vecData.size(); i++) {
|
2017-05-12 20:28:25 +02:00
|
|
|
value->SetInt(i, vecData[i]);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper function for AXNodeData::ToCefValue - Converts AXState attributes to
|
|
|
|
// CefListValue.
|
|
|
|
CefRefPtr<CefListValue> ToCefValue(uint32_t state) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefListValue> value = CefListValue::Create();
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
int index = 0;
|
|
|
|
// Iterate and find which states are set.
|
2018-04-19 17:44:42 +02:00
|
|
|
for (unsigned i = static_cast<unsigned>(ax::mojom::Role::kMinValue) + 1;
|
|
|
|
i <= static_cast<unsigned>(ax::mojom::Role::kMaxValue); i++) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (state & (1 << i)) {
|
2018-03-20 21:15:08 +01:00
|
|
|
value->SetString(index++, ToString(static_cast<ax::mojom::State>(i)));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper function for AXNodeData::ToCefValue - converts GfxRect to
|
|
|
|
// CefDictionaryValue.
|
|
|
|
CefRefPtr<CefDictionaryValue> ToCefValue(const gfx::RectF& bounds) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefDictionaryValue> value = CefDictionaryValue::Create();
|
2017-05-12 20:28:25 +02:00
|
|
|
value->SetDouble("x", bounds.x());
|
|
|
|
value->SetDouble("y", bounds.y());
|
|
|
|
value->SetDouble("width", bounds.width());
|
|
|
|
value->SetDouble("height", bounds.height());
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper Functor for adding AxNodeData::attributes to AXNodeData::ToCefValue.
|
|
|
|
struct PopulateAxNodeAttributes {
|
|
|
|
CefRefPtr<CefDictionaryValue> attributes;
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
explicit PopulateAxNodeAttributes(CefRefPtr<CefDictionaryValue> attrs)
|
|
|
|
: attributes(attrs) {}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
// Int Attributes
|
2018-03-20 21:15:08 +01:00
|
|
|
void operator()(const std::pair<ax::mojom::IntAttribute, int32_t> attr) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (attr.first == ax::mojom::IntAttribute::kNone) {
|
2017-05-12 20:28:25 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
switch (attr.first) {
|
2018-03-20 21:15:08 +01:00
|
|
|
case ax::mojom::IntAttribute::kNone:
|
2017-05-12 20:28:25 +02:00
|
|
|
break;
|
2018-03-20 21:15:08 +01:00
|
|
|
case ax::mojom::IntAttribute::kScrollX:
|
|
|
|
case ax::mojom::IntAttribute::kScrollXMin:
|
|
|
|
case ax::mojom::IntAttribute::kScrollXMax:
|
|
|
|
case ax::mojom::IntAttribute::kScrollY:
|
|
|
|
case ax::mojom::IntAttribute::kScrollYMin:
|
|
|
|
case ax::mojom::IntAttribute::kScrollYMax:
|
2018-05-20 15:51:42 +02:00
|
|
|
case ax::mojom::IntAttribute::kHasPopup:
|
2023-01-30 18:43:54 +01:00
|
|
|
case ax::mojom::IntAttribute::kIsPopup:
|
2018-03-20 21:15:08 +01:00
|
|
|
case ax::mojom::IntAttribute::kHierarchicalLevel:
|
|
|
|
case ax::mojom::IntAttribute::kTextSelStart:
|
|
|
|
case ax::mojom::IntAttribute::kTextSelEnd:
|
|
|
|
case ax::mojom::IntAttribute::kAriaColumnCount:
|
|
|
|
case ax::mojom::IntAttribute::kAriaCellColumnIndex:
|
|
|
|
case ax::mojom::IntAttribute::kAriaRowCount:
|
|
|
|
case ax::mojom::IntAttribute::kAriaCellRowIndex:
|
|
|
|
case ax::mojom::IntAttribute::kTableRowCount:
|
|
|
|
case ax::mojom::IntAttribute::kTableColumnCount:
|
|
|
|
case ax::mojom::IntAttribute::kTableCellColumnIndex:
|
|
|
|
case ax::mojom::IntAttribute::kTableCellRowIndex:
|
|
|
|
case ax::mojom::IntAttribute::kTableCellColumnSpan:
|
|
|
|
case ax::mojom::IntAttribute::kTableCellRowSpan:
|
|
|
|
case ax::mojom::IntAttribute::kTableColumnHeaderId:
|
|
|
|
case ax::mojom::IntAttribute::kTableColumnIndex:
|
|
|
|
case ax::mojom::IntAttribute::kTableHeaderId:
|
|
|
|
case ax::mojom::IntAttribute::kTableRowHeaderId:
|
|
|
|
case ax::mojom::IntAttribute::kTableRowIndex:
|
|
|
|
case ax::mojom::IntAttribute::kActivedescendantId:
|
|
|
|
case ax::mojom::IntAttribute::kInPageLinkTargetId:
|
2023-08-09 23:17:17 +02:00
|
|
|
case ax::mojom::IntAttribute::kErrormessageIdDeprecated:
|
2024-09-27 16:15:44 +02:00
|
|
|
case ax::mojom::IntAttribute::kDOMNodeIdDeprecated:
|
2023-10-19 20:08:48 +02:00
|
|
|
case ax::mojom::IntAttribute::kDropeffectDeprecated:
|
2018-03-20 21:15:08 +01:00
|
|
|
case ax::mojom::IntAttribute::kMemberOfId:
|
|
|
|
case ax::mojom::IntAttribute::kNextFocusId:
|
2023-02-27 19:52:38 +01:00
|
|
|
case ax::mojom::IntAttribute::kNextWindowFocusId:
|
2018-03-20 21:15:08 +01:00
|
|
|
case ax::mojom::IntAttribute::kNextOnLineId:
|
|
|
|
case ax::mojom::IntAttribute::kPreviousFocusId:
|
2023-02-27 19:52:38 +01:00
|
|
|
case ax::mojom::IntAttribute::kPreviousWindowFocusId:
|
2018-03-20 21:15:08 +01:00
|
|
|
case ax::mojom::IntAttribute::kPreviousOnLineId:
|
|
|
|
case ax::mojom::IntAttribute::kSetSize:
|
|
|
|
case ax::mojom::IntAttribute::kPosInSet:
|
2019-07-16 19:59:21 +02:00
|
|
|
case ax::mojom::IntAttribute::kPopupForId:
|
2017-05-12 20:28:25 +02:00
|
|
|
attributes->SetInt(ToString(attr.first), attr.second);
|
|
|
|
break;
|
2018-03-20 21:15:08 +01:00
|
|
|
case ax::mojom::IntAttribute::kDefaultActionVerb:
|
2017-05-17 11:29:28 +02:00
|
|
|
attributes->SetString(
|
|
|
|
ToString(attr.first),
|
2020-06-09 19:48:00 +02:00
|
|
|
ui::ToString(
|
2018-03-20 21:15:08 +01:00
|
|
|
static_cast<ax::mojom::DefaultActionVerb>(attr.second)));
|
2017-05-12 20:28:25 +02:00
|
|
|
break;
|
2018-03-20 21:15:08 +01:00
|
|
|
case ax::mojom::IntAttribute::kInvalidState: {
|
|
|
|
auto state = static_cast<ax::mojom::InvalidState>(attr.second);
|
|
|
|
if (ax::mojom::InvalidState::kNone != state) {
|
|
|
|
attributes->SetString(ToString(attr.first), ToString(state));
|
2017-05-12 20:28:25 +02:00
|
|
|
}
|
2018-03-20 21:15:08 +01:00
|
|
|
} break;
|
|
|
|
case ax::mojom::IntAttribute::kCheckedState: {
|
|
|
|
auto state = static_cast<ax::mojom::CheckedState>(attr.second);
|
|
|
|
if (ax::mojom::CheckedState::kNone != state) {
|
|
|
|
attributes->SetString(ToString(attr.first), ToString(state));
|
2017-05-31 17:33:30 +02:00
|
|
|
}
|
2018-03-20 21:15:08 +01:00
|
|
|
} break;
|
|
|
|
case ax::mojom::IntAttribute::kRestriction:
|
2017-07-27 01:19:27 +02:00
|
|
|
attributes->SetString(
|
|
|
|
ToString(attr.first),
|
2018-03-20 21:15:08 +01:00
|
|
|
ToString(static_cast<ax::mojom::Restriction>(attr.second)));
|
2017-07-27 01:19:27 +02:00
|
|
|
break;
|
2019-06-05 16:15:45 +02:00
|
|
|
case ax::mojom::IntAttribute::kListStyle: {
|
|
|
|
auto state = static_cast<ax::mojom::ListStyle>(attr.second);
|
|
|
|
if (ax::mojom::ListStyle::kNone != state) {
|
|
|
|
attributes->SetString(ToString(attr.first), ToString(state));
|
|
|
|
}
|
|
|
|
} break;
|
2018-03-20 21:15:08 +01:00
|
|
|
case ax::mojom::IntAttribute::kSortDirection: {
|
|
|
|
auto state = static_cast<ax::mojom::SortDirection>(attr.second);
|
|
|
|
if (ax::mojom::SortDirection::kNone != state) {
|
|
|
|
attributes->SetString(ToString(attr.first), ToString(state));
|
2017-05-12 20:28:25 +02:00
|
|
|
}
|
2018-03-20 21:15:08 +01:00
|
|
|
} break;
|
2020-08-29 00:39:23 +02:00
|
|
|
case ax::mojom::IntAttribute::kTextAlign: {
|
|
|
|
auto state = static_cast<ax::mojom::TextAlign>(attr.second);
|
|
|
|
if (ax::mojom::TextAlign::kNone != state) {
|
|
|
|
attributes->SetString(ToString(attr.first), ToString(state));
|
|
|
|
}
|
|
|
|
} break;
|
2018-03-20 21:15:08 +01:00
|
|
|
case ax::mojom::IntAttribute::kNameFrom:
|
2017-05-17 11:29:28 +02:00
|
|
|
attributes->SetString(
|
|
|
|
ToString(attr.first),
|
2018-03-20 21:15:08 +01:00
|
|
|
ToString(static_cast<ax::mojom::NameFrom>(attr.second)));
|
2017-05-12 20:28:25 +02:00
|
|
|
break;
|
2018-03-20 21:15:08 +01:00
|
|
|
case ax::mojom::IntAttribute::kColorValue:
|
|
|
|
case ax::mojom::IntAttribute::kBackgroundColor:
|
|
|
|
case ax::mojom::IntAttribute::kColor:
|
2017-05-12 20:28:25 +02:00
|
|
|
attributes->SetString(ToString(attr.first),
|
|
|
|
base::StringPrintf("0x%X", attr.second));
|
|
|
|
break;
|
2018-03-20 21:15:08 +01:00
|
|
|
case ax::mojom::IntAttribute::kDescriptionFrom:
|
2017-05-17 11:29:28 +02:00
|
|
|
attributes->SetString(
|
|
|
|
ToString(attr.first),
|
2018-03-20 21:15:08 +01:00
|
|
|
ToString(static_cast<ax::mojom::DescriptionFrom>(attr.second)));
|
2017-05-12 20:28:25 +02:00
|
|
|
break;
|
2018-03-20 21:15:08 +01:00
|
|
|
case ax::mojom::IntAttribute::kAriaCurrentState: {
|
|
|
|
auto state = static_cast<ax::mojom::AriaCurrentState>(attr.second);
|
|
|
|
if (ax::mojom::AriaCurrentState::kNone != state) {
|
|
|
|
attributes->SetString(ToString(attr.first), ToString(state));
|
2017-05-12 20:28:25 +02:00
|
|
|
}
|
2018-03-20 21:15:08 +01:00
|
|
|
} break;
|
2024-03-19 22:11:42 +01:00
|
|
|
case ax::mojom::IntAttribute::kAriaNotificationInterruptDeprecated: {
|
|
|
|
auto state =
|
|
|
|
static_cast<ax::mojom::AriaNotificationInterrupt>(attr.second);
|
|
|
|
if (ax::mojom::AriaNotificationInterrupt::kNone != state) {
|
|
|
|
attributes->SetString(ToString(attr.first), ToString(state));
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case ax::mojom::IntAttribute::kAriaNotificationPriorityDeprecated: {
|
|
|
|
auto state =
|
|
|
|
static_cast<ax::mojom::AriaNotificationPriority>(attr.second);
|
|
|
|
if (ax::mojom::AriaNotificationPriority::kNone != state) {
|
|
|
|
attributes->SetString(ToString(attr.first), ToString(state));
|
|
|
|
}
|
|
|
|
} break;
|
2018-03-20 21:15:08 +01:00
|
|
|
case ax::mojom::IntAttribute::kTextDirection: {
|
2020-08-29 00:39:23 +02:00
|
|
|
auto state = static_cast<ax::mojom::WritingDirection>(attr.second);
|
|
|
|
if (ax::mojom::WritingDirection::kNone != state) {
|
2018-03-20 21:15:08 +01:00
|
|
|
attributes->SetString(ToString(attr.first), ToString(state));
|
2017-05-12 20:28:25 +02:00
|
|
|
}
|
2018-03-20 21:15:08 +01:00
|
|
|
} break;
|
2018-06-01 21:16:26 +02:00
|
|
|
case ax::mojom::IntAttribute::kTextPosition: {
|
|
|
|
auto state = static_cast<ax::mojom::TextPosition>(attr.second);
|
|
|
|
if (ax::mojom::TextPosition::kNone != state) {
|
|
|
|
attributes->SetString(ToString(attr.first), ToString(state));
|
|
|
|
}
|
|
|
|
} break;
|
2018-03-20 21:15:08 +01:00
|
|
|
case ax::mojom::IntAttribute::kTextStyle: {
|
|
|
|
static ax::mojom::TextStyle textStyleArr[] = {
|
2018-11-03 02:15:09 +01:00
|
|
|
ax::mojom::TextStyle::kBold, ax::mojom::TextStyle::kItalic,
|
|
|
|
ax::mojom::TextStyle::kUnderline,
|
2019-06-05 16:15:45 +02:00
|
|
|
ax::mojom::TextStyle::kLineThrough,
|
|
|
|
ax::mojom::TextStyle::kOverline};
|
2017-05-17 11:29:28 +02:00
|
|
|
|
|
|
|
CefRefPtr<CefListValue> list = CefListValue::Create();
|
|
|
|
int index = 0;
|
|
|
|
// Iterate and find which states are set.
|
2024-01-20 23:48:57 +01:00
|
|
|
for (auto& i : textStyleArr) {
|
|
|
|
if (attr.second & static_cast<int>(i)) {
|
|
|
|
list->SetString(index++, ToString(i));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
}
|
2017-05-17 11:29:28 +02:00
|
|
|
attributes->SetList(ToString(attr.first), list);
|
|
|
|
} break;
|
2019-06-05 16:15:45 +02:00
|
|
|
case ax::mojom::IntAttribute::kTextOverlineStyle:
|
|
|
|
case ax::mojom::IntAttribute::kTextStrikethroughStyle:
|
|
|
|
case ax::mojom::IntAttribute::kTextUnderlineStyle: {
|
|
|
|
auto state = static_cast<ax::mojom::TextDecorationStyle>(attr.second);
|
|
|
|
if (ax::mojom::TextDecorationStyle::kNone != state) {
|
|
|
|
attributes->SetString(ToString(attr.first), ToString(state));
|
|
|
|
}
|
|
|
|
} break;
|
2019-09-04 17:13:32 +02:00
|
|
|
case ax::mojom::IntAttribute::kAriaCellColumnSpan:
|
|
|
|
case ax::mojom::IntAttribute::kAriaCellRowSpan:
|
2019-03-13 22:27:37 +01:00
|
|
|
case ax::mojom::IntAttribute::kImageAnnotationStatus: {
|
2019-09-04 17:13:32 +02:00
|
|
|
// TODO(cef): Implement support for Image Annotation Status,
|
|
|
|
// kAriaCellColumnSpan and kAriaCellRowSpan
|
2019-03-13 22:27:37 +01:00
|
|
|
} break;
|
2017-05-12 20:28:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set Bool Attributes.
|
2018-03-20 21:15:08 +01:00
|
|
|
void operator()(const std::pair<ax::mojom::BoolAttribute, bool> attr) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (attr.first != ax::mojom::BoolAttribute::kNone) {
|
2017-05-12 20:28:25 +02:00
|
|
|
attributes->SetBool(ToString(attr.first), attr.second);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
}
|
|
|
|
// Set String Attributes.
|
2018-03-20 21:15:08 +01:00
|
|
|
void operator()(
|
|
|
|
const std::pair<ax::mojom::StringAttribute, std::string>& attr) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (attr.first != ax::mojom::StringAttribute::kNone) {
|
2017-05-12 20:28:25 +02:00
|
|
|
attributes->SetString(ToString(attr.first), attr.second);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
}
|
|
|
|
// Set Float attributes.
|
2018-03-20 21:15:08 +01:00
|
|
|
void operator()(const std::pair<ax::mojom::FloatAttribute, float>& attr) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (attr.first != ax::mojom::FloatAttribute::kNone) {
|
2017-05-12 20:28:25 +02:00
|
|
|
attributes->SetDouble(ToString(attr.first), attr.second);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set Int list attributes.
|
2018-03-20 21:15:08 +01:00
|
|
|
void operator()(const std::pair<ax::mojom::IntListAttribute,
|
|
|
|
std::vector<int32_t>>& attr) {
|
|
|
|
if (attr.first != ax::mojom::IntListAttribute::kNone) {
|
2017-05-12 20:28:25 +02:00
|
|
|
CefRefPtr<CefListValue> list;
|
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
if (ax::mojom::IntListAttribute::kMarkerTypes == attr.first) {
|
2017-05-12 20:28:25 +02:00
|
|
|
list = CefListValue::Create();
|
|
|
|
int index = 0;
|
2024-01-20 23:48:57 +01:00
|
|
|
for (int i : attr.second) {
|
|
|
|
auto type = static_cast<ax::mojom::MarkerType>(i);
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (type == ax::mojom::MarkerType::kNone) {
|
2017-05-12 20:28:25 +02:00
|
|
|
continue;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
static ax::mojom::MarkerType marktypeArr[] = {
|
|
|
|
ax::mojom::MarkerType::kSpelling, ax::mojom::MarkerType::kGrammar,
|
|
|
|
ax::mojom::MarkerType::kTextMatch};
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
// Iterate and find which markers are set.
|
2024-01-20 23:48:57 +01:00
|
|
|
for (auto& j : marktypeArr) {
|
|
|
|
if (i & static_cast<int>(j)) {
|
|
|
|
list->SetString(index++, ToString(j));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
list = ToCefValue(attr.second);
|
|
|
|
}
|
|
|
|
attributes->SetList(ToString(attr.first), list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Converts AXNodeData to CefDictionaryValue(like AXNodeData::ToString).
|
|
|
|
CefRefPtr<CefDictionaryValue> ToCefValue(const ui::AXNodeData& node) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefDictionaryValue> value = CefDictionaryValue::Create();
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (node.id != -1) {
|
2017-05-12 20:28:25 +02:00
|
|
|
value->SetInt("id", node.id);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
value->SetString("role", ToString(node.role));
|
|
|
|
value->SetList("state", ToCefValue(node.state));
|
|
|
|
|
2018-11-30 23:21:07 +01:00
|
|
|
if (node.relative_bounds.offset_container_id != -1) {
|
|
|
|
value->SetInt("offset_container_id",
|
|
|
|
node.relative_bounds.offset_container_id);
|
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2018-11-30 23:21:07 +01:00
|
|
|
value->SetDictionary("location", ToCefValue(node.relative_bounds.bounds));
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
// Transform matrix is private, so we set the string that Clients can parse
|
|
|
|
// and use if needed.
|
2018-11-30 23:21:07 +01:00
|
|
|
if (node.relative_bounds.transform &&
|
|
|
|
!node.relative_bounds.transform->IsIdentity()) {
|
|
|
|
value->SetString("transform", node.relative_bounds.transform->ToString());
|
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2018-11-30 23:21:07 +01:00
|
|
|
if (!node.child_ids.empty()) {
|
2017-05-12 20:28:25 +02:00
|
|
|
value->SetList("child_ids", ToCefValue(node.child_ids));
|
2018-11-30 23:21:07 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2017-05-31 17:33:30 +02:00
|
|
|
CefRefPtr<CefListValue> actions_strings;
|
|
|
|
size_t actions_idx = 0;
|
2018-04-19 17:44:42 +02:00
|
|
|
for (int action_index = static_cast<int>(ax::mojom::Action::kMinValue) + 1;
|
|
|
|
action_index <= static_cast<int>(ax::mojom::Action::kMaxValue);
|
2018-03-20 21:15:08 +01:00
|
|
|
++action_index) {
|
|
|
|
auto action = static_cast<ax::mojom::Action>(action_index);
|
2017-05-31 17:33:30 +02:00
|
|
|
if (node.HasAction(action)) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!actions_strings) {
|
2017-05-31 17:33:30 +02:00
|
|
|
actions_strings = CefListValue::Create();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-31 17:33:30 +02:00
|
|
|
actions_strings->SetString(actions_idx++, ToString(action));
|
|
|
|
}
|
|
|
|
}
|
2023-01-02 23:59:03 +01:00
|
|
|
if (actions_strings) {
|
2017-05-31 17:33:30 +02:00
|
|
|
value->SetList("actions", actions_strings);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-31 17:33:30 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefDictionaryValue> attributes = CefDictionaryValue::Create();
|
2017-05-12 20:28:25 +02:00
|
|
|
PopulateAxNodeAttributes func(attributes);
|
|
|
|
|
|
|
|
// Poupulate Int Attributes.
|
|
|
|
std::for_each(node.int_attributes.begin(), node.int_attributes.end(), func);
|
|
|
|
|
|
|
|
// Poupulate String Attributes.
|
2017-05-17 11:29:28 +02:00
|
|
|
std::for_each(node.string_attributes.begin(), node.string_attributes.end(),
|
|
|
|
func);
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
// Poupulate Float Attributes.
|
2017-05-17 11:29:28 +02:00
|
|
|
std::for_each(node.float_attributes.begin(), node.float_attributes.end(),
|
|
|
|
func);
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
// Poupulate Bool Attributes.
|
|
|
|
std::for_each(node.bool_attributes.begin(), node.bool_attributes.end(), func);
|
|
|
|
|
|
|
|
// Populate int list attributes.
|
2017-05-17 11:29:28 +02:00
|
|
|
std::for_each(node.intlist_attributes.begin(), node.intlist_attributes.end(),
|
|
|
|
func);
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
value->SetDictionary("attributes", attributes);
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Converts AXTreeData to CefDictionaryValue(like AXTreeData::ToString).
|
|
|
|
CefRefPtr<CefDictionaryValue> ToCefValue(const ui::AXTreeData& treeData) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefDictionaryValue> value = CefDictionaryValue::Create();
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!treeData.tree_id.ToString().empty()) {
|
2018-10-02 14:14:11 +02:00
|
|
|
value->SetString("tree_id", treeData.tree_id.ToString());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!treeData.parent_tree_id.ToString().empty()) {
|
2018-10-02 14:14:11 +02:00
|
|
|
value->SetString("parent_tree_id", treeData.parent_tree_id.ToString());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!treeData.focused_tree_id.ToString().empty()) {
|
2018-10-02 14:14:11 +02:00
|
|
|
value->SetString("focused_tree_id", treeData.focused_tree_id.ToString());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!treeData.doctype.empty()) {
|
2017-05-12 20:28:25 +02:00
|
|
|
value->SetString("doctype", treeData.doctype);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
value->SetBool("loaded", treeData.loaded);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (treeData.loading_progress != 0.0) {
|
2017-05-12 20:28:25 +02:00
|
|
|
value->SetDouble("loading_progress", treeData.loading_progress);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!treeData.mimetype.empty()) {
|
2017-05-12 20:28:25 +02:00
|
|
|
value->SetString("mimetype", treeData.mimetype);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (!treeData.url.empty()) {
|
2017-05-12 20:28:25 +02:00
|
|
|
value->SetString("url", treeData.url);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (!treeData.title.empty()) {
|
2017-05-12 20:28:25 +02:00
|
|
|
value->SetString("title", treeData.title);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
if (treeData.sel_anchor_object_id != -1) {
|
|
|
|
value->SetInt("sel_anchor_object_id", treeData.sel_anchor_object_id);
|
|
|
|
value->SetInt("sel_anchor_offset", treeData.sel_anchor_offset);
|
|
|
|
value->SetString("sel_anchor_affinity",
|
|
|
|
ToString(treeData.sel_anchor_affinity));
|
|
|
|
}
|
|
|
|
if (treeData.sel_focus_object_id != -1) {
|
|
|
|
value->SetInt("sel_focus_object_id", treeData.sel_anchor_object_id);
|
|
|
|
value->SetInt("sel_focus_offset", treeData.sel_anchor_offset);
|
|
|
|
value->SetString("sel_focus_affinity",
|
|
|
|
ToString(treeData.sel_anchor_affinity));
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (treeData.focus_id != -1) {
|
2017-05-12 20:28:25 +02:00
|
|
|
value->SetInt("focus_id", treeData.focus_id);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Converts AXTreeUpdate to CefDictionaryValue(like AXTreeUpdate::ToString).
|
|
|
|
CefRefPtr<CefDictionaryValue> ToCefValue(const ui::AXTreeUpdate& update) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefDictionaryValue> value = CefDictionaryValue::Create();
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
if (update.has_tree_data) {
|
|
|
|
value->SetBool("has_tree_data", true);
|
|
|
|
value->SetDictionary("tree_data", ToCefValue(update.tree_data));
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (update.node_id_to_clear != 0) {
|
2017-05-12 20:28:25 +02:00
|
|
|
value->SetInt("node_id_to_clear", update.node_id_to_clear);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (update.root_id != 0) {
|
2017-05-12 20:28:25 +02:00
|
|
|
value->SetInt("root_id", update.root_id);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
value->SetList("nodes", ToCefValue(update.nodes));
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2018-06-08 18:53:10 +02:00
|
|
|
// Converts AXEvent to CefDictionaryValue.
|
|
|
|
CefRefPtr<CefDictionaryValue> ToCefValue(const ui::AXEvent& event) {
|
|
|
|
CefRefPtr<CefDictionaryValue> value = CefDictionaryValue::Create();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (event.event_type != ax::mojom::Event::kNone) {
|
2018-06-08 18:53:10 +02:00
|
|
|
value->SetString("event_type", ToString(event.event_type));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2018-06-08 18:53:10 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (event.id != -1) {
|
2018-06-08 18:53:10 +02:00
|
|
|
value->SetInt("id", event.id);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2018-06-08 18:53:10 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (event.event_from != ax::mojom::EventFrom::kNone) {
|
2018-06-08 18:53:10 +02:00
|
|
|
value->SetString("event_from", ToString(event.event_from));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2018-06-08 18:53:10 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (event.action_request_id != -1) {
|
2018-06-08 18:53:10 +02:00
|
|
|
value->SetInt("action_request_id", event.action_request_id);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2018-06-08 18:53:10 +02:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2017-05-12 20:28:25 +02:00
|
|
|
// Convert AXEventNotificationDetails to CefDictionaryValue.
|
|
|
|
CefRefPtr<CefDictionaryValue> ToCefValue(
|
2024-05-23 03:52:35 +02:00
|
|
|
const ui::AXUpdatesAndEvents& eventData) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefDictionaryValue> value = CefDictionaryValue::Create();
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!eventData.ax_tree_id.ToString().empty()) {
|
2018-10-02 14:14:11 +02:00
|
|
|
value->SetString("ax_tree_id", eventData.ax_tree_id.ToString());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2018-06-08 18:53:10 +02:00
|
|
|
if (eventData.updates.size() > 0) {
|
|
|
|
CefRefPtr<CefListValue> updates = CefListValue::Create();
|
|
|
|
updates->SetSize(eventData.updates.size());
|
|
|
|
size_t i = 0;
|
|
|
|
for (const auto& update : eventData.updates) {
|
|
|
|
updates->SetDictionary(i++, ToCefValue(update));
|
|
|
|
}
|
|
|
|
value->SetList("updates", updates);
|
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2018-06-08 18:53:10 +02:00
|
|
|
if (eventData.events.size() > 0) {
|
|
|
|
CefRefPtr<CefListValue> events = CefListValue::Create();
|
|
|
|
events->SetSize(eventData.events.size());
|
|
|
|
size_t i = 0;
|
|
|
|
for (const auto& event : eventData.events) {
|
|
|
|
events->SetDictionary(i++, ToCefValue(event));
|
|
|
|
}
|
|
|
|
value->SetList("events", events);
|
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert AXRelativeBounds to CefDictionaryValue. Similar to
|
|
|
|
// AXRelativeBounds::ToString. See that for more details
|
|
|
|
CefRefPtr<CefDictionaryValue> ToCefValue(const ui::AXRelativeBounds& location) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefDictionaryValue> value = CefDictionaryValue::Create();
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (location.offset_container_id != -1) {
|
2017-05-12 20:28:25 +02:00
|
|
|
value->SetInt("offset_container_id", location.offset_container_id);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
value->SetDictionary("bounds", ToCefValue(location.bounds));
|
|
|
|
|
|
|
|
// Transform matrix is private, so we set the string that Clients can parse
|
|
|
|
// and use if needed.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (location.transform && !location.transform->IsIdentity()) {
|
2017-05-12 20:28:25 +02:00
|
|
|
value->SetString("transform", location.transform->ToString());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2018-06-08 18:53:10 +02:00
|
|
|
// Convert AXLocationChangeNotificationDetails to CefDictionaryValue.
|
2024-05-23 03:52:35 +02:00
|
|
|
CefRefPtr<CefDictionaryValue> ToCefValue(const ui::AXLocationChanges& locData) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefDictionaryValue> value = CefDictionaryValue::Create();
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (locData.id != -1) {
|
2017-05-12 20:28:25 +02:00
|
|
|
value->SetInt("id", locData.id);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!locData.ax_tree_id.ToString().empty()) {
|
2018-10-02 14:14:11 +02:00
|
|
|
value->SetString("ax_tree_id", locData.ax_tree_id.ToString());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
value->SetDictionary("new_location", ToCefValue(locData.new_location));
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
template <typename T>
|
2017-05-12 20:28:25 +02:00
|
|
|
CefRefPtr<CefListValue> ToCefValue(const std::vector<T>& vecData) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefListValue> value = CefListValue::Create();
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
for (size_t i = 0; i < vecData.size(); i++) {
|
2017-05-12 20:28:25 +02:00
|
|
|
value->SetDictionary(i, ToCefValue(vecData[i]));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace osr_accessibility_util {
|
|
|
|
|
|
|
|
CefRefPtr<CefValue> ParseAccessibilityEventData(
|
2024-05-23 03:52:35 +02:00
|
|
|
const ui::AXUpdatesAndEvents& details) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefValue> value = CefValue::Create();
|
2024-05-23 03:52:35 +02:00
|
|
|
value->SetDictionary(ToCefValue(details));
|
2017-05-12 20:28:25 +02:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefValue> ParseAccessibilityLocationData(
|
2024-05-23 03:52:35 +02:00
|
|
|
const std::vector<ui::AXLocationChanges>& details) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefValue> value = CefValue::Create();
|
2024-05-23 03:52:35 +02:00
|
|
|
value->SetList(ToCefValue(details));
|
2017-05-12 20:28:25 +02:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace osr_accessibility_util
|