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_position.h" |
| 6 |
| 7 #include "base/strings/string16.h" |
| 8 #include "ui/accessibility/ax_enums.h" |
| 9 |
| 10 namespace ui { |
| 11 |
| 12 AXNodePosition::AXNodePosition() {} |
| 13 |
| 14 AXNodePosition::~AXNodePosition() {} |
| 15 |
| 16 int AXNodePosition::AnchorChildCount() const { |
| 17 return GetAnchor() ? GetAnchor()->child_count() : -1; |
| 18 } |
| 19 |
| 20 AXNodePosition* AXNodePosition::GetChildPositionAt(int child_index) const { |
| 21 if (IsNullPosition()) |
| 22 return static_cast<AXNodePosition*>(CreateNullPosition()); |
| 23 |
| 24 if (child_index < 0 || child_index >= AnchorChildCount()) |
| 25 return static_cast<AXNodePosition*>(CreateNullPosition()); |
| 26 |
| 27 AXNode* child_anchor = GetAnchor()->ChildAtIndex(child_index); |
| 28 DCHECK(child_anchor); |
| 29 switch (get_kind()) { |
| 30 case AXPositionKind::NullPosition: |
| 31 NOTREACHED(); |
| 32 return static_cast<AXNodePosition*>(CreateNullPosition()); |
| 33 case AXPositionKind::TreePosition: |
| 34 return static_cast<AXNodePosition*>(CreateTreePosition( |
| 35 get_tree_id(), child_anchor->id(), 0 /* child_index */)); |
| 36 case AXPositionKind::TextPosition: |
| 37 return static_cast<AXNodePosition*>(CreateTextPosition( |
| 38 get_tree_id(), child_anchor->id(), 0 /* text_offset */)); |
| 39 } |
| 40 |
| 41 return static_cast<AXNodePosition*>(CreateNullPosition()); |
| 42 } |
| 43 |
| 44 AXNodePosition* AXNodePosition::GetParentPosition() const { |
| 45 if (IsNullPosition()) |
| 46 return static_cast<AXNodePosition*>(CreateNullPosition()); |
| 47 |
| 48 AXNode* parent_anchor = GetAnchor()->parent(); |
| 49 if (!parent_anchor) |
| 50 return static_cast<AXNodePosition*>(CreateNullPosition()); |
| 51 |
| 52 switch (get_kind()) { |
| 53 case AXPositionKind::NullPosition: |
| 54 NOTREACHED(); |
| 55 return static_cast<AXNodePosition*>(CreateNullPosition()); |
| 56 case AXPositionKind::TreePosition: |
| 57 return static_cast<AXNodePosition*>(CreateTreePosition( |
| 58 get_tree_id(), parent_anchor->id(), 0 /* child_index */)); |
| 59 case AXPositionKind::TextPosition: |
| 60 return static_cast<AXNodePosition*>(CreateTextPosition( |
| 61 get_tree_id(), parent_anchor->id(), 0 /* text_offset */)); |
| 62 } |
| 63 |
| 64 return static_cast<AXNodePosition*>(CreateNullPosition()); |
| 65 } |
| 66 |
| 67 int AXNodePosition::AnchorIndexInParent() const { |
| 68 return GetAnchor() ? GetAnchor()->index_in_parent() : -1; |
| 69 } |
| 70 |
| 71 AXNode* AXNodePosition::GetNodeInTree(int tree_id, int32_t node_id) const { |
| 72 if (IsNullPosition()) |
| 73 return nullptr; |
| 74 DCHECK(tree_); |
| 75 return tree_->GetFromId(node_id); |
| 76 } |
| 77 |
| 78 int AXNodePosition::MaxTextOffset() const { |
| 79 if (IsTextPosition()) { |
| 80 DCHECK(GetAnchor()); |
| 81 base::string16 name = |
| 82 GetAnchor()->data().GetString16Attribute(AX_ATTR_NAME); |
| 83 return static_cast<int>(name.length()); |
| 84 } |
| 85 |
| 86 return 0; |
| 87 } |
| 88 |
| 89 } // namespace ui |
OLD | NEW |