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

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

Issue 90853002: Make tree serialization more robust and add more unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
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>
9
8 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
9
10 #include "ui/accessibility/ax_export.h" 11 #include "ui/accessibility/ax_export.h"
11 #include "ui/accessibility/ax_tree.h" 12 #include "ui/accessibility/ax_tree.h"
12 #include "ui/accessibility/ax_tree_update.h" 13 #include "ui/accessibility/ax_tree_update.h"
13 14
14 namespace ui { 15 namespace ui {
15 16
16 class AXNode; 17 class AXNode;
17 18
18 // AXTree is a live, managed tree of AXNode objects that can receive 19 // AXTree is a live, managed tree of AXNode objects that can receive
19 // updates from another AXTreeSource via AXTreeUpdates, and it can be 20 // updates from another AXTreeSource via AXTreeUpdates, and it can be
20 // used as a source for sending updates to another client tree. 21 // used as a source for sending updates to another client tree.
21 // It's designed to be subclassed to implement support for native 22 // It's designed to be subclassed to implement support for native
22 // accessibility APIs on a specific platform. 23 // accessibility APIs on a specific platform.
23 class AX_EXPORT AXTree { 24 class AX_EXPORT AXTree {
24 public: 25 public:
25 AXTree(); 26 AXTree();
26 explicit AXTree(const AXTreeUpdate& initial_state); 27 explicit AXTree(const AXTreeUpdate& initial_state);
27 virtual ~AXTree(); 28 virtual ~AXTree();
28 29
29 virtual AXNode* GetRoot() const; 30 virtual AXNode* GetRoot() const;
30 virtual AXNode* GetFromId(int32 id) const; 31 virtual AXNode* GetFromId(int32 id) const;
31 32
33 // Returns true on success. If it returns false, it's a fatal error
34 // and this tree should be destroyed, and the source of the tree update
35 // should not be trusted any longer.
32 virtual bool Unserialize(const AXTreeUpdate& update); 36 virtual bool Unserialize(const AXTreeUpdate& update);
33 37
38 // A string describing the error from an unsuccessful Unserialize,
39 // for testing and debugging.
40 const std::string& error() { return error_; }
41
34 protected: 42 protected:
35 // Subclasses can override this to use a subclass of AXNode. 43 // Subclasses can override this to use a subclass of AXNode.
36 virtual AXNode* CreateNode(AXNode* parent, int32 id, int32 index_in_parent); 44 virtual AXNode* CreateNode(AXNode* parent, int32 id, int32 index_in_parent);
37 45
38 // This is called from within Unserialize(), it returns true on success. 46 // This is called from within Unserialize(), it returns true on success.
39 // Subclasses can override this to do additional processing. 47 // Subclasses can override this to do additional processing.
aboxhall 2013/12/02 17:18:08 Could you comment what orphaned_nodes is used for?
dmazzoni 2013/12/03 08:35:04 Done. Sorry, I renamed it to pending_nodes in the
40 virtual bool UpdateNode(const AXNodeData& src); 48 virtual bool UpdateNode(const AXNodeData& src,
49 std::set<AXNode*>* orphaned_nodes);
41 50
42 // Subclasses can override this to do special behavior when the root changes. 51 // Subclasses can override this to do special behavior when the root changes.
43 virtual void OnRootChanged(); 52 virtual void OnRootChanged();
44 53
45 private: 54 private:
46 // Convenience function to create a node and call Initialize on it. 55 // Convenience function to create a node and call Initialize on it.
47 AXNode* CreateAndInitializeNode( 56 AXNode* CreateAndInitializeNode(
48 AXNode* parent, int32 id, int32 index_in_parent); 57 AXNode* parent, int32 id, int32 index_in_parent);
49 58
50 // Call Destroy() on |node|, and delete it from the id map, and then 59 // Call Destroy() on |node|, and delete it from the id map, and then
51 // call recursively on all nodes in its subtree. 60 // call recursively on all nodes in its subtree.
52 void DestroyNodeAndSubtree(AXNode* node); 61 void DestroyNodeAndSubtree(AXNode* node);
53 62
54 // Iterate over the children of |node| and for each child, destroy the 63 // Iterate over the children of |node| and for each child, destroy the
55 // child and its subtree if its id is not in |new_child_ids|. Returns 64 // child and its subtree if its id is not in |new_child_ids|. Returns
56 // true on success, false on fatal error. 65 // true on success, false on fatal error.
57 bool DeleteOldChildren(AXNode* node, 66 bool DeleteOldChildren(AXNode* node,
58 const std::vector<int32> new_child_ids); 67 const std::vector<int32> new_child_ids);
59 68
60 // Iterate over |new_child_ids| and populate |new_children| with 69 // Iterate over |new_child_ids| and populate |new_children| with
61 // pointers to child nodes, reusing existing nodes already in the tree 70 // pointers to child nodes, reusing existing nodes already in the tree
62 // if they exist, and creating otherwise. Reparenting is disallowed, so 71 // if they exist, and creating otherwise. Reparenting is disallowed, so
63 // if the id already exists as the child of another node, that's an 72 // if the id already exists as the child of another node, that's an
64 // error. Returns true on success, false on fatal error. 73 // error. Returns true on success, false on fatal error.
aboxhall 2013/12/02 17:18:08 Could you comment what pending_nodes is used for?
dmazzoni 2013/12/03 08:35:04 Done.
65 bool CreateNewChildVector(AXNode* node, 74 bool CreateNewChildVector(AXNode* node,
66 const std::vector<int32> new_child_ids, 75 const std::vector<int32> new_child_ids,
67 std::vector<AXNode*>* new_children); 76 std::vector<AXNode*>* new_children,
77 std::set<AXNode*>* pending_nodes);
68 78
69 AXNode* root_; 79 AXNode* root_;
70 base::hash_map<int32, AXNode*> id_map_; 80 base::hash_map<int32, AXNode*> id_map_;
81 std::string error_;
71 }; 82 };
72 83
73 } // namespace ui 84 } // namespace ui
74 85
75 #endif // UI_ACCESSIBILITY_AX_TREE_H_ 86 #endif // UI_ACCESSIBILITY_AX_TREE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698