Need a way to produce leaner markup when pasting a fragment containing verbose markup
authorenrica@apple.com <enrica@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Dec 2011 00:32:27 +0000 (00:32 +0000)
committerenrica@apple.com <enrica@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Dec 2011 00:32:27 +0000 (00:32 +0000)
commit919446f816e8b3d9f91b90d9f818e76a9b980ca6
tree17149276726f9bc2535b44aac330f69bba395f3a
parent32d550f42e1b9788392111d90cf383dbd913c019
Need a way to produce leaner markup when pasting a fragment containing verbose markup
https://bugs.webkit.org/show_bug.cgi?id=74514
<rdar://problem/10208653>

Reviewed by Ryosuke Niwa.

Source/WebCore:

This patch is another step in the direction of reducing the verbosity of the markup
produced with editing operations.
After the copied fragment is inserted in the document, it is analyzed to remove all
the elements that don't contribute to the style. The decision is made comparing the
render styles. As part of the cleanup, unstyled divs with single child element are
removed. The logic to determine the blocks that can be removed is the same used in
DeleteSelectionCommand and has been moved in CompositeEditCommand.

Test: editing/pasteboard/paste-and-sanitize.html

* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::isRemovableBlock): Implements logic to determine
if a block can be removed.
* editing/CompositeEditCommand.h: Added isRemovableBlock declaration.
* editing/DeleteSelectionCommand.cpp:
(WebCore::DeleteSelectionCommand::removeRedundantBlocks): Implemented using
isRemovableBlock from CompositeEditCommand.
* editing/Editor.cpp:
(WebCore::Editor::replaceSelectionWithFragment): Added SanitizeFragment option.
* editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplaceSelectionCommand::ReplaceSelectionCommand): Added initialization
of m_sanitizeFragment member.
(WebCore::ReplaceSelectionCommand::removeRedundantMarkup): New method implementing
the cleanup logic.
(WebCore::ReplaceSelectionCommand::doApply): Added call to removeRedundantMarkup
after the fragment is inserted in the document.
* editing/ReplaceSelectionCommand.h: Added new value to the enum CommandOption,
a new member variable and the new method declaration.

LayoutTests:

* editing/pasteboard/paste-and-sanitize-expected.txt: Added.
* editing/pasteboard/paste-and-sanitize.html: Added.
* editing/pasteboard/paste-text-012-expected.txt: Updated to reflect cleanup.
* editing/pasteboard/testcase-9507-expected.txt: Updated to reflect cleanup.
* platform/mac/editing/pasteboard/paste-text-013-expected.txt: Updated to reflect cleanup.
* platform/mac/editing/pasteboard/paste-text-014-expected.txt: Updated to reflect cleanup.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@102846 268f45cc-cd09-0410-ab3c-d52691b4dbfc
14 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/paste-and-sanitize-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/paste-and-sanitize.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/paste-text-012-expected.txt
LayoutTests/editing/pasteboard/testcase-9507-expected.txt
LayoutTests/platform/mac/editing/pasteboard/paste-text-013-expected.txt
LayoutTests/platform/mac/editing/pasteboard/paste-text-014-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/editing/CompositeEditCommand.cpp
Source/WebCore/editing/CompositeEditCommand.h
Source/WebCore/editing/DeleteSelectionCommand.cpp
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/ReplaceSelectionCommand.cpp
Source/WebCore/editing/ReplaceSelectionCommand.h