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

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: Rename update0 to unused_update 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
« no previous file with comments | « ui/accessibility/ax_serializable_tree.cc ('k') | ui/accessibility/ax_tree.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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. |pending_nodes|
40 virtual bool UpdateNode(const AXNodeData& src); 48 // is updated to contain all nodes that have been implicitly referenced
49 // as part of this update, but haven't been updated yet. It's an error if
50 // there are any pending nodes at the end of Unserialize.
51 virtual bool UpdateNode(const AXNodeData& src,
52 std::set<AXNode*>* pending_nodes);
41 53
42 // Subclasses can override this to do special behavior when the root changes. 54 // Subclasses can override this to do special behavior when the root changes.
43 virtual void OnRootChanged(); 55 virtual void OnRootChanged();
44 56
45 private: 57 private:
46 // Convenience function to create a node and call Initialize on it. 58 // Convenience function to create a node and call Initialize on it.
47 AXNode* CreateAndInitializeNode( 59 AXNode* CreateAndInitializeNode(
48 AXNode* parent, int32 id, int32 index_in_parent); 60 AXNode* parent, int32 id, int32 index_in_parent);
49 61
50 // Call Destroy() on |node|, and delete it from the id map, and then 62 // Call Destroy() on |node|, and delete it from the id map, and then
51 // call recursively on all nodes in its subtree. 63 // call recursively on all nodes in its subtree.
52 void DestroyNodeAndSubtree(AXNode* node); 64 void DestroyNodeAndSubtree(AXNode* node);
53 65
54 // Iterate over the children of |node| and for each child, destroy the 66 // 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 67 // child and its subtree if its id is not in |new_child_ids|. Returns
56 // true on success, false on fatal error. 68 // true on success, false on fatal error.
57 bool DeleteOldChildren(AXNode* node, 69 bool DeleteOldChildren(AXNode* node,
58 const std::vector<int32> new_child_ids); 70 const std::vector<int32> new_child_ids);
59 71
60 // Iterate over |new_child_ids| and populate |new_children| with 72 // Iterate over |new_child_ids| and populate |new_children| with
61 // pointers to child nodes, reusing existing nodes already in the tree 73 // pointers to child nodes, reusing existing nodes already in the tree
62 // if they exist, and creating otherwise. Reparenting is disallowed, so 74 // 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 75 // if the id already exists as the child of another node, that's an
64 // error. Returns true on success, false on fatal error. 76 // error. Returns true on success, false on fatal error. See
77 // UpdateNode, above, for an explanation of |pending_nodes|.
65 bool CreateNewChildVector(AXNode* node, 78 bool CreateNewChildVector(AXNode* node,
66 const std::vector<int32> new_child_ids, 79 const std::vector<int32> new_child_ids,
67 std::vector<AXNode*>* new_children); 80 std::vector<AXNode*>* new_children,
81 std::set<AXNode*>* pending_nodes);
68 82
69 AXNode* root_; 83 AXNode* root_;
70 base::hash_map<int32, AXNode*> id_map_; 84 base::hash_map<int32, AXNode*> id_map_;
85 std::string error_;
71 }; 86 };
72 87
73 } // namespace ui 88 } // namespace ui
74 89
75 #endif // UI_ACCESSIBILITY_AX_TREE_H_ 90 #endif // UI_ACCESSIBILITY_AX_TREE_H_
OLDNEW
« no previous file with comments | « ui/accessibility/ax_serializable_tree.cc ('k') | ui/accessibility/ax_tree.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698