Chromium Code Reviews| 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..12ea140c153b38f2f02c7f73ce6e6cf5b7c3c7f6 |
| --- /dev/null |
| +++ b/ui/accessibility/ax_position.h |
| @@ -0,0 +1,120 @@ |
| +// 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_enums.h" |
| + |
| +namespace ui { |
| + |
| +// 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. |
| +template <class AXNodeType> |
| +class AXPosition { |
| + public: |
| + virtual ~AXPosition(); |
| + |
| + static typename AXNodeType::AXPosition CreateNullPosition(); |
| + static typename AXNodeType::AXPosition CreateTreePosition(int tree_id, |
|
dmazzoni
2016/10/05 18:15:30
Why is it returning a typename AXNodeType::AXPosit
|
| + int32_t anchor_id, |
| + int child_index); |
| + static typename AXNodeType::AXPosition CreateTextPosition(int tree_id, |
| + int32_t anchor_id, |
| + int text_offset); |
| + |
| + int get_tree_id() const { return tree_id_; } |
| + int32_t get_anchor_id() const { return anchor_id_; } |
| + AXNodeType* GetAnchor() const; |
| + int get_child_index() const { return child_index_; } |
| + int get_text_offset() const { return text_offset_; } |
| + ui::AXTextAffinity get_affinity() const { 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: |
| + AXPosition(int tree_id, |
| + int32_t anchor_id, |
| + int child_index, |
| + int text_offset, |
| + AXPositionType type); |
| + |
| + virtual int AnchorChildCount() const { |
| + return GetAnchor() ? GetAnchor()->child_count() : -1; |
|
dmazzoni
2016/10/05 18:15:30
BrowserAccessibility doesn't have a method called
|
| + } |
| + 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 AXNodeType* GetNodeInTree(int tree_id, int32_t node_id) const = 0; |
| + virtual int MaxTextOffset() const = 0; |
| + |
| + 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_; |
| + |
| + // TODO(nektar): Get rid of affinity and make Blink handle affinity |
| + // internally since inline text objects don't span lines. |
| + ui::AXTextAffinity affinity_; |
| +}; |
| + |
| +template <class AXNodeType> |
| +bool operator==(const AXPosition<AXNodeType>& first, |
| + const AXPosition<AXNodeType>& second); |
| +template <class AXNodeType> |
| +bool operator!=(const AXPosition<AXNodeType>& first, |
| + const AXPosition<AXNodeType>& second); |
| + |
| +} // namespace ui |
| + |
| +#endif // UI_ACCESSIBILITY_AX_POSITION_H_ |