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

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 overrides for parent and childAtIndex for BrowserAccessibility. 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(AXTreeID tree_id,
12 int32_t anchor_id,
13 int child_index,
14 int text_offset,
15 ui::AXPositionType type)
16 : AXPosition(tree_id, anchor_id, child_index, text_offset, type) {}
17
18 AXPlatformPosition::~AXPlatformPosition() {}
19
20 AXPosition* AXPlatformPosition::GetChildPositionAt(int child_index) const {
21 if (IsNullPosition())
22 return CreateNullPosition();
23
24 if (child_index < 0 || child_index >= AnchorChildCount())
25 return CreateNullPosition();
26
27 AXNodeType* child_anchor = GetAnchor()->PlatformGetChild(child_index);
28 DCHECK(child_anchor);
29 switch (type_) {
30 case AXPositionType::NullPosition:
31 NOTREACHED();
32 return CreateNullPosition();
33 case AXPositionType::TreePosition:
34 return CreateTreePosition(tree_id_, child_anchor->id(),
35 0 /* child_index */);
36 case AXPositionType::TextPosition:
37 return CreateTextPosition(tree_id_, child_anchor->id(),
38 0 /* text_offset */);
39 }
40 }
41
42 AXPosition* AXPlatformPosition::GetParentPosition() const {
43 if (IsNullPosition())
44 return CreateNullPosition();
45
46 AXNodeType* parent_anchor = GetAnchor()->PlatformGetParent();
47 if (!parent_anchor)
48 return CreateNullPosition();
49
50 switch (type_) {
51 case AXPositionType::NullPosition:
52 NOTREACHED();
53 return CreateNullPosition();
54 case AXPositionType::TreePosition:
55 return CreateTreePosition(tree_id_, parent_anchor->id(),
56 0 /* child_index */);
57 case AXPositionType::TextPosition:
58 return CreateTextPosition(tree_id_, parent_anchor->id(),
59 0 /* text_offset */);
60 }
61 }
62
63 BrowserAccessibility* AXPlatformPosition::GetNodeInTree(AXTreeID tree_id,
64 int32_t node_id) const {
65 if (IsNullPosition())
66 return nullptr;
67
68 auto manager = BrowserAccessibilityManager::FromID(tree_id);
69 if (!manager)
70 return nullptr;
71 return manager->GetFromID(node_id);
72 }
73
74 int AXPlatformPosition::MaxTextOffset() const {
75 if (IsNullPosition())
76 return -1;
77
78 BrowserAccessibility* anchor = GetNodeInTree(get_tree_id(), get_anchor_id());
79 if (!anchor)
80 return -1;
81 return static_cast<int>(anchor->GetText().length());
82 }
83
84 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698