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 namespace content { |
| 8 |
| 9 AXPlatformPosition::AXPlatformPosition( |
| 10 AXTreeIDRegistry::AXTreeID tree_id, |
| 11 int32_t anchor_id, |
| 12 int child_index, |
| 13 int text_offset, |
| 14 ui::AXPositionType type, |
| 15 std::unique_ptr<ui::AXPositionFactory> factory) |
| 16 : ui::AXPosition(tree_id, |
| 17 anchor_id, |
| 18 child_index, |
| 19 text_offset, |
| 20 type, |
| 21 factory) {} |
| 22 |
| 23 AXPlatformPosition::~AXPlatformPosition() {} |
| 24 |
| 25 ui::AXPosition AXPlatformPositionFactory::CreateNullPosition() { |
| 26 return AXPlatformPosition(-1 /* tree_id */, -1 /* anchor_id */, |
| 27 -1 /* child_index */, -1 /* text_offset */, |
| 28 ui::AXPositionType::NullPosition); |
| 29 } |
| 30 |
| 31 ui::AXPosition AXPlatformPositionFactory::CreateTreePosition(int tree_id, |
| 32 int32_t anchor_id, |
| 33 int child_index) { |
| 34 return AXPlatformPosition(tree_id, anchor_id, child_index, |
| 35 -1 /* text_offset */, |
| 36 ui::AXPositionType::TreePosition); |
| 37 } |
| 38 |
| 39 ui::AXPosition AXPlatformPositionFactory::CreateTextPosition(int tree_id, |
| 40 int32_t anchor_id, |
| 41 int text_offset) { |
| 42 return AXPlatformPosition(tree_id, anchor_id, -1 /* child_index */, |
| 43 text_offset, ui::AXPositionType::TextPosition); |
| 44 } |
| 45 |
| 46 BrowserAccessibility* AXPlatformPosition::GetPlatformNodeInTree( |
| 47 AXTreeIDRegistry::AXTreeID tree_id, |
| 48 int32_t node_id) const { |
| 49 if (IsNullPosition()) |
| 50 return nullptr; |
| 51 |
| 52 auto manager = BrowserAccessibilityManager::FromID(tree_id); |
| 53 if (!manager) |
| 54 return nullptr; |
| 55 return manager->GetFromID(node_id); |
| 56 } |
| 57 |
| 58 ui::AXNode* AXPlatformPosition::GetNodeInTree( |
| 59 AXTreeIDRegistry::AXTreeID tree_id, |
| 60 int32_t node_id) const { |
| 61 BrowserAccessibility* anchor = GetPlatformNodeInTree(tree_id, node_id); |
| 62 return anchor ? anchor->node() : nullptr; |
| 63 } |
| 64 |
| 65 int AXPlatformPosition::MaxTextOffset() const { |
| 66 if (IsNullPosition()) |
| 67 return -1; |
| 68 |
| 69 BrowserAccessibility* anchor = |
| 70 GetPlatformNodeInTree(get_tree_id(), get_anchor_id()); |
| 71 if (!anchor) |
| 72 return -1; |
| 73 return static_cast<int>(anchor->GetText().length()); |
| 74 } |
| 75 |
| 76 } // namespace content |
OLD | NEW |