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

Unified 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 side-by-side diff with in-line comments
Download patch
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..d4ab388f09593db0699c47f3a908643ad3894da3
--- /dev/null
+++ b/ui/accessibility/ax_position.h
@@ -0,0 +1,93 @@
+// 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 <stdint.h>
+
+#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 {
+ public:
+ static AXPosition CreateNullPosition();
+ static AXPosition CreateTreePosition(int tree_id, int32_t anchor_id, int child_index = 0);
+ static AXPosition CreateTextPosition(int tree_id, int32_t anchor_id, int text_offset = 0);
+
+ virtual ~AXPosition();
+
+ static AXPosition CommonAncestor(const AXPosition& first, const AXPosition& second);
+
+ int get_tree_id() const { return tree_id_; }
+ int32_t get_anchor_id() const { return anchor_id_; }
+ AXNode* GetAnchor() const;
+ int get_child_index() const { return child_index_; }
+ int get_text_offset() const { return text_offset_; }
+
+ bool IsNullPosition() const { return !GetAnchor(); }
+ bool IsTreePosition() const { return GetAnchor() && type_ == AXPositionType::TreePosition; }
+ bool IsTextPosition() const { return GetAnchor() && type_ == AXPositionType::TextPosition; }
+
+ 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;
+
+ AXPosition GetPositionAtStartOfAnchor() const;
+ AXPosition GetPositionAtEndOfAnchor() const;
+
+ // The following methods work across anchors.
+
+ AXPosition GetNextCharacterPosition() const;
+ AXPosition GetPreviousCharacterPosition() const;
+ // TODO(nektar): Add word, line and paragraph navigation methods.
+
+ protected:
+ AXPosition(int tree_id, int32_t anchor_id, int offset, AXPositionType type);
+
+ virtual int AnchorChildCount() const { return GetAnchor() ? GetAnchor()->child_count() : -1; }
+ virtual AXPosition GetChildPositionAt(int child_index) const;
+ virtual AXPosition GetParentPosition() const;
+ virtual int AnchorIndexInParent() const { return GetAnchor() ? GetAnchor()->index_in_parent() : -1; }
+ // Uses depth-first pre-order traversal.
+ virtual AXPosition GetNextAnchorPosition() const;
+ // Uses depth-first pre-order traversal.
+ virtual AXPosition GetPreviousAnchorPosition() const;
+
+ virtual AXNode* GetNodeInTree(int tree_id, int32-t node_id) const = 0;
+ virtual int MaxTextOffset() const = 0;
+
+ // Defines the type of position in the accessibility tree.
+ enum class AXPositionType {
+ TreePosition,
+ TextPosition
+ };
+
+ private:
+ int tree_id_;
+ int32_t anchor_id_;
+
+ // For text positions, |child_index_| is initially set to |-1| and only computed on demand. The same with tree positions and |text_offset_|.
+ int child_index_;
+ int text_offset_;
+
+ AXPositionType type_;
+};
+
+bool operator==(const AXPosition& first, const AXPosition& second);
+bool operator!=(const AXPosition& first, const AXPosition& second);
+
+} // namespace ui
+
+#endif // UI_ACCESSIBILITY_AX_POSITION_H_

Powered by Google App Engine
This is Rietveld 408576698