| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef UI_ACCESSIBILITY_AX_TREE_H_ | 5 #ifndef UI_ACCESSIBILITY_AX_TREE_H_ |
| 6 #define UI_ACCESSIBILITY_AX_TREE_H_ | 6 #define UI_ACCESSIBILITY_AX_TREE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include <set> | 10 #include <set> |
| 9 | 11 |
| 10 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
| 11 #include "ui/accessibility/ax_export.h" | 13 #include "ui/accessibility/ax_export.h" |
| 12 #include "ui/accessibility/ax_node_data.h" | 14 #include "ui/accessibility/ax_node_data.h" |
| 13 #include "ui/accessibility/ax_tree_data.h" | 15 #include "ui/accessibility/ax_tree_data.h" |
| 14 #include "ui/accessibility/ax_tree_update.h" | 16 #include "ui/accessibility/ax_tree_update.h" |
| 15 | 17 |
| 16 namespace ui { | 18 namespace ui { |
| 17 | 19 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 explicit AXTree(const AXTreeUpdate& initial_state); | 98 explicit AXTree(const AXTreeUpdate& initial_state); |
| 97 virtual ~AXTree(); | 99 virtual ~AXTree(); |
| 98 | 100 |
| 99 virtual void SetDelegate(AXTreeDelegate* delegate); | 101 virtual void SetDelegate(AXTreeDelegate* delegate); |
| 100 | 102 |
| 101 AXNode* root() const { return root_; } | 103 AXNode* root() const { return root_; } |
| 102 | 104 |
| 103 const AXTreeData& data() const { return data_; } | 105 const AXTreeData& data() const { return data_; } |
| 104 | 106 |
| 105 // Returns the AXNode with the given |id| if it is part of this AXTree. | 107 // Returns the AXNode with the given |id| if it is part of this AXTree. |
| 106 AXNode* GetFromId(int32 id) const; | 108 AXNode* GetFromId(int32_t id) const; |
| 107 | 109 |
| 108 // Returns true on success. If it returns false, it's a fatal error | 110 // Returns true on success. If it returns false, it's a fatal error |
| 109 // and this tree should be destroyed, and the source of the tree update | 111 // and this tree should be destroyed, and the source of the tree update |
| 110 // should not be trusted any longer. | 112 // should not be trusted any longer. |
| 111 virtual bool Unserialize(const AXTreeUpdate& update); | 113 virtual bool Unserialize(const AXTreeUpdate& update); |
| 112 | 114 |
| 113 virtual void UpdateData(const AXTreeData& data); | 115 virtual void UpdateData(const AXTreeData& data); |
| 114 | 116 |
| 115 // Return a multi-line indented string representation, for logging. | 117 // Return a multi-line indented string representation, for logging. |
| 116 std::string ToString() const; | 118 std::string ToString() const; |
| 117 | 119 |
| 118 // A string describing the error from an unsuccessful Unserialize, | 120 // A string describing the error from an unsuccessful Unserialize, |
| 119 // for testing and debugging. | 121 // for testing and debugging. |
| 120 const std::string& error() const { return error_; } | 122 const std::string& error() const { return error_; } |
| 121 | 123 |
| 122 int size() { return static_cast<int>(id_map_.size()); } | 124 int size() { return static_cast<int>(id_map_.size()); } |
| 123 | 125 |
| 124 private: | 126 private: |
| 125 AXNode* CreateNode(AXNode* parent, int32 id, int32 index_in_parent); | 127 AXNode* CreateNode(AXNode* parent, int32_t id, int32_t index_in_parent); |
| 126 | 128 |
| 127 // This is called from within Unserialize(), it returns true on success. | 129 // This is called from within Unserialize(), it returns true on success. |
| 128 bool UpdateNode(const AXNodeData& src, AXTreeUpdateState* update_state); | 130 bool UpdateNode(const AXNodeData& src, AXTreeUpdateState* update_state); |
| 129 | 131 |
| 130 void OnRootChanged(); | 132 void OnRootChanged(); |
| 131 | 133 |
| 132 // Notify the delegate that the subtree rooted at |node| will be destroyed, | 134 // Notify the delegate that the subtree rooted at |node| will be destroyed, |
| 133 // then call DestroyNodeAndSubtree on it. | 135 // then call DestroyNodeAndSubtree on it. |
| 134 void DestroySubtree(AXNode* node, AXTreeUpdateState* update_state); | 136 void DestroySubtree(AXNode* node, AXTreeUpdateState* update_state); |
| 135 | 137 |
| 136 // Call Destroy() on |node|, and delete it from the id map, and then | 138 // Call Destroy() on |node|, and delete it from the id map, and then |
| 137 // call recursively on all nodes in its subtree. | 139 // call recursively on all nodes in its subtree. |
| 138 void DestroyNodeAndSubtree(AXNode* node, AXTreeUpdateState* update_state); | 140 void DestroyNodeAndSubtree(AXNode* node, AXTreeUpdateState* update_state); |
| 139 | 141 |
| 140 // Iterate over the children of |node| and for each child, destroy the | 142 // Iterate over the children of |node| and for each child, destroy the |
| 141 // child and its subtree if its id is not in |new_child_ids|. Returns | 143 // child and its subtree if its id is not in |new_child_ids|. Returns |
| 142 // true on success, false on fatal error. | 144 // true on success, false on fatal error. |
| 143 bool DeleteOldChildren(AXNode* node, | 145 bool DeleteOldChildren(AXNode* node, |
| 144 const std::vector<int32>& new_child_ids, | 146 const std::vector<int32_t>& new_child_ids, |
| 145 AXTreeUpdateState* update_state); | 147 AXTreeUpdateState* update_state); |
| 146 | 148 |
| 147 // Iterate over |new_child_ids| and populate |new_children| with | 149 // Iterate over |new_child_ids| and populate |new_children| with |
| 148 // pointers to child nodes, reusing existing nodes already in the tree | 150 // pointers to child nodes, reusing existing nodes already in the tree |
| 149 // if they exist, and creating otherwise. Reparenting is disallowed, so | 151 // if they exist, and creating otherwise. Reparenting is disallowed, so |
| 150 // if the id already exists as the child of another node, that's an | 152 // if the id already exists as the child of another node, that's an |
| 151 // error. Returns true on success, false on fatal error. | 153 // error. Returns true on success, false on fatal error. |
| 152 bool CreateNewChildVector(AXNode* node, | 154 bool CreateNewChildVector(AXNode* node, |
| 153 const std::vector<int32>& new_child_ids, | 155 const std::vector<int32_t>& new_child_ids, |
| 154 std::vector<AXNode*>* new_children, | 156 std::vector<AXNode*>* new_children, |
| 155 AXTreeUpdateState* update_state); | 157 AXTreeUpdateState* update_state); |
| 156 | 158 |
| 157 AXTreeDelegate* delegate_; | 159 AXTreeDelegate* delegate_; |
| 158 AXNode* root_; | 160 AXNode* root_; |
| 159 base::hash_map<int32, AXNode*> id_map_; | 161 base::hash_map<int32_t, AXNode*> id_map_; |
| 160 std::string error_; | 162 std::string error_; |
| 161 AXTreeData data_; | 163 AXTreeData data_; |
| 162 }; | 164 }; |
| 163 | 165 |
| 164 } // namespace ui | 166 } // namespace ui |
| 165 | 167 |
| 166 #endif // UI_ACCESSIBILITY_AX_TREE_H_ | 168 #endif // UI_ACCESSIBILITY_AX_TREE_H_ |
| OLD | NEW |