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

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: Re-wrote implementation to include tree_id and platform specific AXPosition. 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_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 {
20 public:
21 static AXPosition CreateNullPosition();
22 static AXPosition CreateTreePosition(int tree_id, int32_t anchor_id, int child _index = 0);
23 static AXPosition CreateTextPosition(int tree_id, int32_t anchor_id, int text_ offset = 0);
24
25 virtual ~AXPosition();
26
27 static AXPosition CommonAncestor(const AXPosition& first, const AXPosition& se cond);
28
29 int get_tree_id() const { return tree_id_; }
30 int32_t get_anchor_id() const { return anchor_id_; }
31 AXNode* GetAnchor() const;
32 int get_child_index() const { return child_index_; }
33 int get_text_offset() const { return text_offset_; }
34
35 bool IsNullPosition() const { return !GetAnchor(); }
36 bool IsTreePosition() const { return GetAnchor() && type_ == AXPositionType::T reePosition; }
37 bool IsTextPosition() const { return GetAnchor() && type_ == AXPositionType::T extPosition; }
38
39 bool AtStartOfAnchor() const;
40 bool AtEndOfAnchor() const;
41
42 bool operator<(const AXPosition& position) const;
43 bool operator<=(const AXPosition& position) const;
44 bool operator>(const AXPosition& position) const;
45 bool operator>=(const AXPosition& position) const;
46
47 AXPosition GetPositionAtStartOfAnchor() const;
48 AXPosition GetPositionAtEndOfAnchor() const;
49
50 // The following methods work across anchors.
51
52 AXPosition GetNextCharacterPosition() const;
53 AXPosition GetPreviousCharacterPosition() const;
54 // TODO(nektar): Add word, line and paragraph navigation methods.
55
56 protected:
57 AXPosition(int tree_id, int32_t anchor_id, int offset, AXPositionType type);
58
59 virtual int AnchorChildCount() const { return GetAnchor() ? GetAnchor()->child _count() : -1; }
60 virtual AXPosition GetChildPositionAt(int child_index) const;
61 virtual AXPosition GetParentPosition() const;
62 virtual int AnchorIndexInParent() const { return GetAnchor() ? GetAnchor()->in dex_in_parent() : -1; }
63 // Uses depth-first pre-order traversal.
64 virtual AXPosition GetNextAnchorPosition() const;
65 // Uses depth-first pre-order traversal.
66 virtual AXPosition GetPreviousAnchorPosition() const;
67
68 virtual AXNode* GetNodeInTree(int tree_id, int32-t node_id) const = 0;
69 virtual int MaxTextOffset() const = 0;
70
71 // Defines the type of position in the accessibility tree.
72 enum class AXPositionType {
73 TreePosition,
74 TextPosition
75 };
76
77 private:
78 int tree_id_;
79 int32_t anchor_id_;
80
81 // For text positions, |child_index_| is initially set to |-1| and only comput ed on demand. The same with tree positions and |text_offset_|.
82 int child_index_;
83 int text_offset_;
84
85 AXPositionType type_;
86 };
87
88 bool operator==(const AXPosition& first, const AXPosition& second);
89 bool operator!=(const AXPosition& first, const AXPosition& second);
90
91 } // namespace ui
92
93 #endif // UI_ACCESSIBILITY_AX_POSITION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698