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 CONTENT_COMMON_AX_TREE_IMPL_H_ |
| 6 #define CONTENT_COMMON_AX_TREE_IMPL_H_ |
| 7 |
| 8 #include "base/containers/hash_tables.h" |
| 9 |
| 10 #include "content/common/ax_tree_source.h" |
| 11 #include "content/common/content_export.h" |
| 12 #include "content/public/common/ax_tree.h" |
| 13 #include "content/public/common/ax_tree_update.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 class AXNodeImpl; |
| 18 |
| 19 // AXTreeImpl 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 implement support for native |
| 23 // accessibility APIs on a specific platform. |
| 24 class CONTENT_EXPORT AXTreeImpl: public AXTree { |
| 25 public: |
| 26 AXTreeImpl(); |
| 27 explicit AXTreeImpl(const AXTreeUpdate& initial_state); |
| 28 virtual ~AXTreeImpl(); |
| 29 |
| 30 // AXTree implementation. |
| 31 virtual AXNode* GetRoot() const OVERRIDE; |
| 32 virtual AXNode* GetFromId(int32 id) const OVERRIDE; |
| 33 virtual bool Unserialize(const AXTreeUpdate& update) OVERRIDE; |
| 34 |
| 35 // Get a TreeSource interface for this tree. The client gets ownership |
| 36 // of the return value and should delete it when done. |
| 37 virtual AXTreeSource<AXNode>* CreateTreeSource(); |
| 38 |
| 39 protected: |
| 40 // Subclasses can override this to use a subclass of AXNodeImpl. |
| 41 virtual AXNodeImpl* CreateNode(); |
| 42 |
| 43 // This is called from within Unserialize(), it returns true on success. |
| 44 // Subclasses can override this to do additional processing. |
| 45 virtual bool UpdateNode(const AXNodeData& src); |
| 46 |
| 47 // Subclasses can override this to do special behavior when the root changes. |
| 48 virtual void OnRootChanged(); |
| 49 |
| 50 private: |
| 51 // Convenience function to create a node and call Initialize on it. |
| 52 AXNodeImpl* CreateAndInitializeNode( |
| 53 AXNodeImpl* parent, int32 id, int32 index_in_parent); |
| 54 |
| 55 // Call Destroy() on |node|, and delete it from the id map, and then |
| 56 // call recursively on all nodes in its subtree. |
| 57 void DestroyNodeAndSubtree(AXNodeImpl* node); |
| 58 |
| 59 // Iterate over the children of |node| and for each child, destroy the |
| 60 // child and its subtree if its id is not in |new_child_ids|. Returns |
| 61 // true on success, false on fatal error. |
| 62 bool DeleteOldChildren(AXNodeImpl* node, |
| 63 const std::vector<int32> new_child_ids); |
| 64 |
| 65 // Iterate over |new_child_ids| and populate |new_children| with |
| 66 // pointers to child nodes, reusing existing nodes already in the tree |
| 67 // if they exist, and creating otherwise. Reparenting is disallowed, so |
| 68 // if the id already exists as the child of another node, that's an |
| 69 // error. Returns true on success, false on fatal error. |
| 70 bool CreateNewChildVector(AXNodeImpl* node, |
| 71 const std::vector<int32> new_child_ids, |
| 72 std::vector<AXNodeImpl*>* new_children); |
| 73 |
| 74 AXNodeImpl* root_; |
| 75 base::hash_map<int32, AXNodeImpl*> id_map_; |
| 76 }; |
| 77 |
| 78 } // namespace content |
| 79 |
| 80 #endif // CONTENT_COMMON_AX_TREE_IMPL_H_ |
OLD | NEW |