LayoutTests:
authorjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Oct 2006 20:42:17 +0000 (20:42 +0000)
committerjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Oct 2006 20:42:17 +0000 (20:42 +0000)
        Reviewed by harrison

        <http://bugs.webkit.org/show_bug.cgi?id=11423>
        REGRESSION: First newline missing from textarea's value

        Changes reflect the removal of more brs that were about
        to collapse:
        * editing/deleting/delete-4038408-fix-expected.txt:
        * editing/inserting/insert-3654864-fix-expected.txt:
        * editing/inserting/insert-3659587-fix-expected.txt:
        * editing/inserting/insert-3775316-fix-expected.txt:
        * editing/inserting/insert-at-end-01-expected.txt:
        * editing/inserting/insert-at-end-02-expected.txt:
        * editing/inserting/insert-br-001-expected.txt:
        * editing/inserting/insert-br-005-expected.txt:

        Added to demonstrate fix:
        * fast/forms/11423-expected.txt: Added.
        * fast/forms/11423.html: Added.

WebCore:

        Reviewed by harrison

        <http://bugs.webkit.org/show_bug.cgi?id=11423>
        REGRESSION: First newline missing from textarea's value

        The regression is that foo, return, bar in a textarea serializes as 'foobar'.

        Before my change in r11423, return (an InsertLineBreak) would insert a '\n'
        (the line break) then a br to prevent the '\n' from collapsing, since the
        insertion is being done at the end of a block (the textarea's shadow div).  Then,
        inserting "bar" would displace the br, and "foo\nbar" would serialize as "foo\nbar".
        After my change in r11423, InsertLineBreak would insert a br then a '\n' (reversed
        the order).  Then inserting "bar" would displace the '\n' and "foo"<br>"bar" would
        serialize as "foobar" because when serializing RenderTextControl intentionally asks
        textContent to not convert brs to newlines.  It seems to think that the only brs in
        the shadow div will be placeholders or collapsed.

        We could remove this assumption, but, for consistancy's sake, I changed InsertLineBreak
        to insert two '\n's when at the end of a block in white-space:pre text.  This alone
        would have fixed the bug, but introduced a new one, because foo, return, bar would
        produce "foo\nbar\n" which would serialize as "foo\nbar\n" (even though the second
        '\n' is collapsed, because of 9661).  So, then I changed placeholder displacement to
        displace a '\n' if it's acting as a placeholder.  A "placeholder" is now defined as
        a br or '\n' that will collapse (become superfluous) when content is inserted just
        before it.

        * editing/CompositeEditCommand.cpp:
        (WebCore::CompositeEditCommand::removePlaceholderAt): Renamed.  Remove
        a br or '\n' if content inserted just before it will cause it to collapse.
        * editing/CompositeEditCommand.h:
        * editing/InsertLineBreakCommand.cpp:
        (WebCore::InsertLineBreakCommand::doApply): Insert the same type of node
        to prevent a collapse as was used for the line break.  Fixed comments.
        * editing/InsertTextCommand.cpp:
        (WebCore::InsertTextCommand::input): Call the renamed function.

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

16 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/deleting/delete-4038408-fix-expected.txt
LayoutTests/editing/inserting/insert-3654864-fix-expected.txt
LayoutTests/editing/inserting/insert-3659587-fix-expected.txt
LayoutTests/editing/inserting/insert-3775316-fix-expected.txt
LayoutTests/editing/inserting/insert-at-end-01-expected.txt
LayoutTests/editing/inserting/insert-at-end-02-expected.txt
LayoutTests/editing/inserting/insert-br-001-expected.txt
LayoutTests/editing/inserting/insert-br-005-expected.txt
LayoutTests/fast/forms/11423-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/11423.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/editing/CompositeEditCommand.cpp
WebCore/editing/CompositeEditCommand.h
WebCore/editing/InsertLineBreakCommand.cpp
WebCore/editing/InsertTextCommand.cpp

index c2179a9..f9bd002 100644 (file)
@@ -1,3 +1,25 @@
+2006-10-26  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by harrison
+        
+        <http://bugs.webkit.org/show_bug.cgi?id=11423>
+        REGRESSION: First newline missing from textarea's value
+
+        Changes reflect the removal of more brs that were about 
+        to collapse:
+        * editing/deleting/delete-4038408-fix-expected.txt:
+        * editing/inserting/insert-3654864-fix-expected.txt:
+        * editing/inserting/insert-3659587-fix-expected.txt:
+        * editing/inserting/insert-3775316-fix-expected.txt:
+        * editing/inserting/insert-at-end-01-expected.txt:
+        * editing/inserting/insert-at-end-02-expected.txt:
+        * editing/inserting/insert-br-001-expected.txt:
+        * editing/inserting/insert-br-005-expected.txt:
+
+        Added to demonstrate fix:
+        * fast/forms/11423-expected.txt: Added.
+        * fast/forms/11423.html: Added.
+        
 2006-10-27  Darin Adler  <darin@apple.com>
 
         - new test results for a couple of tests
index 6e99c88..e6d87b5 100644 (file)
@@ -27,7 +27,8 @@ EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 35 of #text > DIV > BLOCKQUOTE > DIV > DIV > BODY > HTML > #document to 35 of #text > DIV > BLOCKQUOTE > DIV > DIV > BODY > HTML > #document toDOMRange:range from 2 of DIV > DIV > BODY > HTML > #document to 2 of DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 31 of #text > DIV > DIV > BODY > HTML > #document to 31 of #text > DIV > DIV > BODY > HTML > #document toDOMRange:range from 31 of #text > DIV > DIV > BODY > HTML > #document to 31 of #text > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 31 of #text > DIV > DIV > BODY > HTML > #document to 31 of #text > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 layer at (0,0) size 800x600
@@ -63,5 +64,4 @@ layer at (0,0) size 800x600
           RenderBlock (anonymous) at (0,68) size 756x18
             RenderText {#text} at (0,0) size 195x18
               text run at (0,0) width 195: "This text should not be quoted."
-            RenderBR {BR} at (195,14) size 0x0
 caret: position 31 of child 2 {#text} of child 11 {DIV} of child 1 {DIV} of child 1 {BODY} of child 0 {HTML} of document
index 902acb2..520d58c 100644 (file)
@@ -7,7 +7,8 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
 EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of BODY > HTML > #document to 1 of BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text > BODY > HTML > #document to 1 of #text > BODY > HTML > #document toDOMRange:range from 1 of #text > BODY > HTML > #document to 1 of #text > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > BODY > HTML > #document to 1 of #text > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text > BODY > HTML > #document to 1 of #text > BODY > HTML > #document toDOMRange:range from 2 of #text > BODY > HTML > #document to 2 of #text > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
@@ -24,5 +25,7 @@ layer at (0,0) size 800x600
       RenderBR {BR} at (14,14) size 0x28
       RenderText {#text} at (14,42) size 36x28
         text run at (14,42) width 36: "xxx"
-      RenderBR {BR} at (50,64) size 0x0
+      RenderText {#text} at (0,0) size 0x0
+      RenderText {#text} at (0,0) size 0x0
+      RenderText {#text} at (0,0) size 0x0
 caret: position 3 of child 1 {#text} of child 1 {BODY} of child 0 {HTML} of document
index f9796e4..9c4871e 100644 (file)
@@ -29,7 +29,8 @@ EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 10 of #text > B > SPAN > DIV > BODY > HTML > #document to 10 of #text > B > SPAN > DIV > BODY > HTML > #document toDOMRange:range from 2 of B > SPAN > DIV > BODY > HTML > #document to 2 of B > SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text > B > SPAN > DIV > BODY > HTML > #document to 1 of #text > B > SPAN > DIV > BODY > HTML > #document toDOMRange:range from 1 of #text > B > SPAN > DIV > BODY > HTML > #document to 1 of #text > B > SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > B > SPAN > DIV > BODY > HTML > #document to 1 of #text > B > SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text > B > SPAN > DIV > BODY > HTML > #document to 1 of #text > B > SPAN > DIV > BODY > HTML > #document toDOMRange:range from 2 of #text > B > SPAN > DIV > BODY > HTML > #document to 2 of #text > B > SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
@@ -51,5 +52,4 @@ layer at (0,0) size 800x600
             RenderBR {BR} at (122,36) size 0x0
             RenderText {#text} at (14,42) size 36x28
               text run at (14,42) width 36: "xxx"
-            RenderBR {BR} at (50,64) size 0x0
 caret: position 3 of child 2 {#text} of child 0 {B} of child 1 {SPAN} of child 1 {DIV} of child 1 {BODY} of child 0 {HTML} of document
index 1be748f..600f412 100644 (file)
@@ -5,7 +5,8 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text > SPAN > DIV > BODY > HTML > #document to 1 of #text > SPAN > DIV > BODY > HTML > #document toDOMRange:range from 2 of SPAN > DIV > BODY > HTML > #document to 2 of SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text > SPAN > DIV > BODY > HTML > #document to 1 of #text > SPAN > DIV > BODY > HTML > #document toDOMRange:range from 1 of #text > SPAN > DIV > BODY > HTML > #document to 1 of #text > SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > SPAN > DIV > BODY > HTML > #document to 1 of #text > SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text > SPAN > DIV > BODY > HTML > #document to 1 of #text > SPAN > DIV > BODY > HTML > #document toDOMRange:range from 0 of #text > SPAN > DIV > BODY > HTML > #document to 1 of #text > SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
@@ -16,13 +17,14 @@ EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
-EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > SPAN > DIV > BODY > HTML > #document to 1 of #text > SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > DIV > BODY > HTML > #document to 1 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text > SPAN > DIV > BODY > HTML > #document to 1 of #text > SPAN > DIV > BODY > HTML > #document toDOMRange:range from 2 of SPAN > DIV > BODY > HTML > #document to 2 of SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text > DIV > BODY > HTML > #document to 1 of #text > DIV > BODY > HTML > #document toDOMRange:range from 2 of DIV > BODY > HTML > #document to 2 of DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text > SPAN > DIV > BODY > HTML > #document to 1 of #text > SPAN > DIV > BODY > HTML > #document toDOMRange:range from 1 of #text > SPAN > DIV > BODY > HTML > #document to 1 of #text > SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > DIV > BODY > HTML > #document to 1 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 layer at (0,0) size 800x600
@@ -31,12 +33,9 @@ layer at (0,0) size 800x600
   RenderBlock {HTML} at (0,0) size 800x600
     RenderBody {BODY} at (8,8) size 784x584
       RenderBlock {DIV} at (0,0) size 784x84 [border: (2px solid #FF0000)]
-        RenderInline {SPAN} at (0,0) size 12x56
-          RenderText {#text} at (14,14) size 12x28
-            text run at (14,14) width 12: "x"
-          RenderBR {BR} at (26,36) size 0x0
-          RenderText {#text} at (14,42) size 12x28
-            text run at (14,42) width 12: "x"
-          RenderBR {BR} at (26,64) size 0x0
-        RenderText {#text} at (0,0) size 0x0
-caret: position 1 of child 2 {#text} of child 0 {SPAN} of child 1 {DIV} of child 1 {BODY} of child 0 {HTML} of document
+        RenderText {#text} at (14,14) size 12x28
+          text run at (14,14) width 12: "x"
+        RenderBR {BR} at (26,36) size 0x0
+        RenderText {#text} at (14,42) size 12x28
+          text run at (14,42) width 12: "x"
+caret: position 1 of child 2 {#text} of child 1 {DIV} of child 1 {BODY} of child 0 {HTML} of document
index 3e7e5ed..a9184cf 100644 (file)
@@ -3,7 +3,8 @@ EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text > DIV > BODY > HTML > #document to 1 of #text > DIV > BODY > HTML > #document toDOMRange:range from 1 of #text > DIV > BODY > HTML > #document to 1 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > DIV > BODY > HTML > #document to 1 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 layer at (0,0) size 800x600
@@ -29,5 +30,4 @@ layer at (0,0) size 800x600
         RenderBlock (anonymous) at (2,46) size 780x18
           RenderText {#text} at (0,0) size 8x18
             text run at (0,0) width 8: "x"
-          RenderBR {BR} at (8,14) size 0x0
 caret: position 1 of child 5 {#text} of child 5 {DIV} of child 1 {BODY} of child 0 {HTML} of document
index 3dbe1ba..a7d12bd 100644 (file)
@@ -3,7 +3,8 @@ EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text > DIV > BODY > HTML > #document to 1 of #text > DIV > BODY > HTML > #document toDOMRange:range from 1 of #text > DIV > BODY > HTML > #document to 1 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > DIV > BODY > HTML > #document to 1 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 layer at (0,0) size 800x600
@@ -29,5 +30,4 @@ layer at (0,0) size 800x600
         RenderBlock (anonymous) at (2,46) size 780x18
           RenderText {#text} at (0,0) size 8x18
             text run at (0,0) width 8: "x"
-          RenderBR {BR} at (8,14) size 0x0
 caret: position 1 of child 5 {#text} of child 5 {DIV} of child 1 {BODY} of child 0 {HTML} of document
index 40e53be..4f76c93 100644 (file)
@@ -7,7 +7,8 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 4 of #text > SPAN > DIV > BODY > HTML > #document to 4 of #text > SPAN > DIV > BODY > HTML > #document toDOMRange:range from 2 of SPAN > DIV > BODY > HTML > #document to 2 of SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text > SPAN > DIV > BODY > HTML > #document to 1 of #text > SPAN > DIV > BODY > HTML > #document toDOMRange:range from 1 of #text > SPAN > DIV > BODY > HTML > #document to 1 of #text > SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > SPAN > DIV > BODY > HTML > #document to 1 of #text > SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 layer at (0,0) size 800x600
@@ -22,6 +23,5 @@ layer at (0,0) size 800x600
           RenderBR {BR} at (48,36) size 0x0
           RenderText {#text} at (14,42) size 12x28
             text run at (14,42) width 12: "x"
-          RenderBR {BR} at (26,64) size 0x0
         RenderText {#text} at (0,0) size 0x0
 caret: position 1 of child 2 {#text} of child 1 {SPAN} of child 1 {DIV} of child 1 {BODY} of child 0 {HTML} of document
index 75b3c14..adcb247 100644 (file)
@@ -9,7 +9,8 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 3 of SPAN > DIV > BODY > HTML > #document to 3 of SPAN > DIV > BODY > HTML > #document toDOMRange:range from 3 of SPAN > DIV > BODY > HTML > #document to 3 of SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text > SPAN > DIV > BODY > HTML > #document to 1 of #text > SPAN > DIV > BODY > HTML > #document toDOMRange:range from 1 of #text > SPAN > DIV > BODY > HTML > #document to 1 of #text > SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > SPAN > DIV > BODY > HTML > #document to 1 of #text > SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 layer at (0,0) size 800x600
@@ -25,6 +26,5 @@ layer at (0,0) size 800x600
           RenderBR {BR} at (14,42) size 0x28
           RenderText {#text} at (14,70) size 12x28
             text run at (14,70) width 12: "x"
-          RenderBR {BR} at (26,92) size 0x0
         RenderText {#text} at (0,0) size 0x0
 caret: position 1 of child 3 {#text} of child 1 {SPAN} of child 1 {DIV} of child 1 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/fast/forms/11423-expected.txt b/LayoutTests/fast/forms/11423-expected.txt
new file mode 100644 (file)
index 0000000..f9290e9
--- /dev/null
@@ -0,0 +1,15 @@
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV to 0 of DIV toDOMRange:range from 3 of #text > DIV to 3 of #text > DIV affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 3 of #text > DIV to 3 of #text > DIV toDOMRange:range from 1 of #text > DIV to 1 of #text > DIV affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text > DIV to 1 of #text > DIV toDOMRange:range from 3 of #text > DIV to 3 of #text > DIV affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+This tests to see that a line break inserted in a textarea is serialized as a '\n'.
+
+
+Success
+
diff --git a/LayoutTests/fast/forms/11423.html b/LayoutTests/fast/forms/11423.html
new file mode 100644 (file)
index 0000000..24a73a5
--- /dev/null
@@ -0,0 +1,26 @@
+<p>This tests to see that a line break inserted in a textarea is serialized as a '\n'.</p>
+<textarea rows="5" id="textarea"></textarea>
+<ul id="console"></ul>
+
+<script>
+function log(str) {
+    var li = document.createElement("li");
+    li.appendChild(document.createTextNode(str));
+    var console = document.getElementById("console");
+    console.appendChild(li);
+}
+
+if (window.layoutTestController)
+    window.layoutTestController.dumpAsText();
+    
+var textarea = document.getElementById("textarea");
+textarea.focus();
+document.execCommand("InsertText", false, "foo");
+document.execCommand("InsertLineBreak");
+document.execCommand("InsertText", false, "bar");
+
+if (textarea.value != "foo\nbar")
+    log("Failure");
+else
+    log("Success");
+</script>
index 268ed6a..d212367 100644 (file)
@@ -1,3 +1,41 @@
+2006-10-26  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by harrison
+        
+        <http://bugs.webkit.org/show_bug.cgi?id=11423>
+        REGRESSION: First newline missing from textarea's value
+        
+        The regression is that foo, return, bar in a textarea serializes as 'foobar'.
+        
+        Before my change in r11423, return (an InsertLineBreak) would insert a '\n' 
+        (the line break) then a br to prevent the '\n' from collapsing, since the 
+        insertion is being done at the end of a block (the textarea's shadow div).  Then, 
+        inserting "bar" would displace the br, and "foo\nbar" would serialize as "foo\nbar".  
+        After my change in r11423, InsertLineBreak would insert a br then a '\n' (reversed 
+        the order).  Then inserting "bar" would displace the '\n' and "foo"<br>"bar" would 
+        serialize as "foobar" because when serializing RenderTextControl intentionally asks 
+        textContent to not convert brs to newlines.  It seems to think that the only brs in 
+        the shadow div will be placeholders or collapsed.
+        
+        We could remove this assumption, but, for consistancy's sake, I changed InsertLineBreak 
+        to insert two '\n's when at the end of a block in white-space:pre text.  This alone 
+        would have fixed the bug, but introduced a new one, because foo, return, bar would 
+        produce "foo\nbar\n" which would serialize as "foo\nbar\n" (even though the second 
+        '\n' is collapsed, because of 9661).  So, then I changed placeholder displacement to 
+        displace a '\n' if it's acting as a placeholder.  A "placeholder" is now defined as 
+        a br or '\n' that will collapse (become superfluous) when content is inserted just 
+        before it.
+        
+        * editing/CompositeEditCommand.cpp:
+        (WebCore::CompositeEditCommand::removePlaceholderAt): Renamed.  Remove
+        a br or '\n' if content inserted just before it will cause it to collapse.
+        * editing/CompositeEditCommand.h:
+        * editing/InsertLineBreakCommand.cpp:
+        (WebCore::InsertLineBreakCommand::doApply): Insert the same type of node
+        to prevent a collapse as was used for the line break.  Fixed comments.
+        * editing/InsertTextCommand.cpp:
+        (WebCore::InsertTextCommand::input): Call the renamed function.
+        
 2006-10-27  Geoffrey Garen  <ggaren@apple.com>
 
         Reviewed by Brady.
index 1a3195e..e4dfc4b 100644 (file)
@@ -484,14 +484,24 @@ Node* CompositeEditCommand::addBlockPlaceholderIfNeeded(Node* node)
     return 0;
 }
 
-void CompositeEditCommand::removeBlockPlaceholder(const VisiblePosition& visiblePosition)
+// Removes '\n's and brs that will collapse when content is inserted just before them.
+// FIXME: We shouldn't really have to remove placeholders, but removing them is a workaround for 9661.
+void CompositeEditCommand::removePlaceholderAt(const VisiblePosition& visiblePosition)
 {
     if (visiblePosition.isNull())
         return;
         
     Position p = visiblePosition.deepEquivalent().downstream();
-    if (p.node()->hasTagName(brTag) && p.offset() == 0 && isEndOfBlock(visiblePosition) && isStartOfBlock(visiblePosition))
-        removeNode(p.node());
+    // If a br or '\n' is at the end of a block and not at the start of a paragraph,
+    // then it is superfluous, so adding content before a br or '\n' that is at
+    // the start of a paragraph will render it superfluous.
+    // FIXME: This doesn't remove placeholders at the end of anonymous blocks.
+    if (isEndOfBlock(visiblePosition) && isStartOfParagraph(visiblePosition)) {
+        if (p.node()->hasTagName(brTag) && p.offset() == 0)
+            removeNode(p.node());
+        else if (p.node()->renderer()->style()->preserveNewline() && visiblePosition.characterAfter() == '\n')
+            deleteTextFromNode(static_cast<Text*>(p.node()), p.offset(), 1);
+    }
 }
 
 void CompositeEditCommand::moveParagraphContentsToNewBlockIfNecessary(const Position& pos)
index 9c2a454..a933f17 100644 (file)
@@ -87,7 +87,7 @@ protected:
     Node *appendBlockPlaceholder(Node*);
     Node *insertBlockPlaceholder(const Position&);
     Node *addBlockPlaceholderIfNeeded(Node*);
-    void removeBlockPlaceholder(const VisiblePosition&);
+    void removePlaceholderAt(const VisiblePosition&);
 
     void moveParagraphContentsToNewBlockIfNecessary(const Position&);
     
index ab51f5e..15ae99f 100644 (file)
@@ -110,9 +110,9 @@ void InsertLineBreakCommand::doApply()
                canonicalPos.node()->hasTagName(hrTag)) {
         if (canonicalPos.offset() == 0) {
             insertNodeBefore(nodeToInsert.get(), canonicalPos.node());
-            // Insert an extra br if the just inserted one collapsed.
+            // Insert an extra br or '\n' if the just inserted one collapsed.
             if (!isStartOfParagraph(VisiblePosition(Position(nodeToInsert.get(), 0))))
-                insertNodeBefore(createBreakElement(document()).get(), nodeToInsert.get());
+                insertNodeBefore(nodeToInsert->cloneNode(false).get(), nodeToInsert.get());
             // Leave the selection where it was, just before the table/horizontal rule.
         } else if (canonicalPos.offset() == maxDeepOffset(canonicalPos.node())) {
             insertNodeAfter(nodeToInsert.get(), canonicalPos.node());
@@ -126,9 +126,9 @@ void InsertLineBreakCommand::doApply()
         insertNodeAt(nodeToInsert.get(), pos.node(), pos.offset());
         VisiblePosition endingPosition(endOfBlock(VisiblePosition(pos)));
         
-        // Insert an extra br if the inserted one collapsed.
+        // Insert an extra br or '\n' if the inserted one collapsed.
         if (!isStartOfParagraph(endingPosition))
-            insertNodeBefore(createBreakElement(document()).get(), nodeToInsert.get());
+            insertNodeBefore(nodeToInsert->cloneNode(false).get(), nodeToInsert.get());
         
         setEndingSelection(Selection(endingPosition));
     } else if (pos.offset() <= pos.node()->caretMinOffset()) {
index 862b8f1..c335003 100644 (file)
@@ -106,12 +106,12 @@ void InsertTextCommand::input(const String &text, bool selectInsertedText)
     if (text == "\t") {
         endPosition = insertTab(startPosition);
         startPosition = endPosition.previous();
-        removeBlockPlaceholder(VisiblePosition(startPosition));
+        removePlaceholderAt(VisiblePosition(startPosition));
         m_charactersAdded += 1;
     } else {
         // Make sure the document is set up to receive text
         startPosition = prepareForTextInsertion(startPosition);
-        removeBlockPlaceholder(VisiblePosition(startPosition));
+        removePlaceholderAt(VisiblePosition(startPosition));
         Text *textNode = static_cast<Text *>(startPosition.node());
         int offset = startPosition.offset();