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

Unified Diff: content/common/ax_tree_impl.h

Issue 67283004: First step to move common accessibility code out of content. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactored AXTreeImpl::UpdateNode Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: content/common/ax_tree_impl.h
diff --git a/content/common/ax_tree_impl.h b/content/common/ax_tree_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..a05bd7dac1a6d847bdacdfe6fe6da336550c0c8d
--- /dev/null
+++ b/content/common/ax_tree_impl.h
@@ -0,0 +1,80 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_COMMON_AX_TREE_IMPL_H_
+#define CONTENT_COMMON_AX_TREE_IMPL_H_
+
+#include "base/containers/hash_tables.h"
+
+#include "content/common/ax_tree_source.h"
+#include "content/common/content_export.h"
+#include "content/public/common/ax_tree.h"
+#include "content/public/common/ax_tree_update.h"
+
+namespace content {
+
+class AXNodeImpl;
+
+// AXTreeImpl is a live, managed tree of AXNode objects that can receive
+// updates from another AXTreeSource via AXTreeUpdates, and it can be
+// used as a source for sending updates to another client tree.
+// It's designed to be subclassed to implement support for native
+// accessibility APIs on a specific platform.
+class CONTENT_EXPORT AXTreeImpl: public AXTree {
+ public:
+ AXTreeImpl();
+ explicit AXTreeImpl(const AXTreeUpdate& initial_state);
+ virtual ~AXTreeImpl();
+
+ // AXTree implementation.
+ virtual AXNode* GetRoot() const OVERRIDE;
+ virtual AXNode* GetFromId(int32 id) const OVERRIDE;
+ virtual bool Unserialize(const AXTreeUpdate& update) OVERRIDE;
+
+ // Get a TreeSource interface for this tree. The client gets ownership
+ // of the return value and should delete it when done.
+ virtual AXTreeSource<AXNode>* CreateTreeSource();
+
+ protected:
+ // Subclasses can override this to use a subclass of AXNodeImpl.
+ virtual AXNodeImpl* CreateNode();
+
+ // This is called from within Unserialize(), it returns true on success.
+ // Subclasses can override this to do additional processing.
+ virtual bool UpdateNode(const AXNodeData& src);
+
+ // Subclasses can override this to do special behavior when the root changes.
+ virtual void OnRootChanged();
+
+ private:
+ // Convenience function to create a node and call Initialize on it.
+ AXNodeImpl* CreateAndInitializeNode(
+ AXNodeImpl* parent, int32 id, int32 index_in_parent);
+
+ // Call Destroy() on |node|, and delete it from the id map, and then
+ // call recursively on all nodes in its subtree.
+ void DestroyNodeAndSubtree(AXNodeImpl* node);
+
+ // Iterate over the children of |node| and for each child, destroy the
+ // child and its subtree if its id is not in |new_child_ids|. Returns
+ // true on success, false on fatal error.
+ bool DeleteOldChildren(AXNodeImpl* node,
+ const std::vector<int32> new_child_ids);
+
+ // Iterate over |new_child_ids| and populate |new_children| with
+ // pointers to child nodes, reusing existing nodes already in the tree
+ // if they exist, and creating otherwise. Reparenting is disallowed, so
+ // if the id already exists as the child of another node, that's an
+ // error. Returns true on success, false on fatal error.
+ bool CreateNewChildVector(AXNodeImpl* node,
+ const std::vector<int32> new_child_ids,
+ std::vector<AXNodeImpl*>* new_children);
+
+ AXNodeImpl* root_;
+ base::hash_map<int32, AXNodeImpl*> id_map_;
+};
+
+} // namespace content
+
+#endif // CONTENT_COMMON_AX_TREE_IMPL_H_

Powered by Google App Engine
This is Rietveld 408576698