| Index: ui/accessibility/ax_position.cc
|
| diff --git a/ui/accessibility/ax_position.cc b/ui/accessibility/ax_position.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0ce336a43524c5ce338bd75e66d4a7f43be616ca
|
| --- /dev/null
|
| +++ b/ui/accessibility/ax_position.cc
|
| @@ -0,0 +1,71 @@
|
| +// 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.
|
| +
|
| +#include "ui/accessibility/ax_position.h"
|
| +
|
| +namespace ui {
|
| +
|
| +constexpr int AXPositionBase::INVALID_TREE_ID;
|
| +constexpr int32_t AXPositionBase::INVALID_ANCHOR_ID;
|
| +constexpr int AXPositionBase::BEFORE_TEXT;
|
| +constexpr int AXPositionBase::INVALID_INDEX;
|
| +constexpr int AXPositionBase::INVALID_OFFSET;
|
| +
|
| +int AXPositionBase::MaxTextOffsetInParent() const {
|
| + return MaxTextOffset();
|
| +}
|
| +
|
| +bool operator==(const AXPositionBase& first, const AXPositionBase& second) {
|
| + if (first.IsNullPosition() && second.IsNullPosition())
|
| + return true;
|
| + return first.tree_id() == second.tree_id() &&
|
| + first.anchor_id() == second.anchor_id() &&
|
| + first.child_index() == second.child_index() &&
|
| + first.text_offset() == second.text_offset() &&
|
| + first.affinity() == second.affinity();
|
| +}
|
| +
|
| +bool operator!=(const AXPositionBase& first, const AXPositionBase& second) {
|
| + return !(first == second);
|
| +}
|
| +
|
| +bool operator<(const AXPositionBase& first, const AXPositionBase& second) {
|
| + if (first.IsNullPosition() || second.IsNullPosition())
|
| + return false;
|
| +
|
| + std::unique_ptr<AXPositionBase> first_ancestor =
|
| + first.LowestCommonAncestor(second)->AsTreePosition();
|
| + std::unique_ptr<AXPositionBase> second_ancestor =
|
| + second.LowestCommonAncestor(first)->AsTreePosition();
|
| + DCHECK_EQ(first_ancestor->GetOpaqueAnchor(),
|
| + second_ancestor->GetOpaqueAnchor());
|
| + return !first_ancestor->IsNullPosition() &&
|
| + first_ancestor->AsTextPosition()->text_offset() <
|
| + second_ancestor->AsTextPosition()->text_offset();
|
| +}
|
| +
|
| +bool operator<=(const AXPositionBase& first, const AXPositionBase& second) {
|
| + return first == second || first < second;
|
| +}
|
| +
|
| +bool operator>(const AXPositionBase& first, const AXPositionBase& second) {
|
| + if (first.IsNullPosition() || second.IsNullPosition())
|
| + return false;
|
| +
|
| + std::unique_ptr<AXPositionBase> first_ancestor =
|
| + first.LowestCommonAncestor(second)->AsTreePosition();
|
| + std::unique_ptr<AXPositionBase> second_ancestor =
|
| + second.LowestCommonAncestor(first)->AsTreePosition();
|
| + DCHECK_EQ(first_ancestor->GetOpaqueAnchor(),
|
| + second_ancestor->GetOpaqueAnchor());
|
| + return !first_ancestor->IsNullPosition() &&
|
| + first_ancestor->AsTextPosition()->text_offset() >
|
| + second_ancestor->AsTextPosition()->text_offset();
|
| +}
|
| +
|
| +bool operator>=(const AXPositionBase& first, const AXPositionBase& second) {
|
| + return first == second || first > second;
|
| +}
|
| +
|
| +} // namespace ui
|
|
|