summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/editing/position_with_affinity.cc
blob: 368575bf7045d23e47736689a01460e4354f4101 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2014 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 "third_party/blink/renderer/core/editing/position_with_affinity.h"

#include "third_party/blink/renderer/core/editing/text_affinity.h"

namespace blink {

template <typename Strategy>
PositionWithAffinityTemplate<Strategy>::PositionWithAffinityTemplate(
    const PositionTemplate<Strategy>& position,
    TextAffinity affinity)
    : position_(position), affinity_(affinity) {}

template <typename Strategy>
PositionWithAffinityTemplate<Strategy>::PositionWithAffinityTemplate()
    : affinity_(TextAffinity::kDownstream) {}

template <typename Strategy>
PositionWithAffinityTemplate<Strategy>::PositionWithAffinityTemplate(
    const PositionTemplate<Strategy>& position)
    : position_(position), affinity_(TextAffinity::kDownstream) {}

template <typename Strategy>
PositionWithAffinityTemplate<Strategy>::~PositionWithAffinityTemplate() =
    default;

template <typename Strategy>
void PositionWithAffinityTemplate<Strategy>::Trace(Visitor* visitor) {
  visitor->Trace(position_);
}

template <typename Strategy>
bool PositionWithAffinityTemplate<Strategy>::operator==(
    const PositionWithAffinityTemplate& other) const {
  if (IsNull())
    return other.IsNull();
  return affinity_ == other.affinity_ && position_ == other.position_;
}

PositionWithAffinity ToPositionInDOMTreeWithAffinity(
    const PositionWithAffinity& position) {
  return position;
}

PositionWithAffinity ToPositionInDOMTreeWithAffinity(
    const PositionInFlatTreeWithAffinity& position) {
  return PositionWithAffinity(ToPositionInDOMTree(position.GetPosition()),
                              position.Affinity());
}

PositionInFlatTreeWithAffinity ToPositionInFlatTreeWithAffinity(
    const PositionWithAffinity& position) {
  return PositionInFlatTreeWithAffinity(
      ToPositionInFlatTree(position.GetPosition()), position.Affinity());
}

PositionInFlatTreeWithAffinity ToPositionInFlatTreeWithAffinity(
    const PositionInFlatTreeWithAffinity& position) {
  return position;
}

template class CORE_TEMPLATE_EXPORT
    PositionWithAffinityTemplate<EditingStrategy>;
template class CORE_TEMPLATE_EXPORT
    PositionWithAffinityTemplate<EditingInFlatTreeStrategy>;

std::ostream& operator<<(std::ostream& ostream,
                         const PositionWithAffinity& position_with_affinity) {
  return ostream << position_with_affinity.GetPosition() << '/'
                 << position_with_affinity.Affinity();
}

std::ostream& operator<<(
    std::ostream& ostream,
    const PositionInFlatTreeWithAffinity& position_with_affinity) {
  return ostream << position_with_affinity.GetPosition() << '/'
                 << position_with_affinity.Affinity();
}

}  // namespace blink