Windows: cefclient: Fix accessibility where TreeId type has changed from int to string

This commit is contained in:
Andrei Kurushin 2020-04-02 21:19:25 +00:00 committed by Marshall Greenblatt
parent 261a8899fc
commit ea1324a9f1
4 changed files with 42 additions and 42 deletions

View File

@ -7,7 +7,7 @@
namespace client {
OsrAXTree::OsrAXTree() : parent_tree_id_(-1), root_node_id_(-1) {}
OsrAXTree::OsrAXTree() : root_node_id_(-1) {}
OsrAXNode* OsrAXTree::GetNode(int nodeId) const {
auto result = node_map_.find(nodeId);
@ -27,10 +27,9 @@ void OsrAXTree::AddNode(OsrAXNode* node) {
void OsrAXTree::UpdateTreeData(CefRefPtr<CefDictionaryValue> value) {
if (value->HasKey("parent_tree_id")) {
parent_tree_id_ =
OsrAccessibilityHelper::CastToInt(value->GetValue("parent_tree_id"));
parent_tree_id_ = value->GetString("parent_tree_id");
} else {
parent_tree_id_ = -1;
parent_tree_id_ = "";
}
// may also update following:
@ -39,9 +38,7 @@ void OsrAXTree::UpdateTreeData(CefRefPtr<CefDictionaryValue> value) {
OsrAccessibilityHelper::OsrAccessibilityHelper(CefRefPtr<CefValue> value,
CefRefPtr<CefBrowser> browser)
: root_tree_id_(-1),
focused_tree_id_(-1),
focused_node_id_(-1),
: focused_node_id_(-1),
browser_(browser) {
UpdateAccessibilityTree(value);
}
@ -75,7 +72,7 @@ void OsrAccessibilityHelper::UpdateAccessibilityLocation(
!locationChangeDict->HasKey("id")) {
continue;
}
int treeId = CastToInt(locationChangeDict->GetValue("ax_tree_id"));
CefString treeId = locationChangeDict->GetString("ax_tree_id");
int nodeId = CastToInt(locationChangeDict->GetValue("id"));
CefRefPtr<CefDictionaryValue> newLocationDict =
@ -103,7 +100,7 @@ void OsrAccessibilityHelper::UpdateAccessibilityTree(
return;
}
int treeId = CastToInt(mainDict->GetValue("ax_tree_id"));
CefString treeId = mainDict->GetString("ax_tree_id");
CefRefPtr<CefListValue> updatesList = mainDict->GetList("updates");
size_t updatesCount = updatesList->GetSize();
@ -130,7 +127,8 @@ OsrAXNode* OsrAccessibilityHelper::GetFocusedNode() const {
return nullptr;
}
OsrAXNode* OsrAccessibilityHelper::GetTreeRootNode(int treeId) const {
OsrAXNode* OsrAccessibilityHelper::GetTreeRootNode(
const CefString& treeId) const {
auto tree = accessibility_node_map_.find(treeId);
if (tree != accessibility_node_map_.end()) {
return tree->second.GetNode(tree->second.GetRootNodeId());
@ -140,7 +138,7 @@ OsrAXNode* OsrAccessibilityHelper::GetTreeRootNode(int treeId) const {
}
void OsrAccessibilityHelper::UpdateLayout(
int treeId,
const CefString& treeId,
CefRefPtr<CefDictionaryValue> update) {
if (!update) {
return;
@ -154,12 +152,12 @@ void OsrAccessibilityHelper::UpdateLayout(
auto tree = accessibility_node_map_.find(treeId);
if (tree != accessibility_node_map_.end()) {
if (tree->second.GetRootNodeId() == nodeId) {
root_tree_id_ = -1;
root_tree_id_ = "";
tree->second.SetRootNodeId(-1);
}
}
if ((focused_tree_id_ == treeId) && (focused_node_id_ == nodeId)) {
UpdateFocusedNode(-1, -1);
UpdateFocusedNode("", -1);
}
OsrAXNode* node = GetNode(treeId, nodeId);
DestroyNode(node);
@ -172,11 +170,11 @@ void OsrAccessibilityHelper::UpdateLayout(
update->GetDictionary("tree_data");
auto& tree = accessibility_node_map_[treeId];
tree.UpdateTreeData(tree_data);
if (tree.GetParentTreeId() == -1) {
if (tree.GetParentTreeId().empty()) {
root_tree_id_ = treeId;
}
if (tree_data->HasKey("focus_id") && tree_data->HasKey("focused_tree_id")) {
UpdateFocusedNode(CastToInt(tree_data->GetValue("focused_tree_id")),
UpdateFocusedNode(tree_data->GetString("focused_tree_id"),
CastToInt(tree_data->GetValue("focus_id")));
}
}
@ -212,7 +210,8 @@ void OsrAccessibilityHelper::UpdateLayout(
}
}
void OsrAccessibilityHelper::UpdateFocusedNode(int treeId, int nodeId) {
void OsrAccessibilityHelper::UpdateFocusedNode(const CefString& treeId,
int nodeId) {
if ((focused_tree_id_ == treeId) && (focused_node_id_ == nodeId)) {
return;
}
@ -228,13 +227,14 @@ void OsrAccessibilityHelper::UpdateFocusedNode(int treeId, int nodeId) {
void OsrAccessibilityHelper::Reset() {
accessibility_node_map_.clear();
root_tree_id_ = -1;
focused_tree_id_ = focused_node_id_ = -1;
root_tree_id_ = "";
focused_tree_id_ = "";
focused_node_id_ = -1;
}
void OsrAccessibilityHelper::DestroyNode(OsrAXNode* node) {
if (node) {
int treeId = node->OsrAXTreeId();
CefString treeId = node->OsrAXTreeId();
int numChilds = node->GetChildCount();
if (numChilds > 0) {
for (int i = 0; i < numChilds; i++) {
@ -257,7 +257,8 @@ void OsrAccessibilityHelper::DestroyNode(OsrAXNode* node) {
}
}
OsrAXNode* OsrAccessibilityHelper::GetNode(int treeId, int nodeId) const {
OsrAXNode* OsrAccessibilityHelper::GetNode(const CefString& treeId,
int nodeId) const {
auto tree = accessibility_node_map_.find(treeId);
if (tree != accessibility_node_map_.end()) {
return tree->second.GetNode(nodeId);

View File

@ -21,12 +21,12 @@ class OsrAXTree {
void EraseNode(int nodeId);
void UpdateTreeData(CefRefPtr<CefDictionaryValue> value);
void AddNode(OsrAXNode* node);
int GetParentTreeId() const { return parent_tree_id_; }
const CefString& GetParentTreeId() const { return parent_tree_id_; }
int GetRootNodeId() const { return root_node_id_; }
void SetRootNodeId(int nodeId) { root_node_id_ = nodeId; }
private:
int parent_tree_id_;
CefString parent_tree_id_;
int root_node_id_;
std::map<int, OsrAXNode*> node_map_;
};
@ -53,26 +53,27 @@ class OsrAccessibilityHelper {
CefRefPtr<CefBrowser> GetBrowser() const { return browser_; }
OsrAXNode* GetNode(int treeId, int nodeId) const;
OsrAXNode* GetNode(const CefString& treeId, int nodeId) const;
OsrAXNode* GetTreeRootNode(int treeId) const;
OsrAXNode* GetTreeRootNode(const CefString& treeId) const;
static int CastToInt(CefRefPtr<CefValue> value);
private:
void Reset();
void UpdateLayout(int treeId, CefRefPtr<CefDictionaryValue> update);
void UpdateLayout(const CefString& treeId,
CefRefPtr<CefDictionaryValue> update);
void UpdateFocusedNode(int treeId, int nodeId);
void UpdateFocusedNode(const CefString& treeId, int nodeId);
// Destroy the node and remove from Map
void DestroyNode(OsrAXNode* node);
int root_tree_id_;
int focused_tree_id_;
CefString root_tree_id_;
CefString focused_tree_id_;
int focused_node_id_;
CefRefPtr<CefBrowser> browser_;
std::map<int, OsrAXTree> accessibility_node_map_;
std::map<CefString, OsrAXTree> accessibility_node_map_;
};
} // namespace client

View File

@ -11,13 +11,12 @@
namespace client {
OsrAXNode::OsrAXNode(int treeId,
OsrAXNode::OsrAXNode(const CefString& treeId,
int nodeId,
CefRefPtr<CefDictionaryValue> value,
OsrAccessibilityHelper* helper)
: tree_id_(treeId),
node_id_(nodeId),
child_tree_id_(-1),
platform_accessibility_(nullptr),
parent_(nullptr),
offset_container_id_(-1),
@ -68,7 +67,7 @@ void OsrAXNode::UpdateValue(CefRefPtr<CefDictionaryValue> value) {
}
// Update attributes
if (value->HasKey("attributes")) {
child_tree_id_ = -1;
child_tree_id_ = "";
attributes_ = value->GetDictionary("attributes");
@ -84,8 +83,7 @@ void OsrAXNode::UpdateValue(CefRefPtr<CefDictionaryValue> value) {
}
if (attributes_ && attributes_->HasKey("childTreeId")) {
child_tree_id_ = OsrAccessibilityHelper::CastToInt(
attributes_->GetValue("childTreeId"));
child_tree_id_ = attributes_->GetString("childTreeId");
}
if (attributes_ && attributes_->HasKey("name"))
name_ = attributes_->GetString("name");
@ -139,7 +137,7 @@ CefRect OsrAXNode::AxLocation() const {
int OsrAXNode::GetChildCount() const {
int count = static_cast<int>(child_ids_.size());
if (child_tree_id_ >= 0) {
if (!child_tree_id_.empty()) {
OsrAXNode* childTreeRootNode =
accessibility_helper_->GetTreeRootNode(child_tree_id_);
if (childTreeRootNode) {
@ -153,7 +151,7 @@ OsrAXNode* OsrAXNode::ChildAtIndex(int index) const {
int count = static_cast<int>(child_ids_.size());
if (index < count)
return accessibility_helper_->GetNode(OsrAXTreeId(), child_ids_[index]);
if ((index == count) && (child_tree_id_ >= 0)) {
if ((index == count) && (!child_tree_id_.empty())) {
OsrAXNode* childTreeRootNode =
accessibility_helper_->GetTreeRootNode(child_tree_id_);
if (childTreeRootNode) {
@ -165,7 +163,7 @@ OsrAXNode* OsrAXNode::ChildAtIndex(int index) const {
}
// Create and return the platform specific OsrAXNode Object
OsrAXNode* OsrAXNode::CreateNode(int treeId,
OsrAXNode* OsrAXNode::CreateNode(const CefString& treeId,
int nodeId,
CefRefPtr<CefDictionaryValue> value,
OsrAccessibilityHelper* helper) {

View File

@ -40,7 +40,7 @@ class OsrAccessibilityHelper;
class OsrAXNode {
public:
// Create and return the platform specific OsrAXNode Object.
static OsrAXNode* CreateNode(int treeId,
static OsrAXNode* CreateNode(const CefString& treeId,
int nodeId,
CefRefPtr<CefDictionaryValue> value,
OsrAccessibilityHelper* helper);
@ -77,7 +77,7 @@ class OsrAXNode {
const CefString& AxRole() const { return role_; }
int OsrAXTreeId() const { return tree_id_; }
const CefString& OsrAXTreeId() const { return tree_id_; }
int OsrAXNodeId() const { return node_id_; }
@ -96,14 +96,14 @@ class OsrAXNode {
void SetParent(OsrAXNode* parent);
protected:
OsrAXNode(int treeId,
OsrAXNode(const CefString& treeId,
int nodeId,
CefRefPtr<CefDictionaryValue> value,
OsrAccessibilityHelper* helper);
int tree_id_;
CefString tree_id_;
int node_id_;
int child_tree_id_;
CefString child_tree_id_;
CefString role_;
CefString value_;
CefString name_;