1f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 2f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// found in the LICENSE file. 4f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 5f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ui/accessibility/ax_tree_update.h" 6f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 70529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "base/containers/hash_tables.h" 80529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "base/strings/string_number_conversions.h" 90529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 10f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace ui { 11f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 12a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)AXTreeUpdate::AXTreeUpdate() : node_id_to_clear(0) { 13f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 14f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 15f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)AXTreeUpdate::~AXTreeUpdate() { 16f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstd::string AXTreeUpdate::ToString() const { 190529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch std::string result; 200529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch if (node_id_to_clear != 0) { 210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch result += "AXTreeUpdate: clear node " + 220529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch base::IntToString(node_id_to_clear) + "\n"; 230529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 240529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 250529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // The challenge here is that we want to indent the nodes being updated 260529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // so that parent/child relationships are clear, but we don't have access 270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // to the rest of the tree for context, so we have to try to show the 280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // relative indentation of child nodes in this update relative to their 290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // parents. 300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch base::hash_map<int32, int> id_to_indentation; 310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch for (size_t i = 0; i < nodes.size(); ++i) { 320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch int indent = id_to_indentation[nodes[i].id]; 330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch result += std::string(2 * indent, ' '); 340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch result += nodes[i].ToString() + "\n"; 350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch for (size_t j = 0; j < nodes[i].child_ids.size(); ++j) 360529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch id_to_indentation[nodes[i].child_ids[j]] = indent + 1; 370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 380529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 390529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return result; 400529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch} 410529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 42f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} // namespace ui 43