Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: content/browser/accessibility/ax_platform_position.cc

Issue 2271893002: Creates AXPosition to uniquely identify a position in the accessibility tree (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added a number of unit tests. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 int AXPlatformPosition::AnchorChildCount() const {
16 return GetAnchor() ? static_cast<int>(GetAnchor()->PlatformChildCount()) : -1;
17 }
18
19 AXPlatformPosition* AXPlatformPosition::GetChildPositionAt(
20 int child_index) const {
21 if (IsNullPosition())
22 return static_cast<AXPlatformPosition*>(CreateNullPosition());
23
24 if (child_index < 0 || child_index >= AnchorChildCount())
25 return static_cast<AXPlatformPosition*>(CreateNullPosition());
26
27 BrowserAccessibility* child_anchor =
28 GetAnchor()->PlatformGetChild(child_index);
29 DCHECK(child_anchor);
30 switch (get_kind()) {
31 case ui::AXPositionKind::NullPosition:
32 NOTREACHED();
33 return static_cast<AXPlatformPosition*>(CreateNullPosition());
34 case ui::AXPositionKind::TreePosition:
35 return static_cast<AXPlatformPosition*>(CreateTreePosition(
36 get_tree_id(), child_anchor->GetId(), 0 /* child_index */));
37 case ui::AXPositionKind::TextPosition:
38 return static_cast<AXPlatformPosition*>(CreateTextPosition(
39 get_tree_id(), child_anchor->GetId(), 0 /* text_offset */));
40 }
41 return static_cast<AXPlatformPosition*>(CreateNullPosition());
42 }
43
44 AXPlatformPosition* AXPlatformPosition::GetParentPosition() const {
45 if (IsNullPosition())
46 return static_cast<AXPlatformPosition*>(CreateNullPosition());
47
48 BrowserAccessibility* parent_anchor = GetAnchor()->GetParent();
49 if (!parent_anchor)
50 return static_cast<AXPlatformPosition*>(CreateNullPosition());
51
52 switch (get_kind()) {
53 case ui::AXPositionKind::NullPosition:
54 NOTREACHED();
55 return static_cast<AXPlatformPosition*>(CreateNullPosition());
56 case ui::AXPositionKind::TreePosition:
57 return static_cast<AXPlatformPosition*>(CreateTreePosition(
58 get_tree_id(), parent_anchor->GetId(), 0 /* child_index */));
59 case ui::AXPositionKind::TextPosition:
60 return static_cast<AXPlatformPosition*>(CreateTextPosition(
61 get_tree_id(), parent_anchor->GetId(), 0 /* text_offset */));
62 }
63 return static_cast<AXPlatformPosition*>(CreateNullPosition());
64 }
65
66 int AXPlatformPosition::AnchorIndexInParent() const {
67 return GetAnchor() ? static_cast<int>(GetAnchor()->GetIndexInParent()) : -1;
68 }
69
70 BrowserAccessibility* AXPlatformPosition::GetNodeInTree(AXTreeID tree_id,
71 int32_t node_id) const {
72 if (IsNullPosition())
73 return nullptr;
74
75 auto manager = BrowserAccessibilityManager::FromID(tree_id);
76 if (!manager)
77 return nullptr;
78 return manager->GetFromID(node_id);
79 }
80
81 int AXPlatformPosition::MaxTextOffset() const {
82 if (IsNullPosition())
83 return -1;
84
85 BrowserAccessibility* anchor = GetNodeInTree(get_tree_id(), get_anchor_id());
86 if (!anchor)
87 return -1;
88 return static_cast<int>(anchor->GetText().length());
89 }
90
91 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698