| Index: ui/accessibility/ax_node_position.cc
|
| diff --git a/ui/accessibility/ax_node_position.cc b/ui/accessibility/ax_node_position.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..368a253da1528e65d4c60b42fef73b9ebd6df77a
|
| --- /dev/null
|
| +++ b/ui/accessibility/ax_node_position.cc
|
| @@ -0,0 +1,90 @@
|
| +// Copyright 2016 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.
|
| +
|
| +#include "ui/accessibility/ax_node_position.h"
|
| +
|
| +#include "base/strings/string16.h"
|
| +#include "ui/accessibility/ax_enums.h"
|
| +
|
| +namespace ui {
|
| +
|
| +AXTree* AXNodePosition::tree_ = nullptr;
|
| +
|
| +AXNodePosition::AXNodePosition() {}
|
| +
|
| +AXNodePosition::~AXNodePosition() {}
|
| +
|
| +int AXNodePosition::AnchorChildCount() const {
|
| + return GetAnchor() ? GetAnchor()->child_count() : -1;
|
| +}
|
| +
|
| +AXNodePosition* AXNodePosition::GetChildPositionAt(int child_index) const {
|
| + if (IsNullPosition())
|
| + return static_cast<AXNodePosition*>(CreateNullPosition());
|
| +
|
| + if (child_index < 0 || child_index >= AnchorChildCount())
|
| + return static_cast<AXNodePosition*>(CreateNullPosition());
|
| +
|
| + AXNode* child_anchor = GetAnchor()->ChildAtIndex(child_index);
|
| + DCHECK(child_anchor);
|
| + switch (get_kind()) {
|
| + case AXPositionKind::NullPosition:
|
| + NOTREACHED();
|
| + return static_cast<AXNodePosition*>(CreateNullPosition());
|
| + case AXPositionKind::TreePosition:
|
| + return static_cast<AXNodePosition*>(CreateTreePosition(
|
| + get_tree_id(), child_anchor->id(), 0 /* child_index */));
|
| + case AXPositionKind::TextPosition:
|
| + return static_cast<AXNodePosition*>(CreateTextPosition(
|
| + get_tree_id(), child_anchor->id(), 0 /* text_offset */));
|
| + }
|
| +
|
| + return static_cast<AXNodePosition*>(CreateNullPosition());
|
| +}
|
| +
|
| +AXNodePosition* AXNodePosition::GetParentPosition() const {
|
| + if (IsNullPosition())
|
| + return static_cast<AXNodePosition*>(CreateNullPosition());
|
| +
|
| + AXNode* parent_anchor = GetAnchor()->parent();
|
| + if (!parent_anchor)
|
| + return static_cast<AXNodePosition*>(CreateNullPosition());
|
| +
|
| + switch (get_kind()) {
|
| + case AXPositionKind::NullPosition:
|
| + NOTREACHED();
|
| + return static_cast<AXNodePosition*>(CreateNullPosition());
|
| + case AXPositionKind::TreePosition:
|
| + return static_cast<AXNodePosition*>(CreateTreePosition(
|
| + get_tree_id(), parent_anchor->id(), 0 /* child_index */));
|
| + case AXPositionKind::TextPosition:
|
| + return static_cast<AXNodePosition*>(CreateTextPosition(
|
| + get_tree_id(), parent_anchor->id(), 0 /* text_offset */));
|
| + }
|
| +
|
| + return static_cast<AXNodePosition*>(CreateNullPosition());
|
| +}
|
| +
|
| +int AXNodePosition::AnchorIndexInParent() const {
|
| + return GetAnchor() ? GetAnchor()->index_in_parent() : -1;
|
| +}
|
| +
|
| +AXNode* AXNodePosition::GetNodeInTree(int tree_id, int32_t node_id) const {
|
| + if (IsNullPosition() || !tree_)
|
| + return nullptr;
|
| + return AXNodePosition::tree_->GetFromId(node_id);
|
| +}
|
| +
|
| +int AXNodePosition::MaxTextOffset() const {
|
| + if (IsTextPosition()) {
|
| + DCHECK(GetAnchor());
|
| + base::string16 name =
|
| + GetAnchor()->data().GetString16Attribute(AX_ATTR_NAME);
|
| + return static_cast<int>(name.length());
|
| + }
|
| +
|
| + return 0;
|
| +}
|
| +
|
| +} // namespace ui
|
|
|