OLD | NEW |
---|---|
(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 #include "ui/accessibility/ax_node.h" | |
12 | |
13 namespace ui { | |
14 | |
15 // Defines the type of position in the accessibility tree. | |
16 enum class AXPositionType { NullPosition, TreePosition, TextPosition }; | |
David Tseng
2016/10/07 21:02:42
Please expand a little on these. What exactly is a
| |
17 | |
18 // A position in the |AXTree|. | |
19 // It could either indicate a non-textual node in the accessibility tree, or a | |
20 // text node and a character offset. | |
David Tseng
2016/10/07 21:02:41
What is a text node?
| |
21 template <class AXNodeType> | |
22 class AXPosition { | |
23 public: | |
24 virtual ~AXPosition(); | |
25 | |
26 static typename AXNodeType::AXPosition* CreateNullPosition(); | |
27 static typename AXNodeType::AXPosition* CreateTreePosition(int tree_id, | |
28 int32_t anchor_id, | |
29 int child_index); | |
30 static typename AXNodeType::AXPosition* CreateTextPosition(int tree_id, | |
31 int32_t anchor_id, | |
32 int text_offset); | |
33 | |
34 int get_tree_id() const { return tree_id_; } | |
David Tseng
2016/10/07 21:02:42
Remove the get_ here
| |
35 int32_t get_anchor_id() const { return anchor_id_; } | |
David Tseng
2016/10/07 21:02:41
Remove the get_ here
| |
36 AXNodeType* GetAnchor() const; | |
37 int get_child_index() const { return child_index_; } | |
38 int get_text_offset() const { return text_offset_; } | |
David Tseng
2016/10/07 21:02:42
I think we should re-think the design here.
eithe
| |
39 ui::AXTextAffinity get_affinity() const { return affinity_; } | |
40 void set_affinity(ui::AXTextAffinity affinity) { affinity_ = affinity; } | |
David Tseng
2016/10/07 21:02:42
I think it would make more sense to make all prope
| |
41 | |
42 bool IsNullPosition() const { | |
43 return type_ == AXPositionType::NullPosition || !GetAnchor(); | |
44 } | |
45 bool IsTreePosition() const { | |
46 return GetAnchor() && type_ == AXPositionType::TreePosition; | |
47 } | |
48 bool IsTextPosition() const { | |
49 return GetAnchor() && type_ == AXPositionType::TextPosition; | |
David Tseng
2016/10/07 21:02:42
So, in theory, I could construct an AXPosition (w
| |
50 } | |
51 | |
52 bool AtStartOfAnchor() const; | |
53 bool AtEndOfAnchor() const; | |
David Tseng
2016/10/07 21:02:41
In Blink, the position types are:
offsetInAnchor,
| |
54 | |
55 AXPosition* CommonAncestor(const AXPosition& second) const; | |
56 | |
57 bool operator<(const AXPosition& position) const; | |
David Tseng
2016/10/07 21:02:42
Please add some comments for all of these and abov
| |
58 bool operator<=(const AXPosition& position) const; | |
59 bool operator>(const AXPosition& position) const; | |
60 bool operator>=(const AXPosition& position) const; | |
61 | |
62 AXPosition* GetPositionAtStartOfAnchor() const; | |
63 AXPosition* GetPositionAtEndOfAnchor() const; | |
64 | |
65 // The following methods work across anchors. | |
66 | |
67 AXPosition* GetNextCharacterPosition() const; | |
68 AXPosition* GetPreviousCharacterPosition() const; | |
69 // TODO(nektar): Add word, line and paragraph navigation methods. | |
70 | |
71 protected: | |
72 AXPosition(int tree_id, | |
73 int32_t anchor_id, | |
74 int child_index, | |
75 int text_offset, | |
76 AXPositionType type); | |
77 | |
78 // Uses depth-first pre-order traversal. | |
David Tseng
2016/10/07 21:02:42
What does this mean? The next tree or character po
| |
79 virtual AXPosition* GetNextAnchorPosition() const; | |
80 // Uses depth-first pre-order traversal. | |
81 virtual AXPosition* GetPreviousAnchorPosition() const; | |
82 | |
83 virtual AXPosition* GetChildPositionAt(int child_index) const = 0; | |
David Tseng
2016/10/07 21:02:41
The more I read this, the more I thnk we should se
| |
84 virtual AXPosition* GetParentPosition() const = 0; | |
85 virtual int AnchorChildCount() const = 0; | |
86 virtual int AnchorIndexInParent() const = 0; | |
87 virtual AXNodeType* GetNodeInTree(int tree_id, int32_t node_id) const = 0; | |
88 virtual int MaxTextOffset() const = 0; | |
David Tseng
2016/10/07 21:02:41
Definitely needs comment.
| |
89 | |
90 private: | |
91 int tree_id_; | |
92 int32_t anchor_id_; | |
93 | |
94 // For text positions, |child_index_| is initially set to |-1| and only | |
95 // computed on demand. The same with tree positions and |text_offset_|. | |
96 int child_index_; | |
97 int text_offset_; | |
98 | |
99 AXPositionType type_; | |
100 | |
101 // TODO(nektar): Get rid of affinity and make Blink handle affinity | |
102 // internally since inline text objects don't span lines. | |
103 ui::AXTextAffinity affinity_; | |
104 }; | |
105 | |
106 template <class AXNodeType> | |
107 bool operator==(const AXPosition<AXNodeType>& first, | |
108 const AXPosition<AXNodeType>& second); | |
109 template <class AXNodeType> | |
110 bool operator!=(const AXPosition<AXNodeType>& first, | |
111 const AXPosition<AXNodeType>& second); | |
112 | |
113 class AX_EXPORT AXNodePosition : public AXPosition<AXNode> { | |
114 public: | |
115 ~AXNodePosition() override; | |
116 | |
117 protected: | |
118 AXNodePosition(int tree_id, | |
119 int32_t anchor_id, | |
120 int child_index, | |
121 int text_offset, | |
122 AXPositionType type); | |
123 | |
124 int AnchorChildCount() const override { | |
125 return GetAnchor() ? GetAnchor()->child_count() : -1; | |
126 } | |
127 AXPosition* GetChildPositionAt(int child_index) const override; | |
128 AXPosition* GetParentPosition() const override; | |
129 int AnchorIndexInParent() const override { | |
130 return GetAnchor() ? GetAnchor()->index_in_parent() : -1; | |
131 } | |
132 }; | |
133 | |
134 } // namespace ui | |
135 | |
136 #endif // UI_ACCESSIBILITY_AX_POSITION_H_ | |
OLD | NEW |