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