Changeset 25484 in webkit


Ignore:
Timestamp:
Sep 10, 2007 6:03:00 PM (17 years ago)
Author:
harrison
Message:

WebCore:

Reviewed by Kevin and Tristan.

Tests added:

  • editing/pasteboard/paste-into-anchor-text.html: Added.
  • editing/pasteboard/paste-table-cells.html: Added.

Source changes:

  • editing/CompositeEditCommand.cpp: (WebCore::CompositeEditCommand::positionAvoidingSpecialElementBoundary): Nil check enclosingAnchor.


  • editing/ReplaceSelectionCommand.cpp: (WebCore::ReplaceSelectionCommand::removeNodeAndPruneAncestors): New. Keeps m_firstNodeInserted and m_lastLeafInserted updated.


(WebCore::ReplaceSelectionCommand::negateStyleRulesThatAffectAppearance):
Added a comment.


(WebCore::ReplaceSelectionCommand::removeRedundantStyles):
Let ReplaceSelectionCommand::removeNodeAndPruneAncestors() update the nodes.


(WebCore::ReplaceSelectionCommand::doApply):
Pass originalVisPosBeforeEndBR to shouldRemoveEndBR()


(WebCore::ReplaceSelectionCommand::shouldRemoveEndBR):
Don't remove the br if nothing was inserted.


  • editing/ReplaceSelectionCommand.h: Add VisiblePosition parameter to shouldRemoveEndBR()


  • editing/markup.cpp: (WebCore::createMarkup): Wrap orphan tr element with a table element, just like we were doing for tobody elements.

LayoutTests:

Reviewed by Kevin and Tristan.

<rdar://problem/5456800> Mail crashes at WebCore::nextCandidate() after pasting back into a <table> multiple times

  • editing/pasteboard/paste-into-anchor-text.html: Added.
  • editing/pasteboard/paste-table-cells.html: Added.
  • editing/pasteboard/quirks-mode-br-1-expected.checksum:
  • editing/pasteboard/quirks-mode-br-1-expected.txt:
  • editing/pasteboard/quirks-mode-br-1.html:
  • platform/mac/editing/pasteboard/paste-into-anchor-text-expected.checksum: Added.
  • platform/mac/editing/pasteboard/paste-into-anchor-text-expected.png: Added.
  • platform/mac/editing/pasteboard/paste-into-anchor-text-expected.txt: Added.
  • platform/mac/editing/pasteboard/paste-table-cells-expected.checksum: Added.
  • platform/mac/editing/pasteboard/paste-table-cells-expected.png: Added.
  • platform/mac/editing/pasteboard/paste-table-cells-expected.txt: Added.
Location:
trunk
Files:
8 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r25482 r25484  
     12007-09-10  David Harrison  <harrison@apple.com>
     2
     3        Reviewed by Kevin and Tristan.
     4
     5        <rdar://problem/5456800> Mail crashes at WebCore::nextCandidate() after pasting back into a <table> multiple times
     6
     7        * editing/pasteboard/paste-into-anchor-text.html: Added.
     8        * editing/pasteboard/paste-table-cells.html: Added.
     9        * editing/pasteboard/quirks-mode-br-1-expected.checksum:
     10        * editing/pasteboard/quirks-mode-br-1-expected.txt:
     11        * editing/pasteboard/quirks-mode-br-1.html:
     12        * platform/mac/editing/pasteboard/paste-into-anchor-text-expected.checksum: Added.
     13        * platform/mac/editing/pasteboard/paste-into-anchor-text-expected.png: Added.
     14        * platform/mac/editing/pasteboard/paste-into-anchor-text-expected.txt: Added.
     15        * platform/mac/editing/pasteboard/paste-table-cells-expected.checksum: Added.
     16        * platform/mac/editing/pasteboard/paste-table-cells-expected.png: Added.
     17        * platform/mac/editing/pasteboard/paste-table-cells-expected.txt: Added.
     18
    1192007-09-10  Kevin McCullough  <kmccullough@apple.com>
    220
  • trunk/LayoutTests/editing/pasteboard/quirks-mode-br-1-expected.checksum

    r20274 r25484  
    1 25c02b740ed1e07d4119a21c57f8d992
     1dba7fc10054f5af9c815ddfc425bb74a
  • trunk/LayoutTests/editing/pasteboard/quirks-mode-br-1-expected.txt

    r20950 r25484  
    33EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    44EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    5 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 61 of #text > DIV > DIV > BODY > HTML > #document to 61 of #text > DIV > DIV > BODY > HTML > #document toDOMRange:range from 1 of DIV > BODY > HTML > #document to 1 of DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
    6 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    7 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
    85layer at (0,0) size 800x600
    96  RenderView at (0,0) size 800x600
     
    1613          text run at (0,18) width 184: "end of blocks are collapsed). "
    1714          text run at (184,18) width 509: "This test used to fail because of unrendered content to the left of the collapsed br."
    18       RenderBlock {DIV} at (0,52) size 784x36
     15      RenderBlock {DIV} at (0,52) size 784x18
    1916        RenderBlock {DIV} at (0,0) size 784x18
    2017          RenderText {#text} at (0,0) size 370x18
    2118            text run at (0,0) width 370: "The test should add a single blank line after this paragraph."
    2219          RenderInline {SPAN} at (0,0) size 0x18
    23         RenderBlock (anonymous) at (0,18) size 784x18
    24           RenderBR {BR} at (0,0) size 0x18
    25 caret: position 0 of child 1 {BR} of child 2 {DIV} of child 1 {BODY} of child 0 {HTML} of document
     20          RenderBR {BR} at (370,14) size 0x0
     21caret: position 61 of child 0 {#text} of child 0 {DIV} of child 2 {DIV} of child 1 {BODY} of child 0 {HTML} of document
  • trunk/LayoutTests/editing/pasteboard/quirks-mode-br-1.html

    r17562 r25484  
    1212s.setPosition(e, 0);
    1313s.modify("move", "forward", "line");
    14 document.execCommand("InsertHTML", false, "<br>");
    1514</script>
  • trunk/WebCore/ChangeLog

    r25473 r25484  
     12007-09-10  David Harrison  <harrison@apple.com>
     2
     3        Reviewed by Kevin and Tristan.
     4
     5        Tests added:
     6        * editing/pasteboard/paste-into-anchor-text.html: Added.
     7        * editing/pasteboard/paste-table-cells.html: Added.
     8
     9        Source changes:
     10        * editing/CompositeEditCommand.cpp:
     11        (WebCore::CompositeEditCommand::positionAvoidingSpecialElementBoundary):
     12        Nil check enclosingAnchor.
     13       
     14        * editing/ReplaceSelectionCommand.cpp:
     15        (WebCore::ReplaceSelectionCommand::removeNodeAndPruneAncestors):
     16        New. Keeps m_firstNodeInserted and m_lastLeafInserted updated.
     17       
     18        (WebCore::ReplaceSelectionCommand::negateStyleRulesThatAffectAppearance):
     19        Added a comment.
     20       
     21        (WebCore::ReplaceSelectionCommand::removeRedundantStyles):
     22        Let ReplaceSelectionCommand::removeNodeAndPruneAncestors() update the nodes.
     23         
     24        (WebCore::ReplaceSelectionCommand::doApply):
     25        Pass originalVisPosBeforeEndBR to shouldRemoveEndBR()
     26       
     27        (WebCore::ReplaceSelectionCommand::shouldRemoveEndBR):
     28        Don't remove the br if nothing was inserted.
     29       
     30        * editing/ReplaceSelectionCommand.h:
     31        Add VisiblePosition parameter to shouldRemoveEndBR()
     32       
     33        * editing/markup.cpp:
     34        (WebCore::createMarkup):
     35        Wrap orphan tr element with a table element, just like we were doing
     36        for tobody elements.
     37
    1382007-09-10  David Kilzer  <ddkilzer@apple.com>
    239
  • trunk/WebCore/editing/CompositeEditCommand.cpp

    r25327 r25484  
    856856                pushAnchorElementDown(enclosingAnchor);
    857857                enclosingAnchor = enclosingAnchorElement(original);
     858                if (!enclosingAnchor)
     859                    return original;
    858860            }
    859861            // Don't insert outside an anchor if doing so would skip over a line break.  It would
  • trunk/WebCore/editing/ReplaceSelectionCommand.cpp

    r25332 r25484  
    324324}
    325325
    326 // Virtual method used so that ReplaceSelectionCommand can update the node's it tracks.
     326// Wrap CompositeEditCommand::removeNodePreservingChildren() so we can update the nodes we track
    327327void ReplaceSelectionCommand::removeNodePreservingChildren(Node* node)
    328328{
     
    332332        m_lastLeafInserted = node->lastChild() ? node->lastChild() : node->traverseNextSibling();
    333333    CompositeEditCommand::removeNodePreservingChildren(node);
     334}
     335
     336// Wrap CompositeEditCommand::removeNodeAndPruneAncestors() so we can update the nodes we track
     337void ReplaceSelectionCommand::removeNodeAndPruneAncestors(Node* node)
     338{
     339    // prepare in case m_firstNodeInserted and/or m_lastLeafInserted get removed
     340    // FIXME: shouldn't m_lastLeafInserted be adjusted using traversePreviousNode()?
     341    Node* afterFirst = m_firstNodeInserted ? m_firstNodeInserted->traverseNextSibling() : 0;
     342    Node* afterLast = m_lastLeafInserted ? m_lastLeafInserted->traverseNextSibling() : 0;
     343   
     344    CompositeEditCommand::removeNodeAndPruneAncestors(node);
     345   
     346    // adjust m_firstNodeInserted and m_lastLeafInserted since either or both may have been removed
     347    if (m_lastLeafInserted && !m_lastLeafInserted->inDocument())
     348        m_lastLeafInserted = afterLast;
     349    if (m_firstNodeInserted && !m_firstNodeInserted->inDocument())
     350        m_firstNodeInserted = m_lastLeafInserted && m_lastLeafInserted->inDocument() ? afterFirst : 0;
    334351}
    335352
     
    362379            // but these are the two important ones because they'll prevent
    363380            // inserted content from appearing in the right paragraph.
     381            // FIXME: Hyatt is concerned that selectively using display:inline will give inconsistent
     382            // results. We already know one issue because td elements ignore their display property
     383            // in quirks mode (which Mail.app is always in). We should look for an alternative.
    364384            if (isBlock(e))
    365385                e->getInlineStyleDecl()->setProperty(CSS_PROP_DISPLAY, CSS_VAL_INLINE);
     
    414434        // Remove empty style spans.
    415435        if (isStyleSpan(element) && !element->hasChildNodes()) {
    416             if (m_firstNodeInserted == m_lastLeafInserted && m_firstNodeInserted == element)
    417                 m_firstNodeInserted = 0;
    418             if (m_firstNodeInserted == element)
    419                 m_firstNodeInserted = element->traverseNextSibling();
    420             if (m_lastLeafInserted == element)
    421                 m_lastLeafInserted = element->traverseNextSibling();
    422436            removeNodeAndPruneAncestors(element);
    423437            continue;
     
    548562    // away, there are positions after the br which map to the same visible position as [br, 0]). 
    549563    Node* endBR = insertionPos.downstream().node()->hasTagName(brTag) ? insertionPos.downstream().node() : 0;
     564    VisiblePosition originalVisPosBeforeEndBR;
     565    if (endBR)
     566        originalVisPosBeforeEndBR = VisiblePosition(endBR, 0, DOWNSTREAM).previous();
    550567   
    551568    startBlock = enclosingBlock(insertionPos.node());
     
    632649    bool interchangeNewlineAtEnd = fragment.hasInterchangeNewlineAtEnd();
    633650
    634     if (shouldRemoveEndBR(endBR))
     651    if (shouldRemoveEndBR(endBR, originalVisPosBeforeEndBR))
    635652        removeNodeAndPruneAncestors(endBR);
    636        
     653   
    637654    if (shouldMergeStart(selectionStartWasStartOfParagraph, fragment.hasInterchangeNewlineAtStart())) {
    638655        // Bail to avoid infinite recursion.
    639656        if (m_movingParagraph) {
    640             ASSERT_NOT_REACHED();
     657            // setting display:inline does not work for td elements in quirks mode
     658            ASSERT(m_firstNodeInserted->hasTagName(tdTag));
    641659            return;
    642660        }
     
    750768}
    751769
    752 bool ReplaceSelectionCommand::shouldRemoveEndBR(Node* endBR)
     770bool ReplaceSelectionCommand::shouldRemoveEndBR(Node* endBR, const VisiblePosition& originalVisPosBeforeEndBR)
    753771{
    754772    if (!endBR || !endBR->inDocument())
     
    757775    VisiblePosition visiblePos(Position(endBR, 0));
    758776   
    759     return
    760         // The br is collapsed away and so is unnecessary.
    761         !document()->inStrictMode() && isEndOfBlock(visiblePos) && !isStartOfParagraph(visiblePos) ||
    762         // A br that was originally holding a line open should be displaced by inserted content or turned into a line break.
    763         // A br that was originally acting as a line break should still be acting as a line break, not as a placeholder.
    764         isStartOfParagraph(visiblePos) && isEndOfParagraph(visiblePos);
     777    // Don't remove the br if nothing was inserted.
     778    if (visiblePos.previous() == originalVisPosBeforeEndBR)
     779        return false;
     780   
     781    // Remove the br if it is collapsed away and so is unnecessary.
     782    if (!document()->inStrictMode() && isEndOfBlock(visiblePos) && !isStartOfParagraph(visiblePos))
     783        return true;
     784       
     785    // A br that was originally holding a line open should be displaced by inserted content or turned into a line break.
     786    // A br that was originally acting as a line break should still be acting as a line break, not as a placeholder.
     787    return isStartOfParagraph(visiblePos) && isEndOfParagraph(visiblePos);
    765788}
    766789
  • trunk/WebCore/editing/ReplaceSelectionCommand.h

    r24792 r25484  
    8484
    8585    void updateNodesInserted(Node*);
    86     bool shouldRemoveEndBR(Node*);
     86    bool shouldRemoveEndBR(Node*, const VisiblePosition&);
    8787   
    8888    bool shouldMergeStart(bool, bool);
     
    9696   
    9797    virtual void removeNodePreservingChildren(Node*);
     98    virtual void removeNodeAndPruneAncestors(Node*);
    9899   
    99100    VisiblePosition positionAtStartOfInsertedContent();
  • trunk/WebCore/editing/markup.cpp

    r25327 r25484  
    589589    Node* commonAncestorBlock = commonAncestor ? enclosingBlock(commonAncestor) : 0;
    590590    if (annotate && commonAncestorBlock) {
    591         if (commonAncestorBlock->hasTagName(tbodyTag)) {
     591        if (commonAncestorBlock->hasTagName(tbodyTag) || commonAncestorBlock->hasTagName(trTag)) {
    592592            Node* table = commonAncestorBlock->parentNode();
    593593            while (table && !table->hasTagName(tableTag))
Note: See TracChangeset for help on using the changeset viewer.