[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.15.1-1414-gc69ee75

rniwa at webkit.org rniwa at webkit.org
Thu Oct 29 20:42:46 UTC 2009


The following commit has been merged in the webkit-1.1 branch:
commit e7d601d09ee82cbe157614c6a40231d220ca81bb
Author: rniwa at webkit.org <rniwa at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Sat Oct 10 03:36:51 2009 +0000

    ApplyStyleCommand removes presentational tags even when not necessary
    https://bugs.webkit.org/show_bug.cgi?id=28091
    
    Patch by Ryosuke Niwa <rniwa at webkit.org> on 2009-10-09
    Reviewed by Eric Seidel.
    
    WebCore:
    
    This patch updates implicitlyStyledElementShouldBeRemovedWhenApplyingStyle to return true
    (triggering removal of tag) only if the style implicitly added by the element is not present in
    the new style to apply. It also changes surroundNodeRangeWithElement so that it merges the
    surrounding element when possible. applyTextDecorationStyle is modified so that it does not add
    style span when the style attribute is empty.
    
    Test: editing/execCommand/toggle-style-3.html
    
    * editing/ApplyStyleCommand.cpp:
    (WebCore::ApplyStyleCommand::shouldRemoveTextDecorationTag): Returns true if specified text
    decoration is not present in the style to apply
    (WebCore::ApplyStyleCommand::implicitlyStyledElementShouldBeRemovedWhenApplyingStyle): No longer
    returns true if the tag is used in new style
    (WebCore::ApplyStyleCommand::applyTextDecorationStyle): Does not add style-span when redundant
    (WebCore::ApplyStyleCommand::surroundNodeRangeWithElement): Merges the newly created element
    with the surrounding identical elements
    * editing/ApplyStyleCommand.h:
    
    LayoutTests:
    
    This patch adds test to make sure to preserve presentational tag
    (u, s, strike, i, em, sup, sub, b, & strong) when the corresponding style is present in
    the final computed style. i.e. avoid removing tag and re-applying the style later
    
    * editing/execCommand/19653-2-expected.txt: Two b elements are merged.
    * editing/execCommand/createLink-expected.txt: Two anchor elements are merged.
    * editing/execCommand/script-tests/toggle-style-3.js: Added.
    (testSingleToggle):
    * editing/execCommand/strikethroughSelection-expected.txt: Redundant style spans are no longer added.
    * editing/execCommand/toggle-style-3-expected.txt: Added.
    * editing/execCommand/toggle-style-3.html: Added.
    * editing/execCommand/unlink-expected.txt: Two anchor elements are merged.
    * platform/mac/editing/style/5228141-expected.txt: Two b elements are merged.
    * platform/mac/editing/style/style-boundary-001-expected.txt: Two b elements are merged.
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@49414 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 14e0788..8cb2827 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,25 @@
+2009-10-09  Ryosuke Niwa  <rniwa at webkit.org>
+
+        Reviewed by Eric Seidel.
+
+        ApplyStyleCommand removes presentational tags even when not necessary
+        https://bugs.webkit.org/show_bug.cgi?id=28091
+
+        This patch adds test to make sure to preserve presentational tag
+        (u, s, strike, i, em, sup, sub, b, & strong) when the corresponding style is present in
+        the final computed style. i.e. avoid removing tag and re-applying the style later
+
+        * editing/execCommand/19653-2-expected.txt: Two b elements are merged.
+        * editing/execCommand/createLink-expected.txt: Two anchor elements are merged.
+        * editing/execCommand/script-tests/toggle-style-3.js: Added.
+        (testSingleToggle):
+        * editing/execCommand/strikethroughSelection-expected.txt: Redundant style spans are no longer added.
+        * editing/execCommand/toggle-style-3-expected.txt: Added.
+        * editing/execCommand/toggle-style-3.html: Added.
+        * editing/execCommand/unlink-expected.txt: Two anchor elements are merged.
+        * platform/mac/editing/style/5228141-expected.txt: Two b elements are merged.
+        * platform/mac/editing/style/style-boundary-001-expected.txt: Two b elements are merged.
+
 2009-10-09  Alexey Proskuryakov  <ap at apple.com>
 
         Reviewed by Brady Eidson.
diff --git a/LayoutTests/editing/execCommand/19653-2-expected.txt b/LayoutTests/editing/execCommand/19653-2-expected.txt
index 8b30bab..4d8da4f 100644
--- a/LayoutTests/editing/execCommand/19653-2-expected.txt
+++ b/LayoutTests/editing/execCommand/19653-2-expected.txt
@@ -2,4 +2,4 @@ This tests splitting two paragraphs with InsertParagraph while the typing style
 x<div><b>Bold</b>x</div>
 
 This tests splitting two paragraphs with InsertLineBreak while the typing style is bold. New text entered after the split should be bold. The inserted <br> doesn't need to be surrounded by a bold tag here.
-x<b><br></b><b>Bold</b>x
+x<b><br>Bold</b>x
diff --git a/LayoutTests/editing/execCommand/createLink-expected.txt b/LayoutTests/editing/execCommand/createLink-expected.txt
index c39f6a9..4d294ae 100644
--- a/LayoutTests/editing/execCommand/createLink-expected.txt
+++ b/LayoutTests/editing/execCommand/createLink-expected.txt
@@ -59,4 +59,4 @@ innerHTML of editable regions after the test:
 <a href="http://www.google.com/">This paragraph starts unlinked. The entire paragraph should end up being a link to google.com.</a>
 <a href="http://www.apple.com/">This</a><a href="http://www.google.com/"> paragraph</a><a href="http://www.apple.com/"> starts out as a link to apple.com. The second word in the paragraph should end up being a link to google.com.</a>
 <a href="http://www.apple.com/">This</a><a href="http://www.google.com/"> paragraph</a><a href="http://www.apple.com/"> starts out as a link to apple.com. The second word in the paragraph should end up being a link to google.com.</a>
-<p><a href="http://www.google.com/">This </a><i><a href="http://www.google.com/">editable region</a></i><a href="http://www.google.com/"> contains lists, tables, styled text, and images. The entire region should end up being a link to google.com.</a></p> <ul> <li><a href="http://www.google.com/">Item 1</a></li> <li><a href="http://www.google.com/">Item 2</a></li> </ul> <table border="1"><tbody><tr><td><a href="http://www.google.com/">1</a></td><td><a href="http://www.google.com/">2</a></td><td><a href="http://www.google.com/">3</a></td></tr></tbody></table> <a href="http://www.google.com/"><br> This </a><b><a href="http://www.google.com/">line</a></b><a href="http://www.google.com/"> contains </a><a href="http://www.google.com/"><img src="../resources/abe.png"> an image. </a>
+<p><a href="http://www.google.com/">This </a><i><a href="http://www.google.com/">editable region</a></i><a href="http://www.google.com/"> contains lists, tables, styled text, and images. The entire region should end up being a link to google.com.</a></p> <ul> <li><a href="http://www.google.com/">Item 1</a></li> <li><a href="http://www.google.com/">Item 2</a></li> </ul> <table border="1"><tbody><tr><td><a href="http://www.google.com/">1</a></td><td><a href="http://www.google.com/">2</a></td><td><a href="http://www.google.com/">3</a></td></tr></tbody></table> <a href="http://www.google.com/"><br> This </a><b><a href="http://www.google.com/">line</a></b><a href="http://www.google.com/"> contains <img src="../resources/abe.png"> an image. </a>
diff --git a/LayoutTests/editing/execCommand/script-tests/toggle-style-3.js b/LayoutTests/editing/execCommand/script-tests/toggle-style-3.js
new file mode 100644
index 0000000..f4c8b83
--- /dev/null
+++ b/LayoutTests/editing/execCommand/script-tests/toggle-style-3.js
@@ -0,0 +1,26 @@
+description("Test to make sure we remove span tags with no attributes if we removed the last attribute.")
+
+var testContainer = document.createElement("div");
+testContainer.contentEditable = true;
+document.body.appendChild(testContainer);
+
+function testSingleToggle(toggleCommand, initialContents, expectedContents)
+{
+    testContainer.innerHTML = initialContents;
+    window.getSelection().selectAllChildren(testContainer);
+    document.execCommand(toggleCommand, false, null);
+    if (testContainer.innerHTML === expectedContents) {
+        testPassed("one " + toggleCommand + " command converted " + initialContents + " to " + expectedContents);
+    } else {
+        testFailed("one " + toggleCommand + " command converted " + initialContents + " to " + testContainer.innerHTML + ", expected " + expectedContents);
+    }
+}
+
+testSingleToggle("bold", 'hello<b id="test">world</b>', '<b>hello</b><b id="test">world</b>');
+testSingleToggle("bold", 'hello<b><i>world</i></b>', '<b>hello<i>world</i></b>');
+testSingleToggle("italic", 'hello <i>world</i> <b>webkit</b>', '<i>hello world </i><b><i>webkit</i></b>');
+testSingleToggle("italic", 'hello <i>world</i> webkit', '<i>hello world webkit</i>');
+
+document.body.removeChild(testContainer);
+
+var successfullyParsed = true;
diff --git a/LayoutTests/editing/execCommand/strikethroughSelection-expected.txt b/LayoutTests/editing/execCommand/strikethroughSelection-expected.txt
index 5ad00a6..bf226b7 100644
--- a/LayoutTests/editing/execCommand/strikethroughSelection-expected.txt
+++ b/LayoutTests/editing/execCommand/strikethroughSelection-expected.txt
@@ -4,21 +4,21 @@ This test striking through the first 21st letters. Every letter including spaces
 execStrikethroughCommand: <span id="test"><s>"</s>The quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
 execStrikethroughCommand: <span id="test">"The quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
 execStrikethroughCommand: <span id="test"><s>"Th</s>e quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
-execStrikethroughCommand: <span id="test">"<span class="Apple-style-span">T</span><span class="Apple-style-span">h</span>e quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
-execStrikethroughCommand: <span id="test"><s>"</s><span class="Apple-style-span"><s>T</s></span><span class="Apple-style-span"><s>h</s></span><s>e </s>quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
-execStrikethroughCommand: <span id="test">"<span class="Apple-style-span">T</span><span class="Apple-style-span">h</span>e quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
-execStrikethroughCommand: <span id="test"><s>"</s><span class="Apple-style-span"><s>T</s></span><span class="Apple-style-span"><s>h</s></span><s>e qu</s>ick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
-execStrikethroughCommand: <span id="test">"<span class="Apple-style-span">T</span><span class="Apple-style-span">h</span>e quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
-execStrikethroughCommand: <span id="test"><s>"</s><span class="Apple-style-span"><s>T</s></span><span class="Apple-style-span"><s>h</s></span><s>e quic</s>k brown fox jumps over the lazy dog" uses every letter in the english language. </span>
-execStrikethroughCommand: <span id="test">"<span class="Apple-style-span">T</span><span class="Apple-style-span">h</span>e quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
-execStrikethroughCommand: <span id="test"><s>"</s><span class="Apple-style-span"><s>T</s></span><span class="Apple-style-span"><s>h</s></span><s>e quick </s>brown fox jumps over the lazy dog" uses every letter in the english language. </span>
-execStrikethroughCommand: <span id="test">"<span class="Apple-style-span">T</span><span class="Apple-style-span">h</span>e quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
-execStrikethroughCommand: <span id="test"><s>"</s><span class="Apple-style-span"><s>T</s></span><span class="Apple-style-span"><s>h</s></span><s>e quick br</s>own fox jumps over the lazy dog" uses every letter in the english language. </span>
-execStrikethroughCommand: <span id="test">"<span class="Apple-style-span">T</span><span class="Apple-style-span">h</span>e quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
-execStrikethroughCommand: <span id="test"><s>"</s><span class="Apple-style-span"><s>T</s></span><span class="Apple-style-span"><s>h</s></span><s>e quick brow</s>n fox jumps over the lazy dog" uses every letter in the english language. </span>
-execStrikethroughCommand: <span id="test">"<span class="Apple-style-span">T</span><span class="Apple-style-span">h</span>e quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
-execStrikethroughCommand: <span id="test"><s>"</s><span class="Apple-style-span"><s>T</s></span><span class="Apple-style-span"><s>h</s></span><s>e quick brown </s>fox jumps over the lazy dog" uses every letter in the english language. </span>
-execStrikethroughCommand: <span id="test">"<span class="Apple-style-span">T</span><span class="Apple-style-span">h</span>e quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
-execStrikethroughCommand: <span id="test"><s>"</s><span class="Apple-style-span"><s>T</s></span><span class="Apple-style-span"><s>h</s></span><s>e quick brown fo</s>x jumps over the lazy dog" uses every letter in the english language. </span>
-execStrikethroughCommand: <span id="test">"<span class="Apple-style-span">T</span><span class="Apple-style-span">h</span>e quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
-execStrikethroughCommand: <span id="test"><s>"</s><span class="Apple-style-span"><s>T</s></span><span class="Apple-style-span"><s>h</s></span><s>e quick brown fox </s>jumps over the lazy dog" uses every letter in the english language. </span>
+execStrikethroughCommand: <span id="test">"The quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
+execStrikethroughCommand: <span id="test"><s>"The </s>quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
+execStrikethroughCommand: <span id="test">"The quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
+execStrikethroughCommand: <span id="test"><s>"The qu</s>ick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
+execStrikethroughCommand: <span id="test">"The quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
+execStrikethroughCommand: <span id="test"><s>"The quic</s>k brown fox jumps over the lazy dog" uses every letter in the english language. </span>
+execStrikethroughCommand: <span id="test">"The quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
+execStrikethroughCommand: <span id="test"><s>"The quick </s>brown fox jumps over the lazy dog" uses every letter in the english language. </span>
+execStrikethroughCommand: <span id="test">"The quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
+execStrikethroughCommand: <span id="test"><s>"The quick br</s>own fox jumps over the lazy dog" uses every letter in the english language. </span>
+execStrikethroughCommand: <span id="test">"The quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
+execStrikethroughCommand: <span id="test"><s>"The quick brow</s>n fox jumps over the lazy dog" uses every letter in the english language. </span>
+execStrikethroughCommand: <span id="test">"The quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
+execStrikethroughCommand: <span id="test"><s>"The quick brown </s>fox jumps over the lazy dog" uses every letter in the english language. </span>
+execStrikethroughCommand: <span id="test">"The quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
+execStrikethroughCommand: <span id="test"><s>"The quick brown fo</s>x jumps over the lazy dog" uses every letter in the english language. </span>
+execStrikethroughCommand: <span id="test">"The quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>
+execStrikethroughCommand: <span id="test"><s>"The quick brown fox </s>jumps over the lazy dog" uses every letter in the english language. </span>
diff --git a/LayoutTests/editing/execCommand/toggle-style-3-expected.txt b/LayoutTests/editing/execCommand/toggle-style-3-expected.txt
new file mode 100644
index 0000000..e7efc39
--- /dev/null
+++ b/LayoutTests/editing/execCommand/toggle-style-3-expected.txt
@@ -0,0 +1,13 @@
+Test to make sure we remove span tags with no attributes if we removed the last attribute.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS one bold command converted hello<b id="test">world</b> to <b>hello</b><b id="test">world</b>
+PASS one bold command converted hello<b><i>world</i></b> to <b>hello<i>world</i></b>
+PASS one italic command converted hello <i>world</i> <b>webkit</b> to <i>hello world </i><b><i>webkit</i></b>
+PASS one italic command converted hello <i>world</i> webkit to <i>hello world webkit</i>
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/editing/execCommand/toggle-style-3.html b/LayoutTests/editing/execCommand/toggle-style-3.html
new file mode 100644
index 0000000..f7e1cfb
--- /dev/null
+++ b/LayoutTests/editing/execCommand/toggle-style-3.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/toggle-style-3.js"></script>
+<script src="../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/editing/execCommand/unlink-expected.txt b/LayoutTests/editing/execCommand/unlink-expected.txt
index 7f736a3..7df305c 100644
--- a/LayoutTests/editing/execCommand/unlink-expected.txt
+++ b/LayoutTests/editing/execCommand/unlink-expected.txt
@@ -66,4 +66,4 @@ The innerHTML of editable regions after the test:
 This paragraph should should end up unlinked.
 <a href="http://www.apple.com/">The</a> second<a href="http://www.apple.com/"> word in this paragraph should end up being unlinked, everything else should be a link.</a>
 This paragraph starts with <i><a href="http://www.google.com">a</a></i><span id="test3start"> link</span> in the middle. Only the 'a' in the previous sentence should be linked after the test.
-<p>This <i>editable region</i> contains lists, tables, styled text, and images. Everything in this region that is not selected should be a link, nothing that is selected should be a link.</p> <ul> <li>Item 1</li> <li>Item 2</li> </ul> <table border="1"><tbody><tr><td>1</td><td>2</td><td><span id="test4end"><a href="http://www.google.com/">3</a></span></td></tr></tbody></table> <a href="http://www.google.com/"><br> This </a><b><a href="http://www.google.com/">line</a></b><a href="http://www.google.com/"> contains </a><a href="http://www.google.com/"><img src="../resources/abe.png"> an image. </a>
+<p>This <i>editable region</i> contains lists, tables, styled text, and images. Everything in this region that is not selected should be a link, nothing that is selected should be a link.</p> <ul> <li>Item 1</li> <li>Item 2</li> </ul> <table border="1"><tbody><tr><td>1</td><td>2</td><td><span id="test4end"><a href="http://www.google.com/">3</a></span></td></tr></tbody></table> <a href="http://www.google.com/"><br> This </a><b><a href="http://www.google.com/">line</a></b><a href="http://www.google.com/"> contains <img src="../resources/abe.png"> an image. </a>
diff --git a/LayoutTests/platform/mac/editing/style/5228141-expected.txt b/LayoutTests/platform/mac/editing/style/5228141-expected.txt
index b06d2ae..f5b1197 100644
--- a/LayoutTests/platform/mac/editing/style/5228141-expected.txt
+++ b/LayoutTests/platform/mac/editing/style/5228141-expected.txt
@@ -11,10 +11,9 @@ layer at (0,0) size 800x600
           RenderInline {B} at (0,0) size 0x18
             RenderBR {BR} at (0,0) size 0x18
         RenderBlock {DIV} at (0,18) size 784x107
-          RenderInline {B} at (0,0) size 166x18
+          RenderInline {B} at (0,0) size 242x18
             RenderText {#text} at (0,89) size 166x18
               text run at (0,89) width 166: "This text should be bold."
-          RenderInline {B} at (0,0) size 76x18
             RenderImage {IMG} at (166,0) size 76x103
 selection start: position 0 of child 0 {BR} of child 0 {B} of child 2 {DIV} of child 1 {BODY} of child 0 {HTML} of document
-selection end:   position 1 of child 0 {IMG} of child 1 {B} of child 1 {DIV} of child 2 {DIV} of child 1 {BODY} of child 0 {HTML} of document
+selection end:   position 1 of child 1 {IMG} of child 0 {B} of child 1 {DIV} of child 2 {DIV} of child 1 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/platform/mac/editing/style/style-boundary-001-expected.txt b/LayoutTests/platform/mac/editing/style/style-boundary-001-expected.txt
index 953d550..e02d606 100644
--- a/LayoutTests/platform/mac/editing/style/style-boundary-001-expected.txt
+++ b/LayoutTests/platform/mac/editing/style/style-boundary-001-expected.txt
@@ -31,11 +31,10 @@ layer at (0,0) size 800x600
           RenderText {#text} at (0,0) size 0x0
       RenderBlock {DIV} at (0,180) size 784x32
         RenderBlock {DIV} at (0,0) size 784x32 [border: (2px solid #FF0000)]
-          RenderInline {B} at (0,0) size 12x28
+          RenderInline {B} at (0,0) size 25x28
             RenderText {#text} at (2,2) size 12x28
               text run at (2,2) width 12: "a"
-          RenderInline {B} at (0,0) size 13x28
             RenderText {#text} at (14,2) size 13x28
               text run at (14,2) width 13: "b"
-selection start: position 0 of child 0 {#text} of child 1 {B} of child 1 {DIV} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
-selection end:   position 1 of child 0 {#text} of child 1 {B} of child 1 {DIV} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
+selection start: position 0 of child 1 {#text} of child 0 {B} of child 1 {DIV} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
+selection end:   position 1 of child 1 {#text} of child 0 {B} of child 1 {DIV} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 2ce6350..a174d6e 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,28 @@
+2009-10-09  Ryosuke Niwa  <rniwa at webkit.org>
+
+        Reviewed by Eric Seidel.
+
+        ApplyStyleCommand removes presentational tags even when not necessary
+        https://bugs.webkit.org/show_bug.cgi?id=28091
+
+        This patch updates implicitlyStyledElementShouldBeRemovedWhenApplyingStyle to return true
+        (triggering removal of tag) only if the style implicitly added by the element is not present in
+        the new style to apply. It also changes surroundNodeRangeWithElement so that it merges the
+        surrounding element when possible. applyTextDecorationStyle is modified so that it does not add
+        style span when the style attribute is empty.
+
+        Test: editing/execCommand/toggle-style-3.html
+
+        * editing/ApplyStyleCommand.cpp:
+        (WebCore::ApplyStyleCommand::shouldRemoveTextDecorationTag): Returns true if specified text
+        decoration is not present in the style to apply
+        (WebCore::ApplyStyleCommand::implicitlyStyledElementShouldBeRemovedWhenApplyingStyle): No longer
+        returns true if the tag is used in new style
+        (WebCore::ApplyStyleCommand::applyTextDecorationStyle): Does not add style-span when redundant
+        (WebCore::ApplyStyleCommand::surroundNodeRangeWithElement): Merges the newly created element
+        with the surrounding identical elements
+        * editing/ApplyStyleCommand.h:
+
 2009-10-09  Adam Barth  <abarth at webkit.org>
 
         Reviewed by Darin Adler.
diff --git a/WebCore/editing/ApplyStyleCommand.cpp b/WebCore/editing/ApplyStyleCommand.cpp
index 83d0bd3..89d862f 100644
--- a/WebCore/editing/ApplyStyleCommand.cpp
+++ b/WebCore/editing/ApplyStyleCommand.cpp
@@ -1079,6 +1079,23 @@ void ApplyStyleCommand::applyInlineStyleToRange(CSSMutableStyleDeclaration* styl
     }
 }
 
+bool ApplyStyleCommand::shouldRemoveTextDecorationTag(CSSStyleDeclaration* styleToApply, int textDecorationAddedByTag) const
+{
+    // Honor text-decorations-in-effect
+    RefPtr<CSSValue> textDecorationsToApply = styleToApply->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect);
+    if (!textDecorationsToApply || !textDecorationsToApply->isValueList())
+        textDecorationsToApply = styleToApply->getPropertyCSSValue(CSSPropertyTextDecoration);
+
+    // When there is no text decorations to apply, remove any one of u, s, & strike
+    if (!textDecorationsToApply || !textDecorationsToApply->isValueList())
+        return true;
+
+    // Remove node if it implicitly adds style not present in styleToApply
+    CSSValueList* valueList = static_cast<CSSValueList*>(textDecorationsToApply.get());
+    RefPtr<CSSPrimitiveValue> value = CSSPrimitiveValue::createIdentifier(textDecorationAddedByTag);
+    return !valueList->hasValue(value.get());
+}
+
 // This function maps from styling tags to CSS styles.  Used for knowing which
 // styling tags should be removed when toggling styles.
 bool ApplyStyleCommand::implicitlyStyledElementShouldBeRemovedWhenApplyingStyle(HTMLElement* elem, CSSMutableStyleDeclaration* style)
@@ -1092,36 +1109,25 @@ bool ApplyStyleCommand::implicitlyStyledElementShouldBeRemovedWhenApplyingStyle(
         case CSSPropertyFontWeight:
             // IE inserts "strong" tags for execCommand("bold"), so we remove them, even though they're not strictly presentational
             if (elem->hasLocalName(bTag) || elem->hasLocalName(strongTag))
-                return true;
+                return !equalIgnoringCase(property.value()->cssText(), "bold") || !elem->hasChildNodes();
             break;
         case CSSPropertyVerticalAlign:
-            if (elem->hasLocalName(subTag) || elem->hasLocalName(supTag))
-                return true;
+            if (elem->hasLocalName(subTag))
+                return !equalIgnoringCase(property.value()->cssText(), "sub") || !elem->hasChildNodes();
+            if (elem->hasLocalName(supTag))
+                return !equalIgnoringCase(property.value()->cssText(), "sup") || !elem->hasChildNodes();
             break;
         case CSSPropertyFontStyle:
             // IE inserts "em" tags for execCommand("italic"), so we remove them, even though they're not strictly presentational
             if (elem->hasLocalName(iTag) || elem->hasLocalName(emTag))
-                return true;
+                return !equalIgnoringCase(property.value()->cssText(), "italic") || !elem->hasChildNodes();
             break;
         case CSSPropertyTextDecoration:
         case CSSPropertyWebkitTextDecorationsInEffect:
-                ASSERT(property.value());
-                if (property.value()->isValueList()) {
-                    CSSValueList* valueList = static_cast<CSSValueList*>(property.value());
-                    DEFINE_STATIC_LOCAL(RefPtr<CSSPrimitiveValue>, underline, (CSSPrimitiveValue::createIdentifier(CSSValueUnderline)));
-                    DEFINE_STATIC_LOCAL(RefPtr<CSSPrimitiveValue>, lineThrough, (CSSPrimitiveValue::createIdentifier(CSSValueLineThrough)));
-                    // Because style is new style to be applied, we delete element only if the element is not used in style.
-                    if (!valueList->hasValue(underline.get()) && elem->hasLocalName(uTag))
-                        return true;
-                    if (!valueList->hasValue(lineThrough.get()) && (elem->hasLocalName(strikeTag) || elem->hasLocalName(sTag)))
-                        return true;
-                } else {
-                    // If the value is NOT a list, then it must be "none", in which case we should remove all text decorations.
-                    ASSERT(property.value()->cssText() == "none");
-                    if (elem->hasLocalName(uTag) || elem->hasLocalName(strikeTag) || elem->hasLocalName(sTag))
-                        return true;
-                }
-                break;
+                if (elem->hasLocalName(uTag))
+                    return shouldRemoveTextDecorationTag(style, CSSValueUnderline) || !elem->hasChildNodes();
+                else if (elem->hasLocalName(sTag) || elem->hasTagName(strikeTag))
+                    return shouldRemoveTextDecorationTag(style,CSSValueLineThrough) || !elem->hasChildNodes();
         }
     }
     return false;
@@ -1307,19 +1313,18 @@ void ApplyStyleCommand::applyTextDecorationStyle(Node *node, CSSMutableStyleDecl
     if (!style || style->cssText().isEmpty())
         return;
 
-    if (node->isTextNode()) {
-        RefPtr<HTMLElement> styleSpan = createStyleSpanElement(document());
-        surroundNodeRangeWithElement(node, node, styleSpan.get());
-        node = styleSpan.get();
-    }
-
-    if (!node->isElementNode())
-        return;
+    StyleChange styleChange(style, Position(node, 0));
+    if (styleChange.cssStyle().length()) {
+        if (node->isTextNode()) {
+            RefPtr<HTMLElement> styleSpan = createStyleSpanElement(document());
+            surroundNodeRangeWithElement(node, node, styleSpan.get());
+            node = styleSpan.get();
+        }
 
-    HTMLElement *element = static_cast<HTMLElement *>(node);
+        if (!node->isElementNode())
+            return;
 
-    StyleChange styleChange(style, Position(element, 0));
-    if (styleChange.cssStyle().length()) {
+        HTMLElement *element = static_cast<HTMLElement *>(node);
         String cssText = styleChange.cssStyle();
         CSSMutableStyleDeclaration *decl = element->inlineStyleDecl();
         if (decl)
@@ -1679,6 +1684,20 @@ void ApplyStyleCommand::surroundNodeRangeWithElement(Node* startNode, Node* endN
             break;
         node = next;
     }
+
+    Node* nextSibling = element->nextSibling();
+    Node* previousSibling = element->previousSibling();
+    if (nextSibling && nextSibling->isElementNode() && nextSibling->isContentEditable()
+        && areIdenticalElements(element.get(), static_cast<Element*>(nextSibling)))
+        mergeIdenticalElements(element, static_cast<Element*>(nextSibling));
+
+    if (previousSibling && previousSibling->isElementNode() && previousSibling->isContentEditable()) {
+        Node* mergedElement = previousSibling->nextSibling();
+        if (mergedElement->isElementNode() && mergedElement->isContentEditable()
+            && areIdenticalElements(static_cast<Element*>(previousSibling), static_cast<Element*>(mergedElement)))
+            mergeIdenticalElements(static_cast<Element*>(previousSibling), static_cast<Element*>(mergedElement));
+    }
+
     // FIXME: We should probably call updateStartEnd if the start or end was in the node
     // range so that the endingSelection() is canonicalized.  See the comments at the end of
     // VisibleSelection::validate().
diff --git a/WebCore/editing/ApplyStyleCommand.h b/WebCore/editing/ApplyStyleCommand.h
index 29aa483..2804604 100644
--- a/WebCore/editing/ApplyStyleCommand.h
+++ b/WebCore/editing/ApplyStyleCommand.h
@@ -62,6 +62,7 @@ private:
     CSSMutableStyleDeclaration* style() const { return m_style.get(); }
 
     // style-removal helpers
+    bool shouldRemoveTextDecorationTag(CSSStyleDeclaration* styleToApply, int textDecorationAddedByTag) const;
     bool implicitlyStyledElementShouldBeRemovedWhenApplyingStyle(HTMLElement*, CSSMutableStyleDeclaration*);
     void replaceWithSpanOrRemoveIfWithoutAttributes(HTMLElement*&);
     void removeHTMLFontStyle(CSSMutableStyleDeclaration*, HTMLElement*);

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list