Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1169)

Side by Side Diff: ui/accessibility/ax_tree_combiner.cc

Issue 2572923002: AXTreeCombiner no longer needs to convert to global coordinates. (Closed)
Patch Set: Fixed unittests Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/accessibility/ax_tree_combiner.h ('k') | ui/accessibility/ax_tree_combiner_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/accessibility/ax_tree.h" 5 #include "ui/accessibility/ax_tree.h"
6 #include "ui/accessibility/ax_tree_combiner.h" 6 #include "ui/accessibility/ax_tree_combiner.h"
7 #include "ui/gfx/geometry/rect_f.h" 7 #include "ui/gfx/geometry/rect_f.h"
8 8
9 namespace ui { 9 namespace ui {
10 namespace { 10 namespace {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 } 161 }
162 162
163 int32_t AXTreeCombiner::MapId(int32_t tree_id, int32_t node_id) { 163 int32_t AXTreeCombiner::MapId(int32_t tree_id, int32_t node_id) {
164 auto tree_id_node_id = std::make_pair(tree_id, node_id); 164 auto tree_id_node_id = std::make_pair(tree_id, node_id);
165 if (tree_id_node_id_map_[tree_id_node_id] == 0) 165 if (tree_id_node_id_map_[tree_id_node_id] == 0)
166 tree_id_node_id_map_[tree_id_node_id] = next_id_++; 166 tree_id_node_id_map_[tree_id_node_id] = next_id_++;
167 return tree_id_node_id_map_[tree_id_node_id]; 167 return tree_id_node_id_map_[tree_id_node_id];
168 } 168 }
169 169
170 void AXTreeCombiner::ProcessTree(const AXTreeUpdate* tree) { 170 void AXTreeCombiner::ProcessTree(const AXTreeUpdate* tree) {
171 // The root of each tree may contain a transform that needs to apply
172 // to all of its descendants.
173 gfx::Transform old_transform = transform_;
174 if (!tree->nodes.empty() && tree->nodes[0].transform)
175 transform_.ConcatTransform(*tree->nodes[0].transform);
176
177 int32_t tree_id = tree->tree_data.tree_id; 171 int32_t tree_id = tree->tree_data.tree_id;
178 for (size_t i = 0; i < tree->nodes.size(); ++i) { 172 for (size_t i = 0; i < tree->nodes.size(); ++i) {
179 AXNodeData node = tree->nodes[i]; 173 AXNodeData node = tree->nodes[i];
180 int32_t child_tree_id = node.GetIntAttribute(AX_ATTR_CHILD_TREE_ID); 174 int32_t child_tree_id = node.GetIntAttribute(AX_ATTR_CHILD_TREE_ID);
181 175
182 // Map the node's ID. 176 // Map the node's ID.
183 node.id = MapId(tree_id, node.id); 177 node.id = MapId(tree_id, node.id);
184 178
185 // Map the node's child IDs. 179 // Map the node's child IDs.
186 for (size_t j = 0; j < node.child_ids.size(); ++j) 180 for (size_t j = 0; j < node.child_ids.size(); ++j)
187 node.child_ids[j] = MapId(tree_id, node.child_ids[j]); 181 node.child_ids[j] = MapId(tree_id, node.child_ids[j]);
188 182
189 // Reset the offset container ID because we make all bounding boxes 183 // Map the container id.
190 // absolute. 184 if (node.offset_container_id > 0)
191 node.offset_container_id = -1; 185 node.offset_container_id = MapId(tree_id, node.offset_container_id);
192 186
193 // Map other int attributes that refer to node IDs, and remove the 187 // Map other int attributes that refer to node IDs, and remove the
194 // AX_ATTR_CHILD_TREE_ID attribute. 188 // AX_ATTR_CHILD_TREE_ID attribute.
195 for (size_t j = 0; j < node.int_attributes.size(); ++j) { 189 for (size_t j = 0; j < node.int_attributes.size(); ++j) {
196 auto& attr = node.int_attributes[j]; 190 auto& attr = node.int_attributes[j];
197 if (IsNodeIdIntAttribute(attr.first)) 191 if (IsNodeIdIntAttribute(attr.first))
198 attr.second = MapId(tree_id, attr.second); 192 attr.second = MapId(tree_id, attr.second);
199 if (attr.first == AX_ATTR_CHILD_TREE_ID) { 193 if (attr.first == AX_ATTR_CHILD_TREE_ID) {
200 attr.first = AX_INT_ATTRIBUTE_NONE; 194 attr.first = AX_INT_ATTRIBUTE_NONE;
201 attr.second = 0; 195 attr.second = 0;
202 } 196 }
203 } 197 }
204 198
205 // Map other int list attributes that refer to node IDs. 199 // Map other int list attributes that refer to node IDs.
206 for (size_t j = 0; j < node.intlist_attributes.size(); ++j) { 200 for (size_t j = 0; j < node.intlist_attributes.size(); ++j) {
207 auto& attr = node.intlist_attributes[j]; 201 auto& attr = node.intlist_attributes[j];
208 if (IsNodeIdIntListAttribute(attr.first)) { 202 if (IsNodeIdIntListAttribute(attr.first)) {
209 for (size_t k = 0; k < attr.second.size(); k++) 203 for (size_t k = 0; k < attr.second.size(); k++)
210 attr.second[k] = MapId(tree_id, attr.second[k]); 204 attr.second[k] = MapId(tree_id, attr.second[k]);
211 } 205 }
212 } 206 }
213 207
214 // Apply the transformation to the object's bounds to put it in
215 // the coordinate space of the root frame.
216 transform_.TransformRect(&node.location);
217
218 // See if this node has a child tree. As a sanity check make sure the 208 // See if this node has a child tree. As a sanity check make sure the
219 // child tree lists this tree as its parent tree id. 209 // child tree lists this tree as its parent tree id.
220 const AXTreeUpdate* child_tree = nullptr; 210 const AXTreeUpdate* child_tree = nullptr;
221 if (tree_id_map_.find(child_tree_id) != tree_id_map_.end()) { 211 if (tree_id_map_.find(child_tree_id) != tree_id_map_.end()) {
222 child_tree = tree_id_map_.find(child_tree_id)->second; 212 child_tree = tree_id_map_.find(child_tree_id)->second;
223 if (child_tree->tree_data.parent_tree_id != tree_id) 213 if (child_tree->tree_data.parent_tree_id != tree_id)
224 child_tree = nullptr; 214 child_tree = nullptr;
225 if (child_tree && child_tree->nodes.empty()) 215 if (child_tree && child_tree->nodes.empty())
226 child_tree = nullptr; 216 child_tree = nullptr;
227 if (child_tree) { 217 if (child_tree) {
228 node.child_ids.push_back(MapId(child_tree_id, 218 node.child_ids.push_back(MapId(child_tree_id,
229 child_tree->nodes[0].id)); 219 child_tree->nodes[0].id));
230 } 220 }
231 } 221 }
232 222
233 // Put the rewritten AXNodeData into the output data structure. 223 // Put the rewritten AXNodeData into the output data structure.
234 combined_.nodes.push_back(node); 224 combined_.nodes.push_back(node);
235 225
236 // Recurse into the child tree now, if any. 226 // Recurse into the child tree now, if any.
237 if (child_tree) 227 if (child_tree)
238 ProcessTree(child_tree); 228 ProcessTree(child_tree);
239 } 229 }
240
241 // Reset the transform.
242 transform_ = old_transform;
243 } 230 }
244 231
245 } // namespace ui 232 } // namespace ui
OLDNEW
« no previous file with comments | « ui/accessibility/ax_tree_combiner.h ('k') | ui/accessibility/ax_tree_combiner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698