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