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

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 4 years, 3 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
« no previous file with comments | « no previous file | ui/accessibility/ax_position.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 #ifndef UI_ACCESSIBILITY_AX_POSITION_H_
6 #define UI_ACCESSIBILITY_AX_POSITION_H_
7
8 #include <vector>
9
10 #include "ui/accessibility/ax_node.h"
11
12 namespace ui {
13
14 // A position in the |AXTree|.
15 // It could either indicate a non-textual node in the accessibility tree, or a
16 // text node and a character offset.
17 //
18 // This class is copiable.
19 class AX_EXPORT AXPosition {
dmazzoni 2016/08/24 05:46:59 Do you want this class to handle embedded object c
20 public:
21 static AXPosition CreateNullPosition();
22 static AXPosition CreateTreePosition(AXNode* anchor);
dmazzoni 2016/08/24 05:46:59 Should probably pass the tree in
23 static AXPosition CreateTextPosition(AXNode* anchor, int offset = 0);
24
25 virtual ~AXPosition();
26
27 static AXPosition CommonAncestor(const AXPosition& first, const AXPosition& se cond);
28
29 AXNode* get_anchor() const { return anchor_; }
30 int get_offset() const { return offset_; }
31
32 bool IsNullPosition() const { return !anchor_; }
33 bool IsTreePosition() const { return type_ == AXPositionType::TreePosition; }
34 bool IsTextPosition() const { return type_ == AXPositionType::TextPosition; }
35
36 // Only meaningful for text positions.
37 bool AtStartOfAnchor() const;
38 bool AtEndOfAnchor() const;
39
40 bool operator<(const AXPosition& position) const;
41 bool operator<=(const AXPosition& position) const;
42 bool operator>(const AXPosition& position) const;
43 bool operator>=(const AXPosition& position) const;
44
45 // The following two methods allow the creation of text positions that are
46 // equivalent to other positions, not necessarily text ones.
47 AXPosition ToLeafTextPosition() const;
dmazzoni 2016/08/24 05:46:59 Could you define these two more clearly?
48 AXPosition ToTextPositionInAnchor(const AXNode* anchor) const;
49
50 // Returns a text position representing the first character in the current
51 // anchor.
52 AXPosition GetPositionAtStartOfAnchor() const;
53 // Returns a position representing one past the last character in the current
54 // anchor.
55 AXPosition GetPositionAtEndOfAnchor() const;
56
57 // Following methods work across anchors.
58
59 AXPosition GetNextCharacterPosition() const;
60 AXPosition GetPreviousCharacterPosition() const;
61
62 AXPosition GetNextWordStartPosition() const;
dmazzoni 2016/08/24 05:46:58 It might be better to just have a single function
63 AXPosition GetPreviousWordStartPosition() const;
64 AXPosition GetNextWordEndPosition() const;
65 AXPosition GetPreviousWordEndPosition() const;
66
67 AXPosition GetNextSentenceStartPosition() const;
68 AXPosition GetPreviousSentenceStartPosition() const;
69 AXPosition GetNextSentenceEndPosition() const;
70 AXPosition GetPreviousSentenceEndPosition() const;
71
72 AXPosition GetNextParagraphStartPosition() const;
73 AXPosition GetPreviousParagraphStartPosition() const;
74 AXPosition GetNextParagraphEndPosition() const;
75 AXPosition GetPreviousParagraphEndPosition() const;
dmazzoni 2016/08/24 05:46:59 I'm not sure para is as interesting, but line shou
76
77 protected:
78 virtual int AnchorChildCount() const = 0;
79 virtual AXPosition GetChildPositionAt(int index) const = 0;
80 virtual AXPosition GetParentPosition() const = 0;
81 virtual int AnchorIndexInParent() const = 0;
82 // Uses depth-first pre-order traversal.
83 virtual AXPosition GetNextAnchorPosition() const;
84 // Uses depth-first pre-order traversal.
85 virtual AXPosition GetPreviousAnchorPosition() const = 0;
86 virtual int MaxOffset() const = 0;
87
88 virtual std::vector<int> GetWordStartOffsets() = 0;
dmazzoni 2016/08/24 05:46:59 I'm not sure these need to be abstract. You can ge
89 virtual std::vector<int> GetWordEndOffsets() = 0;
90 virtual std::vector<int> GetParagraphStartOffsets() = 0;
91 virtual std::vector<int> GetParagraphEndOffsets() = 0;
92
93 private:
94 // Defines the type of position in the accessibility tree.
95 enum class AXPositionType {
96 TreePosition,
97 TextPosition
98 };
99
100 AXPosition(AXNode* anchor, int offset, AXPositionType type);
101
102 AXNode* anchor_;
dmazzoni 2016/08/24 05:46:59 You probably need to store the AXTree here, since
103 int offset_;
104 AXPositionType type_;
dmazzoni 2016/08/24 05:46:58 I think this class needs to store the affinity. We
105 };
106
107 bool operator==(const AXPosition& first, const AXPosition& second);
108 bool operator!=(const AXPosition& first, const AXPosition& second);
109
110 } // namespace ui
111
112 #endif // UI_ACCESSIBILITY_AX_POSITION_H_
OLDNEW
« no previous file with comments | « no previous file | ui/accessibility/ax_position.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698