Chromium Code Reviews| Index: Source/core/editing/SurroundingText.cpp |
| diff --git a/Source/core/editing/SurroundingText.cpp b/Source/core/editing/SurroundingText.cpp |
| index cefe4005a39eb0a239b7d95b177dff9a0aeb1182..1d23c6ab5afeaa08a82ad89ca7054f71bee38ff9 100644 |
| --- a/Source/core/editing/SurroundingText.cpp |
| +++ b/Source/core/editing/SurroundingText.cpp |
| @@ -32,38 +32,48 @@ |
| #include "core/editing/SurroundingText.h" |
| #include "core/dom/Document.h" |
| +#include "core/dom/Position.h" |
| #include "core/dom/Range.h" |
| #include "core/editing/TextIterator.h" |
| -#include "core/editing/VisiblePosition.h" |
| -#include "core/editing/VisibleUnits.h" |
| namespace WebCore { |
| -SurroundingText::SurroundingText(const VisiblePosition& visiblePosition, unsigned maxLength) |
| +SurroundingText::SurroundingText(const Position& position, unsigned maxLength) |
| : m_positionOffsetInContent(0) |
| { |
| - if (visiblePosition.isNull()) |
| + if (position.isNull()) |
| return; |
| const unsigned halfMaxLength = maxLength / 2; |
| - CharacterIterator forwardIterator(makeRange(visiblePosition, endOfDocument(visiblePosition)).get(), TextIteratorStopsOnFormControls); |
| - if (!forwardIterator.atEnd()) |
| - forwardIterator.advance(maxLength - halfMaxLength); |
| - Position position = visiblePosition.deepEquivalent().parentAnchoredEquivalent(); |
| Document* document = position.document(); |
| ASSERT(document); |
|
yosin_UTC9
2014/06/04 01:04:05
nit: We don't need to have this |ASSERT(document)|
yosin_UTC9
2014/06/04 01:13:10
How about unify |Position::isNull| and |Position::
mlamouri (slow - plz ping)
2014/06/04 09:52:12
Done.
|
| - RefPtrWillBeRawPtr<Range> forwardRange = forwardIterator.range(); |
| + |
| + // The forward range starts at the selection end and ends at the document's |
| + // end. It will then be updated to only contain the text in the text in the |
| + // right range around the selection. |
| + RefPtrWillBeRawPtr<Range> forwardRange = rangeOfContents(document); |
| + forwardRange->setStart(position); |
| + CharacterIterator forwardIterator(forwardRange.get(), TextIteratorStopsOnFormControls); |
| + if (!forwardIterator.atEnd()) |
| + forwardIterator.advance(maxLength - halfMaxLength); |
| + |
| + forwardRange = forwardIterator.range(); |
| if (!forwardRange || !Range::create(*document, position, forwardRange->startPosition())->text().length()) { |
| ASSERT(forwardRange); |
| return; |
| } |
| - BackwardsCharacterIterator backwardsIterator(makeRange(startOfDocument(visiblePosition), visiblePosition).get(), TextIteratorStopsOnFormControls); |
| + // Same as with the forward range but with the backward range. The range |
| + // starts at the document's start and ends at the selection start and will |
| + // be updated. |
| + RefPtrWillBeRawPtr<Range> backwardsRange = rangeOfContents(document); |
| + backwardsRange->setEnd(position); |
| + BackwardsCharacterIterator backwardsIterator(backwardsRange.get(), TextIteratorStopsOnFormControls); |
| if (!backwardsIterator.atEnd()) |
| backwardsIterator.advance(halfMaxLength); |
| - RefPtrWillBeRawPtr<Range> backwardsRange = backwardsIterator.range(); |
| + backwardsRange = backwardsIterator.range(); |
| if (!backwardsRange) { |
| ASSERT(backwardsRange); |
| return; |