diff options
author | Steve Block <steveblock@google.com> | 2010-04-27 16:31:00 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2010-05-11 14:42:12 +0100 |
commit | dcc8cf2e65d1aa555cce12431a16547e66b469ee (patch) | |
tree | 92a8d65cd5383bca9749f5327fb5e440563926e6 /WebCore/editing/TextIterator.cpp | |
parent | ccac38a6b48843126402088a309597e682f40fe6 (diff) | |
download | external_webkit-dcc8cf2e65d1aa555cce12431a16547e66b469ee.zip external_webkit-dcc8cf2e65d1aa555cce12431a16547e66b469ee.tar.gz external_webkit-dcc8cf2e65d1aa555cce12431a16547e66b469ee.tar.bz2 |
Merge webkit.org at r58033 : Initial merge by git
Change-Id: If006c38561af287c50cd578d251629b51e4d8cd1
Diffstat (limited to 'WebCore/editing/TextIterator.cpp')
-rw-r--r-- | WebCore/editing/TextIterator.cpp | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/WebCore/editing/TextIterator.cpp b/WebCore/editing/TextIterator.cpp index 923f537..e022e3b 100644 --- a/WebCore/editing/TextIterator.cpp +++ b/WebCore/editing/TextIterator.cpp @@ -256,10 +256,11 @@ TextIterator::TextIterator() , m_lastCharacter(0) , m_emitCharactersBetweenAllVisiblePositions(false) , m_enterTextControls(false) + , m_emitsTextWithoutTranscoding(false) { } -TextIterator::TextIterator(const Range* r, bool emitCharactersBetweenAllVisiblePositions, bool enterTextControls) +TextIterator::TextIterator(const Range* r, bool emitCharactersBetweenAllVisiblePositions, bool enterTextControls) : m_startContainer(0) , m_startOffset(0) , m_endContainer(0) @@ -269,6 +270,27 @@ TextIterator::TextIterator(const Range* r, bool emitCharactersBetweenAllVisibleP , m_textLength(0) , m_emitCharactersBetweenAllVisiblePositions(emitCharactersBetweenAllVisiblePositions) , m_enterTextControls(enterTextControls) + , m_emitsTextWithoutTranscoding(false) +{ + init(r); +} + +TextIterator::TextIterator(const Range* r, TextIteratorBehavior behavior) + : m_startContainer(0) + , m_startOffset(0) + , m_endContainer(0) + , m_endOffset(0) + , m_positionNode(0) + , m_textCharacters(0) + , m_textLength(0) + , m_emitCharactersBetweenAllVisiblePositions(behavior & TextIteratorBehaviorEmitCharactersBetweenAllVisiblePositions) + , m_enterTextControls(behavior & TextIteratorBehaviorEnterTextControls) + , m_emitsTextWithoutTranscoding(behavior & TextIteratorBehaviorEmitsTextsWithoutTranscoding) +{ + init(r); +} + +void TextIterator::init(const Range* r) { if (!r) return; @@ -889,7 +911,7 @@ void TextIterator::emitCharacter(UChar c, Node* textNode, Node* offsetBaseNode, void TextIterator::emitText(Node* textNode, int textStartOffset, int textEndOffset) { RenderText* renderer = toRenderText(m_node->renderer()); - String str = renderer->text(); + String str = m_emitsTextWithoutTranscoding ? renderer->textWithoutTranscoding() : renderer->text(); ASSERT(str.characters()); m_positionNode = textNode; @@ -2037,16 +2059,25 @@ PassRefPtr<Range> TextIterator::rangeFromLocationAndLength(Element* scope, int r // Fix textRunRange->endPosition(), but only if foundStart || foundEnd, because it is only // in those cases that textRunRange is used. - if (foundStart || foundEnd) { + if (foundEnd) { // FIXME: This is a workaround for the fact that the end of a run is often at the wrong // position for emitted '\n's. if (len == 1 && it.characters()[0] == '\n') { - Position runStart = textRunRange->startPosition(); - Position runEnd = VisiblePosition(runStart).next().deepEquivalent(); - if (runEnd.isNotNull()) { + scope->document()->updateLayoutIgnorePendingStylesheets(); + it.advance(); + if (!it.atEnd()) { + RefPtr<Range> range = it.range(); ExceptionCode ec = 0; - textRunRange->setEnd(runEnd.node(), runEnd.deprecatedEditingOffset(), ec); + textRunRange->setEnd(range->startContainer(), range->startOffset(), ec); ASSERT(!ec); + } else { + Position runStart = textRunRange->startPosition(); + Position runEnd = VisiblePosition(runStart).next().deepEquivalent(); + if (runEnd.isNotNull()) { + ExceptionCode ec = 0; + textRunRange->setEnd(runEnd.node(), runEnd.deprecatedEditingOffset(), ec); + ASSERT(!ec); + } } } } @@ -2095,7 +2126,7 @@ PassRefPtr<Range> TextIterator::rangeFromLocationAndLength(Element* scope, int r // -------- -UChar* plainTextToMallocAllocatedBuffer(const Range* r, unsigned& bufferLength, bool isDisplayString) +UChar* plainTextToMallocAllocatedBuffer(const Range* r, unsigned& bufferLength, bool isDisplayString) { UChar* result = 0; @@ -2107,7 +2138,7 @@ UChar* plainTextToMallocAllocatedBuffer(const Range* r, unsigned& bufferLength, Vector<TextSegment>* textSegments = 0; Vector<UChar> textBuffer; textBuffer.reserveInitialCapacity(cMaxSegmentSize); - for (TextIterator it(r); !it.atEnd(); it.advance()) { + for (TextIterator it(r, isDisplayString ? TextIteratorBehaviorDefault : TextIteratorBehaviorEmitsTextsWithoutTranscoding); !it.atEnd(); it.advance()) { if (textBuffer.size() && textBuffer.size() + it.length() > cMaxSegmentSize) { UChar* newSegmentBuffer = static_cast<UChar*>(malloc(textBuffer.size() * sizeof(UChar))); if (!newSegmentBuffer) |