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

Unified Diff: Source/core/editing/TextIterator.cpp

Issue 576073003: Removal of more temporary Range objects. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix build; accidentally removed .get() call Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/editing/TextIterator.h ('k') | Source/core/editing/VisiblePosition.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/TextIterator.cpp
diff --git a/Source/core/editing/TextIterator.cpp b/Source/core/editing/TextIterator.cpp
index 6dbacf33703c2168d0f513fa614a98d9c101d2b3..f806c98df89e1187bd7e88b26f7ffa9211a591ee 100644
--- a/Source/core/editing/TextIterator.cpp
+++ b/Source/core/editing/TextIterator.cpp
@@ -1849,9 +1849,9 @@ void BackwardsCharacterIterator::advance(int count)
// --------
-WordAwareIterator::WordAwareIterator(const Range* range)
+WordAwareIterator::WordAwareIterator(const Position& start, const Position& end)
: m_didLookAhead(true) // So we consider the first chunk from the text iterator.
- , m_textIterator(range)
+ , m_textIterator(start, end)
{
advance(); // Get in position over the first chunk of text.
}
@@ -2242,6 +2242,18 @@ int TextIterator::rangeLength(const Range* r, bool forSelectionPreservation)
return length;
}
+int TextIterator::rangeLength(const Position& start, const Position& end, bool forSelectionPreservation)
+{
+ int length = 0;
+ TextIteratorBehaviorFlags behaviorFlags = TextIteratorEmitsObjectReplacementCharacter;
+ if (forSelectionPreservation)
+ behaviorFlags |= TextIteratorEmitsCharactersBetweenAllVisiblePositions;
+ for (TextIterator it(start, end, behaviorFlags); !it.atEnd(); it.advance())
+ length += it.length();
+
+ return length;
+}
+
PassRefPtrWillBeRawPtr<Range> TextIterator::subrange(Range* entireRange, int characterOffset, int characterCount)
{
CharacterIterator entireRangeIterator(entireRange);
@@ -2251,9 +2263,15 @@ PassRefPtrWillBeRawPtr<Range> TextIterator::subrange(Range* entireRange, int cha
return Range::create(entireRange->ownerDocument(), start, end);
}
+void TextIterator::subrange(Position& start, Position& end, int characterOffset, int characterCount)
+{
+ CharacterIterator entireRangeIterator(start, end);
+ calculateCharacterSubrange(entireRangeIterator, characterOffset, characterCount, start, end);
+}
+
// --------
-String plainText(const Range* r, TextIteratorBehaviorFlags behavior)
+static String createPlainText(TextIterator& it)
{
// The initial buffer size can be critical for performance: https://bugs.webkit.org/show_bug.cgi?id=81192
static const unsigned initialCapacity = 1 << 15;
@@ -2262,7 +2280,7 @@ String plainText(const Range* r, TextIteratorBehaviorFlags behavior)
StringBuilder builder;
builder.reserveCapacity(initialCapacity);
- for (TextIterator it(r, behavior); !it.atEnd(); it.advance()) {
+ for (; !it.atEnd(); it.advance()) {
it.appendTextToStringBuilder(builder);
bufferLength += it.length();
}
@@ -2273,6 +2291,18 @@ String plainText(const Range* r, TextIteratorBehaviorFlags behavior)
return builder.toString();
}
+String plainText(const Range* r, TextIteratorBehaviorFlags behavior)
+{
+ TextIterator it(r, behavior);
+ return createPlainText(it);
+}
+
+String plainText(const Position& start, const Position& end, TextIteratorBehaviorFlags behavior)
+{
+ TextIterator it(start, end, behavior);
+ return createPlainText(it);
+}
+
static PassRefPtrWillBeRawPtr<Range> collapsedToBoundary(const Range* range, bool forward)
{
RefPtrWillBeRawPtr<Range> result = range->cloneRange();
« no previous file with comments | « Source/core/editing/TextIterator.h ('k') | Source/core/editing/VisiblePosition.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698