[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

enrica at apple.com enrica at apple.com
Thu Apr 8 01:59:39 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit b5adb4e241f2a3f528b9b6337099e06b84f97206
Author: enrica at apple.com <enrica at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Feb 26 00:43:50 2010 +0000

    Extra layout on keypress after a space (problem with rebalanceWhitespaceAt in InsertTextCommand).
    https://bugs.webkit.org/show_bug.cgi?id=30946
    <rdar://problem/7639184>
    
    Reviewed by Adele Peterson.
    
    WebCore:
    
    Do text insertion and whitespace rebalancing around the insertion in one step so that there's only one layout.
    This patch was originally made by Justin Garcia.
    
    Test: editing/inserting/rebalance-whitespace-1.html
    
    * editing/CompositeEditCommand.cpp:
    (WebCore::CompositeEditCommand::rebalanceWhitespaceAt): No behavior changes here,
    just pushed the code that determined the extent of whitespace surrounding a position
    to its own helper function.
    * editing/InsertTextCommand.cpp:
    (WebCore::InsertTextCommand::insertTextIntoNodeAndRebalanceWhitespace): Added.  Find
    whitespace surrounding the insertion position, add the text to insert, rebalance that entire
    string, then insert it into the document.
    (WebCore::InsertTextCommand::input):
    * editing/InsertTextCommand.h:
    * editing/htmlediting.cpp:
    (WebCore::isWhitespace): Moved from CompositeEditCommand.cpp.
    (WebCore::extentOfWhitespaceForRebalancingAt): Moved code from rebalanceWhitespaceAt into this helper
    function.  Obtains the offset of the start and end of whitespace around a particular position.
    * editing/htmlediting.h:
    
    LayoutTests:
    
    There are now regular spaces where nbsps were used unnecessarily before.  Also,
    multi-character insertions now have their whitespace rebalanced, and this is
    reflected in a few tests.
    
    * editing/execCommand/5142012-3-expected.txt:
    * editing/inserting/rebalance-whitespace-1-expected.txt: Added.
    * editing/inserting/rebalance-whitespace-1.html: Added.
    * editing/pasteboard/5521237-expected.txt:
    * platform/mac/editing/execCommand/5482023-expected.checksum:
    * platform/mac/editing/execCommand/5482023-expected.png: Removed.
    * platform/mac/editing/execCommand/5482023-expected.txt:
    * platform/mac/editing/execCommand/remove-formatting-2-expected.checksum:
    * platform/mac/editing/execCommand/remove-formatting-2-expected.png: Removed.
    * platform/mac/editing/execCommand/remove-formatting-expected.checksum:
    * platform/mac/editing/execCommand/remove-formatting-expected.png: Removed.
    * platform/mac/editing/execCommand/remove-formatting-expected.txt:
    * platform/mac/editing/inserting/editable-html-element-expected.checksum:
    * platform/mac/editing/inserting/editable-html-element-expected.png: Removed.
    * platform/mac/editing/inserting/editable-html-element-expected.txt:
    * platform/mac/editing/pasteboard/4989774-expected.checksum:
    * platform/mac/editing/pasteboard/4989774-expected.png: Removed.
    * platform/mac/editing/pasteboard/4989774-expected.txt:
    * platform/mac/editing/selection/4983858-expected.checksum:
    * platform/mac/editing/selection/4983858-expected.png: Removed.
    * platform/mac/editing/selection/4983858-expected.txt:
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@55263 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 14a3f43..51a3680 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,37 @@
+2010-02-25  Enrica Casucci  <enrica at apple.com>
+
+        Reviewed by Adele Peterson.
+
+        Extra layout on keypress after a space (problem with rebalanceWhitespaceAt in InsertTextCommand).
+        https://bugs.webkit.org/show_bug.cgi?id=30946
+        <rdar://problem/7639184>
+
+        There are now regular spaces where nbsps were used unnecessarily before.  Also,
+        multi-character insertions now have their whitespace rebalanced, and this is
+        reflected in a few tests.
+
+        * editing/execCommand/5142012-3-expected.txt:
+        * editing/inserting/rebalance-whitespace-1-expected.txt: Added.
+        * editing/inserting/rebalance-whitespace-1.html: Added.
+        * editing/pasteboard/5521237-expected.txt:
+        * platform/mac/editing/execCommand/5482023-expected.checksum:
+        * platform/mac/editing/execCommand/5482023-expected.png: Removed.
+        * platform/mac/editing/execCommand/5482023-expected.txt:
+        * platform/mac/editing/execCommand/remove-formatting-2-expected.checksum:
+        * platform/mac/editing/execCommand/remove-formatting-2-expected.png: Removed.
+        * platform/mac/editing/execCommand/remove-formatting-expected.checksum:
+        * platform/mac/editing/execCommand/remove-formatting-expected.png: Removed.
+        * platform/mac/editing/execCommand/remove-formatting-expected.txt:
+        * platform/mac/editing/inserting/editable-html-element-expected.checksum:
+        * platform/mac/editing/inserting/editable-html-element-expected.png: Removed.
+        * platform/mac/editing/inserting/editable-html-element-expected.txt:
+        * platform/mac/editing/pasteboard/4989774-expected.checksum:
+        * platform/mac/editing/pasteboard/4989774-expected.png: Removed.
+        * platform/mac/editing/pasteboard/4989774-expected.txt:
+        * platform/mac/editing/selection/4983858-expected.checksum:
+        * platform/mac/editing/selection/4983858-expected.png: Removed.
+        * platform/mac/editing/selection/4983858-expected.txt:
+
 2010-02-25  Alexey Proskuryakov  <ap at apple.com>
 
         Reviewed by Anders Carlsson.
diff --git a/LayoutTests/editing/execCommand/5142012-3-expected.txt b/LayoutTests/editing/execCommand/5142012-3-expected.txt
index cd1ef06..39f76d8 100644
--- a/LayoutTests/editing/execCommand/5142012-3-expected.txt
+++ b/LayoutTests/editing/execCommand/5142012-3-expected.txt
@@ -1,5 +1,5 @@
 This tests for a bug when inserting after a link at the end of the document. Like TextEdit, we insert content outside of the link, but inserting outside of the link shouldn't cause the content to be inserted in the wrong paragraph.
 
 This paragraph should not contains links.
-This sentence should be a link. This sentence should not.
-<a href="#">This sentence should be a link.</a>&nbsp;This sentence should not.
+This sentence should be a link. This sentence should not.
+<a href="#">This sentence should be a link.</a> This sentence should not.
diff --git a/LayoutTests/editing/inserting/rebalance-whitespace-1-expected.txt b/LayoutTests/editing/inserting/rebalance-whitespace-1-expected.txt
new file mode 100644
index 0000000..66ccfb2
--- /dev/null
+++ b/LayoutTests/editing/inserting/rebalance-whitespace-1-expected.txt
@@ -0,0 +1,12 @@
+This tests whitespace rebalancing when inserting characters in and around already balanced sequences. In each div below, 2 or more adjacent whitespace characters should be alternate between regular whitespace and non-breaking spaces (note that editable regions use -webkit-nbsp-mode:space).
+
+hellox world
+hellox  world
+hellox   world
+hello x world
+hello  x world
+hello  x  world
+hello  x   world
+hello   x  world
+hello   x   world
+
diff --git a/LayoutTests/editing/inserting/rebalance-whitespace-1.html b/LayoutTests/editing/inserting/rebalance-whitespace-1.html
new file mode 100644
index 0000000..047448f
--- /dev/null
+++ b/LayoutTests/editing/inserting/rebalance-whitespace-1.html
@@ -0,0 +1,123 @@
+<script>
+if (window.layoutTestController)
+    window.layoutTestController.dumpAsText();
+</script>
+
+<div contentEditable="true" id="test1">hello world</div>
+<script>
+// Test rebalancing a single space on one side.
+test = document.getElementById("test1");
+text = test.firstChild;
+window.getSelection().setPosition(text, 5);
+document.execCommand("InsertText", false, "x");
+</script>
+
+<div contentEditable="true" id="test2">hello world</div>
+<script>
+// Test rebalancing two spaces on one side.
+test = document.getElementById("test2");
+text = test.firstChild;
+window.getSelection().setPosition(text, 5);
+document.execCommand("InsertText", false, " ");
+window.getSelection().setPosition(text, 5);
+document.execCommand("InsertText", false, "x");
+</script>
+
+<div contentEditable="true" id="test3">hello world</div>
+<script>
+// Test rebalancing three spaces on one side.
+test = document.getElementById("test3");
+text = test.firstChild;
+window.getSelection().setPosition(text, 5);
+document.execCommand("InsertText", false, " ");
+document.execCommand("InsertText", false, " ");
+window.getSelection().setPosition(text, 5);
+document.execCommand("InsertText", false, "x");
+</script>
+
+<div contentEditable="true" id="test4">hello world</div>
+<script>
+// Test rebalancing one space on either side of the insertion.
+test = document.getElementById("test4");
+text = test.firstChild;
+window.getSelection().setPosition(text, 5);
+document.execCommand("InsertText", false, " ");
+window.getSelection().setPosition(text, 6);
+document.execCommand("InsertText", false, "x");
+</script>
+
+<div contentEditable="true" id="test5">hello world</div>
+<script>
+// Test rebalancing two spaces on one side and one space on the other side of the insertion.
+test = document.getElementById("test5");
+text = test.firstChild;
+window.getSelection().setPosition(text, 5);
+document.execCommand("InsertText", false, " ");
+document.execCommand("InsertText", false, " ");
+window.getSelection().setPosition(text, 7);
+document.execCommand("InsertText", false, "x");
+</script>
+
+<div contentEditable="true" id="test6">hello world</div>
+<script>
+// Test rebalancing two spaces on either side of the insertion.
+test = document.getElementById("test6");
+text = test.firstChild;
+window.getSelection().setPosition(text, 5);
+document.execCommand("InsertText", false, " ");
+document.execCommand("InsertText", false, " ");
+document.execCommand("InsertText", false, " ");
+window.getSelection().setPosition(text, 7);
+document.execCommand("InsertText", false, "x");
+</script>
+
+<div contentEditable="true" id="test7">hello world</div>
+<script>
+// Test rebalancing two spaces on either side of the insertion.
+test = document.getElementById("test7");
+text = test.firstChild;
+window.getSelection().setPosition(text, 5);
+document.execCommand("InsertText", false, " ");
+document.execCommand("InsertText", false, " ");
+document.execCommand("InsertText", false, " ");
+document.execCommand("InsertText", false, " ");
+window.getSelection().setPosition(text, 7);
+document.execCommand("InsertText", false, "x");
+</script>
+
+<div contentEditable="true" id="test8">hello world</div>
+<script>
+// Test rebalancing three spaces on one side and two on the other side of the insertion.
+test = document.getElementById("test8");
+text = test.firstChild;
+window.getSelection().setPosition(text, 5);
+document.execCommand("InsertText", false, " ");
+document.execCommand("InsertText", false, " ");
+document.execCommand("InsertText", false, " ");
+document.execCommand("InsertText", false, " ");
+window.getSelection().setPosition(text, 8);
+document.execCommand("InsertText", false, "x");
+</script>
+
+<div contentEditable="true" id="test9">hello world</div>
+<script>
+// Test rebalancing three spaces on either side of the insertion.
+test = document.getElementById("test9");
+text = test.firstChild;
+window.getSelection().setPosition(text, 5);
+document.execCommand("InsertText", false, " ");
+document.execCommand("InsertText", false, " ");
+document.execCommand("InsertText", false, " ");
+document.execCommand("InsertText", false, " ");
+document.execCommand("InsertText", false, " ");
+window.getSelection().setPosition(text, 8);
+document.execCommand("InsertText", false, "x");
+</script>
+
+<script>
+divs = document.getElementsByTagName("div");
+var output = "This tests whitespace rebalancing when inserting characters in and around already balanced sequences. In each div below, 2 or more adjacent whitespace characters should be alternate between regular whitespace and non-breaking spaces (note that editable regions use -webkit-nbsp-mode:space).\n\n";
+for (i = 0; i < divs.length; i++)
+    output += divs[i].innerText + "\n";
+document.body.innerText = output;
+</script>
diff --git a/LayoutTests/editing/pasteboard/5521237-expected.txt b/LayoutTests/editing/pasteboard/5521237-expected.txt
index 41b2ff9..13d76ca 100644
--- a/LayoutTests/editing/pasteboard/5521237-expected.txt
+++ b/LayoutTests/editing/pasteboard/5521237-expected.txt
@@ -1,3 +1,3 @@
 This tests for a bug when pasting a word copied from TextEdit after a regular, breaking space.
 
-Everything in this editable region should be in one paragraph.
+Everything in this editable region should be in one paragraph.
diff --git a/LayoutTests/platform/mac/editing/execCommand/5482023-expected.checksum b/LayoutTests/platform/mac/editing/execCommand/5482023-expected.checksum
index b22dc85..54b515b 100644
--- a/LayoutTests/platform/mac/editing/execCommand/5482023-expected.checksum
+++ b/LayoutTests/platform/mac/editing/execCommand/5482023-expected.checksum
@@ -1 +1 @@
-e67357e5552e5cf2f062416e2f357fa7
\ No newline at end of file
+72752236297a99482053d1bf0732fbfe
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/editing/execCommand/5482023-expected.png b/LayoutTests/platform/mac/editing/execCommand/5482023-expected.png
deleted file mode 100644
index bb306c2..0000000
Binary files a/LayoutTests/platform/mac/editing/execCommand/5482023-expected.png and /dev/null differ
diff --git a/LayoutTests/platform/mac/editing/execCommand/5482023-expected.txt b/LayoutTests/platform/mac/editing/execCommand/5482023-expected.txt
index eaf8cec..b667214 100644
--- a/LayoutTests/platform/mac/editing/execCommand/5482023-expected.txt
+++ b/LayoutTests/platform/mac/editing/execCommand/5482023-expected.txt
@@ -4,11 +4,10 @@ layer at (0,0) size 800x600
   RenderBlock {HTML} at (0,0) size 800x600
     RenderBody {BODY} at (8,8) size 784x571
       RenderBlock {H1} at (0,0) size 784x111
-        RenderText {#text} at (0,0) size 779x111
+        RenderText {#text} at (0,0) size 784x111
           text run at (0,0) width 721: "This tests for a bug when performing a FormatBlock"
           text run at (721,0) width 8: " "
-          text run at (0,37) width 512: "inside a body with no visible content. "
-          text run at (512,37) width 259: "This text should be"
-          text run at (771,37) width 8: " "
+          text run at (0,37) width 779: "inside a body with no visible content.  This text should be"
+          text run at (779,37) width 5: " "
           text run at (0,74) width 287: "inside an h1 element."
 caret: position 132 of child 0 {#text} of child 0 {H1} of child 1 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/platform/mac/editing/execCommand/remove-formatting-2-expected.checksum b/LayoutTests/platform/mac/editing/execCommand/remove-formatting-2-expected.checksum
index 70f6e8b..f619319 100644
--- a/LayoutTests/platform/mac/editing/execCommand/remove-formatting-2-expected.checksum
+++ b/LayoutTests/platform/mac/editing/execCommand/remove-formatting-2-expected.checksum
@@ -1 +1 @@
-13c97dae5ae20ea4fbf38b5855f386b0
\ No newline at end of file
+1f30e9cf361c234b16900a0459474544
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/editing/execCommand/remove-formatting-2-expected.png b/LayoutTests/platform/mac/editing/execCommand/remove-formatting-2-expected.png
deleted file mode 100644
index 83fa881..0000000
Binary files a/LayoutTests/platform/mac/editing/execCommand/remove-formatting-2-expected.png and /dev/null differ
diff --git a/LayoutTests/platform/mac/editing/execCommand/remove-formatting-expected.checksum b/LayoutTests/platform/mac/editing/execCommand/remove-formatting-expected.checksum
index b0fd569..f38ae7c 100644
--- a/LayoutTests/platform/mac/editing/execCommand/remove-formatting-expected.checksum
+++ b/LayoutTests/platform/mac/editing/execCommand/remove-formatting-expected.checksum
@@ -1 +1 @@
-a0e53bd03cecb9392c13f0f16e18cb15
\ No newline at end of file
+cd6a356e264bbdbc23d6826d314ae259
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/editing/execCommand/remove-formatting-expected.png b/LayoutTests/platform/mac/editing/execCommand/remove-formatting-expected.png
deleted file mode 100644
index 7cfa298..0000000
Binary files a/LayoutTests/platform/mac/editing/execCommand/remove-formatting-expected.png and /dev/null differ
diff --git a/LayoutTests/platform/mac/editing/execCommand/remove-formatting-expected.txt b/LayoutTests/platform/mac/editing/execCommand/remove-formatting-expected.txt
index 0316daf..3721ea1 100644
--- a/LayoutTests/platform/mac/editing/execCommand/remove-formatting-expected.txt
+++ b/LayoutTests/platform/mac/editing/execCommand/remove-formatting-expected.txt
@@ -24,7 +24,7 @@ layer at (0,0) size 800x600
           text run at (0,0) width 63: "foobarbaz"
         RenderBR {BR} at (63,14) size 0x0
         RenderText {#text} at (0,18) size 71x18
-          text run at (0,18) width 71: "foo\x{9}bar\x{9}baz"
+          text run at (0,18) width 71: "foo bar baz"
         RenderBR {BR} at (71,32) size 0x0
         RenderText {#text} at (0,36) size 63x18
           text run at (0,36) width 63: "foobarbaz"
diff --git a/LayoutTests/platform/mac/editing/inserting/editable-html-element-expected.checksum b/LayoutTests/platform/mac/editing/inserting/editable-html-element-expected.checksum
index fa6239b..6ea2b18 100644
--- a/LayoutTests/platform/mac/editing/inserting/editable-html-element-expected.checksum
+++ b/LayoutTests/platform/mac/editing/inserting/editable-html-element-expected.checksum
@@ -1 +1 @@
-f17d800334a5794072abbfc30916a28c
\ No newline at end of file
+68690c967f7f6a8300ff78621ef29e5f
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/editing/inserting/editable-html-element-expected.png b/LayoutTests/platform/mac/editing/inserting/editable-html-element-expected.png
deleted file mode 100644
index c1dfaa1..0000000
Binary files a/LayoutTests/platform/mac/editing/inserting/editable-html-element-expected.png and /dev/null differ
diff --git a/LayoutTests/platform/mac/editing/inserting/editable-html-element-expected.txt b/LayoutTests/platform/mac/editing/inserting/editable-html-element-expected.txt
index a0478dd..0c17df5 100644
--- a/LayoutTests/platform/mac/editing/inserting/editable-html-element-expected.txt
+++ b/LayoutTests/platform/mac/editing/inserting/editable-html-element-expected.txt
@@ -17,10 +17,9 @@ layer at (0,0) size 800x600
   RenderBlock {HTML} at (0,0) size 800x600
     RenderBody {BODY} at (8,8) size 784x584
       RenderBlock (anonymous) at (0,0) size 784x54
-        RenderText {#text} at (0,0) size 783x54
-          text run at (0,0) width 714: "This tests to make sure that when the enclosing block is the body element, and when the html element is editable, "
-          text run at (714,0) width 65: "inserting a"
-          text run at (779,0) width 4: " "
+        RenderText {#text} at (0,0) size 784x54
+          text run at (0,0) width 783: "This tests to make sure that when the enclosing block is the body element, and when the html element is editable,  inserting a"
+          text run at (783,0) width 1: " "
           text run at (0,18) width 751: "paragraph separator doesn't split the body (inserting a paragraph separator usually splits/clones the enclosing block flow"
           text run at (751,18) width 4: " "
           text run at (0,36) width 58: "element)."
diff --git a/LayoutTests/platform/mac/editing/pasteboard/4989774-expected.checksum b/LayoutTests/platform/mac/editing/pasteboard/4989774-expected.checksum
index 9872d29..8d0b5c7 100644
--- a/LayoutTests/platform/mac/editing/pasteboard/4989774-expected.checksum
+++ b/LayoutTests/platform/mac/editing/pasteboard/4989774-expected.checksum
@@ -1 +1 @@
-2b8203352f8754425ebf04afdf9fc1dd
\ No newline at end of file
+2af51840dfd0e575314da7c6befff2d6
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/editing/pasteboard/4989774-expected.png b/LayoutTests/platform/mac/editing/pasteboard/4989774-expected.png
deleted file mode 100644
index c075358..0000000
Binary files a/LayoutTests/platform/mac/editing/pasteboard/4989774-expected.png and /dev/null differ
diff --git a/LayoutTests/platform/mac/editing/pasteboard/4989774-expected.txt b/LayoutTests/platform/mac/editing/pasteboard/4989774-expected.txt
index 3fecc9e..a84e66e 100644
--- a/LayoutTests/platform/mac/editing/pasteboard/4989774-expected.txt
+++ b/LayoutTests/platform/mac/editing/pasteboard/4989774-expected.txt
@@ -7,11 +7,10 @@ layer at (0,0) size 800x600
       RenderImage {IMG} at (76,0) size 76x103
       RenderImage {IMG} at (152,0) size 76x103
       RenderBR {BR} at (228,103) size 0x0
-      RenderText {#text} at (0,103) size 784x36
-        text run at (0,103) width 629: "This tests for a bug where an images pasted on the same line would appear on different lines. "
-        text run at (629,103) width 153: "You should see several"
-        text run at (782,103) width 2: " "
-        text run at (0,121) width 307: "pictures above all in the same line/paragraph."
+      RenderText {#text} at (0,103) size 739x36
+        text run at (0,103) width 735: "This tests for a bug where an images pasted on the same line would appear on different lines.  You should see"
+        text run at (735,103) width 4: " "
+        text run at (0,121) width 358: "several pictures above all in the same line/paragraph."
       RenderText {#text} at (0,0) size 0x0
       RenderText {#text} at (0,0) size 0x0
 caret: position 164 of child 4 {#text} of child 1 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/platform/mac/editing/selection/4983858-expected.checksum b/LayoutTests/platform/mac/editing/selection/4983858-expected.checksum
index 581d9ad..e489240 100644
--- a/LayoutTests/platform/mac/editing/selection/4983858-expected.checksum
+++ b/LayoutTests/platform/mac/editing/selection/4983858-expected.checksum
@@ -1 +1 @@
-1ea76bed3d177e7dea634dc0a3658c6f
\ No newline at end of file
+e23b4757a2355938acae1fffcfb07362
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/editing/selection/4983858-expected.png b/LayoutTests/platform/mac/editing/selection/4983858-expected.png
deleted file mode 100644
index 6baf5ef..0000000
Binary files a/LayoutTests/platform/mac/editing/selection/4983858-expected.png and /dev/null differ
diff --git a/LayoutTests/platform/mac/editing/selection/4983858-expected.txt b/LayoutTests/platform/mac/editing/selection/4983858-expected.txt
index 53160a5..f658a53 100644
--- a/LayoutTests/platform/mac/editing/selection/4983858-expected.txt
+++ b/LayoutTests/platform/mac/editing/selection/4983858-expected.txt
@@ -4,11 +4,9 @@ layer at (0,0) size 800x600
   RenderBlock {HTML} at (0,0) size 800x600
     RenderBody {BODY} at (8,8) size 784x584
       RenderBlock (anonymous) at (0,0) size 784x36
-        RenderText {#text} at (0,0) size 772x36
-          text run at (0,0) width 570: "This tests for a bug where selecting a word would select the line break and word before it. "
-          text run at (570,0) width 135: "Only the word in the "
-          text run at (705,0) width 63: "paragraph"
-          text run at (768,0) width 4: " "
+        RenderText {#text} at (0,0) size 780x36
+          text run at (0,0) width 776: "This tests for a bug where selecting a word would select the line break and word before it.  Only the word in the  paragraph"
+          text run at (776,0) width 4: " "
           text run at (0,18) width 162: "below should be selected:"
         RenderText {#text} at (0,0) size 0x0
       RenderBlock {DIV} at (0,36) size 784x18
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 7e74536..9b36577 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,32 @@
+2010-02-25  Enrica Casucci  <enrica at apple.com>
+
+        Reviewed by Adele Peterson.
+
+        Extra layout on keypress after a space (problem with rebalanceWhitespaceAt in InsertTextCommand).
+        https://bugs.webkit.org/show_bug.cgi?id=30946
+        <rdar://problem/7639184>
+
+        Do text insertion and whitespace rebalancing around the insertion in one step so that there's only one layout.
+        This patch was originally made by Justin Garcia.
+        
+        Test: editing/inserting/rebalance-whitespace-1.html
+
+        * editing/CompositeEditCommand.cpp:
+        (WebCore::CompositeEditCommand::rebalanceWhitespaceAt): No behavior changes here,
+        just pushed the code that determined the extent of whitespace surrounding a position
+        to its own helper function.
+        * editing/InsertTextCommand.cpp:
+        (WebCore::InsertTextCommand::insertTextIntoNodeAndRebalanceWhitespace): Added.  Find 
+        whitespace surrounding the insertion position, add the text to insert, rebalance that entire
+        string, then insert it into the document.
+        (WebCore::InsertTextCommand::input):
+        * editing/InsertTextCommand.h:
+        * editing/htmlediting.cpp:
+        (WebCore::isWhitespace): Moved from CompositeEditCommand.cpp.
+        (WebCore::extentOfWhitespaceForRebalancingAt): Moved code from rebalanceWhitespaceAt into this helper
+        function.  Obtains the offset of the start and end of whitespace around a particular position.
+        * editing/htmlediting.h:
+
 2010-02-25  Alexey Proskuryakov  <ap at apple.com>
 
         Reviewed by Anders Carlsson.
diff --git a/WebCore/editing/CompositeEditCommand.cpp b/WebCore/editing/CompositeEditCommand.cpp
index e9b6971..4c4088a 100644
--- a/WebCore/editing/CompositeEditCommand.cpp
+++ b/WebCore/editing/CompositeEditCommand.cpp
@@ -385,11 +385,6 @@ void CompositeEditCommand::setNodeAttribute(PassRefPtr<Element> element, const Q
     applyCommandToComposite(SetNodeAttributeCommand::create(element, attribute, value));
 }
 
-static inline bool isWhitespace(UChar c)
-{
-    return c == noBreakSpace || c == ' ' || c == '\n' || c == '\t';
-}
-
 // FIXME: Doesn't go into text nodes that contribute adjacent text (siblings, cousins, etc).
 void CompositeEditCommand::rebalanceWhitespaceAt(const Position& position)
 {
@@ -398,34 +393,14 @@ void CompositeEditCommand::rebalanceWhitespaceAt(const Position& position)
         return;
     Text* textNode = static_cast<Text*>(node);
     
-    if (textNode->length() == 0)
-        return;
-    RenderObject* renderer = textNode->renderer();
-    if (renderer && !renderer->style()->collapseWhiteSpace())
-        return;
-        
     String text = textNode->data();
-    ASSERT(!text.isEmpty());
-
-    int offset = position.deprecatedEditingOffset();
-    // If neither text[offset] nor text[offset - 1] are some form of whitespace, do nothing.
-    if (!isWhitespace(text[offset])) {
-        offset--;
-        if (offset < 0 || !isWhitespace(text[offset]))
-            return;
-    }
-    
-    // Set upstream and downstream to define the extent of the whitespace surrounding text[offset].
-    int upstream = offset;
-    while (upstream > 0 && isWhitespace(text[upstream - 1]))
-        upstream--;
     
-    int downstream = offset;
-    while ((unsigned)downstream + 1 < text.length() && isWhitespace(text[downstream + 1]))
-        downstream++;
+    unsigned upstream, downstream;
+    if (!extentOfWhitespaceForRebalancingAt(textNode, position.deprecatedEditingOffset(), upstream, downstream))
+        return;
     
-    int length = downstream - upstream + 1;
-    ASSERT(length > 0);
+    ASSERT(downstream > upstream);
+    int length = downstream - upstream;
     
     VisiblePosition visibleUpstreamPos(Position(position.node(), upstream));
     VisiblePosition visibleDownstreamPos(Position(position.node(), downstream + 1));
diff --git a/WebCore/editing/InsertTextCommand.cpp b/WebCore/editing/InsertTextCommand.cpp
index f10d71b..5f7c672 100644
--- a/WebCore/editing/InsertTextCommand.cpp
+++ b/WebCore/editing/InsertTextCommand.cpp
@@ -106,9 +106,33 @@ bool InsertTextCommand::performTrivialReplace(const String& text, bool selectIns
     return true;
 }
 
-void InsertTextCommand::input(const String& text, bool selectInsertedText)
+void InsertTextCommand::insertTextIntoNodeAndRebalanceWhitespace(const String& textToInsert, Text* node, unsigned offset)
 {
+    unsigned whitespaceStart, whitespaceEnd;
+    if (!extentOfWhitespaceForRebalancingAt(node, offset, whitespaceStart, whitespaceEnd)) {
+        VisiblePosition visiblePosition(Position(node, offset));
+        String rebalancedText = stringWithRebalancedWhitespace(textToInsert, isStartOfParagraph(visiblePosition), isEndOfParagraph(visiblePosition));
+        insertTextIntoNode(node, offset, rebalancedText);
+        return;
+    }
+    
+    ASSERT(whitespaceEnd > whitespaceStart);
+    unsigned length = whitespaceEnd - whitespaceStart;
+    String string = node->data().substring(whitespaceStart, length);
+    
+    // Insert textToInsert into the whitespace we found.
+    string.insert(textToInsert, offset - whitespaceStart);
+    
+    VisiblePosition visibleStart(Position(node, whitespaceStart));
+    VisiblePosition visibleEnd(Position(node, whitespaceEnd + textToInsert.length()));
     
+    String rebalancedString = stringWithRebalancedWhitespace(string, isStartOfParagraph(visibleStart), isEndOfParagraph(visibleEnd));
+                                                             
+    replaceTextInNode(node, whitespaceStart, length, rebalancedString);
+}
+
+void InsertTextCommand::input(const String& text, bool selectInsertedText)
+{
     ASSERT(text.find('\n') == -1);
 
     if (endingSelection().isNone())
@@ -170,14 +194,9 @@ void InsertTextCommand::input(const String& text, bool selectInsertedText)
         Text *textNode = static_cast<Text *>(startPosition.node());
         int offset = startPosition.deprecatedEditingOffset();
 
-        insertTextIntoNode(textNode, offset, text);
+        insertTextIntoNodeAndRebalanceWhitespace(text, textNode, offset);
+        
         endPosition = Position(textNode, offset + text.length());
-
-        // The insertion may require adjusting adjacent whitespace, if it is present.
-        rebalanceWhitespaceAt(endPosition);
-        // Rebalancing on both sides isn't necessary if we've inserted a space.
-        if (text != " ") 
-            rebalanceWhitespaceAt(startPosition);
             
         m_charactersAdded += text.length();
     }
diff --git a/WebCore/editing/InsertTextCommand.h b/WebCore/editing/InsertTextCommand.h
index 650ca65..5d9fb2a 100644
--- a/WebCore/editing/InsertTextCommand.h
+++ b/WebCore/editing/InsertTextCommand.h
@@ -52,6 +52,8 @@ private:
     Position insertTab(const Position&);
     
     bool performTrivialReplace(const String&, bool selectInsertedText);
+    
+    void insertTextIntoNodeAndRebalanceWhitespace(const String& text, Text* node, unsigned offset);
 
     unsigned m_charactersAdded;
 };
diff --git a/WebCore/editing/htmlediting.cpp b/WebCore/editing/htmlediting.cpp
index c0a9b63..a0b85a7 100644
--- a/WebCore/editing/htmlediting.cpp
+++ b/WebCore/editing/htmlediting.cpp
@@ -425,6 +425,43 @@ String stringWithRebalancedWhitespace(const String& string, bool startIsStartOfP
     return rebalancedString;
 }
 
+// FIXME: Move this into PlatformString.h or StringImpl.h and rename it to distinguish it from similar functions.
+static inline bool isWhitespace(UChar c)
+{
+    return c == noBreakSpace || c == ' ' || c == '\n' || c == '\t';
+}
+
+// Find the extent of whitespace around a particular offset.  If whitespace characters (' ') are preserved, then we don't
+// do whitespace rebalancing and this function returns false.
+bool extentOfWhitespaceForRebalancingAt(PassRefPtr<Text> node, unsigned offset, unsigned& start, unsigned& end)
+{
+    RenderObject* renderer = node->renderer();
+    if (renderer && !renderer->style()->collapseWhiteSpace())
+        return false;
+    
+    String text = node->data();
+    
+    start = offset;
+    end = offset;
+    if (offset == text.length() || !isWhitespace(text[offset])) {
+        if (!offset || !isWhitespace(text[offset - 1]))
+            // If neither text[offset] nor text[offset - 1] are some form of whitespace, no rebalancing is necessary.
+            return false;
+            
+        // text[offset] is not whitespace, but text[offset - 1] is, adjust start and end offsets.
+        start = offset - 1;
+        end = offset;
+    }
+    
+    while (start > 0 && isWhitespace(text[start - 1]))
+        start--;
+        
+    while (end < text.length() && isWhitespace(text[end]))
+        end++;
+    
+    return true;
+}
+
 bool isTableStructureNode(const Node *node)
 {
     RenderObject *r = node->renderer();
diff --git a/WebCore/editing/htmlediting.h b/WebCore/editing/htmlediting.h
index 1559fa5..0651f3b 100644
--- a/WebCore/editing/htmlediting.h
+++ b/WebCore/editing/htmlediting.h
@@ -40,6 +40,7 @@ class Node;
 class Position;
 class Range;
 class String;
+class Text;
 class VisiblePosition;
 class VisibleSelection;
 
@@ -229,6 +230,7 @@ VisibleSelection selectionForParagraphIteration(const VisibleSelection&);
 // Miscellaneous functions on String
     
 String stringWithRebalancedWhitespace(const String&, bool, bool);
+bool extentOfWhitespaceForRebalancingAt(PassRefPtr<Text> node, unsigned offset, unsigned& start, unsigned& end);
 const String& nonBreakingSpaceString();
 bool validBlockTag(const AtomicString&);
     

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list