Changeset 19036 in webkit


Ignore:
Timestamp:
Jan 22, 2007 5:30:50 PM (17 years ago)
Author:
justing
Message:

LayoutTests:

Reviewed by darin

<rdar://problem/4944770>
editing/pasteboard/4641033 layout test is broken (12328)

The fixes not only make this test pass, but also fix a bug that
was reflected in the results checked in for this test. The caret
was in the wrong position:

  • editing/pasteboard/4641033-expected.checksum:
  • editing/pasteboard/4641033-expected.png:
  • editing/pasteboard/4641033-expected.txt: Added:
  • editing/pasteboard/4944770-1-expected.checksum: Added.
  • editing/pasteboard/4944770-1-expected.png: Added.
  • editing/pasteboard/4944770-1-expected.txt: Added.
  • editing/pasteboard/4944770-1.html: Added.
  • editing/pasteboard/4944770-2-expected.checksum: Added.
  • editing/pasteboard/4944770-2-expected.png: Added.
  • editing/pasteboard/4944770-2-expected.txt: Added.
  • editing/pasteboard/4944770-2.html: Added.
  • editing/pasteboard/4944770-expected.checksum: Added.
  • editing/pasteboard/4944770-expected.png: Added.
  • editing/pasteboard/4944770-expected.txt: Added. Equivalent render trees:
  • editing/execCommand/format-block-from-range-selection-expected.txt:
  • editing/pasteboard/drag-drop-modifies-page-expected.txt: Fixed:
  • editing/pasteboard/nested-blocks-with-text-area-expected.checksum:
  • editing/pasteboard/nested-blocks-with-text-area-expected.png:
  • editing/pasteboard/nested-blocks-with-text-area-expected.txt:
  • editing/pasteboard/nested-blocks-with-text-field-expected.checksum:
  • editing/pasteboard/nested-blocks-with-text-field-expected.png:
  • editing/pasteboard/nested-blocks-with-text-field-expected.txt:

WebCore:

Reviewed by darin


<rdar://problem/4944770>
editing/pasteboard/4641033 layout test is broken (12328)


This layout test failure demonstrates three bugs:
Smart replace shouldn't be turned on, but is because a word
selection granularity from the previous test isn't cleared.
Smart replace shouldn't add any spaces because the paste is performed
in an empty paragraph.
Smart replace spaces are added to the text of options inside
the select element instead of before/after the select element.


This patch fixes the second two problems. During a
ReplaceSelectionCommand, the VisiblePosition for the end of
the inserted content is the last position in the last leaf
inserted. This is a problem when the last leaf is inside a
select element, since VP creation is inconsistent there.
Second, smart spaces were inserted inside the last leaf, not
at the endOfInsertedContent.

  • editing/ReplaceSelectionCommand.cpp: (WebCore::ReplaceSelectionCommand::shouldMergeStart): Renamed m_lastNodeInserted to m_lastLeafInserted. Use the start/endOfInsertedContent getters. (WebCore::ReplaceSelectionCommand::shouldMergeEnd): Ditto. (WebCore::ReplaceSelectionCommand::removeNodePreservingChildren): Ditto. (WebCore::ReplaceSelectionCommand::removeRedundantStyles): Ditto. (WebCore::ReplaceSelectionCommand::positionAtEndOfInsertedContent): Added. Special case for when the last leaf inserted is inside a select element: return the VisiblePosition after the select element. (WebCore::ReplaceSelectionCommand::positionAtStartOfInsertedContent): Added. (WebCore::ReplaceSelectionCommand::doApply): Did renaming. Used the start/endOfInsertedContent getters. Insert smart replace spaces into the right nodes. (WebCore::ReplaceSelectionCommand::shouldRemoveEndBR): Renaming. (WebCore::ReplaceSelectionCommand::completeHTMLReplacement): Ditto. (WebCore::ReplaceSelectionCommand::updateNodesInserted): Ditto.
  • editing/ReplaceSelectionCommand.h:
Location:
trunk
Files:
11 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r19034 r19036  
     12007-01-22  Justin Garcia  <justin.garcia@apple.com>
     2
     3        Reviewed by darin
     4
     5        <rdar://problem/4944770>
     6        editing/pasteboard/4641033 layout test is broken (12328)
     7
     8        The fixes not only make this test pass, but also fix a bug that
     9        was reflected in the results checked in for this test.  The caret
     10        was in the wrong position:
     11        * editing/pasteboard/4641033-expected.checksum:
     12        * editing/pasteboard/4641033-expected.png:
     13        * editing/pasteboard/4641033-expected.txt:
     14        Added:
     15        * editing/pasteboard/4944770-1-expected.checksum: Added.
     16        * editing/pasteboard/4944770-1-expected.png: Added.
     17        * editing/pasteboard/4944770-1-expected.txt: Added.
     18        * editing/pasteboard/4944770-1.html: Added.
     19        * editing/pasteboard/4944770-2-expected.checksum: Added.
     20        * editing/pasteboard/4944770-2-expected.png: Added.
     21        * editing/pasteboard/4944770-2-expected.txt: Added.
     22        * editing/pasteboard/4944770-2.html: Added.
     23        * editing/pasteboard/4944770-expected.checksum: Added.
     24        * editing/pasteboard/4944770-expected.png: Added.
     25        * editing/pasteboard/4944770-expected.txt: Added.
     26        Equivalent render trees:
     27        * editing/execCommand/format-block-from-range-selection-expected.txt:
     28        * editing/pasteboard/drag-drop-modifies-page-expected.txt:
     29        Fixed:
     30        * editing/pasteboard/nested-blocks-with-text-area-expected.checksum:
     31        * editing/pasteboard/nested-blocks-with-text-area-expected.png:
     32        * editing/pasteboard/nested-blocks-with-text-area-expected.txt:
     33        * editing/pasteboard/nested-blocks-with-text-field-expected.checksum:
     34        * editing/pasteboard/nested-blocks-with-text-field-expected.png:
     35        * editing/pasteboard/nested-blocks-with-text-field-expected.txt:
     36
    1372007-01-22  Beth Dakin  <bdakin@apple.com>
    238
  • trunk/LayoutTests/editing/execCommand/format-block-from-range-selection-expected.txt

    r17562 r19036  
    3838          RenderBlock (anonymous) at (0,102) size 782x0
    3939        RenderBlock {DL} at (1,153) size 782x18
    40           RenderText {#text} at (0,0) size 24x18
    41             text run at (0,0) width 24: "dar "
     40          RenderText {#text} at (0,0) size 20x18
     41            text run at (0,0) width 20: "dar"
     42          RenderText {#text} at (20,0) size 4x18
     43            text run at (20,0) width 4: " "
    4244        RenderBlock (anonymous) at (1,187) size 782x0
    4345        RenderBlock {DL} at (1,187) size 782x18
  • trunk/LayoutTests/editing/pasteboard/4641033-expected.checksum

    r17532 r19036  
    1 0b5df9dee82211eee3dc09b171ac8e1e
     15675296d472f20e3cd206c66257490d1
  • trunk/LayoutTests/editing/pasteboard/4641033-expected.txt

    r17572 r19036  
    44EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    55EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document givenAction:WebViewInsertActionPasted
    6 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document toDOMRange:range from 1 of #text > DIV > BODY > HTML > #document to 1 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
     6EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document toDOMRange:range from 1 of SELECT > DIV > BODY > HTML > #document to 1 of SELECT > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
    77EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    88EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
     
    3535        RenderText {#text} at (0,0) size 0x0
    3636        RenderText {#text} at (0,0) size 0x0
    37 caret: position 1 of child 1 {#text} of child 2 {DIV} of child 1 {BODY} of child 0 {HTML} of document
     37caret: position 1 of child 2 {SELECT} of child 2 {DIV} of child 1 {BODY} of child 0 {HTML} of document
  • trunk/LayoutTests/editing/pasteboard/drag-drop-modifies-page-expected.txt

    r16237 r19036  
    55EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 6 of #text > DIV > BODY > HTML > #document to 6 of #text > DIV > BODY > HTML > #document givenAction:WebViewInsertActionDropped
    66EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    7 EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of #text > DIV > BODY > HTML > #document to 5 of #text > SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
     7EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of #text > SPAN > DIV > BODY > HTML > #document to 6 of #text > SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
    88EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    99EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
     
    1919        RenderText {#text} at (0,0) size 37x18
    2020          text run at (0,0) width 37: "world"
    21         RenderText {#text} at (37,0) size 4x18
    22           text run at (37,0) width 4: " "
    23         RenderInline {SPAN} at (0,0) size 31x18
    24           RenderText {#text} at (41,0) size 31x18
    25             text run at (41,0) width 31: "hello"
    26 selection start: position 0 of child 1 {#text} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
    27 selection end:   position 5 of child 0 {#text} of child 2 {SPAN} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
     21        RenderInline {SPAN} at (0,0) size 35x18
     22          RenderText {#text} at (37,0) size 35x18
     23            text run at (37,0) width 35: " hello"
     24selection start: position 0 of child 0 {#text} of child 1 {SPAN} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
     25selection end:   position 6 of child 0 {#text} of child 1 {SPAN} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
  • trunk/LayoutTests/editing/pasteboard/nested-blocks-with-text-area-expected.checksum

    r17503 r19036  
    1 42f40f2de8e30b88cf944866bc01c28d
     1d51b2e2b20e242798713b3250d852760
  • trunk/LayoutTests/editing/pasteboard/nested-blocks-with-text-area-expected.txt

    r18264 r19036  
    66EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    77EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    8 EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > DIV > BODY > HTML > #document to 1 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
     8EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > SPAN > DIV > DIV > BODY > HTML > #document to 1 of #text > SPAN > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
    99EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    1010EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
     
    2222          text run at (29,0) width 725: "This test checks that pasing in a combination of nested blocks where one starts with a text field doesn't crash or fail "
    2323          text run at (359,18) width 65: "assertions."
    24       RenderBlock {DIV} at (0,54) size 784x54
     24      RenderBlock {DIV} at (0,54) size 784x36
    2525        RenderBlock {DIV} at (0,0) size 784x36
    2626          RenderTextControl {TEXTAREA} at (304,2) size 163x28 [bgcolor=#FFFFFF] [border: (1px solid #000000)]
     
    3131              text run at (473,18) width 8: "x"
    3232          RenderText {#text} at (0,0) size 0x0
    33         RenderBlock (anonymous) at (0,36) size 784x18
    34           RenderText {#text} at (390,0) size 4x18
    35             text run at (390,0) width 4: " "
    36       RenderBlock (anonymous) at (0,108) size 784x0
     33      RenderBlock (anonymous) at (0,90) size 784x0
    3734layer at (313,65) size 161x26
    3835  RenderBlock {DIV} at (1,1) size 161x26
    3936    RenderText {#text} at (3,0) size 3x13
    4037      text run at (3,0) width 3: " "
    41 caret: position 1 of child 2 {#text} of child 4 {DIV} of child 1 {BODY} of child 0 {HTML} of document
     38caret: position 1 of child 0 {#text} of child 3 {SPAN} of child 1 {DIV} of child 4 {DIV} of child 1 {BODY} of child 0 {HTML} of document
  • trunk/LayoutTests/editing/pasteboard/nested-blocks-with-text-field-expected.checksum

    r17503 r19036  
    1 a6385ec9d39c114d126a7edecabefe1b
     156aaf1cc29340afef53a465a62204e4e
  • trunk/LayoutTests/editing/pasteboard/nested-blocks-with-text-field-expected.txt

    r18264 r19036  
    66EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    77EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    8 EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > DIV > BODY > HTML > #document to 1 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
     8EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > SPAN > DIV > DIV > BODY > HTML > #document to 1 of #text > SPAN > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
    99EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    1010EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
     
    2222          text run at (29,0) width 725: "This test checks that pasing in a combination of nested blocks where one starts with a text field doesn't crash or fail "
    2323          text run at (359,18) width 65: "assertions."
    24       RenderBlock {DIV} at (0,54) size 784x41
     24      RenderBlock {DIV} at (0,54) size 784x23
    2525        RenderBlock {DIV} at (0,0) size 784x23
    2626          RenderTextControl {INPUT} at (312,2) size 148x19 [bgcolor=#FFFFFF] [border: (2px inset #000000)]
     
    3131              text run at (466,2) width 8: "x"
    3232          RenderText {#text} at (0,0) size 0x0
    33         RenderBlock (anonymous) at (0,23) size 784x18
    34           RenderText {#text} at (390,0) size 4x18
    35             text run at (390,0) width 4: " "
    36       RenderBlock (anonymous) at (0,95) size 784x0
     33      RenderBlock (anonymous) at (0,77) size 784x0
    3734layer at (323,67) size 142x13
    3835  RenderBlock {DIV} at (3,3) size 142x13
    39 caret: position 1 of child 2 {#text} of child 4 {DIV} of child 1 {BODY} of child 0 {HTML} of document
     36caret: position 1 of child 0 {#text} of child 3 {SPAN} of child 1 {DIV} of child 4 {DIV} of child 1 {BODY} of child 0 {HTML} of document
  • trunk/WebCore/ChangeLog

    r19035 r19036  
     12007-01-22  Justin Garcia  <justin.garcia@apple.com>
     2
     3        Reviewed by darin
     4       
     5        <rdar://problem/4944770>
     6        editing/pasteboard/4641033 layout test is broken (12328)
     7       
     8        This layout test failure demonstrates three bugs:
     9        Smart replace shouldn't be turned on, but is because a word
     10        selection granularity from the previous test isn't cleared.
     11        Smart replace shouldn't add any spaces because the paste is performed
     12        in an empty paragraph.
     13        Smart replace spaces are added to the text of options inside
     14        the select element instead of before/after the select element.
     15       
     16        This patch fixes the second two problems.  During a
     17        ReplaceSelectionCommand, the VisiblePosition for the end of
     18        the inserted content is the last position in the last leaf
     19        inserted.  This is a problem when the last leaf is inside a
     20        select element, since VP creation is inconsistent there. 
     21        Second, smart spaces were inserted inside the last leaf, not
     22        at the endOfInsertedContent.
     23
     24        * editing/ReplaceSelectionCommand.cpp:
     25        (WebCore::ReplaceSelectionCommand::shouldMergeStart): Renamed
     26        m_lastNodeInserted to m_lastLeafInserted.  Use the
     27        start/endOfInsertedContent getters.
     28        (WebCore::ReplaceSelectionCommand::shouldMergeEnd): Ditto.
     29        (WebCore::ReplaceSelectionCommand::removeNodePreservingChildren): Ditto.
     30        (WebCore::ReplaceSelectionCommand::removeRedundantStyles): Ditto.
     31        (WebCore::ReplaceSelectionCommand::positionAtEndOfInsertedContent): Added.
     32        Special case for when the last leaf inserted is inside a select
     33        element: return the VisiblePosition after the select element.
     34        (WebCore::ReplaceSelectionCommand::positionAtStartOfInsertedContent): Added.
     35        (WebCore::ReplaceSelectionCommand::doApply): Did renaming.  Used
     36        the start/endOfInsertedContent getters.  Insert smart replace spaces
     37        into the right nodes.
     38        (WebCore::ReplaceSelectionCommand::shouldRemoveEndBR): Renaming.
     39        (WebCore::ReplaceSelectionCommand::completeHTMLReplacement): Ditto.
     40        (WebCore::ReplaceSelectionCommand::updateNodesInserted): Ditto.
     41        * editing/ReplaceSelectionCommand.h:
     42
    1432007-01-22  Darin Adler  <darin@apple.com>
    244
  • trunk/WebCore/editing/ReplaceSelectionCommand.cpp

    r18944 r19036  
    288288bool ReplaceSelectionCommand::shouldMergeStart(bool selectionStartWasStartOfParagraph, bool fragmentHasInterchangeNewlineAtStart)
    289289{
    290     VisiblePosition startOfInsertedContent(Position(m_firstNodeInserted.get(), 0));
     290    VisiblePosition startOfInsertedContent(positionAtStartOfInsertedContent());
    291291    VisiblePosition prev = startOfInsertedContent.previous(true);
    292292    if (prev.isNull())
     
    302302bool ReplaceSelectionCommand::shouldMergeEnd(bool selectionEndWasEndOfParagraph)
    303303{
    304     VisiblePosition endOfInsertedContent(Position(m_lastNodeInserted.get(), maxDeepOffset(m_lastNodeInserted.get())));
     304    VisiblePosition endOfInsertedContent(positionAtEndOfInsertedContent());
    305305    VisiblePosition next = endOfInsertedContent.next(true);
    306306    if (next.isNull())
     
    323323    if (m_firstNodeInserted == node)
    324324        m_firstNodeInserted = node->traverseNextNode();
    325     if (m_lastNodeInserted == node)
    326         m_lastNodeInserted = node->lastChild() ? node->lastChild() : node->traverseNextSibling();
     325    if (m_lastLeafInserted == node)
     326        m_lastLeafInserted = node->lastChild() ? node->lastChild() : node->traverseNextSibling();
    327327    CompositeEditCommand::removeNodePreservingChildren(node);
    328328}
     
    401401            styles.append(style.release());
    402402        }
    403         if (node == m_lastNodeInserted)
     403        if (node == m_lastLeafInserted)
    404404            break;
    405405    }
     
    449449    if (isMailPasteAsQuotationNode(node))
    450450        static_cast<Element*>(node)->setAttribute(classAttr, "");
     451}
     452
     453VisiblePosition ReplaceSelectionCommand::positionAtEndOfInsertedContent()
     454{
     455    Node* lastNode = m_lastLeafInserted.get();
     456    Node* enclosingSelect = enclosingNodeWithTag(lastNode, selectTag);
     457    if (enclosingSelect)
     458        lastNode = enclosingSelect;
     459    return VisiblePosition(Position(lastNode, maxDeepOffset(lastNode)));
     460}
     461
     462VisiblePosition ReplaceSelectionCommand::positionAtStartOfInsertedContent()
     463{
     464    return VisiblePosition(Position(m_firstNodeInserted.get(), 0));
    451465}
    452466
     
    590604    removeRedundantStyles(mailBlockquoteEnclosingSelectionStart);
    591605   
    592     endOfInsertedContent = VisiblePosition(Position(m_lastNodeInserted.get(), maxDeepOffset(m_lastNodeInserted.get())));
    593     startOfInsertedContent = VisiblePosition(Position(m_firstNodeInserted.get(), 0));
     606    endOfInsertedContent = positionAtEndOfInsertedContent();
     607    startOfInsertedContent = positionAtStartOfInsertedContent();
    594608   
    595609    // We inserted before the startBlock to prevent nesting, and the content before the startBlock wasn't in its own block and
     
    605619        if (interchangeNewlineAtEnd) {
    606620            interchangeNewlineAtEnd = false;
    607             m_lastNodeInserted = endBR;
    608             lastPositionToSelect = VisiblePosition(Position(m_lastNodeInserted.get(), 0)).deepEquivalent();
     621            m_lastLeafInserted = endBR;
     622            lastPositionToSelect = VisiblePosition(Position(m_lastLeafInserted.get(), 0)).deepEquivalent();
    609623        } else
    610624            removeNodeAndPruneAncestors(endBR);
     
    619633        moveParagraph(startOfParagraphToMove, endOfParagraph(startOfParagraphToMove), destination);
    620634        m_firstNodeInserted = endingSelection().visibleStart().deepEquivalent().downstream().node();
    621         if (!m_lastNodeInserted->inDocument())
    622             m_lastNodeInserted = endingSelection().visibleEnd().deepEquivalent().upstream().node();
     635        if (!m_lastLeafInserted->inDocument())
     636            m_lastLeafInserted = endingSelection().visibleEnd().deepEquivalent().upstream().node();
    623637    }
    624638           
    625     endOfInsertedContent = VisiblePosition(Position(m_lastNodeInserted.get(), maxDeepOffset(m_lastNodeInserted.get())));
    626     startOfInsertedContent = VisiblePosition(Position(m_firstNodeInserted.get(), 0));
     639    endOfInsertedContent = positionAtEndOfInsertedContent();
     640    startOfInsertedContent = positionAtStartOfInsertedContent();
    627641   
    628642    if (interchangeNewlineAtEnd) {
     
    643657        }
    644658
    645     } else if (m_lastNodeInserted->hasTagName(brTag)) {
     659    } else if (m_lastLeafInserted->hasTagName(brTag)) {
    646660        // We want to honor the last incoming line break, so, if it will collapse away because of quirks mode,
    647661        // add an extra one.
     
    649663        // FIXME: Should we expand all incoming brs that collapse because of quirks mode?
    650664        if (!document()->inStrictMode() && isEndOfBlock(endOfInsertedContent) && !isStartOfParagraph(endOfInsertedContent))
    651             insertNodeBeforeAndUpdateNodesInserted(createBreakElement(document()).get(), m_lastNodeInserted.get());
     665            insertNodeBeforeAndUpdateNodesInserted(createBreakElement(document()).get(), m_lastLeafInserted.get());
    652666           
    653667    } else if (shouldMergeEnd(selectionEndWasEndOfParagraph)) {
     
    662676
    663677        moveParagraph(startOfParagraphToMove, endOfParagraph(startOfParagraphToMove), destination);
    664         // Merging forward will remove m_lastNodeInserted from the document.
     678        // Merging forward will remove m_lastLeafInserted from the document.
    665679        // FIXME: Maintain positions for the start and end of inserted content instead of keeping nodes.  The nodes are
    666680        // only ever used to create positions where inserted content starts/ends.
    667681        if (mergeForward) {
    668             m_lastNodeInserted = destination.previous().deepEquivalent().node();
     682            m_lastLeafInserted = destination.previous().deepEquivalent().node();
    669683            if (!m_firstNodeInserted->inDocument())
    670684                m_firstNodeInserted = endingSelection().visibleStart().deepEquivalent().node();
     
    674688    handlePasteAsQuotationNode();
    675689   
    676     endOfInsertedContent = VisiblePosition(Position(m_lastNodeInserted.get(), maxDeepOffset(m_lastNodeInserted.get())));
    677     startOfInsertedContent = VisiblePosition(Position(m_firstNodeInserted.get(), 0));   
     690    endOfInsertedContent = positionAtEndOfInsertedContent();
     691    startOfInsertedContent = positionAtStartOfInsertedContent();
    678692   
    679693    // Add spaces for smart replace.
     
    688702                                  !frame->isCharacterSmartReplaceExempt(endOfInsertedContent.characterAfter(), false);
    689703        if (needsTrailingSpace) {
    690             RenderObject* renderer = m_lastNodeInserted->renderer();
     704            RenderObject* renderer = m_lastLeafInserted->renderer();
    691705            bool collapseWhiteSpace = !renderer || renderer->style()->collapseWhiteSpace();
    692             if (m_lastNodeInserted->isTextNode()) {
    693                 Text* text = static_cast<Text*>(m_lastNodeInserted.get());
     706            Node* endNode = positionAtEndOfInsertedContent().deepEquivalent().upstream().node();
     707            if (endNode->isTextNode()) {
     708                Text* text = static_cast<Text*>(endNode);
    694709                insertTextIntoNode(text, text->length(), collapseWhiteSpace ? nonBreakingSpaceString() : " ");
    695710            } else {
    696711                RefPtr<Node> node = document()->createEditingTextNode(collapseWhiteSpace ? nonBreakingSpaceString() : " ");
    697                 insertNodeAfterAndUpdateNodesInserted(node.get(), m_lastNodeInserted.get());
     712                insertNodeAfterAndUpdateNodesInserted(node.get(), endNode);
    698713            }
    699714        }
     
    702717                                 !frame->isCharacterSmartReplaceExempt(startOfInsertedContent.previous().characterAfter(), true);
    703718        if (needsLeadingSpace) {
    704             RenderObject* renderer = m_lastNodeInserted->renderer();
     719            RenderObject* renderer = m_lastLeafInserted->renderer();
    705720            bool collapseWhiteSpace = !renderer || renderer->style()->collapseWhiteSpace();
    706             if (m_firstNodeInserted->isTextNode()) {
    707                 Text* text = static_cast<Text*>(m_firstNodeInserted.get());
     721            Node* startNode = positionAtStartOfInsertedContent().deepEquivalent().downstream().node();
     722            if (startNode->isTextNode()) {
     723                Text* text = static_cast<Text*>(startNode);
    708724                insertTextIntoNode(text, 0, collapseWhiteSpace ? nonBreakingSpaceString() : " ");
    709725            } else {
    710726                RefPtr<Node> node = document()->createEditingTextNode(collapseWhiteSpace ? nonBreakingSpaceString() : " ");
    711                 // Don't updateNodesInserted.  Doing so would set m_lastNodeInserted to be the node containing the
    712                 // leading space, but m_lastNodeInserted is supposed to mark the end of pasted content.
    713                 insertNodeBefore(node.get(), m_firstNodeInserted.get());
     727                // Don't updateNodesInserted.  Doing so would set m_lastLeafInserted to be the node containing the
     728                // leading space, but m_lastLeafInserted is supposed to mark the end of pasted content.
     729                insertNodeBefore(node.get(), startNode);
    714730                // FIXME: Use positions to track the start/end of inserted content.
    715731                m_firstNodeInserted = node;
     
    733749        // A br that was originally holding a line open should be displaced by inserted content or turned into a line break.
    734750        // A br that was originally acting as a line break should still be acting as a line break, not as a placeholder.
    735         isStartOfParagraph(visiblePos) && isEndOfParagraph(visiblePos) && !m_lastNodeInserted->hasTagName(brTag);
     751        isStartOfParagraph(visiblePos) && isEndOfParagraph(visiblePos) && !m_lastLeafInserted->hasTagName(brTag);
    736752}
    737753
     
    741757    Position end;
    742758
    743     if (m_firstNodeInserted && m_firstNodeInserted->inDocument() && m_lastNodeInserted && m_lastNodeInserted->inDocument()) {
    744        
    745         Node* lastLeaf = m_lastNodeInserted->lastDescendant();
    746         Node* firstLeaf = m_firstNodeInserted->firstDescendant();
    747        
    748         start = Position(firstLeaf, 0);
    749         end = Position(lastLeaf, maxDeepOffset(lastLeaf));
     759    // FIXME: This should never not be the case.
     760    if (m_firstNodeInserted && m_firstNodeInserted->inDocument() && m_lastLeafInserted && m_lastLeafInserted->inDocument()) {
     761       
     762        start = positionAtStartOfInsertedContent().deepEquivalent();
     763        end = positionAtEndOfInsertedContent().deepEquivalent();
    750764       
    751765        // FIXME (11475): Remove this and require that the creator of the fragment to use nbsps.
     
    802816        m_firstNodeInserted = node;
    803817   
    804     if (node == m_lastNodeInserted)
    805         return;
    806    
    807     m_lastNodeInserted = node->lastDescendant();
     818    if (node == m_lastLeafInserted)
     819        return;
     820   
     821    m_lastLeafInserted = node->lastDescendant();
    808822}
    809823
  • trunk/WebCore/editing/ReplaceSelectionCommand.h

    r18874 r19036  
    9595   
    9696    virtual void removeNodePreservingChildren(Node*);
     97   
     98    VisiblePosition positionAtStartOfInsertedContent();
     99    VisiblePosition positionAtEndOfInsertedContent();
    97100
    98101    RefPtr<Node> m_firstNodeInserted;
    99     RefPtr<Node> m_lastNodeInserted;
     102    RefPtr<Node> m_lastLeafInserted;
    100103    RefPtr<CSSMutableStyleDeclaration> m_insertionStyle;
    101104    bool m_selectReplacement;
Note: See TracChangeset for help on using the changeset viewer.