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

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

Issue 1409073004: Return EphemeralRange from Editor::findRangeOfString. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Extract text bounds collecting to a function Created 5 years, 1 month 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 "config.h" 5 #include "config.h"
6 #include "core/editing/EphemeralRange.h" 6 #include "core/editing/EphemeralRange.h"
7 7
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/dom/Element.h" 9 #include "core/dom/Element.h"
10 #include "core/dom/Range.h" 10 #include "core/dom/Range.h"
11 #include "core/dom/Text.h" 11 #include "core/dom/Text.h"
12 #include "core/editing/EditingUtilities.h"
13 #include "core/layout/LayoutText.h"
12 14
13 namespace blink { 15 namespace blink {
14 16
15 template <typename Strategy> 17 template <typename Strategy>
16 EphemeralRangeTemplate<Strategy>::EphemeralRangeTemplate(const PositionTemplate< Strategy>& start, const PositionTemplate<Strategy>& end) 18 EphemeralRangeTemplate<Strategy>::EphemeralRangeTemplate(const PositionTemplate< Strategy>& start, const PositionTemplate<Strategy>& end)
17 : m_startPosition(start) 19 : m_startPosition(start)
18 , m_endPosition(end) 20 , m_endPosition(end)
19 #if ENABLE(ASSERT) 21 #if ENABLE(ASSERT)
20 , m_domTreeVersion(start.isNull() ? 0 : start.document()->domTreeVersion()) 22 , m_domTreeVersion(start.isNull() ? 0 : start.document()->domTreeVersion())
21 #endif 23 #endif
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 ASSERT(isValid()); 118 ASSERT(isValid());
117 return m_startPosition == m_endPosition; 119 return m_startPosition == m_endPosition;
118 } 120 }
119 121
120 template <typename Strategy> 122 template <typename Strategy>
121 EphemeralRangeTemplate<Strategy> EphemeralRangeTemplate<Strategy>::rangeOfConten ts(const Node& node) 123 EphemeralRangeTemplate<Strategy> EphemeralRangeTemplate<Strategy>::rangeOfConten ts(const Node& node)
122 { 124 {
123 return EphemeralRangeTemplate<Strategy>(PositionTemplate<Strategy>::firstPos itionInNode(&const_cast<Node&>(node)), PositionTemplate<Strategy>::lastPositionI nNode(&const_cast<Node&>(node))); 125 return EphemeralRangeTemplate<Strategy>(PositionTemplate<Strategy>::firstPos itionInNode(&const_cast<Node&>(node)), PositionTemplate<Strategy>::lastPositionI nNode(&const_cast<Node&>(node)));
124 } 126 }
125 127
128 static IntRect uniteRects(const Vector<IntRect>& rects)
129 {
130 IntRect result;
131 for (const auto& rect : rects)
132 result.unite(rect);
133 return result;
134 }
135
136 template <typename Strategy>
137 IntRect EphemeralRangeTemplate<Strategy>::textBoundingBox() const
138 {
139 if (isCollapsed())
140 return IntRect();
141
142 Vector<IntRect> rects;
143 collectTextBoundsInRange(
144 m_startPosition, m_endPosition,
145 m_startPosition.nodeAsRangeFirstNode(), m_endPosition.nodeAsRangePastLas tNode(),
146 rects);
147
148 return uniteRects(rects);
149 }
150
126 #if ENABLE(ASSERT) 151 #if ENABLE(ASSERT)
127 template <typename Strategy> 152 template <typename Strategy>
128 bool EphemeralRangeTemplate<Strategy>::isValid() const 153 bool EphemeralRangeTemplate<Strategy>::isValid() const
129 { 154 {
130 return m_startPosition.isNull() || m_domTreeVersion == m_startPosition.docum ent()->domTreeVersion(); 155 return m_startPosition.isNull() || m_domTreeVersion == m_startPosition.docum ent()->domTreeVersion();
131 } 156 }
132 #else 157 #else
133 template <typename Strategy> 158 template <typename Strategy>
134 bool EphemeralRangeTemplate<Strategy>::isValid() const 159 bool EphemeralRangeTemplate<Strategy>::isValid() const
135 { 160 {
136 return true; 161 return true;
137 } 162 }
138 #endif 163 #endif
139 164
140 PassRefPtrWillBeRawPtr<Range> createRange(const EphemeralRange& range) 165 PassRefPtrWillBeRawPtr<Range> createRange(const EphemeralRange& range)
141 { 166 {
142 if (range.isNull()) 167 if (range.isNull())
143 return nullptr; 168 return nullptr;
144 return Range::create(range.document(), range.startPosition(), range.endPosit ion()); 169 return Range::create(range.document(), range.startPosition(), range.endPosit ion());
145 } 170 }
146 171
147 template class CORE_TEMPLATE_EXPORT EphemeralRangeTemplate<EditingStrategy>; 172 template class CORE_TEMPLATE_EXPORT EphemeralRangeTemplate<EditingStrategy>;
148 template class CORE_TEMPLATE_EXPORT EphemeralRangeTemplate<EditingInComposedTree Strategy>; 173 template class CORE_TEMPLATE_EXPORT EphemeralRangeTemplate<EditingInComposedTree Strategy>;
149 174
150 } // namespace blink 175 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698