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

Side by Side Diff: ui/accessibility/ax_node_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: Fixed some compilation errors on the Mac. Created 4 years, 1 month 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
« no previous file with comments | « ui/accessibility/ax_node_position.h ('k') | ui/accessibility/ax_node_position_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ui/accessibility/ax_node_position.h"
6
7 #include "base/strings/string16.h"
8 #include "ui/accessibility/ax_enums.h"
9
10 namespace ui {
11
12 AXTree* AXNodePosition::tree_ = nullptr;
13
14 AXNodePosition::AXNodePosition() {}
15
16 AXNodePosition::~AXNodePosition() {}
17
18 void AXNodePosition::AnchorChild(int child_index,
19 int* tree_id,
20 int32_t* child_id) const {
21 DCHECK(tree_id);
22 DCHECK(child_id);
23
24 if (!GetAnchor() || child_index < 0 || child_index >= AnchorChildCount()) {
25 *tree_id = AXPosition::INVALID_TREE_ID;
26 *child_id = AXPosition::INVALID_ANCHOR_ID;
27 return;
28 }
29
30 AXNode* child = GetAnchor()->ChildAtIndex(child_index);
31 DCHECK(child);
32 *tree_id = this->tree_id();
33 *child_id = child->id();
34 }
35
36 int AXNodePosition::AnchorChildCount() const {
37 return GetAnchor() ? GetAnchor()->child_count() : 0;
38 }
39
40 int AXNodePosition::AnchorIndexInParent() const {
41 return GetAnchor() ? GetAnchor()->index_in_parent()
42 : AXPosition::INVALID_INDEX;
43 }
44
45 void AXNodePosition::AnchorParent(int* tree_id, int32_t* parent_id) const {
46 DCHECK(tree_id);
47 DCHECK(parent_id);
48
49 if (!GetAnchor() || !GetAnchor()->parent()) {
50 *tree_id = AXPosition::INVALID_TREE_ID;
51 *parent_id = AXPosition::INVALID_ANCHOR_ID;
52 return;
53 }
54
55 AXNode* parent = GetAnchor()->parent();
56 *tree_id = this->tree_id();
57 *parent_id = parent->id();
58 }
59
60 AXNode* AXNodePosition::GetNodeInTree(int tree_id, int32_t node_id) const {
61 if (!tree_ || node_id == AXPosition::INVALID_ANCHOR_ID)
62 return nullptr;
63 return AXNodePosition::tree_->GetFromId(node_id);
64 }
65
66 int AXNodePosition::MaxTextOffset() const {
67 if (IsTextPosition()) {
68 DCHECK(GetAnchor());
69 base::string16 name =
70 GetAnchor()->data().GetString16Attribute(AX_ATTR_NAME);
71 return static_cast<int>(name.length());
72 } else if (IsTreePosition()) {
73 return 0;
74 }
75
76 return AXPosition::INVALID_INDEX;
77 }
78
79 } // namespace ui
OLDNEW
« no previous file with comments | « ui/accessibility/ax_node_position.h ('k') | ui/accessibility/ax_node_position_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698