OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 #include "ui/accessibility/ax_node.h" |
| 6 |
| 7 namespace ui { |
| 8 |
| 9 AXPosition::AXPosition() : anchor_(nullptr), offset(-1) {} |
| 10 |
| 11 AXPosition::AXPosition(AXNode* anchor, int offset) |
| 12 : anchor_(anchor), offset_(offset) { |
| 13 DCHECK(anchor); |
| 14 DCHECK_GE(offset, 0); |
| 15 } |
| 16 |
| 17 AXPosition::~AXPosition() { |
| 18 } |
| 19 |
| 20 bool AXPosition::IsNull() const { |
| 21 return anchor_ == nullptr; |
| 22 } |
| 23 |
| 24 AXPosition AXPosition::ToLeafEquivalent() const { |
| 25 if (IsNull()) |
| 26 return AXPosition(); |
| 27 |
| 28 if (!anchor_->child_count()) |
| 29 return AXPosition(anchor_, offset_); |
| 30 |
| 31 if (offset_ >= anchor_->child_count()) |
| 32 return AXPosition(); |
| 33 |
| 34 AXNode* child = anchor_->children()[offset_]; |
| 35 DCHECK(child); |
| 36 while (child->children()[0]) |
| 37 child = child->children()[0]; |
| 38 return AXPosition(child, 0); |
| 39 } |
| 40 |
| 41 AXPosition AXPosition::GetCorrespondingPositionInParent( |
| 42 const AXNode& parent) const { |
| 43 auto parent_node = const_cast<AXNode*>(&parent); |
| 44 AXNode* current_node = anchor_; |
| 45 while (current_node && parent_node != current_node->parent()) |
| 46 current_node = current_node->parent(); |
| 47 |
| 48 if (!current_node) |
| 49 return AXPosition(); |
| 50 |
| 51 return AXPosition(parent_node, current_node->index_in_parent()); |
| 52 } |
| 53 |
| 54 } // namespace ui |
OLD | NEW |