Changeset 101575 in webkit


Ignore:
Timestamp:
Nov 30, 2011 5:16:13 PM (12 years ago)
Author:
enrica@apple.com
Message:

Source/WebCore: Copy/paste of the same content produces increasingly nested markup
https://bugs.webkit.org/show_bug.cgi?id=73497
<rdar://problem/10208605>

When pasting a fragment over a selection, we perfom a DeleteSelection command
followed by a ReplaceSelection command. Delete selection preserves the style
of the selection start, leaving all the blocks containing the insertion point.
This patch eliminates all the nested divs that don't provide additional style,
avoiding the proliferation of nested divs.

Reviewed by Darin Adler.

Tests: editing/deleting/delete-and-cleanup.html

editing/pasteboard/paste-without-nesting.html

  • editing/DeleteSelectionCommand.cpp:

(WebCore::DeleteSelectionCommand::removeRedundantBlocks):
(WebCore::DeleteSelectionCommand::doApply):

  • editing/DeleteSelectionCommand.h:

LayoutTests: Copy/paste of the same content produces increasingly nested markup
https://bugs.webkit.org/show_bug.cgi?id=73497
<rdar://problem/10208605>

Reviewed by Darin Adler.

  • editing/deleting/delete-and-cleanup-expected.txt: Added.
  • editing/deleting/delete-and-cleanup.html: Added.
  • editing/pasteboard/paste-without-nesting-expected.txt: Added.
  • editing/pasteboard/paste-without-nesting.html: Added.
Location:
trunk
Files:
4 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r101573 r101575  
     12011-11-30  Enrica Casucci  <enrica@apple.com>
     2
     3        Copy/paste of the same content produces increasingly nested markup
     4        https://bugs.webkit.org/show_bug.cgi?id=73497
     5        <rdar://problem/10208605>
     6
     7        Reviewed by Darin Adler.
     8
     9        * editing/deleting/delete-and-cleanup-expected.txt: Added.
     10        * editing/deleting/delete-and-cleanup.html: Added.
     11        * editing/pasteboard/paste-without-nesting-expected.txt: Added.
     12        * editing/pasteboard/paste-without-nesting.html: Added.
     13
    1142011-11-30  Chris Fleizach  <cfleizach@apple.com>
    215
  • trunk/Source/WebCore/ChangeLog

    r101574 r101575  
     12011-11-30  Enrica Casucci  <enrica@apple.com>
     2
     3        Copy/paste of the same content produces increasingly nested markup
     4        https://bugs.webkit.org/show_bug.cgi?id=73497
     5        <rdar://problem/10208605>
     6       
     7        When pasting a fragment over a selection, we perfom a DeleteSelection command
     8        followed by a ReplaceSelection command. Delete selection preserves the style
     9        of the selection start, leaving all the blocks containing the insertion point.
     10        This patch eliminates all the nested divs that don't provide additional style,
     11        avoiding the proliferation of nested divs.
     12
     13        Reviewed by Darin Adler.
     14
     15        Tests: editing/deleting/delete-and-cleanup.html
     16               editing/pasteboard/paste-without-nesting.html
     17
     18        * editing/DeleteSelectionCommand.cpp:
     19        (WebCore::DeleteSelectionCommand::removeRedundantBlocks):
     20        (WebCore::DeleteSelectionCommand::doApply):
     21        * editing/DeleteSelectionCommand.h:
     22
    1232011-11-30  Dan Bernstein  <mitz@apple.com>
    224
  • trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp

    r97395 r101575  
    747747}
    748748
     749// This method removes div elements with no attributes that have only one child or no children at all.
     750void DeleteSelectionCommand::removeRedundantBlocks()
     751{
     752    Node* node = m_endingPosition.deprecatedNode();
     753    Node* rootNode = node->rootEditableElement();
     754   
     755    while (node != rootNode) {
     756        Node* parentNode = node->parentNode();
     757        if ((parentNode && parentNode->firstChild() != parentNode->lastChild()) || !node->hasTagName(divTag)) {
     758            node = parentNode;
     759            continue;
     760        }
     761        const NamedNodeMap* attributeMap = node->attributes();
     762        if (!attributeMap || attributeMap->isEmpty()) {
     763            if (node == m_endingPosition.anchorNode())
     764                updatePositionForNodeRemoval(m_endingPosition, node);
     765           
     766            CompositeEditCommand::removeNodePreservingChildren(node);
     767            node = m_endingPosition.anchorNode();
     768        } else
     769            node = parentNode;
     770    }
     771}
     772
    749773void DeleteSelectionCommand::doApply()
    750774{
     
    811835    RefPtr<Node> placeholder = m_needPlaceholder ? createBreakElement(document()).get() : 0;
    812836   
    813     if (placeholder)
     837    if (placeholder) {
     838        removeRedundantBlocks();
    814839        insertNodeAt(placeholder.get(), m_endingPosition);
     840    }
    815841
    816842    rebalanceWhitespaceAt(m_endingPosition);
  • trunk/Source/WebCore/editing/DeleteSelectionCommand.h

    r86295 r101575  
    6868    virtual void removeNode(PassRefPtr<Node>);
    6969    virtual void deleteTextFromNode(PassRefPtr<Text>, unsigned, unsigned);
     70    void removeRedundantBlocks();
    7071
    7172    // This function provides access to original string after the correction has been deleted.
Note: See TracChangeset for help on using the changeset viewer.