Index: Source/core/editing/TextIterator.cpp |
diff --git a/Source/core/editing/TextIterator.cpp b/Source/core/editing/TextIterator.cpp |
index 3c452ce0bcb46bf8bd74f4379d47a8edb93838d9..2120c104c1d30bc9f379d2d4c7befa6f28da19ad 100644 |
--- a/Source/core/editing/TextIterator.cpp |
+++ b/Source/core/editing/TextIterator.cpp |
@@ -247,9 +247,15 @@ TextIterator::TextIterator(const Range* range, TextIteratorBehaviorFlags behavio |
, m_endOffset(0) |
, m_positionNode(0) |
, m_textLength(0) |
+ , m_needsAnotherNewline(false) |
+ , m_textBox(0) |
, m_remainingTextBox(0) |
, m_firstLetterText(0) |
+ , m_lastTextNode(0) |
+ , m_lastTextNodeEndedWithCollapsedSpace(false) |
+ , m_lastCharacter(0) |
, m_sortedTextBoxesPosition(0) |
+ , m_hasEmitted(false) |
, m_emitsCharactersBetweenAllVisiblePositions(behavior & TextIteratorEmitsCharactersBetweenAllVisiblePositions) |
, m_entersTextControls(behavior & TextIteratorEntersTextControls) |
, m_emitsOriginalText(behavior & TextIteratorEmitsOriginalText) |
@@ -260,49 +266,81 @@ TextIterator::TextIterator(const Range* range, TextIteratorBehaviorFlags behavio |
, m_emitsImageAltText(behavior & TextIteratorEmitsImageAltText) |
, m_entersAuthorShadowRoots(behavior & TextIteratorEntersAuthorShadowRoots) |
{ |
- if (!range) |
- return; |
+ if (range) |
+ initialize(range->startPosition(), range->endPosition()); |
+} |
+ |
+TextIterator::TextIterator(const Position& start, const Position& end, TextIteratorBehaviorFlags behavior) |
+ : m_shadowDepth(0) |
+ , m_startContainer(0) |
+ , m_startOffset(0) |
+ , m_endContainer(0) |
+ , m_endOffset(0) |
+ , m_positionNode(0) |
+ , m_textLength(0) |
+ , m_needsAnotherNewline(false) |
+ , m_textBox(0) |
+ , m_remainingTextBox(0) |
+ , m_firstLetterText(0) |
+ , m_lastTextNode(0) |
+ , m_lastTextNodeEndedWithCollapsedSpace(false) |
+ , m_lastCharacter(0) |
+ , m_sortedTextBoxesPosition(0) |
+ , m_hasEmitted(false) |
+ , m_emitsCharactersBetweenAllVisiblePositions(behavior & TextIteratorEmitsCharactersBetweenAllVisiblePositions) |
+ , m_entersTextControls(behavior & TextIteratorEntersTextControls) |
+ , m_emitsOriginalText(behavior & TextIteratorEmitsOriginalText) |
+ , m_handledFirstLetter(false) |
+ , m_ignoresStyleVisibility(behavior & TextIteratorIgnoresStyleVisibility) |
+ , m_stopsOnFormControls(behavior & TextIteratorStopsOnFormControls) |
+ , m_shouldStop(false) |
+ , m_emitsImageAltText(behavior & TextIteratorEmitsImageAltText) |
+ , m_entersAuthorShadowRoots(behavior & TextIteratorEntersAuthorShadowRoots) |
yosin_UTC9
2014/03/26 01:08:02
Once Blink incorporate C++11 delegating constructo
Yuta Kitamura
2014/03/26 01:58:58
Yup; actually this long initializer list is kind o
|
+{ |
+ initialize(start, end); |
+} |
+ |
+void TextIterator::initialize(const Position& start, const Position& end) |
+{ |
+ ASSERT(comparePositions(start, end) <= 0); |
- // get and validate the range endpoints |
- Node* startContainer = range->startContainer(); |
+ // Get and validate |start| and |end|. |
+ Node* startContainer = start.containerNode(); |
if (!startContainer) |
return; |
- int startOffset = range->startOffset(); |
- Node* endContainer = range->endContainer(); |
- int endOffset = range->endOffset(); |
- |
- // Callers should be handing us well-formed ranges. If we discover that this isn't |
- // the case, we could consider changing this assertion to an early return. |
- ASSERT(range->boundaryPointsValid()); |
+ int startOffset = start.computeOffsetInContainerNode(); |
+ Node* endContainer = end.containerNode(); |
+ if (!endContainer) |
+ return; |
+ int endOffset = end.computeOffsetInContainerNode(); |
- // remember range - this does not change |
+ // Remember the range - this does not change. |
m_startContainer = startContainer; |
m_startOffset = startOffset; |
m_endContainer = endContainer; |
m_endOffset = endOffset; |
- // set up the current node for processing |
- m_node = range->firstNode(); |
+ // Set up the current node for processing. |
+ if (startContainer->offsetInCharacters()) |
+ m_node = startContainer; |
+ else if (Node* child = startContainer->traverseToChildAt(startOffset)) |
+ m_node = child; |
+ else if (!startOffset) |
+ m_node = startContainer; |
+ else |
+ m_node = NodeTraversal::nextSkippingChildren(*startContainer); |
+ |
if (!m_node) |
return; |
+ |
setUpFullyClippedStack(m_fullyClippedStack, m_node); |
m_offset = m_node == m_startContainer ? m_startOffset : 0; |
m_iterationProgress = HandledNone; |
- // calculate first out of bounds node |
+ // Calculate first out of bounds node. |
m_pastEndNode = nextInPreOrderCrossingShadowBoundaries(endContainer, endOffset); |
- // initialize node processing state |
- m_needsAnotherNewline = false; |
- m_textBox = 0; |
- |
- // initialize record of previous node processing |
- m_hasEmitted = false; |
- m_lastTextNode = 0; |
- m_lastTextNodeEndedWithCollapsedSpace = false; |
- m_lastCharacter = 0; |
- |
- // identify the first run |
+ // Identify the first run. |
advance(); |
} |