| 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 <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| 11 #include "ui/accessibility/ax_export.h" | 11 #include "ui/accessibility/ax_export.h" |
| 12 #include "ui/accessibility/ax_node_data.h" |
| 13 #include "ui/accessibility/ax_tree_data.h" |
| 12 #include "ui/accessibility/ax_tree_update.h" | 14 #include "ui/accessibility/ax_tree_update.h" |
| 13 | 15 |
| 14 namespace ui { | 16 namespace ui { |
| 15 | 17 |
| 16 class AXNode; | 18 class AXNode; |
| 17 class AXTree; | 19 class AXTree; |
| 18 struct AXTreeUpdateState; | 20 struct AXTreeUpdateState; |
| 19 | 21 |
| 20 // Used when you want to be notified when changes happen to the tree. | 22 // Used when you want to be notified when changes happen to the tree. |
| 21 // | 23 // |
| 22 // Some of the notifications are called in the middle of an update operation. | 24 // Some of the notifications are called in the middle of an update operation. |
| 23 // Be careful, as the tree may be in an inconsistent state at this time; | 25 // Be careful, as the tree may be in an inconsistent state at this time; |
| 24 // don't walk the parents and children at this time: | 26 // don't walk the parents and children at this time: |
| 25 // OnNodeWillBeDeleted | 27 // OnNodeWillBeDeleted |
| 26 // OnSubtreeWillBeDeleted | 28 // OnSubtreeWillBeDeleted |
| 27 // OnNodeCreated | 29 // OnNodeCreated |
| 28 // OnNodeChanged | 30 // OnNodeChanged |
| 29 // | 31 // |
| 30 // In addition, one additional notification is fired at the end of an | 32 // In addition, one additional notification is fired at the end of an |
| 31 // atomic update, and it provides a vector of nodes that were added or | 33 // atomic update, and it provides a vector of nodes that were added or |
| 32 // changed, for final postprocessing: | 34 // changed, for final postprocessing: |
| 33 // OnAtomicUpdateFinished | 35 // OnAtomicUpdateFinished |
| 34 // | 36 // |
| 35 class AX_EXPORT AXTreeDelegate { | 37 class AX_EXPORT AXTreeDelegate { |
| 36 public: | 38 public: |
| 37 AXTreeDelegate(); | 39 AXTreeDelegate(); |
| 38 virtual ~AXTreeDelegate(); | 40 virtual ~AXTreeDelegate(); |
| 39 | 41 |
| 42 // Called when tree data changes. |
| 43 virtual void OnTreeDataChanged(AXTree* tree) = 0; |
| 44 |
| 40 // Called just before a node is deleted. Its id and data will be valid, | 45 // Called just before a node is deleted. Its id and data will be valid, |
| 41 // but its links to parents and children are invalid. This is called | 46 // but its links to parents and children are invalid. This is called |
| 42 // in the middle of an update, the tree may be in an invalid state! | 47 // in the middle of an update, the tree may be in an invalid state! |
| 43 virtual void OnNodeWillBeDeleted(AXTree* tree, AXNode* node) = 0; | 48 virtual void OnNodeWillBeDeleted(AXTree* tree, AXNode* node) = 0; |
| 44 | 49 |
| 45 // Same as OnNodeWillBeDeleted, but only called once for an entire subtree. | 50 // Same as OnNodeWillBeDeleted, but only called once for an entire subtree. |
| 46 // This is called in the middle of an update, the tree may be in an | 51 // This is called in the middle of an update, the tree may be in an |
| 47 // invalid state! | 52 // invalid state! |
| 48 virtual void OnSubtreeWillBeDeleted(AXTree* tree, AXNode* node) = 0; | 53 virtual void OnSubtreeWillBeDeleted(AXTree* tree, AXNode* node) = 0; |
| 49 | 54 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 }; | 86 }; |
| 82 | 87 |
| 83 // AXTree is a live, managed tree of AXNode objects that can receive | 88 // AXTree is a live, managed tree of AXNode objects that can receive |
| 84 // updates from another AXTreeSource via AXTreeUpdates, and it can be | 89 // updates from another AXTreeSource via AXTreeUpdates, and it can be |
| 85 // used as a source for sending updates to another client tree. | 90 // used as a source for sending updates to another client tree. |
| 86 // It's designed to be subclassed to implement support for native | 91 // It's designed to be subclassed to implement support for native |
| 87 // accessibility APIs on a specific platform. | 92 // accessibility APIs on a specific platform. |
| 88 class AX_EXPORT AXTree { | 93 class AX_EXPORT AXTree { |
| 89 public: | 94 public: |
| 90 AXTree(); | 95 AXTree(); |
| 91 explicit AXTree(const AXTreeUpdate<AXNodeData>& initial_state); | 96 explicit AXTree(const AXTreeUpdate& initial_state); |
| 92 virtual ~AXTree(); | 97 virtual ~AXTree(); |
| 93 | 98 |
| 94 virtual void SetDelegate(AXTreeDelegate* delegate); | 99 virtual void SetDelegate(AXTreeDelegate* delegate); |
| 95 | 100 |
| 96 AXNode* root() const { return root_; } | 101 AXNode* root() const { return root_; } |
| 97 | 102 |
| 103 const AXTreeData& data() const { return data_; } |
| 104 |
| 98 // Returns the AXNode with the given |id| if it is part of this AXTree. | 105 // Returns the AXNode with the given |id| if it is part of this AXTree. |
| 99 AXNode* GetFromId(int32 id) const; | 106 AXNode* GetFromId(int32 id) const; |
| 100 | 107 |
| 101 // Returns true on success. If it returns false, it's a fatal error | 108 // Returns true on success. If it returns false, it's a fatal error |
| 102 // and this tree should be destroyed, and the source of the tree update | 109 // and this tree should be destroyed, and the source of the tree update |
| 103 // should not be trusted any longer. | 110 // should not be trusted any longer. |
| 104 virtual bool Unserialize(const AXTreeUpdate<AXNodeData>& update); | 111 virtual bool Unserialize(const AXTreeUpdate& update); |
| 112 |
| 113 virtual void UpdateData(const AXTreeData& data); |
| 105 | 114 |
| 106 // Return a multi-line indented string representation, for logging. | 115 // Return a multi-line indented string representation, for logging. |
| 107 std::string ToString() const; | 116 std::string ToString() const; |
| 108 | 117 |
| 109 // A string describing the error from an unsuccessful Unserialize, | 118 // A string describing the error from an unsuccessful Unserialize, |
| 110 // for testing and debugging. | 119 // for testing and debugging. |
| 111 const std::string& error() const { return error_; } | 120 const std::string& error() const { return error_; } |
| 112 | 121 |
| 113 int size() { return static_cast<int>(id_map_.size()); } | 122 int size() { return static_cast<int>(id_map_.size()); } |
| 114 | 123 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 142 // error. Returns true on success, false on fatal error. | 151 // error. Returns true on success, false on fatal error. |
| 143 bool CreateNewChildVector(AXNode* node, | 152 bool CreateNewChildVector(AXNode* node, |
| 144 const std::vector<int32>& new_child_ids, | 153 const std::vector<int32>& new_child_ids, |
| 145 std::vector<AXNode*>* new_children, | 154 std::vector<AXNode*>* new_children, |
| 146 AXTreeUpdateState* update_state); | 155 AXTreeUpdateState* update_state); |
| 147 | 156 |
| 148 AXTreeDelegate* delegate_; | 157 AXTreeDelegate* delegate_; |
| 149 AXNode* root_; | 158 AXNode* root_; |
| 150 base::hash_map<int32, AXNode*> id_map_; | 159 base::hash_map<int32, AXNode*> id_map_; |
| 151 std::string error_; | 160 std::string error_; |
| 161 AXTreeData data_; |
| 152 }; | 162 }; |
| 153 | 163 |
| 154 } // namespace ui | 164 } // namespace ui |
| 155 | 165 |
| 156 #endif // UI_ACCESSIBILITY_AX_TREE_H_ | 166 #endif // UI_ACCESSIBILITY_AX_TREE_H_ |
| OLD | NEW |