Changeset 92823

Timestamp:
08/10/11 23:29:18 (5 years ago)
Author:
rniwa@webkit.org
Message:

Copying can result in span around block elements on the clipboard
https://bugs.webkit.org/show_bug.cgi?id=34564

Reviewed by Tony Chang.

Source/WebCore:

Completely overhauled the way WebKit preserves style in copy and paste. Instead of wrapping the entire
serialized contents by a Apple style span, WebKit now adds inline style to the top level elements,
wrap top level text nodes by a style span.

  • editing/EditingStyle.cpp:

(WebCore::EditingStyle::collapseTextDecorationProperties): Remove text-decoration property when the value
of -webkit-text-decorations-in-effect is none.
(WebCore::EditingStyle::removeStyleFromRulesAndContext): Since display: inline and float: none are now
added on copy, remove these properties on paste.
(WebCore::EditingStyle::removePropertiesInElementDefaultStyle): Takes Element* instead of StyledElement*.
(WebCore::EditingStyle::forceInline): Added.
(WebCore::getPropertiesNotIn): Remove properties only when the base style has them.

  • editing/EditingStyle.h:
  • editing/markup.cpp:

(WebCore::StyledMarkupAccumulator::shouldApplyWrappingStyle): Added.
(WebCore::StyledMarkupAccumulator::StyledMarkupAccumulator): Takes highestNodeToBeSerialized.
(WebCore::StyledMarkupAccumulator::wrapWithStyleNode): Calls appendStyleNodeOpenTag and styleNodeCloseTag.
(WebCore::StyledMarkupAccumulator::appendStyleNodeOpenTag): Extracted from wrapWithStyleNode.
(WebCore::StyledMarkupAccumulator::styleNodeCloseTag): Ditto.
(WebCore::StyledMarkupAccumulator::appendText): Wraps text node with a style span if needed.
Set display: inline and float: none so that it won't be converted to a block on paste side.
(WebCore::StyledMarkupAccumulator::appendElement): Add wrapping style if appropriate; Remove any properties
that are overridden by default style and any style that may conflict with the computed style of node to
avoid modifying the appearance of the serialized nodes.
(WebCore::StyledMarkupAccumulator::serializeNodes): Compute wrapping style; copies of this style are
modified as needed when serializing top-level elements or text nodes. We call traverseNodesForSerialization
with NodeTraversalMode set to DoNotEmitString first to compute the highest node to be serialized. The second
call to the function actually serialize the nodes.
(WebCore::StyledMarkupAccumulator::traverseNodesForSerialization): Extracted from serializeNodes.
Outputs string only if NodeTraversalMode is set to EmitString.
(WebCore::createMarkup): No longer adds wrapping spans.

LayoutTests:

This patch overhauled the way we preserve styles when copying and pasting HTML contents. Many tests progressed
and lost wrapping spans while others are observing different markup on the clipboard as expected.

  • editing/deleting/deleting-line-break-preserves-underline-color-expected.txt: span's style attribute now has

a trailing space.

  • editing/execCommand/insert-list-with-noneditable-content-expected.txt: LightGray is now rgb(211, 211, 211).
  • editing/pasteboard/data-transfer-items-expected.txt: Different serialization.
  • editing/pasteboard/onpaste-text-html-expected.txt: Ditto.
  • editing/pasteboard/paste-4039777-fix-expected.txt: No longer nests ul erroneously or aligns the inner list

to the right.

  • editing/pasteboard/paste-code-in-pre-expected.txt: No longer produces erroneous wrapping span.
  • editing/pasteboard/paste-pre-001-expected.txt: Ditto.
  • editing/pasteboard/paste-pre-002-expected.txt: Ditto.
  • editing/pasteboard/paste-text-012-expected.txt: Ditto.
  • editing/pasteboard/paste-text-with-style-4-expected.txt: Ditto.
  • fast/events/ondrop-text-html-expected.txt: Different serialization.
  • platform/chromium-win/editing/pasteboard/paste-code-in-pre-expected.txt: Removed.
  • platform/chromium-win/editing/pasteboard/paste-pre-001-expected.txt: Removed.
  • platform/chromium-win/editing/pasteboard/paste-pre-002-expected.txt: Removed.
  • platform/qt-mac/editing/pasteboard/paste-code-in-pre-expected.txt: Removed.
Location:
trunk
Files:
4 deleted
16 edited

Note: See TracChangeset for help on using the changeset viewer.