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

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: Removed AXRange class. 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 "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 int32_t AXNodePosition::AnchorChildID(int child_index) const {
19 if (child_index < 0 || child_index >= AnchorChildCount())
20 return AXPosition::INVALID_ANCHOR_ID;
21
22 AXNode* child = GetAnchor()->ChildAtIndex(child_index);
23 DCHECK(child);
24 int32_t child_id = child->id();
25 DCHECK_NE(child_id, AXPosition::INVALID_ANCHOR_ID);
26 return child_id;
27 }
28
29 int AXNodePosition::AnchorChildCount() const {
30 return GetAnchor() ? GetAnchor()->child_count() : 0;
31 }
32
33 int AXNodePosition::AnchorIndexInParent() const {
34 return GetAnchor() ? GetAnchor()->index_in_parent()
35 : AXPosition::INVALID_INDEX;
36 }
37
38 int32_t AXNodePosition::AnchorParentID() const {
39 if (!GetAnchor() || !GetAnchor()->parent())
40 return INVALID_ANCHOR_ID;
41 return GetAnchor()->parent()->id();
42 }
43
44 AXNode* AXNodePosition::GetNodeInTree(int tree_id, int32_t node_id) const {
45 if (!tree_ || node_id == AXPosition::INVALID_ANCHOR_ID)
46 return nullptr;
47 return AXNodePosition::tree_->GetFromId(node_id);
48 }
49
50 int AXNodePosition::MaxTextOffset() const {
51 if (IsTextPosition()) {
52 DCHECK(GetAnchor());
53 base::string16 name =
54 GetAnchor()->data().GetString16Attribute(AX_ATTR_NAME);
55 return static_cast<int>(name.length());
56 } else if (IsTreePosition()) {
57 return 0;
58 }
59
60 return AXPosition::INVALID_INDEX;
61 }
62
63 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698