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 "content/browser/accessibility/ax_platform_position.h" |
| 6 |
| 7 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 8 |
| 9 namespace content { |
| 10 |
| 11 AXPlatformPosition::AXPlatformPosition() {} |
| 12 |
| 13 AXPlatformPosition::~AXPlatformPosition() {} |
| 14 |
| 15 void AXPlatformPosition::AnchorChild(int child_index, |
| 16 AXTreeID* tree_id, |
| 17 int32_t* child_id) const { |
| 18 DCHECK(tree_id); |
| 19 DCHECK(child_id); |
| 20 |
| 21 if (!GetAnchor() || child_index < 0 || child_index >= AnchorChildCount()) { |
| 22 *tree_id = AXPosition::INVALID_TREE_ID; |
| 23 *child_id = AXPosition::INVALID_ANCHOR_ID; |
| 24 return; |
| 25 } |
| 26 |
| 27 BrowserAccessibility* child = nullptr; |
| 28 if (GetAnchor()->PlatformIsLeaf()) { |
| 29 child = GetAnchor()->InternalGetChild(child_index); |
| 30 } else { |
| 31 child = GetAnchor()->PlatformGetChild(child_index); |
| 32 } |
| 33 DCHECK(child); |
| 34 *tree_id = child->manager()->ax_tree_id(); |
| 35 *child_id = child->GetId(); |
| 36 } |
| 37 |
| 38 int AXPlatformPosition::AnchorChildCount() const { |
| 39 if (!GetAnchor()) |
| 40 return 0; |
| 41 |
| 42 if (GetAnchor()->PlatformIsLeaf()) { |
| 43 return static_cast<int>(GetAnchor()->InternalChildCount()); |
| 44 } else { |
| 45 return static_cast<int>(GetAnchor()->PlatformChildCount()); |
| 46 } |
| 47 } |
| 48 |
| 49 int AXPlatformPosition::AnchorIndexInParent() const { |
| 50 return GetAnchor() ? static_cast<int>(GetAnchor()->GetIndexInParent()) |
| 51 : AXPosition::INVALID_INDEX; |
| 52 } |
| 53 |
| 54 void AXPlatformPosition::AnchorParent(AXTreeID* tree_id, |
| 55 int32_t* parent_id) const { |
| 56 DCHECK(tree_id); |
| 57 DCHECK(parent_id); |
| 58 |
| 59 if (!GetAnchor() || !GetAnchor()->GetParent()) { |
| 60 *tree_id = AXPosition::INVALID_TREE_ID; |
| 61 *parent_id = AXPosition::INVALID_ANCHOR_ID; |
| 62 return; |
| 63 } |
| 64 |
| 65 BrowserAccessibility* parent = GetAnchor()->GetParent(); |
| 66 *tree_id = parent->manager()->ax_tree_id(); |
| 67 *parent_id = parent->GetId(); |
| 68 } |
| 69 |
| 70 BrowserAccessibility* AXPlatformPosition::GetNodeInTree(AXTreeID tree_id, |
| 71 int32_t node_id) const { |
| 72 if (tree_id == AXPosition::INVALID_TREE_ID || |
| 73 node_id == AXPosition::INVALID_ANCHOR_ID) { |
| 74 return nullptr; |
| 75 } |
| 76 |
| 77 auto manager = BrowserAccessibilityManager::FromID(tree_id); |
| 78 if (!manager) |
| 79 return nullptr; |
| 80 return manager->GetFromID(node_id); |
| 81 } |
| 82 |
| 83 int AXPlatformPosition::MaxTextOffset() const { |
| 84 if (IsNullPosition()) |
| 85 return AXPosition::INVALID_OFFSET; |
| 86 |
| 87 BrowserAccessibility* anchor = GetNodeInTree(tree_id(), anchor_id()); |
| 88 if (!anchor) |
| 89 return AXPosition::INVALID_OFFSET; |
| 90 return static_cast<int>(anchor->GetText().length()); |
| 91 } |
| 92 |
| 93 } // namespace content |
OLD | NEW |