Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef UI_ACCESSIBILITY_AX_TREE_H_ | |
| 6 #define UI_ACCESSIBILITY_AX_TREE_H_ | |
| 7 | |
| 8 #include "base/containers/hash_tables.h" | |
| 9 | |
| 10 #include "ui/accessibility/ax_tree.h" | |
| 11 #include "ui/accessibility/ax_tree_source.h" | |
| 12 #include "ui/accessibility/ax_tree_update.h" | |
| 13 #include "ui/base/ui_export.h" | |
| 14 | |
| 15 namespace ui { | |
| 16 | |
| 17 class AXNode; | |
| 18 | |
| 19 // AXTree is a live, managed tree of AXNode objects that can receive | |
| 20 // updates from another AXTreeSource via AXTreeUpdates, and it can be | |
| 21 // used as a source for sending updates to another client tree. | |
| 22 // It's designed to be subclassed to ement support for native | |
|
David Tseng
2013/11/15 18:05:31
Optional: I still think this design isn't a good a
David Tseng
2013/11/15 18:05:31
s/ement/implement
dmazzoni
2013/11/18 08:09:25
Done.
dmazzoni
2013/11/18 08:09:25
OK, I moved that part into a subclass, AXSerializa
| |
| 23 // accessibility APIs on a specific platform. | |
| 24 class UI_EXPORT AXTree { | |
| 25 public: | |
| 26 AXTree(); | |
| 27 explicit AXTree(const AXTreeUpdate& initial_state); | |
| 28 virtual ~AXTree(); | |
| 29 | |
| 30 virtual AXNode* GetRoot() const; | |
| 31 virtual AXNode* GetFromId(int32 id) const; | |
| 32 virtual bool Unserialize(const AXTreeUpdate& update); | |
| 33 | |
| 34 // Get a TreeSource interface for this tree. The client gets ownership | |
| 35 // of the return value and should delete it when done. | |
| 36 virtual AXTreeSource<AXNode>* CreateTreeSource(); | |
|
David Tseng
2013/11/15 18:05:31
I think this method belongs on the AXTreeSource in
dmazzoni
2013/11/18 08:09:25
This is now in AXSerializableTree.
| |
| 37 | |
| 38 protected: | |
| 39 // Subclasses can override this to use a subclass of AXNode. | |
| 40 virtual AXNode* CreateNode(); | |
| 41 | |
| 42 // This is called from within Unserialize(), it returns true on success. | |
| 43 // Subclasses can override this to do additional processing. | |
| 44 virtual bool UpdateNode(const AXNodeData& src); | |
| 45 | |
| 46 // Subclasses can override this to do special behavior when the root changes. | |
| 47 virtual void OnRootChanged(); | |
| 48 | |
| 49 private: | |
| 50 // Convenience function to create a node and call Initialize on it. | |
| 51 AXNode* CreateAndInitializeNode( | |
| 52 AXNode* parent, int32 id, int32 index_in_parent); | |
| 53 | |
| 54 // Call Destroy() on |node|, and delete it from the id map, and then | |
| 55 // call recursively on all nodes in its subtree. | |
| 56 void DestroyNodeAndSubtree(AXNode* node); | |
| 57 | |
| 58 // Iterate over the children of |node| and for each child, destroy the | |
| 59 // child and its subtree if its id is not in |new_child_ids|. Returns | |
| 60 // true on success, false on fatal error. | |
| 61 bool DeleteOldChildren(AXNode* node, | |
| 62 const std::vector<int32> new_child_ids); | |
| 63 | |
| 64 // Iterate over |new_child_ids| and populate |new_children| with | |
| 65 // pointers to child nodes, reusing existing nodes already in the tree | |
| 66 // if they exist, and creating otherwise. Reparenting is disallowed, so | |
| 67 // if the id already exists as the child of another node, that's an | |
| 68 // error. Returns true on success, false on fatal error. | |
| 69 bool CreateNewChildVector(AXNode* node, | |
| 70 const std::vector<int32> new_child_ids, | |
| 71 std::vector<AXNode*>* new_children); | |
| 72 | |
| 73 AXNode* root_; | |
| 74 base::hash_map<int32, AXNode*> id_map_; | |
| 75 }; | |
| 76 | |
| 77 } // namespace ui | |
| 78 | |
| 79 #endif // UI_ACCESSIBILITY_AX_TREE_H_ | |
| OLD | NEW |