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

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: Created a factory. 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 <memory>
11
12 #include "ui/accessibility/ax_node.h"
13
14 namespace ui {
15
16 class AXPositionFactory;
17
18 // Defines the type of position in the accessibility tree.
19 enum class AXPositionType { NullPosition, TreePosition, TextPosition };
20
21 // A position in the |AXTree|.
22 // It could either indicate a non-textual node in the accessibility tree, or a
23 // text node and a character offset.
24 //
25 // This class is copiable.
26 class AX_EXPORT AXPosition {
27 public:
28 virtual ~AXPosition();
29
30 int get_tree_id() const { return tree_id_; }
31 int32_t get_anchor_id() const { return anchor_id_; }
32 AXNode* GetAnchor() const;
33 int get_child_index() const { return child_index_; }
34 int get_text_offset() const { return text_offset_; }
35 ui::AXTextAffinity get_affinity() { return affinity_; }
36 void set_affinity(ui::AXTextAffinity affinity) { affinity_ = affinity; }
37
38 bool IsNullPosition() const {
39 return type_ == AXPositionType::NullPosition || !GetAnchor();
40 }
41 bool IsTreePosition() const {
42 return GetAnchor() && type_ == AXPositionType::TreePosition;
43 }
44 bool IsTextPosition() const {
45 return GetAnchor() && type_ == AXPositionType::TextPosition;
46 }
47
48 bool AtStartOfAnchor() const;
49 bool AtEndOfAnchor() const;
50
51 AXPosition CommonAncestor(const AXPosition& second) const;
52
53 bool operator<(const AXPosition& position) const;
54 bool operator<=(const AXPosition& position) const;
55 bool operator>(const AXPosition& position) const;
56 bool operator>=(const AXPosition& position) const;
57
58 AXPosition GetPositionAtStartOfAnchor() const;
59 AXPosition GetPositionAtEndOfAnchor() const;
60
61 // The following methods work across anchors.
62
63 AXPosition GetNextCharacterPosition() const;
64 AXPosition GetPreviousCharacterPosition() const;
65 // TODO(nektar): Add word, line and paragraph navigation methods.
66
67 protected:
68 // |AXPositionFactory| needs access to our constructor.
69 friend class AXPositionFactory;
70 AXPosition(int tree_id,
71 int32_t anchor_id,
72 int child_index,
73 int text_offset,
74 AXPositionType type,
75 std::unique_ptr<AXPositionFactory> factory);
76
77 virtual int AnchorChildCount() const {
78 return GetAnchor() ? GetAnchor()->child_count() : -1;
79 }
80 virtual AXPosition GetChildPositionAt(int child_index) const;
81 virtual AXPosition GetParentPosition() const;
82 virtual int AnchorIndexInParent() const {
83 return GetAnchor() ? GetAnchor()->index_in_parent() : -1;
84 }
85 // Uses depth-first pre-order traversal.
86 virtual AXPosition GetNextAnchorPosition() const;
87 // Uses depth-first pre-order traversal.
88 virtual AXPosition GetPreviousAnchorPosition() const;
89
90 virtual AXNode* GetNodeInTree(int tree_id, int32_t node_id) const {
91 return nullptr;
92 }
93 virtual int MaxTextOffset() const { return -1; }
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 std::unique_ptr<AXPositionFactory> factory_;
107
108 // TODO(nektar): Get rid of affinity and make Blink handle affinity
109 // internally since inline text objects don't span lines.
110 ui::AXTextAffinity affinity_;
111 };
112
113 bool operator==(const AXPosition& first, const AXPosition& second);
114 bool operator!=(const AXPosition& first, const AXPosition& second);
115
116 // Creates the appropriate subclass of |AXPosition|.
117 class AX_EXPORT AXPositionFactory {
118 public:
119 virtual ~AXPositionFactory() {}
120
121 virtual AXPosition CreateNullPosition() = 0;
122 virtual AXPosition CreateTreePosition(int tree_id,
123 int32_t anchor_id,
124 int child_index) = 0;
125 virtual AXPosition CreateTextPosition(int tree_id,
126 int32_t anchor_id,
127 int text_offset) = 0;
128 };
129
130 } // namespace ui
131
132 #endif // UI_ACCESSIBILITY_AX_POSITION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698