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 c2179a954b474324ca9c903dfaf7831c5f7e4dc3..f9bd00298aab8519ea3433e90e60496138f880ab 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 6e99c881fcd8271c37a362e8fa60f0b2fd29f4fc..e6d87b5aacc9a3526e9c45f6d65ec1ee02ede445 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 902acb29946106e14df8d582d5dec70e6454b3ee..520d58c1a52fa38e1da5385d8d9f087a793e7a89 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 f9796e4e851c4fd7052b12fdecf7301f28f31af0..9c4871e31eac8d92f655415eea69ad64b612332b 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 1be748f6ca6228de0bb61d61485009cf1c7dcc31..600f412aed1a668325566375521b6f86aa07dca8 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 3e7e5ed4f47761aaef60f58df528352d5079b8f0..a9184cf511c05dfe3a15ea75408fd11c16a9421b 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 3dbe1ba62cd79b83c9373b0d76e90e14471861e7..a7d12bd9748f2eedb5f002ba74565a76325386fd 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 40e53bef019906f59912a8ae37cb34be04bf230a..4f76c93c4bad62fd46fa7c8523415a2e3496e54a 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 75b3c1457ffd59b7a266cfa682294e81d649f96d..adcb24758e62db43d2ad7cf0e188c8b8cdc4a54f 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 268ed6a9eb80a1cdbeec905584412c0a79b50402..d212367d9ad39c73e60b00a36462f3ee91faf0d7 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 1a3195e08696d585571a3860e4c2d2c5695e79df..e4dfc4b8ab2145729b273397d2d4b225f9ee5cd9 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 9c2a454eddd57088068b286c99c5cef46f86bc9e..a933f1749a20f1a5b110f74f7c5fd403167ba0ba 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 ab51f5ec1cb79434d6067c4f958bcebc2232a231..15ae99fd174b21465f7d4f42f15e6edca1d35679 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 862b8f1dadd5300c74b2fe89f4ae084b6b3bde2b..c3350035092f7e18ab97789c57b4dfbde0bbed04 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();