| Index: ui/accessibility/ax_position.cc
|
| diff --git a/ui/accessibility/ax_position.cc b/ui/accessibility/ax_position.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..00803a171317fb5e97001e2866f5cbd529a4425c
|
| --- /dev/null
|
| +++ b/ui/accessibility/ax_position.cc
|
| @@ -0,0 +1,54 @@
|
| +// 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.h"
|
| +
|
| +namespace ui {
|
| +
|
| +AXPosition::AXPosition() : anchor_(nullptr), offset(-1) {}
|
| +
|
| +AXPosition::AXPosition(AXNode* anchor, int offset)
|
| + : anchor_(anchor), offset_(offset) {
|
| + DCHECK(anchor);
|
| + DCHECK_GE(offset, 0);
|
| +}
|
| +
|
| +AXPosition::~AXPosition() {
|
| +}
|
| +
|
| +bool AXPosition::IsNull() const {
|
| + return anchor_ == nullptr;
|
| +}
|
| +
|
| +AXPosition AXPosition::ToLeafEquivalent() const {
|
| + if (IsNull())
|
| + return AXPosition();
|
| +
|
| + if (!anchor_->child_count())
|
| + return AXPosition(anchor_, offset_);
|
| +
|
| + if (offset_ >= anchor_->child_count())
|
| + return AXPosition();
|
| +
|
| + AXNode* child = anchor_->children()[offset_];
|
| + DCHECK(child);
|
| + while (child->children()[0])
|
| + child = child->children()[0];
|
| + return AXPosition(child, 0);
|
| +}
|
| +
|
| +AXPosition AXPosition::GetCorrespondingPositionInParent(
|
| + const AXNode& parent) const {
|
| + auto parent_node = const_cast<AXNode*>(&parent);
|
| + AXNode* current_node = anchor_;
|
| + while (current_node && parent_node != current_node->parent())
|
| + current_node = current_node->parent();
|
| +
|
| + if (!current_node)
|
| + return AXPosition();
|
| +
|
| + return AXPosition(parent_node, current_node->index_in_parent());
|
| +}
|
| +
|
| +} // namespace ui
|
|
|