Revert of Roll src/third_party/WebKit e0eac24:489c548 (svn 193311:193320) (patchset...
[chromium-blink-merge.git] / ui / accessibility / ax_node.h
blob6fd766c52ba3caea32220d564de40156cd843d5d
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
3 // found in the LICENSE file.
5 #ifndef UI_ACCESSIBILITY_AX_NODE_H_
6 #define UI_ACCESSIBILITY_AX_NODE_H_
8 #include <vector>
10 #include "ui/accessibility/ax_node_data.h"
12 namespace gfx {
13 class Rect;
16 namespace ui {
18 // One node in an AXTree.
19 class AX_EXPORT AXNode {
20 public:
21 // The constructor requires a parent, id, and index in parent, but
22 // the data is not required. After initialization, only index_in_parent
23 // is allowed to change, the others are guaranteed to never change.
24 AXNode(AXNode* parent, int32 id, int32 index_in_parent);
25 virtual ~AXNode();
27 // Accessors.
28 int32 id() const { return data_.id; }
29 AXNode* parent() const { return parent_; }
30 int child_count() const { return static_cast<int>(children_.size()); }
31 const AXNodeData& data() const { return data_; }
32 const std::vector<AXNode*>& children() const { return children_; }
33 int index_in_parent() const { return index_in_parent_; }
35 // Get the child at the given index.
36 AXNode* ChildAtIndex(int index) const { return children_[index]; }
38 // Set the node's accessibility data. This may be done during initial
39 // initialization or later when the node data changes.
40 void SetData(const AXNodeData& src);
42 // Update this node's location. This is separate from SetData just because
43 // changing only the location is common and should be more efficient than
44 // re-copying all of the data.
45 void SetLocation(const gfx::Rect& new_location);
47 // Set the index in parent, for example if siblings were inserted or deleted.
48 void SetIndexInParent(int index_in_parent);
50 // Swap the internal children vector with |children|. This instance
51 // now owns all of the passed children.
52 void SwapChildren(std::vector<AXNode*>& children);
54 // This is called when the AXTree no longer includes this node in the
55 // tree. Reference counting is used on some platforms because the
56 // operating system may hold onto a reference to an AXNode
57 // object even after we're through with it, so this may decrement the
58 // reference count and clear out the object's data.
59 void Destroy();
61 // Return true if this object is equal to or a descendant of |ancestor|.
62 bool IsDescendantOf(AXNode* ancestor);
64 private:
65 int index_in_parent_;
66 AXNode* parent_;
67 std::vector<AXNode*> children_;
68 AXNodeData data_;
71 } // namespace ui
73 #endif // UI_ACCESSIBILITY_AX_NODE_H_