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 int32_t AXPlatformPosition::AnchorChildID(int child_index) const { | |
dmazzoni
2016/10/18 23:59:11
I just realized that this won't work across iframe
| |
16 if (child_index < 0 || child_index >= AnchorChildCount()) | |
17 return AXPosition::INVALID_ANCHOR_ID; | |
18 | |
19 BrowserAccessibility* child = GetAnchor()->PlatformGetChild(child_index); | |
20 DCHECK(child); | |
21 int32_t child_id = child->GetId(); | |
22 DCHECK_NE(child_id, AXPosition::INVALID_ANCHOR_ID); | |
23 return child_id; | |
24 } | |
25 | |
26 int AXPlatformPosition::AnchorChildCount() const { | |
27 return GetAnchor() ? static_cast<int>(GetAnchor()->PlatformChildCount()) : 0; | |
28 } | |
29 | |
30 int AXPlatformPosition::AnchorIndexInParent() const { | |
31 return GetAnchor() ? static_cast<int>(GetAnchor()->GetIndexInParent()) | |
32 : AXPosition::INVALID_INDEX; | |
33 } | |
34 | |
35 int32_t AXPlatformPosition::AnchorParentID() const { | |
36 if (!GetAnchor() || !GetAnchor()->GetParent()) | |
37 return AXPosition::INVALID_ANCHOR_ID; | |
38 return GetAnchor()->GetParent()->GetId(); | |
39 } | |
40 | |
41 BrowserAccessibility* AXPlatformPosition::GetNodeInTree(AXTreeID tree_id, | |
42 int32_t node_id) const { | |
43 if (tree_id == AXPosition::INVALID_TREE_ID || | |
44 node_id == AXPosition::INVALID_ANCHOR_ID) { | |
45 return nullptr; | |
46 } | |
47 | |
48 auto manager = BrowserAccessibilityManager::FromID(tree_id); | |
49 if (!manager) | |
50 return nullptr; | |
51 return manager->GetFromID(node_id); | |
52 } | |
53 | |
54 int AXPlatformPosition::MaxTextOffset() const { | |
55 if (IsNullPosition()) | |
56 return AXPosition::INVALID_OFFSET; | |
57 | |
58 BrowserAccessibility* anchor = GetNodeInTree(tree_id(), anchor_id()); | |
59 if (!anchor) | |
60 return AXPosition::INVALID_OFFSET; | |
61 return static_cast<int>(anchor->GetText().length()); | |
62 } | |
63 | |
64 } // namespace content | |
OLD | NEW |