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

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: 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 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..7d396829adf74f1a76eaad62e5b33e46df9a6693
--- /dev/null
+++ b/ui/accessibility/ax_position.h
@@ -0,0 +1,132 @@
+// 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 <memory>
+
+#include "ui/accessibility/ax_node.h"
+
+namespace ui {
+
+class AXPositionFactory;
+
+// Defines the type of position in the accessibility tree.
+enum class AXPositionType { NullPosition, TreePosition, TextPosition };
+
+// 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:
+ virtual ~AXPosition();
+
+ 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_; }
+ ui::AXTextAffinity get_affinity() { return affinity_; }
+ void set_affinity(ui::AXTextAffinity affinity) { affinity_ = affinity; }
+
+ bool IsNullPosition() const {
+ return type_ == AXPositionType::NullPosition || !GetAnchor();
+ }
+ bool IsTreePosition() const {
+ return GetAnchor() && type_ == AXPositionType::TreePosition;
+ }
+ bool IsTextPosition() const {
+ return GetAnchor() && type_ == AXPositionType::TextPosition;
+ }
+
+ bool AtStartOfAnchor() const;
+ bool AtEndOfAnchor() const;
+
+ AXPosition CommonAncestor(const AXPosition& second) 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:
+ // |AXPositionFactory| needs access to our constructor.
+ friend class AXPositionFactory;
+ AXPosition(int tree_id,
+ int32_t anchor_id,
+ int child_index,
+ int text_offset,
+ AXPositionType type,
+ std::unique_ptr<AXPositionFactory> factory);
+
+ 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 {
+ return nullptr;
+ }
+ virtual int MaxTextOffset() const { return -1; }
+
+ 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_;
+
+ std::unique_ptr<AXPositionFactory> factory_;
+
+ // TODO(nektar): Get rid of affinity and make Blink handle affinity
+ // internally since inline text objects don't span lines.
+ ui::AXTextAffinity affinity_;
+};
+
+bool operator==(const AXPosition& first, const AXPosition& second);
+bool operator!=(const AXPosition& first, const AXPosition& second);
+
+// Creates the appropriate subclass of |AXPosition|.
+class AX_EXPORT AXPositionFactory {
+ public:
+ virtual ~AXPositionFactory() {}
+
+ virtual AXPosition CreateNullPosition() = 0;
+ virtual AXPosition CreateTreePosition(int tree_id,
+ int32_t anchor_id,
+ int child_index) = 0;
+ virtual AXPosition CreateTextPosition(int tree_id,
+ int32_t anchor_id,
+ int text_offset) = 0;
+};
+
+} // namespace ui
+
+#endif // UI_ACCESSIBILITY_AX_POSITION_H_

Powered by Google App Engine
This is Rietveld 408576698