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