Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / editing / EphemeralRange.cpp
blob1f3acaac471f46538bd5eb292edcc73786f36d9a
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "config.h"
6 #include "core/editing/EphemeralRange.h"
8 #include "core/dom/Document.h"
9 #include "core/dom/Element.h"
10 #include "core/dom/Range.h"
11 #include "core/dom/Text.h"
13 namespace blink {
15 template <typename Strategy>
16 EphemeralRangeTemplate<Strategy>::EphemeralRangeTemplate(const PositionAlgorithm<Strategy>& start, const PositionAlgorithm<Strategy>& end)
17 : m_startPosition(start)
18 , m_endPosition(end)
19 #if ENABLE(ASSERT)
20 , m_domTreeVersion(start.isNull() ? 0 : start.document()->domTreeVersion())
21 #endif
23 if (m_startPosition.isNull()) {
24 ASSERT(m_endPosition.isNull());
25 return;
27 ASSERT(m_endPosition.isNotNull());
28 ASSERT(m_startPosition.document() == m_endPosition.document());
29 ASSERT(m_startPosition.inDocument());
30 ASSERT(m_endPosition.inDocument());
33 template <typename Strategy>
34 EphemeralRangeTemplate<Strategy>::EphemeralRangeTemplate(const EphemeralRangeTemplate<Strategy>& other)
35 : EphemeralRangeTemplate(other.m_startPosition, other.m_endPosition)
37 ASSERT(other.isValid());
40 template <typename Strategy>
41 EphemeralRangeTemplate<Strategy>::EphemeralRangeTemplate(const PositionAlgorithm<Strategy>& position)
42 : EphemeralRangeTemplate(position, position)
46 template <typename Strategy>
47 EphemeralRangeTemplate<Strategy>::EphemeralRangeTemplate(const Range* range)
49 if (!range)
50 return;
51 m_startPosition = fromPositionInDOMTree<Strategy>(range->startPosition());
52 m_endPosition = fromPositionInDOMTree<Strategy>(range->endPosition());
53 #if ENABLE(ASSERT)
54 m_domTreeVersion = range->ownerDocument().domTreeVersion();
55 #endif
58 template <typename Strategy>
59 EphemeralRangeTemplate<Strategy>::EphemeralRangeTemplate()
63 template <typename Strategy>
64 EphemeralRangeTemplate<Strategy>::~EphemeralRangeTemplate()
68 template <typename Strategy>
69 EphemeralRangeTemplate<Strategy>& EphemeralRangeTemplate<Strategy>::operator=(const EphemeralRangeTemplate<Strategy>& other)
71 ASSERT(other.isValid());
72 m_startPosition = other.m_startPosition;
73 m_endPosition = other.m_endPosition;
74 #if ENABLE(ASSERT)
75 m_domTreeVersion = other.m_domTreeVersion;
76 #endif
77 return *this;
80 template <typename Strategy>
81 bool EphemeralRangeTemplate<Strategy>::operator==(const EphemeralRangeTemplate<Strategy>& other) const
83 return startPosition() == other.startPosition() && endPosition() == other.endPosition();
86 template <typename Strategy>
87 bool EphemeralRangeTemplate<Strategy>::operator!=(const EphemeralRangeTemplate<Strategy>& other) const
89 return !operator==(other);
92 template <typename Strategy>
93 Document& EphemeralRangeTemplate<Strategy>::document() const
95 ASSERT(isNotNull());
96 return *m_startPosition.document();
99 template <typename Strategy>
100 PositionAlgorithm<Strategy> EphemeralRangeTemplate<Strategy>::startPosition() const
102 ASSERT(isValid());
103 return m_startPosition;
106 template <typename Strategy>
107 PositionAlgorithm<Strategy> EphemeralRangeTemplate<Strategy>::endPosition() const
109 ASSERT(isValid());
110 return m_endPosition;
113 template <typename Strategy>
114 bool EphemeralRangeTemplate<Strategy>::isCollapsed() const
116 ASSERT(isValid());
117 return m_startPosition == m_endPosition;
120 template <typename Strategy>
121 EphemeralRangeTemplate<Strategy> EphemeralRangeTemplate<Strategy>::rangeOfContents(const Node& node)
123 return EphemeralRangeTemplate<Strategy>(PositionAlgorithm<Strategy>::firstPositionInNode(&const_cast<Node&>(node)), PositionAlgorithm<Strategy>::lastPositionInNode(&const_cast<Node&>(node)));
126 #if ENABLE(ASSERT)
127 template <typename Strategy>
128 bool EphemeralRangeTemplate<Strategy>::isValid() const
130 return m_startPosition.isNull() || m_domTreeVersion == m_startPosition.document()->domTreeVersion();
132 #else
133 template <typename Strategy>
134 bool EphemeralRangeTemplate<Strategy>::isValid() const
136 return true;
138 #endif
140 PassRefPtrWillBeRawPtr<Range> createRange(const EphemeralRange& range)
142 if (range.isNull())
143 return nullptr;
144 return Range::create(range.document(), range.startPosition(), range.endPosition());
147 template class CORE_TEMPLATE_EXPORT EphemeralRangeTemplate<EditingStrategy>;
148 template class CORE_TEMPLATE_EXPORT EphemeralRangeTemplate<EditingInComposedTreeStrategy>;
150 } // namespace blink