Changeset 17276 in webkit
- Timestamp:
- Oct 24, 2006 6:37:04 PM (18 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r17234 r17276 1 2006-10-24 Justin Garcia <justin.garcia@apple.com> 2 3 Reviewed by darin 4 5 <http://bugs.webkit.org/show_bug.cgi?id=10993> 6 GMail Editor: Caret doesn't always position itself after list marker 7 8 * editing/execCommand/create-list-1-expected.checksum: Added. 9 * editing/execCommand/create-list-1-expected.png: Added. 10 * editing/execCommand/create-list-1-expected.txt: Added. 11 * editing/execCommand/create-list-1.html: Added. 12 13 Fixed: 14 * editing/execCommand/create-list-with-hr-expected.checksum: 15 * editing/execCommand/create-list-with-hr-expected.png: 16 * editing/execCommand/create-list-with-hr-expected.txt: 17 * editing/execCommand/create-list-with-hr.html: 18 * editing/execCommand/remove-list-1-expected.checksum: 19 * editing/execCommand/remove-list-1-expected.png: 20 * editing/execCommand/remove-list-1-expected.txt: 21 * fast/text/attributed-substring-from-range-001-expected.txt: 22 1 23 2006-10-23 Justin Garcia <justin.garcia@apple.com> 2 24 -
trunk/LayoutTests/editing/execCommand/create-list-with-hr-expected.checksum
r16746 r17276 1 1a920b25e56e869eaa3be7e22932cd09 1 f557f6e45eb1c0240e2e0e6edfa6b0cc -
trunk/LayoutTests/editing/execCommand/create-list-with-hr-expected.txt
r16746 r17276 3 3 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 4 4 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 5 EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 49 of #text > B > P > BODY > HTML > #document to 49 of #text > B > P> BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE5 EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of DIV > LI > UL > DIV > BODY > HTML > #document to 0 of DIV > LI > UL > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE 6 6 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 7 7 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification … … 11 11 RenderBlock {HTML} at (0,0) size 800x600 12 12 RenderBody {BODY} at (8,8) size 784x576 13 RenderBlock {P} at (0,0) size 784x 5413 RenderBlock {P} at (0,0) size 784x36 14 14 RenderText {#text} at (0,0) size 514x18 15 15 text run at (0,0) width 514: "This test pushes a horizontal rule into an unordered list with InsertUnorderedList. " … … 17 17 RenderText {#text} at (514,0) size 771x36 18 18 text run at (514,0) width 257: "The fact that the horizontal rule is put" 19 text run at (0,18) width 544: "into an unnecessary div when it's pushed into the list might be considered a bug. " 20 RenderInline {B} at (0,0) size 726x36 21 RenderText {#text} at (544,18) size 726x36 22 text run at (544,18) width 182: "The fact that the caret isn't" 23 text run at (0,36) width 127: "preserved is a bug." 24 RenderBlock {DIV} at (0,70) size 784x28 19 text run at (0,18) width 540: "into an unnecessary div when it's pushed into the list might be considered a bug." 20 RenderBlock {DIV} at (0,52) size 784x28 25 21 RenderBlock {UL} at (0,0) size 784x28 26 22 RenderListItem {LI} at (40,0) size 744x28 … … 31 27 RenderBlock (anonymous) at (0,36) size 744x0 32 28 RenderBlock (anonymous) at (0,44) size 784x0 33 caret: position 49 of child 0 {#text} of child 2 {B} of child 0 {P} of child 0 {BODY} of child 0 {HTML} of document29 caret: position 0 of child 0 {HR} of child 0 {DIV} of child 0 {LI} of child 0 {UL} of child 2 {DIV} of child 0 {BODY} of child 0 {HTML} of document -
trunk/LayoutTests/editing/execCommand/create-list-with-hr.html
r16728 r17276 1 <p>This test pushes a horizontal rule into an unordered list with InsertUnorderedList. <b>The fact that the horizontal rule is put into an unnecessary div when it's pushed into the list might be considered a bug. </b><b>The fact that the caret isn't preserved is a bug.</b></p>1 <p>This test pushes a horizontal rule into an unordered list with InsertUnorderedList. <b>The fact that the horizontal rule is put into an unnecessary div when it's pushed into the list might be considered a bug.</b></p> 2 2 <div contenteditable="true" id="div"><hr></div> 3 3 -
trunk/LayoutTests/editing/execCommand/remove-list-1-expected.checksum
r17114 r17276 1 958726dee6c5c5c73089d158c46f17c5 1 2b441a195ceda3a506ff2bb266cbe8a2 -
trunk/LayoutTests/editing/execCommand/remove-list-1-expected.txt
r17114 r17276 5 5 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of LI > OL > DIV > BODY > HTML > #document to 49 of #text > LI > OL > DIV > BODY > HTML > #document toDOMRange:range from 0 of LI > OL > DIV > BODY > HTML > #document to 49 of #text > LI > OL > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE 6 6 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 7 EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 ofDIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE7 EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of DIV > BODY > HTML > #document to 49 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE 8 8 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 9 9 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification … … 24 24 RenderText {#text} at (0,18) size 322x18 25 25 text run at (0,18) width 322: "There should be a empty paragraph above this one." 26 caret: position 0 of child 0 {BR} of child 2 {DIV} of child 0 {BODY} of child 0 {HTML} of document 26 selection start: position 0 of child 0 {BR} of child 2 {DIV} of child 0 {BODY} of child 0 {HTML} of document 27 selection end: position 49 of child 1 {#text} of child 2 {DIV} of child 0 {BODY} of child 0 {HTML} of document -
trunk/LayoutTests/fast/text/attributed-substring-from-range-001-expected.txt
r16642 r17276 9 9 (1, 1): h{ NSColor = NSCalibratedWhiteColorSpace 0 1; NSFont = "Times-Roman 16.00 pt. S [] (0xXXXXXXXX) fobj=0xXXXXXXXX, spc=4.00"; } 10 10 (1, 5): hello{ NSColor = NSCalibratedWhiteColorSpace 0 1; NSFont = "Times-Roman 16.00 pt. S [] (0xXXXXXXXX) fobj=0xXXXXXXXX, spc=4.00"; } 11 (1, 6): hello{ NSColor = NSCalibratedWhiteColorSpace 0 1; NSFont = "Times-Roman 16.00 pt. S [] (0xXXXXXXXX) fobj=0xXXXXXXXX, spc=4.00"; } {}12 (1, 100): hello{ NSColor = NSCalibratedWhiteColorSpace 0 1; NSFont = "Times-Roman 16.00 pt. S [] (0xXXXXXXXX) fobj=0xXXXXXXXX, spc=4.00"; } {}13 (6, 1): {}11 (1, 6): hello{ NSColor = NSCalibratedWhiteColorSpace 0 1; NSFont = "Times-Roman 16.00 pt. S [] (0xXXXXXXXX) fobj=0xXXXXXXXX, spc=4.00"; } 12 (1, 100): hello{ NSColor = NSCalibratedWhiteColorSpace 0 1; NSFont = "Times-Roman 16.00 pt. S [] (0xXXXXXXXX) fobj=0xXXXXXXXX, spc=4.00"; } 13 (6, 1): 14 14 (7, 1): 15 15 (100, 0): undefined -
trunk/WebCore/ChangeLog
r17273 r17276 1 2006-10-24 Justin Garcia <justin.garcia@apple.com> 2 3 Reviewed by darin 4 5 <http://bugs.webkit.org/show_bug.cgi?id=10993> 6 GMail Editor: Caret doesn't always position itself after list marker 7 8 List creation uses moveParagraphs to push content into list items. 9 moveParagraphs uses a TextIterator to restore selections after moves. 10 Some characters emitted by the TextIterator had bad ranges associated 11 with them. rangeFromLocationAndLength would skip past the range it 12 should have used when asked for ranges of length 0. 13 14 * editing/TextIterator.cpp: 15 (WebCore::TextIterator::TextIterator): No longer need to initialize a 16 removed member variable. 17 (WebCore::TextIterator::advance): An extra newline is emitted when leaving 18 some blocks. Use the same range for this newline as for the first newline. 19 We should remove this code and just emit two '\n's. 20 (WebCore::TextIterator::handleTextNode): Setup m_range. 21 (WebCore::TextIterator::handleTextBox): Ditto. 22 (WebCore::TextIterator::handleReplacedElement): Ditto. 23 (WebCore::TextIterator::handleNonTextNode): Ditto. 24 (WebCore::TextIterator::exitNode): Use an m_range from the last VisiblePosition 25 in the block we're leaving to that VP after that one. 26 (WebCore::TextIterator::emitCharacter): This function now takes in the start 27 and the end of the range associated with the emited character, and sets up m_range. 28 (WebCore::TextIterator::range): Return m_range. If it is null (we are atEnd), 29 return the end of the range used to create the iterator, as a convenience to 30 callers that use call range() on an iterator that is atEnd. 31 (WebCore::SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator): 32 Same as the changes made to TextIterator's constructor. 33 (WebCore::SimplifiedBackwardsTextIterator::advance): Use a null m_range instead of 34 a null m_positionNode to signal that we're finished. 35 (WebCore::SimplifiedBackwardsTextIterator::handleTextNode): Ditto. 36 (WebCore::SimplifiedBackwardsTextIterator::handleReplacedElement): Similar to changes 37 made to TextIterator. 38 (WebCore::SimplifiedBackwardsTextIterator::emitCharacter): Ditto. 39 (WebCore::SimplifiedBackwardsTextIterator::emitNewline): Simplified. 40 (WebCore::SimplifiedBackwardsTextIterator::range): Similar to the changes made to 41 TextIterator::range. 42 (WebCore::CharacterIterator::range): This function assumed that an iterator's 43 range() was safe to modify. 44 (WebCore::TextIterator::rangeFromLocationAndLength): 45 If the range we're looking for starts in the current chunk, this function assumed 46 that if the chunk started in a text node, it would end in the same text node. This 47 is no longer the case. 48 If the range we're looking for starts in the middle of the current chunk, I assume 49 that the chunk is inside a text node, because those are the only chunks with length 50 greater than one at the moment. 51 If the range we're looking for is a zero length range that starts/ends at the end of the 52 current chunk, we used to return the start of the next chunk, but that's wrong and 53 is what caused this bug. 54 * editing/TextIterator.h: 55 (WebCore::TextIterator::atEnd): The iterator is atEnd when m_range is null. 56 (WebCore::SimplifiedBackwardsTextIterator::atEnd): 57 * editing/visible_units.cpp: 58 (WebCore::previousBoundary): Cleaned up by using a convenience function. 59 (WebCore::nextBoundary): Ditto. 60 1 61 2006-10-24 Anders Carlsson <acarlsson@apple.com> 2 62 -
trunk/WebCore/editing/TextIterator.cpp
r16737 r17276 74 74 }; 75 75 76 TextIterator::TextIterator() : m_endContainer(0), m_endOffset(0), m_ positionNode(0), m_lastCharacter(0)77 { 78 } 79 80 TextIterator::TextIterator(const Range *r, IteratorKind kind) : m_endContainer(0), m_endOffset(0) , m_positionNode(0)76 TextIterator::TextIterator() : m_endContainer(0), m_endOffset(0), m_lastCharacter(0) 77 { 78 } 79 80 TextIterator::TextIterator(const Range *r, IteratorKind kind) : m_endContainer(0), m_endOffset(0) 81 81 { 82 82 if (!r) … … 121 121 122 122 #ifndef NDEBUG 123 // need this just because of the assert in advance()124 m_ positionNode = m_node;123 // Need this just because of the assert in advance(). 124 m_range = new Range(m_node->document(), Position(m_node, 0), Position(m_node, 0)); 125 125 #endif 126 126 … … 132 132 { 133 133 // reset the run information 134 m_ positionNode = 0;134 m_range = 0; 135 135 m_textLength = 0; 136 136 137 137 // handle remembered node that needed a newline after the text node's newline 138 138 if (m_needAnotherNewline) { 139 // emit the newline, with position a collapsed range at the end of current node. 140 emitCharacter('\n', m_node->parentNode(), m_node, 1, 1); 139 VisiblePosition lastInNode(Position(m_node, maxDeepOffset(m_node))); 140 VisiblePosition next = lastInNode.next(); 141 Position start = lastInNode.deepEquivalent(); 142 Position end = next.isNull() ? start : next.deepEquivalent(); 143 emitCharacter('\n', start, end); 141 144 m_needAnotherNewline = false; 142 145 return; … … 146 149 if (m_textBox) { 147 150 handleTextBox(); 148 if (m_ positionNode)151 if (m_range) 149 152 return; 150 153 } … … 163 166 } else 164 167 m_handledNode = handleNonTextNode(); 165 if (m_ positionNode)168 if (m_range) 166 169 return; 167 170 } … … 179 182 m_node = m_node->parentNode(); 180 183 exitNode(); 181 if (m_ positionNode) {184 if (m_range) { 182 185 m_handledNode = true; 183 186 m_handledChildren = true; … … 194 197 m_handledChildren = false; 195 198 196 // how would this ever be?197 if (m_ positionNode)199 // FIXME: How would this ever be? 200 if (m_range) 198 201 return; 199 202 } … … 216 219 int runStart = m_offset; 217 220 if (m_lastTextNodeEndedWithCollapsedSpace) { 218 emitCharacter(' ', m_node, 0, runStart, runStart);221 emitCharacter(' ', Position(m_node, runStart), Position(m_node, runStart)); 219 222 return false; 220 223 } … … 226 229 return true; 227 230 228 m_positionNode = m_node; 229 m_positionOffsetBaseNode = 0; 230 m_positionStartOffset = runStart; 231 m_positionEndOffset = runEnd; 231 m_range = new Range(m_node->document(), Position(m_node, runStart), Position(m_node, runEnd)); 232 232 233 m_textCharacters = str.characters() + runStart; 233 234 m_textLength = runEnd - runStart; … … 273 274 || (m_textBox == firstTextBox && textBoxStart == runStart && runStart > 0); 274 275 if (needSpace && !isCollapsibleWhitespace(m_lastCharacter) && m_lastCharacter) { 275 emitCharacter(' ', m_node, 0, runStart, runStart);276 emitCharacter(' ', Position(m_node, runStart), Position(m_node, runStart)); 276 277 return; 277 278 } … … 292 293 // This effectively translates newlines to spaces without copying the text. 293 294 if (str[runStart] == '\n') { 294 emitCharacter(' ', m_node, 0, runStart, runStart + 1);295 emitCharacter(' ', Position(m_node, runStart), Position(m_node, runStart + 1)); 295 296 m_offset = runStart + 1; 296 297 } else { … … 301 302 m_offset = subrunEnd; 302 303 303 m_positionNode = m_node; 304 m_positionOffsetBaseNode = 0; 305 m_positionStartOffset = runStart; 306 m_positionEndOffset = subrunEnd; 304 m_range = new Range(m_node->document(), Position(m_node, runStart), Position(m_node, subrunEnd)); 307 305 m_textCharacters = str.characters() + runStart; 308 306 m_textLength = subrunEnd - runStart; … … 314 312 // If we are doing a subrun that doesn't go to the end of the text box, 315 313 // come back again to finish handling this text box; don't advance to the next one. 316 if (m_positionEndOffset < textBoxEnd) 314 ExceptionCode ec; 315 if (m_range->endOffset(ec) < textBoxEnd) 317 316 return; 318 317 … … 336 335 { 337 336 if (m_lastTextNodeEndedWithCollapsedSpace) { 338 emitCharacter(' ', m_lastTextNode->parentNode(), m_lastTextNode, 1, 1);337 emitCharacter(' ', positionAfterNode(m_lastTextNode), positionAfterNode(m_lastTextNode)); 339 338 return false; 340 339 } 341 340 342 m_positionNode = m_node->parentNode(); 343 m_positionOffsetBaseNode = m_node; 344 m_positionStartOffset = 0; 345 m_positionEndOffset = 1; 341 m_range = new Range(m_node->document(), positionBeforeNode(m_node), positionAfterNode(m_node)); 346 342 347 343 m_textCharacters = 0; … … 471 467 { 472 468 if (shouldEmitNewlineForNode(m_node)) { 473 emitCharacter('\n', m_node->parentNode(), m_node, 0, 1); 469 Position start = positionBeforeNode(m_node); 470 VisiblePosition next = VisiblePosition(start).next(); 471 Position end = next.isNull() ? start : next.deepEquivalent(); 472 emitCharacter('\n', start, end); 474 473 } else if (m_lastCharacter != '\n' && m_lastTextNode) { 475 // only add the tab or newline if not at the start of a line 474 // Only add the tab or newline if not at the start of a line. 475 // FIXME: The ranges for these emitted characters should be the part of the 476 // document that this imaginary character would occupy. 476 477 if (shouldEmitTabBeforeNode(m_node)) 477 emitCharacter('\t', m_lastTextNode->parentNode(), m_lastTextNode, 0, 1);478 emitCharacter('\t', positionBeforeNode(m_lastTextNode), positionAfterNode(m_lastTextNode)); 478 479 else if (shouldEmitNewlinesBeforeAndAfterNode(m_node)) 479 emitCharacter('\n', m_lastTextNode->parentNode(), m_lastTextNode, 0, 1);480 emitCharacter('\n', positionBeforeNode(m_lastTextNode), positionAfterNode(m_lastTextNode)); 480 481 else if (shouldEmitSpaceBeforeAndAfterNode(m_node)) 481 emitCharacter(' ', m_lastTextNode->parentNode(), m_lastTextNode, 0, 1);482 emitCharacter(' ', positionBeforeNode(m_lastTextNode), positionAfterNode(m_lastTextNode)); 482 483 } 483 484 … … 487 488 void TextIterator::exitNode() 488 489 { 490 VisiblePosition lastInNode(Position(m_node, maxDeepOffset(m_node))); 491 VisiblePosition next = lastInNode.next(); 492 Position start = lastInNode.deepEquivalent(); 493 Position end = next.isNull() ? start : next.deepEquivalent(); 494 489 495 if (m_lastTextNode && shouldEmitNewlinesBeforeAndAfterNode(m_node)) { 490 496 // use extra newline to represent margin bottom, as needed … … 492 498 493 499 if (m_lastCharacter != '\n') { 494 // insert a newline with a position following this block 495 emitCharacter('\n', m_node->parentNode(), m_node, 1, 1);500 501 emitCharacter('\n', start, end); 496 502 497 503 // remember whether to later add a newline for the current node … … 500 506 } else if (addNewline) { 501 507 // insert a newline with a position following this block 502 emitCharacter('\n', m_node->parentNode(), m_node, 1, 1);508 emitCharacter('\n', start, end); 503 509 } 504 510 } else if (shouldEmitSpaceBeforeAndAfterNode(m_node)) 505 emitCharacter(' ', m_node->parentNode(), m_node, 1, 1); 506 } 507 508 void TextIterator::emitCharacter(UChar c, Node *textNode, Node *offsetBaseNode, int textStartOffset, int textEndOffset) 509 { 510 // remember information with which to construct the TextIterator::range() 511 // NOTE: textNode is often not a text node, so the range will specify child nodes of positionNode 512 m_positionNode = textNode; 513 m_positionOffsetBaseNode = offsetBaseNode; 514 m_positionStartOffset = textStartOffset; 515 m_positionEndOffset = textEndOffset; 511 emitCharacter(' ', start, end); 512 } 513 514 void TextIterator::emitCharacter(UChar c, const Position& start, const Position& end) 515 { 516 m_range = start.isNull() ? 0 : new Range(start.node()->document(), start, end); 516 517 517 518 // remember information with which to construct the TextIterator::characters() and length() … … 527 528 PassRefPtr<Range> TextIterator::range() const 528 529 { 529 // use the current run information, if we have it 530 if (m_positionNode) { 531 if (m_positionOffsetBaseNode) { 532 int index = m_positionOffsetBaseNode->nodeIndex(); 533 m_positionStartOffset += index; 534 m_positionEndOffset += index; 535 m_positionOffsetBaseNode = 0; 536 } 537 return new Range(m_positionNode->document(), m_positionNode, m_positionStartOffset, m_positionNode, m_positionEndOffset); 538 } 539 540 // otherwise, return the end of the overall range we were given 530 if (m_range) 531 return m_range; 532 541 533 if (m_endContainer) 542 534 return new Range(m_endContainer->document(), m_endContainer, m_endOffset, m_endContainer, m_endOffset); 543 535 544 536 return 0; 545 537 } 546 538 547 SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator() : m_positionNode(0)539 SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator() 548 540 { 549 541 } … … 551 543 SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator(const Range *r) 552 544 { 553 m_positionNode = 0;554 555 545 if (!r) 556 546 return; … … 593 583 #ifndef NDEBUG 594 584 // Need this just because of the assert. 595 m_ positionNode = endNode;585 m_range = new Range(endNode->document(), Position(endNode, 0), Position(endNode, 0)); 596 586 #endif 597 587 … … 604 594 void SimplifiedBackwardsTextIterator::advance() 605 595 { 606 assert(m_ positionNode);607 608 m_ positionNode = 0;596 assert(m_range); 597 598 m_range = 0; 609 599 m_textLength = 0; 610 600 … … 621 611 } else 622 612 m_handledNode = handleNonTextNode(); 623 if (m_ positionNode)613 if (m_range) 624 614 return; 625 615 } … … 669 659 m_handledNode = false; 670 660 671 if (m_ positionNode)661 if (m_range) 672 662 return; 673 663 } … … 684 674 return true; 685 675 686 m_positionEndOffset = m_offset; 687 676 Position end(m_node, m_offset); 688 677 m_offset = (m_node == m_startNode) ? m_startOffset : 0; 689 m_positionNode = m_node;690 m_ positionStartOffset = m_offset;691 m_textLength = m_positionEndOffset - m_positionStartOffset;692 m_textCharacters = str.characters() + m_positionStartOffset;693 694 m_lastCharacter = str[ m_positionEndOffset- 1];678 Position start(m_node, m_offset); 679 m_range = new Range(m_node->document(), start, end); 680 m_textLength = end.offset() - start.offset(); 681 m_textCharacters = str.characters() + start.offset(); 682 683 m_lastCharacter = str[end.offset() - 1]; 695 684 696 685 return true; … … 699 688 bool SimplifiedBackwardsTextIterator::handleReplacedElement() 700 689 { 701 int offset = m_node->nodeIndex(); 702 703 m_positionNode = m_node->parentNode(); 704 m_positionStartOffset = offset; 705 m_positionEndOffset = offset + 1; 690 m_range = new Range(m_node->document(), positionBeforeNode(m_node), positionAfterNode(m_node)); 706 691 707 692 m_textCharacters = 0; … … 735 720 } 736 721 737 void SimplifiedBackwardsTextIterator::emitCharacter(UChar c, Node *node, int startOffset, int endOffset)722 void SimplifiedBackwardsTextIterator::emitCharacter(UChar c, const Position& start, const Position& end) 738 723 { 739 724 m_singleCharacterBuffer = c; 740 m_positionNode = node;741 m_ positionStartOffset = startOffset;742 m_positionEndOffset = endOffset;725 726 m_range = start.isNull() ? 0 : new Range(start.node()->document(), start, end); 727 743 728 m_textCharacters = &m_singleCharacterBuffer; 744 729 m_textLength = 1; … … 748 733 void SimplifiedBackwardsTextIterator::emitNewline() 749 734 { 750 int offset; 751 752 if (m_lastTextNode) { 753 offset = m_lastTextNode->nodeIndex(); 754 emitCharacter('\n', m_lastTextNode->parentNode(), offset, offset + 1); 755 } else { 756 offset = m_node->nodeIndex(); 757 emitCharacter('\n', m_node->parentNode(), offset, offset + 1); 758 } 735 if (m_lastTextNode) 736 emitCharacter('\n', positionBeforeNode(m_lastTextNode), positionAfterNode(m_lastTextNode)); 737 else 738 emitCharacter('\n', positionBeforeNode(m_node), positionAfterNode(m_node)); 759 739 } 760 740 761 741 PassRefPtr<Range> SimplifiedBackwardsTextIterator::range() const 762 742 { 763 if (m_ positionNode)764 return new Range(m_positionNode->document(), m_positionNode, m_positionStartOffset, m_positionNode, m_positionEndOffset);743 if (m_range) 744 return m_range; 765 745 766 746 return new Range(m_startNode->document(), m_startNode, m_startOffset, m_startNode, m_startOffset); … … 782 762 PassRefPtr<Range> CharacterIterator::range() const 783 763 { 784 RefPtr<Range> r = m_textIterator.range(); 764 ExceptionCode ec; 765 RefPtr<Range> r = m_textIterator.range()->cloneRange(ec); 785 766 if (!m_textIterator.atEnd()) { 786 767 if (m_textIterator.length() <= 1) { … … 1052 1033 startRangeFound = true; 1053 1034 int exception = 0; 1054 if (textRunRange->startContainer(exception)->isTextNode()) { 1035 if (rangeLocation == docTextPosition + len) 1036 resultRange->setStart(textRunRange->endContainer(exception), textRunRange->endOffset(exception), exception); 1037 else { 1055 1038 int offset = rangeLocation - docTextPosition; 1056 1039 resultRange->setStart(textRunRange->startContainer(exception), offset + textRunRange->startOffset(exception), exception); 1057 } else {1058 if (rangeLocation == docTextPosition)1059 resultRange->setStart(textRunRange->startContainer(exception), textRunRange->startOffset(exception), exception);1060 else1061 resultRange->setStart(textRunRange->endContainer(exception), textRunRange->endOffset(exception), exception);1062 1040 } 1063 1041 } … … 1074 1052 resultRange->setEnd(textRunRange->endContainer(exception), textRunRange->endOffset(exception), exception); 1075 1053 } 1076 if (!(rangeLength == 0 && rangeEnd == docTextPosition + len)) { 1077 docTextPosition += len; 1078 break; 1079 } 1054 1055 docTextPosition += len; 1056 break; 1080 1057 } 1081 1058 docTextPosition += len; -
trunk/WebCore/editing/TextIterator.h
r16737 r17276 63 63 explicit TextIterator(const Range *, IteratorKind kind = CONTENT ); 64 64 65 bool atEnd() const { return !m_ positionNode; }65 bool atEnd() const { return !m_range; } 66 66 void advance(); 67 67 … … 80 80 bool handleNonTextNode(); 81 81 void handleTextBox(); 82 void emitCharacter(UChar, Node *textNode, Node *offsetBaseNode, int textStartOffset, int textEndOffset);82 void emitCharacter(UChar, const Position&, const Position&); 83 83 84 84 // Current position, not necessarily of the text being returned, but position … … 95 95 96 96 // The current text and its position, in the form to be returned from the iterator. 97 Node *m_positionNode; 98 mutable Node *m_positionOffsetBaseNode; 99 mutable int m_positionStartOffset; 100 mutable int m_positionEndOffset; 97 RefPtr<Range> m_range; 101 98 const UChar* m_textCharacters; 102 99 int m_textLength; … … 129 126 explicit SimplifiedBackwardsTextIterator(const Range *); 130 127 131 bool atEnd() const { return !m_ positionNode; }128 bool atEnd() const { return !m_range; } 132 129 void advance(); 133 130 … … 142 139 bool handleReplacedElement(); 143 140 bool handleNonTextNode(); 144 void emitCharacter(UChar, Node *Node, int startOffset, int endOffset);141 void emitCharacter(UChar, const Position&, const Position&); 145 142 void emitNewline(); 146 143 … … 157 154 158 155 // The current text and its position, in the form to be returned from the iterator. 159 Node* m_positionNode; 160 int m_positionStartOffset; 161 int m_positionEndOffset; 156 RefPtr<Range> m_range; 162 157 const UChar* m_textCharacters; 163 158 int m_textLength; -
trunk/WebCore/editing/visible_units.cpp
r17223 r17276 86 86 87 87 if (it.atEnd() && next == 0) { 88 RefPtr<Range> range(it.range()); 89 pos = Position(range->startContainer(exception), range->startOffset(exception)); 88 pos = it.range()->startPosition(); 90 89 } else if (!it.atEnd() && it.length() == 0) { 91 90 // Got a zero-length chunk. … … 162 161 163 162 if (it.atEnd() && next == string.length()) { 164 RefPtr<Range> range(it.range()); 165 int exception = 0; 166 pos = Position(range->startContainer(exception), range->startOffset(exception)); 163 pos = it.range()->startPosition(); 167 164 } else if (!it.atEnd() && it.length() == 0) { 168 165 // Got a zero-length chunk. … … 186 183 CharacterIterator charIt(searchRange.get()); 187 184 charIt.advance(next - 1); 188 pos = Position(charIt.range()->endContainer(ec), charIt.range()->endOffset(ec));185 pos = charIt.range()->endPosition(); 189 186 } 190 187
Note: See TracChangeset
for help on using the changeset viewer.