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

Side by Side Diff: third_party/WebKit/Source/core/editing/EphemeralRange.cpp

Issue 2725603002: createFragmentFromMarkupWithContext() should use EphemeralRange. (Closed)
Patch Set: Addressed Review Comments Created 3 years, 9 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 unified diff | Download patch
OLDNEW
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 template <typename Strategy>
16 Node* commonAncestorContainerNode(const Node* containerA,
17 const Node* containerB) {
18 if (!containerA || !containerB)
19 return nullptr;
20 return Strategy::commonAncestor(*containerA, *containerB);
21 }
22 }
23
14 template <typename Strategy> 24 template <typename Strategy>
15 EphemeralRangeTemplate<Strategy>::EphemeralRangeTemplate( 25 EphemeralRangeTemplate<Strategy>::EphemeralRangeTemplate(
16 const PositionTemplate<Strategy>& start, 26 const PositionTemplate<Strategy>& start,
17 const PositionTemplate<Strategy>& end) 27 const PositionTemplate<Strategy>& end)
18 : m_startPosition(start), 28 : m_startPosition(start),
19 m_endPosition(end) 29 m_endPosition(end)
20 #if DCHECK_IS_ON() 30 #if DCHECK_IS_ON()
21 , 31 ,
22 m_domTreeVersion(start.isNull() ? 0 : start.document()->domTreeVersion()) 32 m_domTreeVersion(start.isNull() ? 0 : start.document()->domTreeVersion())
23 #endif 33 #endif
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 112 }
103 113
104 template <typename Strategy> 114 template <typename Strategy>
105 PositionTemplate<Strategy> EphemeralRangeTemplate<Strategy>::endPosition() 115 PositionTemplate<Strategy> EphemeralRangeTemplate<Strategy>::endPosition()
106 const { 116 const {
107 DCHECK(isValid()); 117 DCHECK(isValid());
108 return m_endPosition; 118 return m_endPosition;
109 } 119 }
110 120
111 template <typename Strategy> 121 template <typename Strategy>
122 Node* EphemeralRangeTemplate<Strategy>::commonAncestorContainer() const {
123 return commonAncestorContainerNode<Strategy>(
124 m_startPosition.computeContainerNode(),
125 m_endPosition.computeContainerNode());
126 }
127
128 template <typename Strategy>
112 bool EphemeralRangeTemplate<Strategy>::isCollapsed() const { 129 bool EphemeralRangeTemplate<Strategy>::isCollapsed() const {
113 DCHECK(isValid()); 130 DCHECK(isValid());
114 return m_startPosition == m_endPosition; 131 return m_startPosition == m_endPosition;
115 } 132 }
116 133
117 template <typename Strategy> 134 template <typename Strategy>
118 typename EphemeralRangeTemplate<Strategy>::RangeTraversal 135 typename EphemeralRangeTemplate<Strategy>::RangeTraversal
119 EphemeralRangeTemplate<Strategy>::nodes() const { 136 EphemeralRangeTemplate<Strategy>::nodes() const {
120 return RangeTraversal(m_startPosition.nodeAsRangeFirstNode(), 137 return RangeTraversal(m_startPosition.nodeAsRangeFirstNode(),
121 m_endPosition.nodeAsRangePastLastNode()); 138 m_endPosition.nodeAsRangePastLastNode());
(...skipping 25 matching lines...) Expand all
147 return nullptr; 164 return nullptr;
148 return Range::create(range.document(), range.startPosition(), 165 return Range::create(range.document(), range.startPosition(),
149 range.endPosition()); 166 range.endPosition());
150 } 167 }
151 168
152 template class CORE_TEMPLATE_EXPORT EphemeralRangeTemplate<EditingStrategy>; 169 template class CORE_TEMPLATE_EXPORT EphemeralRangeTemplate<EditingStrategy>;
153 template class CORE_TEMPLATE_EXPORT 170 template class CORE_TEMPLATE_EXPORT
154 EphemeralRangeTemplate<EditingInFlatTreeStrategy>; 171 EphemeralRangeTemplate<EditingInFlatTreeStrategy>;
155 172
156 } // namespace blink 173 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/EphemeralRange.h ('k') | third_party/WebKit/Source/core/editing/EphemeralRangeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698