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

Unified Diff: ui/accessibility/ax_abstract_position.h

Issue 2940923003: a11y: Move CreateTextMarker[Range] to TextMarkerHelperMac.
Patch Set: squish? Created 3 years, 6 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
« no previous file with comments | « ui/accessibility/BUILD.gn ('k') | ui/accessibility/ax_abstract_position.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/accessibility/ax_abstract_position.h
diff --git a/ui/accessibility/ax_abstract_position.h b/ui/accessibility/ax_abstract_position.h
new file mode 100644
index 0000000000000000000000000000000000000000..4cfb9a38df6094dbe04574825c33133d36bbab75
--- /dev/null
+++ b/ui/accessibility/ax_abstract_position.h
@@ -0,0 +1,116 @@
+// Copyright 2017 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_ABSTRACT_POSITION_H_
+#define UI_ACCESSIBILITY_AX_ABSTRACT_POSITION_H_
+
+#include <memory>
+#include <utility>
+
+#include "base/macros.h"
+#include "ui/accessibility/ax_enums.h"
+#include "ui/accessibility/ax_export.h"
+
+namespace ui {
+
+class AXAbstractPosition;
+
+// Defines the type of position in the accessibility tree.
+// A tree position is used when referring to a specific child of a node in the
+// accessibility tree.
+// A text position is used when referring to a specific character of text inside
+// a particular node.
+// A null position is used to signify that the provided data is invalid or that
+// a boundary has been reached.
+enum class AXPositionKind { NULL_POSITION, TREE_POSITION, TEXT_POSITION };
+
+// Plain old data to serialize and deserialize a position. See AXPosition.
+struct AX_EXPORT AXPositionData {
+ AXPositionKind kind;
+ int tree_id;
+ int32_t anchor_id;
+ int child_index;
+ int text_offset;
+ AXTextAffinity affinity;
+};
+
+// An immutable move-only type that wraps a polymorphic AXAbstractPosition.
+class AX_EXPORT AXPositionPointer {
+ public:
+ // Allow moving. Declaring this implicitly deletes other constructors.
+ AXPositionPointer(AXPositionPointer&& other);
+
+ // Allow implicit upcasting when using std::move on a std::unique_ptr.
+ template <class Concrete>
+ AXPositionPointer(std::unique_ptr<Concrete> other) : ptr_(other.release()) {}
+
+ // Allow implicit conversion from nullptr.
+ AXPositionPointer(std::nullptr_t);
+
+ ~AXPositionPointer();
+
+ explicit operator bool() const { return ptr_.get() != nullptr; }
+ const AXAbstractPosition* operator->() const { return ptr_.get(); }
+
+ // Downcasting must be explicit.
+ template <class Concrete>
+ const Concrete* DownCastTo() const {
+ return static_cast<Concrete*>(ptr_.get());
+ }
+
+ private:
+ std::unique_ptr<AXAbstractPosition> ptr_;
+
+ DISALLOW_COPY_AND_ASSIGN(AXPositionPointer);
+};
+
+using AXRangePointer = std::pair<AXPositionPointer, AXPositionPointer>;
+
+// Represents a tree or text position. An AXAbstractPosition exposes the methods
+// required to manipulate the position, without having to know details of how to
+// represent it.
+class AX_EXPORT AXAbstractPosition {
+ public:
+ static constexpr int INVALID_TREE_ID = -1;
+ static constexpr int32_t INVALID_ANCHOR_ID = -1;
+ static constexpr int BEFORE_TEXT = -1;
+ static constexpr int INVALID_INDEX = -2;
+ static constexpr int INVALID_OFFSET = -1;
+
+ // TODO(tapted): Make this constexpr. It can't be currently because it tickles
+ // a bogus warning due to an MSVC compiler bug -- https://goo.gl/TGW4Ji . The
+ // warning can be suppressed, but this is usually passed by reference anyway.
+ static const AXPositionData kNullData;
+
+ virtual ~AXAbstractPosition() {}
+
+ virtual void ToData(AXPositionData* data) const = 0;
+ virtual bool IsNull() const = 0;
+
+ // Compare according to the "Compare" C++ standard concept (this < other).
+ virtual bool Compare(const AXPositionPointer& other) const = 0;
+
+ virtual AXPositionPointer PositionAtEndOfAnchor() const = 0;
+ virtual AXPositionPointer PositionAtStartOfAnchor() const = 0;
+
+ virtual AXPositionPointer NextCharacterPosition() const = 0;
+ virtual AXPositionPointer PreviousCharacterPosition() const = 0;
+
+ virtual AXPositionPointer NextWordStartPosition() const = 0;
+ virtual AXPositionPointer PreviousWordStartPosition() const = 0;
+ virtual AXPositionPointer NextWordEndPosition() const = 0;
+ virtual AXPositionPointer PreviousWordEndPosition() const = 0;
+
+ virtual AXPositionPointer NextLineStartPosition() const = 0;
+ virtual AXPositionPointer PreviousLineStartPosition() const = 0;
+ virtual AXPositionPointer NextLineEndPosition() const = 0;
+ virtual AXPositionPointer PreviousLineEndPosition() const = 0;
+
+ protected:
+ AXAbstractPosition() {}
+};
+
+} // namespace ui
+
+#endif // UI_ACCESSIBILITY_AX_ABSTRACT_POSITION_H_
« no previous file with comments | « ui/accessibility/BUILD.gn ('k') | ui/accessibility/ax_abstract_position.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698