OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/editing/EphemeralRange.h" | 5 #include "core/editing/EphemeralRange.h" |
6 | 6 |
7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
8 #include "core/dom/Element.h" | 8 #include "core/dom/Element.h" |
9 #include "core/dom/Range.h" | 9 #include "core/dom/Range.h" |
10 #include "core/dom/Text.h" | 10 #include "core/dom/Text.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 namespace { | |
15 | |
Xiaocheng
2017/03/02 20:00:16
nit: remove this extra blank line.
tanvir
2017/03/04 13:55:31
Done.
| |
16 template <typename Strategy> | |
17 Node* commonAncestorContainerNode(const Node* containerA, | |
18 const Node* containerB) { | |
19 if (!containerA || !containerB) | |
20 return nullptr; | |
21 return Strategy::commonAncestor(*containerA, *containerB); | |
22 } | |
23 } | |
24 | |
14 template <typename Strategy> | 25 template <typename Strategy> |
15 EphemeralRangeTemplate<Strategy>::EphemeralRangeTemplate( | 26 EphemeralRangeTemplate<Strategy>::EphemeralRangeTemplate( |
16 const PositionTemplate<Strategy>& start, | 27 const PositionTemplate<Strategy>& start, |
17 const PositionTemplate<Strategy>& end) | 28 const PositionTemplate<Strategy>& end) |
18 : m_startPosition(start), | 29 : m_startPosition(start), |
19 m_endPosition(end) | 30 m_endPosition(end) |
20 #if DCHECK_IS_ON() | 31 #if DCHECK_IS_ON() |
21 , | 32 , |
22 m_domTreeVersion(start.isNull() ? 0 : start.document()->domTreeVersion()) | 33 m_domTreeVersion(start.isNull() ? 0 : start.document()->domTreeVersion()) |
23 #endif | 34 #endif |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 } | 113 } |
103 | 114 |
104 template <typename Strategy> | 115 template <typename Strategy> |
105 PositionTemplate<Strategy> EphemeralRangeTemplate<Strategy>::endPosition() | 116 PositionTemplate<Strategy> EphemeralRangeTemplate<Strategy>::endPosition() |
106 const { | 117 const { |
107 DCHECK(isValid()); | 118 DCHECK(isValid()); |
108 return m_endPosition; | 119 return m_endPosition; |
109 } | 120 } |
110 | 121 |
111 template <typename Strategy> | 122 template <typename Strategy> |
123 Node* EphemeralRangeTemplate<Strategy>::commonAncestorContainer() const { | |
124 return commonAncestorContainerNode<Strategy>( | |
125 m_startPosition.computeContainerNode(), | |
126 m_endPosition.computeContainerNode()); | |
127 } | |
128 | |
129 template <typename Strategy> | |
112 bool EphemeralRangeTemplate<Strategy>::isCollapsed() const { | 130 bool EphemeralRangeTemplate<Strategy>::isCollapsed() const { |
113 DCHECK(isValid()); | 131 DCHECK(isValid()); |
114 return m_startPosition == m_endPosition; | 132 return m_startPosition == m_endPosition; |
115 } | 133 } |
116 | 134 |
117 template <typename Strategy> | 135 template <typename Strategy> |
118 typename EphemeralRangeTemplate<Strategy>::RangeTraversal | 136 typename EphemeralRangeTemplate<Strategy>::RangeTraversal |
119 EphemeralRangeTemplate<Strategy>::nodes() const { | 137 EphemeralRangeTemplate<Strategy>::nodes() const { |
120 return RangeTraversal(m_startPosition.nodeAsRangeFirstNode(), | 138 return RangeTraversal(m_startPosition.nodeAsRangeFirstNode(), |
121 m_endPosition.nodeAsRangePastLastNode()); | 139 m_endPosition.nodeAsRangePastLastNode()); |
(...skipping 25 matching lines...) Expand all Loading... | |
147 return nullptr; | 165 return nullptr; |
148 return Range::create(range.document(), range.startPosition(), | 166 return Range::create(range.document(), range.startPosition(), |
149 range.endPosition()); | 167 range.endPosition()); |
150 } | 168 } |
151 | 169 |
152 template class CORE_TEMPLATE_EXPORT EphemeralRangeTemplate<EditingStrategy>; | 170 template class CORE_TEMPLATE_EXPORT EphemeralRangeTemplate<EditingStrategy>; |
153 template class CORE_TEMPLATE_EXPORT | 171 template class CORE_TEMPLATE_EXPORT |
154 EphemeralRangeTemplate<EditingInFlatTreeStrategy>; | 172 EphemeralRangeTemplate<EditingInFlatTreeStrategy>; |
155 | 173 |
156 } // namespace blink | 174 } // namespace blink |
OLD | NEW |