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

adele at apple.com adele at apple.com
Thu Oct 29 20:34:23 UTC 2009


The following commit has been merged in the webkit-1.1 branch:
commit d6b05948112634d06088a1c8d40d298053aeabb6
Author: adele at apple.com <adele at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Sep 25 18:55:42 2009 +0000

    WebCore: Fix for https://bugs.webkit.org/show_bug.cgi?id=29740
    <rdar://problem/7168738> Gmail: After changing a foreground text color, pressing return doesn't apply background to new line
    
    Patch by Enrica Casucci <enrica at apple.com> on 2009-09-25
    Reviewed by Darin Adler, Dan Bernstein, Adele Peterson, and others.
    
    Change the way style is preserved when inserting a new paragraph.
    The original code handled insertion at the beginning and at the end of a paragraph as special
    cases. The newly created paragraph contained a set of nodes generated starting from the
    computed style of the insertion node. This approach has two problems:
    1. if the insertion node has a non opaque background color and one of the parent element did have
    a solid background color the new paragraph did not have the element with the solid color in the tree.
    2. in some circumstances it generated more markup than the original paragraph had (a span with bold, italic,
    background color and some font attribute was being reproduced as span + bold + italic + font as separate tags.
    The new approach is to recreate in the new paragraph the same hierarchy of nodes found in the
    paragraph where the insertion point is.
    
    Test: editing/inserting/insert-bg-font.html
    
    * editing/InsertParagraphSeparatorCommand.cpp:
    (WebCore::InsertParagraphSeparatorCommand::getAncestorsInsideBlock): retrieves the list of all the ancestors
    between the insert node and the outer block.
    (WebCore::InsertParagraphSeparatorCommand::cloneHierarchyUnderNewBlock): uses the list of ancestors to recreate
    in the new paragraph the same element hierarchy present in the starting paragraph.
    (WebCore::InsertParagraphSeparatorCommand::doApply): changed the code to handle the general case of insertion
    in the middle of the paragraph to use the new methods. Changed the handling of the insertion at the beginning and
    at the end of the paragraph to use the new methods instead of applying the calculated style.
    * editing/InsertParagraphSeparatorCommand.h: added methods getAncestorsInsideBlock and cloneHierarchyUnderNewBlock.
    
    LayoutTests: Updated the expected results to reflect the changes in the way the new paragraph
    is created and added test case for https://bugs.webkit.org/show_bug.cgi?id=29740
    <rdar://problem/7168738> Gmail: After changing a foreground text color, pressing return doesn't apply background to new line
    
    Patch by Enrica Casucci <enrica at apple.com> on 2009-09-25
    Reviewed by Darin Adler, Dan Bernstein, Adele Peterson, and others.
    
    * editing/inserting/insert-bg-font.html: Added.
    * platform/mac/editing/inserting/insert-bg-font-expected.txt: Added.
    * platform/mac/editing/pasteboard/5478250-expected.txt:
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@48764 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index a21427e..08515f4 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,15 @@
+2009-09-25  Enrica Casucci  <enrica at apple.com>
+
+        Reviewed by Darin Adler, Dan Bernstein, Adele Peterson, and others.
+
+        Updated the expected results to reflect the changes in the way the new paragraph
+        is created and added test case for https://bugs.webkit.org/show_bug.cgi?id=29740
+        <rdar://problem/7168738> Gmail: After changing a foreground text color, pressing return doesn't apply background to new line
+
+        * editing/inserting/insert-bg-font.html: Added.
+        * platform/mac/editing/inserting/insert-bg-font-expected.txt: Added.
+        * platform/mac/editing/pasteboard/5478250-expected.txt:
+
 2009-09-25  Yuan Song  <song.yuan at ericsson.com>
 
         Reviewed by Darin Adler.
diff --git a/LayoutTests/editing/inserting/insert-bg-font.html b/LayoutTests/editing/inserting/insert-bg-font.html
new file mode 100644
index 0000000..5dd8ffa
--- /dev/null
+++ b/LayoutTests/editing/inserting/insert-bg-font.html
@@ -0,0 +1,21 @@
+<html>
+    <head>
+        <script>
+            function test()
+            {
+                if (window.layoutTestController)
+                    layoutTestController.dumpAsText();
+
+                window.getSelection().setPosition(document.getElementById('dv'), 1);
+                document.execCommand("InsertParagraph");
+                document.execCommand("InsertText", false, "this should also be blue over lightgrey");
+
+                document.write("<xmp>" + document.body.innerHTML + "</xmp>");
+            }
+        </script>
+    </head>
+    <body onload="test()">
+        <div id="dv" contenteditable><span style="background-color: lightgrey">lightgrey background<font color="blue">blue font color over lightgrey background</font></span> 
+</div>
+    </body>
+</html>
diff --git a/LayoutTests/platform/mac/editing/inserting/insert-bg-font-expected.txt b/LayoutTests/platform/mac/editing/inserting/insert-bg-font-expected.txt
new file mode 100644
index 0000000..4f9bac2
--- /dev/null
+++ b/LayoutTests/platform/mac/editing/inserting/insert-bg-font-expected.txt
@@ -0,0 +1,6 @@
+
+        <div id="dv" contenteditable=""><span style="background-color: lightgrey">lightgrey background<font color="blue">blue font color over lightgrey background</font></span> 
+<div><span style="background-color: lightgrey"><font color="blue">this should also be blue over lightgrey</font></span></div></div>
+    
+
+
diff --git a/LayoutTests/platform/mac/editing/pasteboard/5478250-expected.txt b/LayoutTests/platform/mac/editing/pasteboard/5478250-expected.txt
index 68ff415..cd25b79 100644
--- a/LayoutTests/platform/mac/editing/pasteboard/5478250-expected.txt
+++ b/LayoutTests/platform/mac/editing/pasteboard/5478250-expected.txt
@@ -17,7 +17,7 @@ layer at (0,0) size 800x600
             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
+          RenderInline {SPAN} 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 1 {BODY} of child 0 {HTML} of document
+caret: position 61 of child 0 {#text} of child 0 {SPAN} of child 2 {DIV} of child 4 {DIV} of child 1 {BODY} of child 0 {HTML} of document
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 9655f54..b433eba 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,33 @@
+2009-09-25  Enrica Casucci  <enrica at apple.com>
+
+        Reviewed by Darin Adler, Dan Bernstein, Adele Peterson, and others.
+
+        Fix for https://bugs.webkit.org/show_bug.cgi?id=29740
+        <rdar://problem/7168738> Gmail: After changing a foreground text color, pressing return doesn't apply background to new line
+
+        Change the way style is preserved when inserting a new paragraph.
+        The original code handled insertion at the beginning and at the end of a paragraph as special
+        cases. The newly created paragraph contained a set of nodes generated starting from the
+        computed style of the insertion node. This approach has two problems:
+        1. if the insertion node has a non opaque background color and one of the parent element did have
+        a solid background color the new paragraph did not have the element with the solid color in the tree.
+        2. in some circumstances it generated more markup than the original paragraph had (a span with bold, italic,
+        background color and some font attribute was being reproduced as span + bold + italic + font as separate tags.
+        The new approach is to recreate in the new paragraph the same hierarchy of nodes found in the
+        paragraph where the insertion point is.
+
+        Test: editing/inserting/insert-bg-font.html
+
+        * editing/InsertParagraphSeparatorCommand.cpp:
+        (WebCore::InsertParagraphSeparatorCommand::getAncestorsInsideBlock): retrieves the list of all the ancestors
+        between the insert node and the outer block.
+        (WebCore::InsertParagraphSeparatorCommand::cloneHierarchyUnderNewBlock): uses the list of ancestors to recreate
+        in the new paragraph the same element hierarchy present in the starting paragraph.
+        (WebCore::InsertParagraphSeparatorCommand::doApply): changed the code to handle the general case of insertion
+        in the middle of the paragraph to use the new methods. Changed the handling of the insertion at the beginning and
+        at the end of the paragraph to use the new methods instead of applying the calculated style.
+        * editing/InsertParagraphSeparatorCommand.h: added methods getAncestorsInsideBlock and cloneHierarchyUnderNewBlock.
+
 2009-09-25  Patrick Mueller  <Patrick_Mueller at us.ibm.com>
 
         Reviewed by Timothy Hatcher.
diff --git a/WebCore/editing/InsertParagraphSeparatorCommand.cpp b/WebCore/editing/InsertParagraphSeparatorCommand.cpp
index 9823aba..695f46a 100644
--- a/WebCore/editing/InsertParagraphSeparatorCommand.cpp
+++ b/WebCore/editing/InsertParagraphSeparatorCommand.cpp
@@ -103,6 +103,30 @@ bool InsertParagraphSeparatorCommand::shouldUseDefaultParagraphElement(Node* enc
            enclosingBlock->hasTagName(h5Tag);
 }
 
+void InsertParagraphSeparatorCommand::getAncestorsInsideBlock(const Node* insertionNode, Element* outerBlock, Vector<Element*>& ancestors)
+{
+    ancestors.clear();
+    
+    // Build up list of ancestors elements between the insertion node and the outer block.
+    if (insertionNode != outerBlock) {
+        for (Element* n = insertionNode->parentElement(); n && n != outerBlock; n = n->parentElement())
+            ancestors.append(n);
+    }
+}
+
+PassRefPtr<Element> InsertParagraphSeparatorCommand::cloneHierarchyUnderNewBlock(const Vector<Element*>& ancestors, PassRefPtr<Element> blockToInsert)
+{
+    // Make clones of ancestors in between the start node and the start block.
+    RefPtr<Element> parent = blockToInsert;
+    for (size_t i = ancestors.size(); i != 0; --i) {
+        RefPtr<Element> child = ancestors[i - 1]->cloneElementWithoutChildren();
+        appendNode(child, parent);
+        parent = child.release();
+    }
+    
+    return parent.release();
+}
+
 void InsertParagraphSeparatorCommand::doApply()
 {
     bool splitText = false;
@@ -193,12 +217,18 @@ void InsertParagraphSeparatorCommand::doApply()
             insertNodeAfter(blockToInsert, startBlock);
         }
 
-        appendBlockPlaceholder(blockToInsert);
-        setEndingSelection(VisibleSelection(Position(blockToInsert.get(), 0), DOWNSTREAM));
-        if (shouldApplyStyleAfterInsertion)
-            applyStyleAfterInsertion(startBlock);
+        // Recreate the same structure in the new paragraph.
+        
+        Vector<Element*> ancestors;
+        getAncestorsInsideBlock(insertionPosition.node(), startBlock, ancestors);      
+        RefPtr<Element> parent = cloneHierarchyUnderNewBlock(ancestors, blockToInsert);
+        
+        appendBlockPlaceholder(parent);
+
+        setEndingSelection(VisibleSelection(Position(parent.get(), 0), DOWNSTREAM));
         return;
     }
+    
 
     //---------------------------------------------------------------------
     // Handle case when position is in the first visible position in its block, and
@@ -217,9 +247,15 @@ void InsertParagraphSeparatorCommand::doApply()
         insertionPosition = insertionPosition.downstream();
         
         insertNodeBefore(blockToInsert, refNode);
-        appendBlockPlaceholder(blockToInsert.get());
-        setEndingSelection(VisibleSelection(Position(blockToInsert.get(), 0), DOWNSTREAM));
-        applyStyleAfterInsertion(startBlock);
+
+        // Recreate the same structure in the new paragraph.
+
+        Vector<Element*> ancestors;
+        getAncestorsInsideBlock(positionAvoidingSpecialElementBoundary(insertionPosition).node(), startBlock, ancestors);
+        
+        appendBlockPlaceholder(cloneHierarchyUnderNewBlock(ancestors, blockToInsert));
+        
+        // In this case, we need to set the new ending selection.
         setEndingSelection(VisibleSelection(insertionPosition, DOWNSTREAM));
         return;
     }
@@ -248,10 +284,7 @@ void InsertParagraphSeparatorCommand::doApply()
 
     // Build up list of ancestors in between the start node and the start block.
     Vector<Element*> ancestors;
-    if (insertionPosition.node() != startBlock) {
-        for (Element* n = insertionPosition.node()->parentElement(); n && n != startBlock; n = n->parentElement())
-            ancestors.append(n);
-    }
+    getAncestorsInsideBlock(insertionPosition.node(), startBlock, ancestors);
 
     // Make sure we do not cause a rendered space to become unrendered.
     // FIXME: We need the affinity for pos, but pos.downstream() does not give it
@@ -284,13 +317,8 @@ void InsertParagraphSeparatorCommand::doApply()
 
     updateLayout();
     
-    // Make clones of ancestors in between the start node and the start block.
-    RefPtr<Element> parent = blockToInsert;
-    for (size_t i = ancestors.size(); i != 0; --i) {
-        RefPtr<Element> child = ancestors[i - 1]->cloneElementWithoutChildren();
-        appendNode(child, parent);
-        parent = child.release();
-    }
+    // Make clones of ancestors in between the start node and the outer block.
+    RefPtr<Element> parent = cloneHierarchyUnderNewBlock(ancestors, blockToInsert);
 
     // If the paragraph separator was inserted at the end of a paragraph, an empty line must be
     // created.  All of the nodes, starting at visiblePos, are about to be added to the new paragraph 
diff --git a/WebCore/editing/InsertParagraphSeparatorCommand.h b/WebCore/editing/InsertParagraphSeparatorCommand.h
index 01c08bf..23ee51c 100644
--- a/WebCore/editing/InsertParagraphSeparatorCommand.h
+++ b/WebCore/editing/InsertParagraphSeparatorCommand.h
@@ -44,6 +44,8 @@ private:
 
     void calculateStyleBeforeInsertion(const Position&);
     void applyStyleAfterInsertion(Node* originalEnclosingBlock);
+    void getAncestorsInsideBlock(const Node* insertionNode, Element* outerBlock, Vector<Element*>& ancestors);
+    PassRefPtr<Element> cloneHierarchyUnderNewBlock(const Vector<Element*>& ancestors, PassRefPtr<Element> blockToInsert);
     
     bool shouldUseDefaultParagraphElement(Node*) const;
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list