Reviewed by Darin.
<rdar://problem/
5478250> REGRESSION: After pasting text copied from Mail subject and typing return, the cursor disappears because of negative left margin
When pasting text from the Mail subject line, the RTF pasteboard contains text that has a first line negative indent along with a
paragraph indent that has a counteracting positive indent. This results in the first line being flush left justified, and the remaining
wrapped lines being indented. When this is converted to a DOM fragment, AppKit makes a block element with a margin-left and a negative
text-indent that matches the RTF. So far this is all correct behavior.
When this content is pasted on the line of an existing paragraph that has content, ReplaceSelectionCommand will decided to merge the paragraphs.
This will convert the block element to a style span that has all inherited style properties. These inherited properties will still contain block
properties that have no affect on inline elements. These block properties will hang around on the style span and will get cloned to new block
elements if the user hit return on that line. The new block elements would then have the text-indent but not the margin-left, so the text would be
hidden off the left edge of the page.
In the end, we should never hang on to block-only properties in our style spans. This cuts out meaningless properties and prevents properties
from magically affecting blocks later if the style is cloned for a new block element during a future editing operation.
* editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplaceSelectionCommand::removeRedundantStyles): Remove any inherited block properties that are now in the span's style.
* editing/markup.cpp:
(WebCore::createMarkup): Ditto.
LayoutTests:
Reviewed by Darin.
Test for <rdar://problem/
5478250> REGRESSION: After pasting text copied from Mail subject and typing return, the cursor disappears because of negative left margin
* editing/pasteboard/
5478250.html: Added.
* platform/mac/editing/pasteboard/
5478250-expected.txt: Added.
Updated results that are affected by the style span being removed or added with different style properties.
* editing/execCommand/
5144139-1-expected.txt:
* editing/execCommand/create-list-with-hr-expected.txt:
* editing/pasteboard/merge-end-blockquote-expected.txt:
* editing/pasteboard/styled-element-markup-expected.txt:
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@25634
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2007-09-18 Timothy Hatcher <timothy@apple.com>
+
+ Reviewed by Darin.
+
+ Test for <rdar://problem/5478250> REGRESSION: After pasting text copied from Mail subject and typing return, the cursor disappears because of negative left margin
+
+ * editing/pasteboard/5478250.html: Added.
+ * platform/mac/editing/pasteboard/5478250-expected.txt: Added.
+
+ Updated results that are affected by the style span being removed or added with different style properties.
+
+ * editing/execCommand/5144139-1-expected.txt:
+ * editing/execCommand/create-list-with-hr-expected.txt:
+ * editing/pasteboard/merge-end-blockquote-expected.txt:
+ * editing/pasteboard/styled-element-markup-expected.txt:
+
2007-09-18 Sam Weinig <sam@webkit.org>
Reviewed by Darin.
RenderBlock {DIV} at (0,34) size 784x46
RenderBlock {UL} at (0,0) size 784x46
RenderListItem {LI} at (40,0) size 744x46
- RenderBlock (anonymous) at (0,0) size 744x18
- RenderListMarker at (-17,0) size 7x18: bullet
- RenderTable {TABLE} at (0,18) size 31x28 [border: (1px outset #808080)]
+ RenderTable {TABLE} at (0,0) size 31x28 [border: (1px outset #808080)]
RenderTableSection {TBODY} at (1,1) size 29x26
RenderTableRow {TR} at (0,2) size 29x22
RenderTableCell {TD} at (2,2) size 25x22 [border: (1px inset #808080)] [r=0 c=0 rs=1 cs=1]
RenderText {#text} at (2,2) size 21x18
text run at (2,2) width 21: "foo"
- RenderBlock (anonymous) at (0,46) size 744x0
+ RenderBlock (anonymous) at (0,28) size 744x18
+ RenderListMarker at (-17,0) size 7x18: bullet
RenderBlock (anonymous) at (0,62) size 784x0
selection start: position 0 of child 0 {TABLE} of child 0 {LI} of child 0 {UL} of child 2 {DIV} of child 0 {BODY} of child 0 {HTML} of document
selection end: position 1 of child 0 {TABLE} of child 0 {LI} of child 0 {UL} of child 2 {DIV} of child 0 {BODY} of child 0 {HTML} of document
RenderBlock {DIV} at (0,52) size 784x28
RenderBlock {UL} at (0,0) size 784x28
RenderListItem {LI} at (40,0) size 744x28
- RenderBlock (anonymous) at (0,0) size 744x0
RenderBlock {HR} at (0,0) size 744x2 [border: (1px inset #000000)]
RenderBlock (anonymous) at (0,10) size 744x18
RenderListMarker at (-17,0) size 7x18: bullet
--- /dev/null
+<p>This tests that inherited block properties do not propigate to the editing style span.</p>
+<div id="copy" contenteditable="true" style="margin: 0 0 0 50px; text-indent: -50px; font-weight: bold; text-align: center;">Some text that is bold.</div>
+<div id="paste" contenteditable="true">Some text that is </div>
+
+<script>
+var copy = document.getElementById("copy");
+window.getSelection().setBaseAndExtent(copy.firstChild, 18, copy, 1);
+document.execCommand("Copy");
+var paste = document.getElementById("paste");
+window.getSelection().setBaseAndExtent(paste, 1, paste, 1);
+document.execCommand("Paste");
+document.execCommand("InsertText", false, "\nThis text should bold and left justified with \"Some text...\".");
+</script>
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
-EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 3 of #text > DIV > BLOCKQUOTE > DIV > BODY > HTML > #document to 3 of #text > DIV > BLOCKQUOTE > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 3 of #text > SPAN > DIV > BLOCKQUOTE > DIV > BODY > HTML > #document to 3 of #text > SPAN > DIV > BLOCKQUOTE > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
layer at (0,0) size 800x600
RenderBlock {DIV} at (0,0) size 704x18
RenderText {#text} at (0,0) size 81x18
text run at (0,0) width 81: "Blockquoted"
- RenderText {#text} at (81,0) size 21x18
- text run at (81,0) width 21: "foo"
+ RenderInline {SPAN} at (0,0) size 21x18
+ RenderText {#text} at (81,0) size 21x18
+ text run at (81,0) width 21: "foo"
RenderBlock {DIV} at (0,18) size 704x18
- RenderText {#text} at (0,0) size 20x18
- text run at (0,0) width 20: "bar"
+ RenderInline {SPAN} at (0,0) size 20x18
+ RenderText {#text} at (0,0) size 20x18
+ text run at (0,0) width 20: "bar"
RenderText {#text} at (20,0) size 33x18
text run at (20,0) width 33: " Text"
-caret: position 3 of child 0 {#text} of child 1 {DIV} of child 0 {BLOCKQUOTE} of child 10 {DIV} of child 1 {BODY} of child 0 {HTML} of document
+caret: position 3 of child 0 {#text} of child 0 {SPAN} of child 1 {DIV} of child 0 {BLOCKQUOTE} of child 10 {DIV} of child 1 {BODY} of child 0 {HTML} of document
EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document givenAction:WebViewInsertActionPasted
-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document toDOMRange:range from 1 of SPAN > DIV > BODY > HTML > #document to 1 of SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document toDOMRange:range from 1 of DIV > BODY > HTML > #document to 1 of DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
layer at (0,0) size 800x600
RenderBlock {CENTER} at (0,0) size 784x103
RenderImage {IMG} at (354,0) size 76x103
RenderBlock {DIV} at (0,207) size 784x103
- RenderInline {SPAN} at (0,0) size 76x14
- RenderImage {IMG} at (0,0) size 76x103
-caret: position 1 of child 0 {IMG} of child 0 {SPAN} of child 6 {DIV} of child 1 {BODY} of child 0 {HTML} of document
+ RenderImage {IMG} at (0,0) size 76x103
+caret: position 1 of child 0 {IMG} of child 6 {DIV} of child 1 {BODY} of child 0 {HTML} of document
--- /dev/null
+layer at (0,0) size 800x600
+ RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+ RenderBlock {HTML} at (0,0) size 800x600
+ RenderBody {BODY} at (8,8) size 784x584
+ RenderBlock {P} at (0,0) size 784x18
+ RenderText {#text} at (0,0) size 513x18
+ text run at (0,0) width 513: "This tests that inherited block properties do not propigate to the editing style span."
+ RenderBlock {DIV} at (50,34) size 734x18
+ RenderText {#text} at (267,0) size 149x18
+ text run at (267,0) width 149: "Some text that is bold."
+ RenderBlock {DIV} at (0,52) size 784x36
+ RenderBlock (anonymous) at (0,0) size 784x18
+ RenderText {#text} at (0,0) size 108x18
+ text run at (0,0) width 108: "Some text that is "
+ RenderInline {SPAN} at (0,0) size 34x18
+ RenderText {#text} at (108,0) size 34x18
+ text run at (108,0) width 34: "bold."
+ RenderBlock {DIV} at (0,18) size 784x18
+ RenderInline {B} at (0,0) size 393x18
+ RenderText {#text} at (0,0) size 393x18
+ text run at (0,0) width 393: "This text should bold and left justified with \"Some text...\"."
+caret: position 61 of child 0 {#text} of child 0 {B} of child 2 {DIV} of child 4 {DIV} of child 0 {BODY} of child 0 {HTML} of document
+2007-09-18 Timothy Hatcher <timothy@apple.com>
+
+ Reviewed by Darin.
+
+ <rdar://problem/5478250> REGRESSION: After pasting text copied from Mail subject and typing return, the cursor disappears because of negative left margin
+
+ When pasting text from the Mail subject line, the RTF pasteboard contains text that has a first line negative indent along with a
+ paragraph indent that has a counteracting positive indent. This results in the first line being flush left justified, and the remaining
+ wrapped lines being indented. When this is converted to a DOM fragment, AppKit makes a block element with a margin-left and a negative
+ text-indent that matches the RTF. So far this is all correct behavior.
+
+ When this content is pasted on the line of an existing paragraph that has content, ReplaceSelectionCommand will decided to merge the paragraphs.
+ This will convert the block element to a style span that has all inherited style properties. These inherited properties will still contain block
+ properties that have no affect on inline elements. These block properties will hang around on the style span and will get cloned to new block
+ elements if the user hit return on that line. The new block elements would then have the text-indent but not the margin-left, so the text would be
+ hidden off the left edge of the page.
+
+ In the end, we should never hang on to block-only properties in our style spans. This cuts out meaningless properties and prevents properties
+ from magically affecting blocks later if the style is cloned for a new block element during a future editing operation.
+
+ * editing/ReplaceSelectionCommand.cpp:
+ (WebCore::ReplaceSelectionCommand::removeRedundantStyles): Remove any inherited block properties that are now in the span's style.
+ * editing/markup.cpp:
+ (WebCore::createMarkup): Ditto.
+
2007-09-18 Dave Hyatt <hyatt@apple.com>
Land a UnicodeRange helper class (ported from Mozilla) that we are going to use to prepare for making
RefPtr<CSSMutableStyleDeclaration> parentStyle = computedStyle(node->parentNode())->copyInheritableProperties();
RefPtr<CSSMutableStyleDeclaration> style = computedStyle(node)->copyInheritableProperties();
parentStyle->diff(style.get());
-
+
+ // Remove any inherited block properties that are now in the span's style. This cuts out meaningless properties
+ // and prevents properties from magically affecting blocks later if the style is cloned for a new block element
+ // during a future editing operation.
+ style->removeBlockProperties();
+
styles.append(style.release());
}
if (node == m_lastLeafInserted)
Node* parentOfLastClosed = lastClosed ? lastClosed->parentNode() : 0;
if (parentOfLastClosed && parentOfLastClosed->renderer()) {
RefPtr<CSSMutableStyleDeclaration> style = computedStyle(parentOfLastClosed)->copyInheritableProperties();
+
// Styles that Mail blockquotes contribute should only be placed on the Mail blockquote, to help
// us differentiate those styles from ones that the user has applied. This helps us
// get the color of content pasted into blockquotes right.
removeEnclosingMailBlockquoteStyle(style.get(), parentOfLastClosed);
+ // Since we are converting blocks to inlines, remove any inherited block properties that are in the style.
+ // This cuts out meaningless properties and prevents properties from magically affecting blocks later
+ // if the style is cloned for a new block element during a future editing operation.
+ if (convertBlocksToInlines)
+ style->removeBlockProperties();
+
if (style->length() > 0) {
DeprecatedString openTag = DeprecatedString("<span class=\"") + AppleStyleSpanClass + "\" style=\"" + escapeTextForMarkup(style->cssText(), true) + "\">";
markups.prepend(openTag);