Deleting line break before h1 converts h1 to span
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 17 Sep 2011 00:00:07 +0000 (00:00 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 17 Sep 2011 00:00:07 +0000 (00:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=45784

Reviewed by Kenneth Rohde Christiansen.

Source/WebCore:

Fixed the bug by treating h1 and other elements that retain structure like Mail blockquote.

We already had a logic to overriding styles of merged paragraphs by Mail blockquote so
just extend this logic for h1-h6, pre, etc...

Tests: editing/deleting/merge-paragraph-from-address.html
       editing/deleting/merge-paragraph-from-h6-with-style.html
       editing/deleting/merge-paragraph-from-h6.html
       editing/deleting/merge-paragraph-from-listing.html
       editing/deleting/merge-paragraph-into-h1-with-style.html
       editing/deleting/merge-paragraph-into-h1.html
       editing/deleting/merge-paragraph-into-pre.html

* editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline):
* editing/markup.cpp:
(WebCore::isBlockNodeToRetainAppearance): Extracted from ancestorToRetainStructureAndAppearance.
(WebCore::StyledMarkupAccumulator::serializeNodes):
(WebCore::ancestorToRetainStructureAndAppearance):
* editing/markup.h:

LayoutTests:

Added a bunch of tests to ensure WebKit does not keep block elements' style when merging paragraphs.
When removing line breaks between <h1>hello</h1>world and hello<pre>world</pre> for example,
we should not be overriding and preserving styles from h1 in the merge paragraph respectively.

* editing/deleting/merge-paragraph-from-address-expected.txt: Added.
* editing/deleting/merge-paragraph-from-address.html: Added.
* editing/deleting/merge-paragraph-from-h6-expected.txt: Added.
* editing/deleting/merge-paragraph-from-h6-with-style-expected.txt: Added.
* editing/deleting/merge-paragraph-from-h6-with-style.html: Added.
* editing/deleting/merge-paragraph-from-h6.html: Added.
* editing/deleting/merge-paragraph-from-listing-expected.txt: Added.
* editing/deleting/merge-paragraph-from-listing.html: Added.
* editing/deleting/merge-paragraph-into-h1-expected.txt: Added.
* editing/deleting/merge-paragraph-into-h1-style-expected.txt: Added.
* editing/deleting/merge-paragraph-into-h1-with-style-expected.txt: Added.
* editing/deleting/merge-paragraph-into-h1-with-style.html: Added.
* editing/deleting/merge-paragraph-into-h1.html: Added.
* editing/deleting/merge-paragraph-into-pre-expected.txt: Added.
* editing/deleting/merge-paragraph-into-pre.html: Added.
* platform/mac/editing/deleting/merge-whitespace-pre-expected.png:
* platform/mac/editing/deleting/merge-whitespace-pre-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@95335 268f45cc-cd09-0410-ab3c-d52691b4dbfc

22 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/deleting/merge-paragraph-from-address-expected.txt [new file with mode: 0644]
LayoutTests/editing/deleting/merge-paragraph-from-address.html [new file with mode: 0644]
LayoutTests/editing/deleting/merge-paragraph-from-h6-expected.txt [new file with mode: 0644]
LayoutTests/editing/deleting/merge-paragraph-from-h6-with-style-expected.txt [new file with mode: 0644]
LayoutTests/editing/deleting/merge-paragraph-from-h6-with-style.html [new file with mode: 0644]
LayoutTests/editing/deleting/merge-paragraph-from-h6.html [new file with mode: 0644]
LayoutTests/editing/deleting/merge-paragraph-from-listing-expected.txt [new file with mode: 0644]
LayoutTests/editing/deleting/merge-paragraph-from-listing.html [new file with mode: 0644]
LayoutTests/editing/deleting/merge-paragraph-into-h1-expected.txt [new file with mode: 0644]
LayoutTests/editing/deleting/merge-paragraph-into-h1-style-expected.txt [new file with mode: 0644]
LayoutTests/editing/deleting/merge-paragraph-into-h1-with-style-expected.txt [new file with mode: 0644]
LayoutTests/editing/deleting/merge-paragraph-into-h1-with-style.html [new file with mode: 0644]
LayoutTests/editing/deleting/merge-paragraph-into-h1.html [new file with mode: 0644]
LayoutTests/editing/deleting/merge-paragraph-into-pre-expected.txt [new file with mode: 0644]
LayoutTests/editing/deleting/merge-paragraph-into-pre.html [new file with mode: 0644]
LayoutTests/platform/mac/editing/deleting/merge-whitespace-pre-expected.png
LayoutTests/platform/mac/editing/deleting/merge-whitespace-pre-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/editing/ReplaceSelectionCommand.cpp
Source/WebCore/editing/markup.cpp
Source/WebCore/editing/markup.h

index ad446ce..a50ca38 100644 (file)
@@ -1,3 +1,32 @@
+2011-09-14  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Deleting line break before h1 converts h1 to span
+        https://bugs.webkit.org/show_bug.cgi?id=45784
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Added a bunch of tests to ensure WebKit does not keep block elements' style when merging paragraphs.
+        When removing line breaks between <h1>hello</h1>world and hello<pre>world</pre> for example,
+        we should not be overriding and preserving styles from h1 in the merge paragraph respectively.
+
+        * editing/deleting/merge-paragraph-from-address-expected.txt: Added.
+        * editing/deleting/merge-paragraph-from-address.html: Added.
+        * editing/deleting/merge-paragraph-from-h6-expected.txt: Added.
+        * editing/deleting/merge-paragraph-from-h6-with-style-expected.txt: Added.
+        * editing/deleting/merge-paragraph-from-h6-with-style.html: Added.
+        * editing/deleting/merge-paragraph-from-h6.html: Added.
+        * editing/deleting/merge-paragraph-from-listing-expected.txt: Added.
+        * editing/deleting/merge-paragraph-from-listing.html: Added.
+        * editing/deleting/merge-paragraph-into-h1-expected.txt: Added.
+        * editing/deleting/merge-paragraph-into-h1-style-expected.txt: Added.
+        * editing/deleting/merge-paragraph-into-h1-with-style-expected.txt: Added.
+        * editing/deleting/merge-paragraph-into-h1-with-style.html: Added.
+        * editing/deleting/merge-paragraph-into-h1.html: Added.
+        * editing/deleting/merge-paragraph-into-pre-expected.txt: Added.
+        * editing/deleting/merge-paragraph-into-pre.html: Added.
+        * platform/mac/editing/deleting/merge-whitespace-pre-expected.png:
+        * platform/mac/editing/deleting/merge-whitespace-pre-expected.txt:
+
 2011-09-16  David Levin  <levin@chromium.org>
 
        [chromium] Rebaseline fix up due to r95239.
diff --git a/LayoutTests/editing/deleting/merge-paragraph-from-address-expected.txt b/LayoutTests/editing/deleting/merge-paragraph-from-address-expected.txt
new file mode 100644 (file)
index 0000000..5240057
--- /dev/null
@@ -0,0 +1,18 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 3 of DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldDeleteDOMRange:range from 7 of #text > DIV > BODY > HTML > #document to 0 of ADDRESS > DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 6 of #text > DIV > BODY > HTML > #document to 6 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidEndEditing:WebViewDidEndEditingNotification
+This tests deleting line break before address.
+WebKit should not cancel styles added by address by those of document's default style.
+| "
+hello<#selection-caret>"
+| "world"
+| "
+"
diff --git a/LayoutTests/editing/deleting/merge-paragraph-from-address.html b/LayoutTests/editing/deleting/merge-paragraph-from-address.html
new file mode 100644 (file)
index 0000000..1e3f140
--- /dev/null
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html> 
+<body>
+<p id="description">This tests deleting line break before address.
+WebKit should not cancel styles added by address by those of document's default style.</p>
+<div id="test" contenteditable>
+hello
+<address>world</address>
+</div>
+</div>
+<script src="../editing.js"></script>
+<script src="../../resources/dump-as-markup.js"></script>
+<script>
+
+function editingTest() {
+    moveSelectionForwardByLineCommand();
+    deleteCommand();
+
+    Markup.description(document.getElementById('description').textContent);
+    Markup.dump('test');
+}
+
+runEditingTest();
+</script>
+</body>
+</html>
diff --git a/LayoutTests/editing/deleting/merge-paragraph-from-h6-expected.txt b/LayoutTests/editing/deleting/merge-paragraph-from-h6-expected.txt
new file mode 100644 (file)
index 0000000..4c123a9
--- /dev/null
@@ -0,0 +1,18 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 3 of DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldDeleteDOMRange:range from 7 of #text > DIV > BODY > HTML > #document to 0 of H1 > DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 6 of #text > DIV > BODY > HTML > #document to 6 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidEndEditing:WebViewDidEndEditingNotification
+This tests deleting line break before h6.
+WebKit should not cancel styles added by h6 by those of document's default style.
+| "
+hello<#selection-caret>"
+| "world"
+| "
+"
diff --git a/LayoutTests/editing/deleting/merge-paragraph-from-h6-with-style-expected.txt b/LayoutTests/editing/deleting/merge-paragraph-from-h6-with-style-expected.txt
new file mode 100644 (file)
index 0000000..df1387d
--- /dev/null
@@ -0,0 +1,22 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 5 of DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldDeleteDOMRange:range from 1 of #text > DIV > BODY > HTML > #document to 0 of H1 > DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 5 of #text > EM > DIV > BODY > HTML > #document to 5 of #text > EM > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidEndEditing:WebViewDidEndEditingNotification
+This tests deleting line break before h6.
+WebKit should not cancel styles added by h6 by those of document's default style but still keep "hello" italicized and "world" in red.
+| "
+"
+| <em>
+|   "hello<#selection-caret>"
+| <span>
+|   style="color: rgb(255, 0, 0); "
+|   "world"
+| "
+"
diff --git a/LayoutTests/editing/deleting/merge-paragraph-from-h6-with-style.html b/LayoutTests/editing/deleting/merge-paragraph-from-h6-with-style.html
new file mode 100644 (file)
index 0000000..2f72097
--- /dev/null
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html> 
+<body>
+<p id="description">This tests deleting line break before h6.
+WebKit should not cancel styles added by h6 by those of document's default style but still keep "hello" italicized and "world" in red.</p>
+<div id="test" contenteditable>
+<em>hello</em>
+<h1><font color="red">world</font></h1>
+</div>
+</div>
+<script src="../editing.js"></script>
+<script src="../../resources/dump-as-markup.js"></script>
+<script>
+
+function editingTest() {
+    moveSelectionForwardByLineCommand();
+    deleteCommand();
+
+    Markup.description(document.getElementById('description').textContent);
+    Markup.dump('test');
+}
+
+runEditingTest();
+</script>
+</body>
+</html>
diff --git a/LayoutTests/editing/deleting/merge-paragraph-from-h6.html b/LayoutTests/editing/deleting/merge-paragraph-from-h6.html
new file mode 100644 (file)
index 0000000..30a187d
--- /dev/null
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html> 
+<body>
+<p id="description">This tests deleting line break before h6.
+WebKit should not cancel styles added by h6 by those of document's default style.</p>
+<div id="test" contenteditable>
+hello
+<h1>world</h1>
+</div>
+</div>
+<script src="../editing.js"></script>
+<script src="../../resources/dump-as-markup.js"></script>
+<script>
+
+function editingTest() {
+    moveSelectionForwardByLineCommand();
+    deleteCommand();
+
+    Markup.description(document.getElementById('description').textContent);
+    Markup.dump('test');
+}
+
+runEditingTest();
+</script>
+</body>
+</html>
diff --git a/LayoutTests/editing/deleting/merge-paragraph-from-listing-expected.txt b/LayoutTests/editing/deleting/merge-paragraph-from-listing-expected.txt
new file mode 100644 (file)
index 0000000..f345a09
--- /dev/null
@@ -0,0 +1,18 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 3 of DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldDeleteDOMRange:range from 7 of #text > DIV > BODY > HTML > #document to 0 of LISTING > DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 6 of #text > DIV > BODY > HTML > #document to 6 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidEndEditing:WebViewDidEndEditingNotification
+This tests deleting line break before listing.
+WebKit should not cancel styles added by listing by those of document's default style.
+| "
+hello<#selection-caret>"
+| "world"
+| "
+"
diff --git a/LayoutTests/editing/deleting/merge-paragraph-from-listing.html b/LayoutTests/editing/deleting/merge-paragraph-from-listing.html
new file mode 100644 (file)
index 0000000..43bc4da
--- /dev/null
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html> 
+<body>
+<p id="description">This tests deleting line break before listing.
+WebKit should not cancel styles added by listing by those of document's default style.</p>
+<div id="test" contenteditable>
+hello
+<listing>world</listing>
+</div>
+</div>
+<script src="../editing.js"></script>
+<script src="../../resources/dump-as-markup.js"></script>
+<script>
+
+function editingTest() {
+    moveSelectionForwardByLineCommand();
+    deleteCommand();
+
+    Markup.description(document.getElementById('description').textContent);
+    Markup.dump('test');
+}
+
+runEditingTest();
+</script>
+</body>
+</html>
diff --git a/LayoutTests/editing/deleting/merge-paragraph-into-h1-expected.txt b/LayoutTests/editing/deleting/merge-paragraph-into-h1-expected.txt
new file mode 100644 (file)
index 0000000..b7cba35
--- /dev/null
@@ -0,0 +1,19 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 3 of DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldDeleteDOMRange:range from 5 of #text > H1 > DIV > BODY > HTML > #document to 0 of #text > DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 5 of #text > H1 > DIV > BODY > HTML > #document to 5 of #text > H1 > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidEndEditing:WebViewDidEndEditingNotification
+This tests deleting line break after h1.
+WebKit should not cancel styles added by h1 by those of document's default style
+| "
+"
+| <h1>
+|   "hello<#selection-caret>"
+|   "world"
diff --git a/LayoutTests/editing/deleting/merge-paragraph-into-h1-style-expected.txt b/LayoutTests/editing/deleting/merge-paragraph-into-h1-style-expected.txt
new file mode 100644 (file)
index 0000000..bfa88f4
--- /dev/null
@@ -0,0 +1,19 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 5 of DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldDeleteDOMRange:range from 5 of #text > H1 > DIV > BODY > HTML > #document to 0 of EM > DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 5 of #text > H1 > DIV > BODY > HTML > #document to 5 of #text > H1 > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidEndEditing:WebViewDidEndEditingNotification
+This tests deleting line break after h1.
+WebKit should not cancel styles added by 1 by those of document's default style but keep "world" italicized.
+| "
+"
+| <h1>
+|   "hello<#selection-caret>"
+|   <em>
+|     "world"
diff --git a/LayoutTests/editing/deleting/merge-paragraph-into-h1-with-style-expected.txt b/LayoutTests/editing/deleting/merge-paragraph-into-h1-with-style-expected.txt
new file mode 100644 (file)
index 0000000..d18d6b6
--- /dev/null
@@ -0,0 +1,19 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 5 of DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldDeleteDOMRange:range from 5 of #text > H1 > DIV > BODY > HTML > #document to 0 of EM > DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 5 of #text > H1 > DIV > BODY > HTML > #document to 5 of #text > H1 > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidEndEditing:WebViewDidEndEditingNotification
+This tests deleting line break after h1.
+WebKit should not cancel styles added by h1 by those of document's default style but keep "world" italicized.
+| "
+"
+| <h1>
+|   "hello<#selection-caret>"
+|   <em>
+|     "world"
diff --git a/LayoutTests/editing/deleting/merge-paragraph-into-h1-with-style.html b/LayoutTests/editing/deleting/merge-paragraph-into-h1-with-style.html
new file mode 100644 (file)
index 0000000..7ce795d
--- /dev/null
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html> 
+<body>
+<p id="description">This tests deleting line break after h1.
+WebKit should not cancel styles added by h1 by those of document's default style but keep "world" italicized.</p>
+<div id="test" contenteditable>
+<h1>hello</h1>
+<em>world</em>
+</div>
+</div>
+<script src="../editing.js"></script>
+<script src="../../resources/dump-as-markup.js"></script>
+<script>
+
+function editingTest() {
+    moveSelectionForwardByLineCommand();
+    deleteCommand();
+
+    Markup.description(document.getElementById('description').textContent);
+    Markup.dump('test');
+}
+
+runEditingTest();
+</script>
+</body>
+</html>
diff --git a/LayoutTests/editing/deleting/merge-paragraph-into-h1.html b/LayoutTests/editing/deleting/merge-paragraph-into-h1.html
new file mode 100644 (file)
index 0000000..75d97b9
--- /dev/null
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html> 
+<body>
+<p id="description">This tests deleting line break after h1.
+WebKit should not cancel styles added by h1 by those of document's default style</p>
+<div id="test" contenteditable>
+<h1>hello</h1>
+world
+</div>
+</div>
+<script src="../editing.js"></script>
+<script src="../../resources/dump-as-markup.js"></script>
+<script>
+
+function editingTest() {
+    moveSelectionForwardByLineCommand();
+    deleteCommand();
+
+    Markup.description(document.getElementById('description').textContent);
+    Markup.dump('test');
+}
+
+runEditingTest();
+</script>
+</body>
+</html>
diff --git a/LayoutTests/editing/deleting/merge-paragraph-into-pre-expected.txt b/LayoutTests/editing/deleting/merge-paragraph-into-pre-expected.txt
new file mode 100644 (file)
index 0000000..6132121
--- /dev/null
@@ -0,0 +1,19 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 3 of DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldDeleteDOMRange:range from 5 of #text > PRE > DIV > BODY > HTML > #document to 0 of #text > DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 5 of #text > PRE > DIV > BODY > HTML > #document to 5 of #text > PRE > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidEndEditing:WebViewDidEndEditingNotification
+This tests deleting line break after pre.
+WebKit should not cancel styles added by pre by those of document's default style.
+| "
+"
+| <pre>
+|   "hello<#selection-caret>"
+|   "world"
diff --git a/LayoutTests/editing/deleting/merge-paragraph-into-pre.html b/LayoutTests/editing/deleting/merge-paragraph-into-pre.html
new file mode 100644 (file)
index 0000000..9eedfef
--- /dev/null
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html> 
+<body>
+<p id="description">This tests deleting line break after pre.
+WebKit should not cancel styles added by pre by those of document's default style.</p>
+<div id="test" contenteditable>
+<pre>hello</pre>
+world
+</div>
+</div>
+<script src="../editing.js"></script>
+<script src="../../resources/dump-as-markup.js"></script>
+<script>
+
+function editingTest() {
+    moveSelectionForwardByLineCommand();
+    deleteCommand();
+
+    Markup.description(document.getElementById('description').textContent);
+    Markup.dump('test');
+}
+
+runEditingTest();
+</script>
+</body>
+</html>
index 44e6703..3a40f3f 100644 (file)
Binary files a/LayoutTests/platform/mac/editing/deleting/merge-whitespace-pre-expected.png and b/LayoutTests/platform/mac/editing/deleting/merge-whitespace-pre-expected.png differ
index 8bb35b0..ba45f7c 100644 (file)
@@ -12,9 +12,8 @@ layer at (0,0) size 800x600
         RenderBlock {DIV} at (0,0) size 784x18
           RenderText {#text} at (0,0) size 21x18
             text run at (0,0) width 21: "foo"
-          RenderInline {SPAN} at (0,0) size 24x15
-            RenderText {#text} at (21,2) size 24x15
-              text run at (21,2) width 24: "bar"
+          RenderText {#text} at (21,0) size 20x18
+            text run at (21,0) width 20: "bar"
         RenderBlock {PRE} at (0,31) size 784x15
           RenderText {#text} at (0,0) size 24x15
             text run at (0,0) width 24: "baz"
index 684d062..ac7db6c 100644 (file)
@@ -1,3 +1,31 @@
+2011-09-14  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Deleting line break before h1 converts h1 to span
+        https://bugs.webkit.org/show_bug.cgi?id=45784
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Fixed the bug by treating h1 and other elements that retain structure like Mail blockquote.
+
+        We already had a logic to overriding styles of merged paragraphs by Mail blockquote so
+        just extend this logic for h1-h6, pre, etc...
+
+        Tests: editing/deleting/merge-paragraph-from-address.html
+               editing/deleting/merge-paragraph-from-h6-with-style.html
+               editing/deleting/merge-paragraph-from-h6.html
+               editing/deleting/merge-paragraph-from-listing.html
+               editing/deleting/merge-paragraph-into-h1-with-style.html
+               editing/deleting/merge-paragraph-into-h1.html
+               editing/deleting/merge-paragraph-into-pre.html
+
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline):
+        * editing/markup.cpp:
+        (WebCore::isBlockNodeToRetainAppearance): Extracted from ancestorToRetainStructureAndAppearance.
+        (WebCore::StyledMarkupAccumulator::serializeNodes):
+        (WebCore::ancestorToRetainStructureAndAppearance):
+        * editing/markup.h:
+
 2011-09-16  Max Perepelitsyn  <pph34r@gmail.com>
 
         Set but not used variables cleanup (gcc 4.6)
index 4c58f6c..4d6b827 100644 (file)
@@ -496,7 +496,7 @@ void ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline()
 
             // If Mail wraps the fragment with a Paste as Quotation blockquote, or if you're pasting into a quoted region,
             // styles from blockquoteNode are allowed to override those from the source document, see <rdar://problem/4930986> and <rdar://problem/5089327>.
-            Node* blockquoteNode = isMailPasteAsQuotationNode(context) ? context : enclosingNodeOfType(firstPositionInNode(context), isMailBlockquote, CanCrossEditingBoundary);
+            Node* blockquoteNode = isMailPasteAsQuotationNode(context) ? context : enclosingNodeOfType(firstPositionInNode(context), isBlockNodeToRetainAppearance, CanCrossEditingBoundary);
             if (blockquoteNode)
                 newInlineStyle->removeStyleFromRulesAndContext(element, document()->documentElement());
 
index e8ca95e..f0e9e0a 100644 (file)
@@ -336,6 +336,24 @@ void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element* element
     appendCloseTag(out, element);
 }
 
+bool isBlockNodeToRetainAppearance(const Node* node)
+{
+    DEFINE_STATIC_LOCAL(HashSet<QualifiedName::QualifiedNameImpl*>, names, ());
+    if (!names.size()) {
+        names.add(addressTag.impl());
+        names.add(blockquoteTag.impl());
+        names.add(h1Tag.impl());
+        names.add(h2Tag.impl());
+        names.add(h3Tag.impl());
+        names.add(h4Tag.impl());
+        names.add(h5Tag.impl());
+        names.add(h6Tag.impl());
+        names.add(listingTag.impl());
+        names.add(preTag.impl());
+    }
+    return node->isElementNode() && names.contains(toElement(node)->tagQName().impl());
+}
+
 Node* StyledMarkupAccumulator::serializeNodes(Node* startNode, Node* pastEnd)
 {
     if (!m_highestNodeToBeSerialized) {
@@ -350,7 +368,7 @@ Node* StyledMarkupAccumulator::serializeNodes(Node* startNode, Node* pastEnd)
         // 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.
-        m_wrappingStyle->removeStyleAddedByNode(enclosingNodeOfType(firstPositionInOrBeforeNode(parentOfHighestNode), isMailBlockquote, CanCrossEditingBoundary));
+        m_wrappingStyle->removeStyleAddedByNode(enclosingNodeOfType(firstPositionInOrBeforeNode(parentOfHighestNode), isBlockNodeToRetainAppearance, CanCrossEditingBoundary));
 
         // Call collapseTextDecorationProperties first or otherwise it'll copy the value over from in-effect to text-decorations.
         m_wrappingStyle->collapseTextDecorationProperties();
@@ -453,17 +471,11 @@ static Node* ancestorToRetainStructureAndAppearance(Node* commonAncestor)
         return table;
     }
 
-    if (commonAncestorBlock->hasTagName(listingTag)
+    if (isBlockNodeToRetainAppearance(commonAncestorBlock)
         || commonAncestorBlock->hasTagName(olTag)
-        || commonAncestorBlock->hasTagName(preTag)
         || commonAncestorBlock->hasTagName(tableTag)
         || commonAncestorBlock->hasTagName(ulTag)
-        || commonAncestorBlock->hasTagName(xmpTag)
-        || commonAncestorBlock->hasTagName(h1Tag)
-        || commonAncestorBlock->hasTagName(h2Tag)
-        || commonAncestorBlock->hasTagName(h3Tag)
-        || commonAncestorBlock->hasTagName(h4Tag)
-        || commonAncestorBlock->hasTagName(h5Tag))
+        || commonAncestorBlock->hasTagName(xmpTag))
         return commonAncestorBlock;
 
     return 0;
index 1bfe900..a3b2ada 100644 (file)
@@ -49,10 +49,11 @@ namespace WebCore {
 
     bool isPlainTextMarkup(Node *node);
 
+    bool isBlockNodeToRetainAppearance(const Node*);
     String createMarkup(const Range*,
         Vector<Node*>* = 0, EAnnotateForInterchange = DoNotAnnotateForInterchange, bool convertBlocksToInlines = false, EAbsoluteURLs = DoNotResolveURLs);
     String createMarkup(const Node*, EChildrenOnly = IncludeNode, Vector<Node*>* = 0, EAbsoluteURLs = DoNotResolveURLs);
-    
+
     String createFullMarkup(const Node*);
     String createFullMarkup(const Range*);