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

Side by Side Diff: ui/accessibility/ax_position.h

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 test skeleton. 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 #ifndef UI_ACCESSIBILITY_AX_POSITION_H_
6 #define UI_ACCESSIBILITY_AX_POSITION_H_
7
8 #include <stdint.h>
9
10 #include "ui/accessibility/ax_enums.h"
11
12 namespace ui {
13
14 // Defines the type of position in the accessibility tree.
15 enum class AXPositionType { NullPosition, TreePosition, TextPosition };
16
17 // A position in the |AXTree|.
18 // It could either indicate a non-textual node in the accessibility tree, or a
19 // text node and a character offset.
20 //
21 // This class is copiable.
22 template <class AXNodeType>
23 class AXPosition {
24 public:
25 virtual ~AXPosition();
26
27 static typename AXNodeType::AXPosition CreateNullPosition();
28 static typename AXNodeType::AXPosition CreateTreePosition(int tree_id,
dmazzoni 2016/10/05 18:15:30 Why is it returning a typename AXNodeType::AXPosit
29 int32_t anchor_id,
30 int child_index);
31 static typename AXNodeType::AXPosition CreateTextPosition(int tree_id,
32 int32_t anchor_id,
33 int text_offset);
34
35 int get_tree_id() const { return tree_id_; }
36 int32_t get_anchor_id() const { return anchor_id_; }
37 AXNodeType* GetAnchor() const;
38 int get_child_index() const { return child_index_; }
39 int get_text_offset() const { return text_offset_; }
40 ui::AXTextAffinity get_affinity() const { return affinity_; }
41 void set_affinity(ui::AXTextAffinity affinity) { affinity_ = affinity; }
42
43 bool IsNullPosition() const {
44 return type_ == AXPositionType::NullPosition || !GetAnchor();
45 }
46 bool IsTreePosition() const {
47 return GetAnchor() && type_ == AXPositionType::TreePosition;
48 }
49 bool IsTextPosition() const {
50 return GetAnchor() && type_ == AXPositionType::TextPosition;
51 }
52
53 bool AtStartOfAnchor() const;
54 bool AtEndOfAnchor() const;
55
56 AXPosition CommonAncestor(const AXPosition& second) const;
57
58 bool operator<(const AXPosition& position) const;
59 bool operator<=(const AXPosition& position) const;
60 bool operator>(const AXPosition& position) const;
61 bool operator>=(const AXPosition& position) const;
62
63 AXPosition GetPositionAtStartOfAnchor() const;
64 AXPosition GetPositionAtEndOfAnchor() const;
65
66 // The following methods work across anchors.
67
68 AXPosition GetNextCharacterPosition() const;
69 AXPosition GetPreviousCharacterPosition() const;
70 // TODO(nektar): Add word, line and paragraph navigation methods.
71
72 protected:
73 AXPosition(int tree_id,
74 int32_t anchor_id,
75 int child_index,
76 int text_offset,
77 AXPositionType type);
78
79 virtual int AnchorChildCount() const {
80 return GetAnchor() ? GetAnchor()->child_count() : -1;
dmazzoni 2016/10/05 18:15:30 BrowserAccessibility doesn't have a method called
81 }
82 virtual AXPosition GetChildPositionAt(int child_index) const;
83 virtual AXPosition GetParentPosition() const;
84 virtual int AnchorIndexInParent() const {
85 return GetAnchor() ? GetAnchor()->index_in_parent() : -1;
86 }
87 // Uses depth-first pre-order traversal.
88 virtual AXPosition GetNextAnchorPosition() const;
89 // Uses depth-first pre-order traversal.
90 virtual AXPosition GetPreviousAnchorPosition() const;
91
92 virtual AXNodeType* GetNodeInTree(int tree_id, int32_t node_id) const = 0;
93 virtual int MaxTextOffset() const = 0;
94
95 private:
96 int tree_id_;
97 int32_t anchor_id_;
98
99 // For text positions, |child_index_| is initially set to |-1| and only
100 // computed on demand. The same with tree positions and |text_offset_|.
101 int child_index_;
102 int text_offset_;
103
104 AXPositionType type_;
105
106 // TODO(nektar): Get rid of affinity and make Blink handle affinity
107 // internally since inline text objects don't span lines.
108 ui::AXTextAffinity affinity_;
109 };
110
111 template <class AXNodeType>
112 bool operator==(const AXPosition<AXNodeType>& first,
113 const AXPosition<AXNodeType>& second);
114 template <class AXNodeType>
115 bool operator!=(const AXPosition<AXNodeType>& first,
116 const AXPosition<AXNodeType>& second);
117
118 } // namespace ui
119
120 #endif // UI_ACCESSIBILITY_AX_POSITION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698