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

Side by Side Diff: ui/accessibility/ax_tree.h

Issue 830943004: Improve the notifications sent from AXTree updates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix win and android compile Created 5 years, 11 months 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
OLDNEW
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_tree_update.h" 12 #include "ui/accessibility/ax_tree_update.h"
13 13
14 namespace ui { 14 namespace ui {
15 15
16 class AXNode; 16 class AXNode;
17 struct AXTreeUpdateState; 17 struct AXTreeUpdateState;
18 18
19 // Used when you want to be notified when changes happen to the tree. 19 // Used when you want to be notified when changes happen to the tree.
20 // 20 //
21 // Some of the notifications are called in the middle of an update operation. 21 // Some of the notifications are called in the middle of an update operation.
22 // Be careful, as the tree may be in an inconsistent state at this time; 22 // Be careful, as the tree may be in an inconsistent state at this time;
23 // don't walk the parents and children at this time: 23 // don't walk the parents and children at this time:
David Tseng 2015/01/23 17:25:39 At least for |OnSubtreeWillBeDeleted|, it appears
dmazzoni 2015/01/23 23:00:17 Technically you're right that the parents and chil
24 // OnNodeWillBeDeleted 24 // OnNodeWillBeDeleted
25 // OnSubtreeWillBeDeleted
25 // OnNodeCreated 26 // OnNodeCreated
26 // OnNodeChanged 27 // OnNodeChanged
27 // 28 //
28 // Other notifications are called at the end of an atomic update operation. 29 // In addition, one additional notification is fired at the end of an
29 // From these, it's safe to walk the tree and do any initialization that 30 // atomic update, and it provides a vector of nodes that were added or
30 // assumes the tree is in a consistent state. 31 // changed, for final postprocessing.
David Tseng 2015/01/23 17:25:39 Do you mean |OnAtomicUpdateFinished|?
dmazzoni 2015/01/23 23:00:17 Oops, yes - I meant to include that in the comment
31 // OnNodeCreationFinished
32 // OnNodeChangeFinished
33 // OnRootChanged
34 class AX_EXPORT AXTreeDelegate { 32 class AX_EXPORT AXTreeDelegate {
35 public: 33 public:
36 AXTreeDelegate(); 34 AXTreeDelegate();
37 virtual ~AXTreeDelegate(); 35 virtual ~AXTreeDelegate();
38 36
39 // Called just before a node is deleted. Its id and data will be valid, 37 // Called just before a node is deleted. Its id and data will be valid,
40 // but its links to parents and children are invalid. This is called 38 // but its links to parents and children are invalid. This is called
41 // in the middle of an update, the tree may be in an invalid state! 39 // in the middle of an update, the tree may be in an invalid state!
42 virtual void OnNodeWillBeDeleted(AXNode* node) = 0; 40 virtual void OnNodeWillBeDeleted(AXNode* node) = 0;
43 41
42 // Same as OnNodeWillBeDeleted, but only called once for an entire subtree.
43 // This is called in the middle of an update, the tree may be in an
44 // invalid state!
45 virtual void OnSubtreeWillBeDeleted(AXNode* node) = 0;
46
44 // Called immediately after a new node is created. The tree may be in 47 // Called immediately after a new node is created. The tree may be in
45 // the middle of an update, don't walk the parents and children now. 48 // the middle of an update, don't walk the parents and children now.
46 virtual void OnNodeCreated(AXNode* node) = 0; 49 virtual void OnNodeCreated(AXNode* node) = 0;
47 50
48 // Called when a node changes its data or children. The tree may be in 51 // Called when a node changes its data or children. The tree may be in
49 // the middle of an update, don't walk the parents and children now. 52 // the middle of an update, don't walk the parents and children now.
50 virtual void OnNodeChanged(AXNode* node) = 0; 53 virtual void OnNodeChanged(AXNode* node) = 0;
51 54
52 // Called for each new node at the end of an update operation, 55 enum ChangeType {
53 // when the tree is in a consistent state. 56 NODE_CREATED,
54 virtual void OnNodeCreationFinished(AXNode* node) = 0; 57 SUBTREE_CREATED,
58 NODE_CHANGED
59 };
55 60
56 // Called for each existing node that changed at the end of an update 61 struct Change {
57 // operation, when the tree is in a consistent state. 62 Change(AXNode* node, ChangeType type) {
58 virtual void OnNodeChangeFinished(AXNode* node) = 0; 63 this->node = node;
64 this->type = type;
65 }
66 AXNode *node;
67 ChangeType type;
68 };
59 69
60 // Called at the end of an update operation when the root node changes. 70 // Called at the end of the update operation. Every node that was added
61 virtual void OnRootChanged(AXNode* new_root) = 0; 71 // or changed will be included in |changes|, along with an enum indicating
72 // the type of change - either (1) a node was created, (2) a node was created
73 // and it's the root of a new subtree, or (3) a node was changed. Finally,
74 // a bool indicates if the root of the tree was changed or not.
75 virtual void OnAtomicUpdateFinished(bool root_changed,
76 const std::vector<Change>& changes) = 0;
62 }; 77 };
63 78
64 // AXTree is a live, managed tree of AXNode objects that can receive 79 // AXTree is a live, managed tree of AXNode objects that can receive
65 // updates from another AXTreeSource via AXTreeUpdates, and it can be 80 // updates from another AXTreeSource via AXTreeUpdates, and it can be
66 // used as a source for sending updates to another client tree. 81 // used as a source for sending updates to another client tree.
67 // It's designed to be subclassed to implement support for native 82 // It's designed to be subclassed to implement support for native
68 // accessibility APIs on a specific platform. 83 // accessibility APIs on a specific platform.
69 class AX_EXPORT AXTree { 84 class AX_EXPORT AXTree {
70 public: 85 public:
71 AXTree(); 86 AXTree();
(...skipping 18 matching lines...) Expand all
90 const std::string& error() { return error_; } 105 const std::string& error() { return error_; }
91 106
92 private: 107 private:
93 AXNode* CreateNode(AXNode* parent, int32 id, int32 index_in_parent); 108 AXNode* CreateNode(AXNode* parent, int32 id, int32 index_in_parent);
94 109
95 // This is called from within Unserialize(), it returns true on success. 110 // This is called from within Unserialize(), it returns true on success.
96 bool UpdateNode(const AXNodeData& src, AXTreeUpdateState* update_state); 111 bool UpdateNode(const AXNodeData& src, AXTreeUpdateState* update_state);
97 112
98 void OnRootChanged(); 113 void OnRootChanged();
99 114
115 // Notify the delegate that the subtree rooted at |node| will be destroyed,
116 // then call DestroyNodeAndSubtree on it.
117 void DestroySubtree(AXNode* node);
David Tseng 2015/01/23 17:25:39 Maybe call this NotifySubtreeWillBeDeleted?
dmazzoni 2015/01/23 23:00:17 It notifies and destroys
118
100 // Call Destroy() on |node|, and delete it from the id map, and then 119 // Call Destroy() on |node|, and delete it from the id map, and then
101 // call recursively on all nodes in its subtree. 120 // call recursively on all nodes in its subtree.
102 void DestroyNodeAndSubtree(AXNode* node); 121 void DestroyNodeAndSubtree(AXNode* node);
103 122
104 // Iterate over the children of |node| and for each child, destroy the 123 // Iterate over the children of |node| and for each child, destroy the
105 // child and its subtree if its id is not in |new_child_ids|. Returns 124 // child and its subtree if its id is not in |new_child_ids|. Returns
106 // true on success, false on fatal error. 125 // true on success, false on fatal error.
107 bool DeleteOldChildren(AXNode* node, 126 bool DeleteOldChildren(AXNode* node,
108 const std::vector<int32> new_child_ids); 127 const std::vector<int32> new_child_ids);
109 128
110 // Iterate over |new_child_ids| and populate |new_children| with 129 // Iterate over |new_child_ids| and populate |new_children| with
111 // pointers to child nodes, reusing existing nodes already in the tree 130 // pointers to child nodes, reusing existing nodes already in the tree
112 // if they exist, and creating otherwise. Reparenting is disallowed, so 131 // if they exist, and creating otherwise. Reparenting is disallowed, so
113 // if the id already exists as the child of another node, that's an 132 // if the id already exists as the child of another node, that's an
114 // error. Returns true on success, false on fatal error. 133 // error. Returns true on success, false on fatal error.
115 bool CreateNewChildVector(AXNode* node, 134 bool CreateNewChildVector(AXNode* node,
116 const std::vector<int32> new_child_ids, 135 const std::vector<int32> new_child_ids,
117 std::vector<AXNode*>* new_children, 136 std::vector<AXNode*>* new_children,
118 AXTreeUpdateState* update_state); 137 AXTreeUpdateState* update_state);
119 138
120 AXTreeDelegate* delegate_; 139 AXTreeDelegate* delegate_;
121 AXNode* root_; 140 AXNode* root_;
122 base::hash_map<int32, AXNode*> id_map_; 141 base::hash_map<int32, AXNode*> id_map_;
123 std::string error_; 142 std::string error_;
124 }; 143 };
125 144
126 } // namespace ui 145 } // namespace ui
127 146
128 #endif // UI_ACCESSIBILITY_AX_TREE_H_ 147 #endif // UI_ACCESSIBILITY_AX_TREE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698