Index: ui/accessibility/ax_position.h |
diff --git a/ui/accessibility/ax_position.h b/ui/accessibility/ax_position.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4d0160bc081aca987b6c5d3a578593942f4df399 |
--- /dev/null |
+++ b/ui/accessibility/ax_position.h |
@@ -0,0 +1,112 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef UI_ACCESSIBILITY_AX_POSITION_H_ |
+#define UI_ACCESSIBILITY_AX_POSITION_H_ |
+ |
+#include <vector> |
+ |
+#include "ui/accessibility/ax_node.h" |
+ |
+namespace ui { |
+ |
+// A position in the |AXTree|. |
+// It could either indicate a non-textual node in the accessibility tree, or a |
+// text node and a character offset. |
+// |
+// This class is copiable. |
+class AX_EXPORT AXPosition { |
dmazzoni
2016/08/24 05:46:59
Do you want this class to handle embedded object c
|
+ public: |
+ static AXPosition CreateNullPosition(); |
+ static AXPosition CreateTreePosition(AXNode* anchor); |
dmazzoni
2016/08/24 05:46:59
Should probably pass the tree in
|
+ static AXPosition CreateTextPosition(AXNode* anchor, int offset = 0); |
+ |
+ virtual ~AXPosition(); |
+ |
+ static AXPosition CommonAncestor(const AXPosition& first, const AXPosition& second); |
+ |
+ AXNode* get_anchor() const { return anchor_; } |
+ int get_offset() const { return offset_; } |
+ |
+ bool IsNullPosition() const { return !anchor_; } |
+ bool IsTreePosition() const { return type_ == AXPositionType::TreePosition; } |
+ bool IsTextPosition() const { return type_ == AXPositionType::TextPosition; } |
+ |
+ // Only meaningful for text positions. |
+ bool AtStartOfAnchor() const; |
+ bool AtEndOfAnchor() const; |
+ |
+ bool operator<(const AXPosition& position) const; |
+ bool operator<=(const AXPosition& position) const; |
+ bool operator>(const AXPosition& position) const; |
+ bool operator>=(const AXPosition& position) const; |
+ |
+ // The following two methods allow the creation of text positions that are |
+ // equivalent to other positions, not necessarily text ones. |
+ AXPosition ToLeafTextPosition() const; |
dmazzoni
2016/08/24 05:46:59
Could you define these two more clearly?
|
+ AXPosition ToTextPositionInAnchor(const AXNode* anchor) const; |
+ |
+ // Returns a text position representing the first character in the current |
+ // anchor. |
+ AXPosition GetPositionAtStartOfAnchor() const; |
+ // Returns a position representing one past the last character in the current |
+ // anchor. |
+ AXPosition GetPositionAtEndOfAnchor() const; |
+ |
+ // Following methods work across anchors. |
+ |
+ AXPosition GetNextCharacterPosition() const; |
+ AXPosition GetPreviousCharacterPosition() const; |
+ |
+ AXPosition GetNextWordStartPosition() const; |
dmazzoni
2016/08/24 05:46:58
It might be better to just have a single function
|
+ AXPosition GetPreviousWordStartPosition() const; |
+ AXPosition GetNextWordEndPosition() const; |
+ AXPosition GetPreviousWordEndPosition() const; |
+ |
+ AXPosition GetNextSentenceStartPosition() const; |
+ AXPosition GetPreviousSentenceStartPosition() const; |
+ AXPosition GetNextSentenceEndPosition() const; |
+ AXPosition GetPreviousSentenceEndPosition() const; |
+ |
+ AXPosition GetNextParagraphStartPosition() const; |
+ AXPosition GetPreviousParagraphStartPosition() const; |
+ AXPosition GetNextParagraphEndPosition() const; |
+ AXPosition GetPreviousParagraphEndPosition() const; |
dmazzoni
2016/08/24 05:46:59
I'm not sure para is as interesting, but line shou
|
+ |
+ protected: |
+ virtual int AnchorChildCount() const = 0; |
+ virtual AXPosition GetChildPositionAt(int index) const = 0; |
+ virtual AXPosition GetParentPosition() const = 0; |
+ virtual int AnchorIndexInParent() const = 0; |
+ // Uses depth-first pre-order traversal. |
+ virtual AXPosition GetNextAnchorPosition() const; |
+ // Uses depth-first pre-order traversal. |
+ virtual AXPosition GetPreviousAnchorPosition() const = 0; |
+ virtual int MaxOffset() const = 0; |
+ |
+ 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
|
+ virtual std::vector<int> GetWordEndOffsets() = 0; |
+ virtual std::vector<int> GetParagraphStartOffsets() = 0; |
+ virtual std::vector<int> GetParagraphEndOffsets() = 0; |
+ |
+ private: |
+ // Defines the type of position in the accessibility tree. |
+ enum class AXPositionType { |
+ TreePosition, |
+ TextPosition |
+ }; |
+ |
+ AXPosition(AXNode* anchor, int offset, AXPositionType type); |
+ |
+ AXNode* anchor_; |
dmazzoni
2016/08/24 05:46:59
You probably need to store the AXTree here, since
|
+ int offset_; |
+ AXPositionType type_; |
dmazzoni
2016/08/24 05:46:58
I think this class needs to store the affinity. We
|
+}; |
+ |
+bool operator==(const AXPosition& first, const AXPosition& second); |
+bool operator!=(const AXPosition& first, const AXPosition& second); |
+ |
+} // namespace ui |
+ |
+#endif // UI_ACCESSIBILITY_AX_POSITION_H_ |