Reviewed by Hyatt.
authorap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Oct 2006 09:06:09 +0000 (09:06 +0000)
committerap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Oct 2006 09:06:09 +0000 (09:06 +0000)
        Fix for http://bugzilla.opendarwin.org/show_bug.cgi?id=10842
        REGRESSION (r15418): contenteditable div truncates rightmost Japanese character

        Make sure we only break after a space (and not any other valid line-break) if
        the style is -webkit-line-break: after-white-space (e.g. for a contentEditable div).
        I also did a logic shuffle at Mitz's request to prevent doing an if on the same expression
        twice in quick succession.

        Test: fast/text/line-breaks-after-white-space.html

        * rendering/bidi.cpp:
        (WebCore::RenderBlock::findNextLineBreak):

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

LayoutTests/ChangeLog
LayoutTests/fast/text/line-breaks-after-white-space-expected.checksum [new file with mode: 0644]
LayoutTests/fast/text/line-breaks-after-white-space-expected.png [new file with mode: 0644]
LayoutTests/fast/text/line-breaks-after-white-space-expected.txt [new file with mode: 0644]
LayoutTests/fast/text/line-breaks-after-white-space.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/rendering/bidi.cpp

index d5a563661be072d53bb86b5e03e7c20ab449ca31..c12c0c8a43cdc6c9b456b03ad9c0330d56b7b03f 100644 (file)
@@ -1,3 +1,15 @@
+2006-10-01  Graham Dennis  <graham.dennis@gmail.com>
+
+        Reviewed by Hyatt.
+        
+        Test for http://bugzilla.opendarwin.org/show_bug.cgi?id=10842
+        REGRESSION (r15418): contenteditable div truncates rightmost Japanese character
+
+        * fast/text/line-breaks-after-white-space-expected.checksum: Added.
+        * fast/text/line-breaks-after-white-space-expected.png: Added.
+        * fast/text/line-breaks-after-white-space-expected.txt: Added.
+        * fast/text/line-breaks-after-white-space.html: Added.
+
 2006-10-01  Alexey Proskuryakov  <ap@nypop.com>
 
         Reviewed by Maciej and Darin.
diff --git a/LayoutTests/fast/text/line-breaks-after-white-space-expected.checksum b/LayoutTests/fast/text/line-breaks-after-white-space-expected.checksum
new file mode 100644 (file)
index 0000000..b9c81ac
--- /dev/null
@@ -0,0 +1 @@
+c538247b02b53bb4f4266d027cf0059a
\ No newline at end of file
diff --git a/LayoutTests/fast/text/line-breaks-after-white-space-expected.png b/LayoutTests/fast/text/line-breaks-after-white-space-expected.png
new file mode 100644 (file)
index 0000000..3d4b5e5
Binary files /dev/null and b/LayoutTests/fast/text/line-breaks-after-white-space-expected.png differ
diff --git a/LayoutTests/fast/text/line-breaks-after-white-space-expected.txt b/LayoutTests/fast/text/line-breaks-after-white-space-expected.txt
new file mode 100644 (file)
index 0000000..1fe0c00
--- /dev/null
@@ -0,0 +1,21 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x220
+  RenderBlock {HTML} at (0,0) size 800x220
+    RenderBody {BODY} at (8,8) size 784x192
+      RenderBlock (anonymous) at (0,0) size 784x18
+        RenderText {#text} at (0,0) size 82x18
+          text run at (0,0) width 82: "This is good:"
+      RenderBlock {DIV} at (0,38) size 200x48
+        RenderBlock {P} at (0,0) size 200x48 [border: (1px solid #008000)]
+          RenderText {#text} at (1,1) size 194x46
+            text run at (1,1) width 194: "lorem ipsum dolor sit??"
+            text run at (1,24) width 40: "amet"
+      RenderBlock (anonymous) at (0,106) size 784x18
+        RenderText {#text} at (0,0) size 249x18
+          text run at (0,0) width 249: "The following should look like \x{201C}good\x{201D}:"
+      RenderBlock {DIV} at (0,144) size 200x48
+        RenderBlock {P} at (0,0) size 200x48 [border: (1px solid #008000)]
+          RenderText {#text} at (1,1) size 194x46
+            text run at (1,1) width 194: "lorem ipsum dolor sit??"
+            text run at (1,24) width 40: "amet"
diff --git a/LayoutTests/fast/text/line-breaks-after-white-space.html b/LayoutTests/fast/text/line-breaks-after-white-space.html
new file mode 100644 (file)
index 0000000..3a4eefd
--- /dev/null
@@ -0,0 +1,22 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<html>
+
+    <head>
+        <title>Line breaks (using the style -webkit-line-break: after-white-space)</title>
+    </head>
+    <body>
+        This is good:
+        <div style="font-size: 20px; width:200px;">
+            <p style="border:solid green 1px;">
+                lorem ipsum dolor sit??amet
+            </p>
+        </div>
+        The following should look like &ldquo;good&rdquo;:
+        <div style="-webkit-line-break: after-white-space; font-size: 20px; width:200px;">
+            <p style="border:solid green 1px;">
+                lorem ipsum dolor sit??amet
+            </p>
+        </div>
+    </body>
+</html>
index 1f35db1a3a67ce69256ca41a6e5923327d2241f0..3ae16d37b7c42c12c1e6c5cfcff482f48f84e134 100644 (file)
@@ -1,3 +1,18 @@
+2006-10-01  Graham Dennis  <graham.dennis@gmail.com>
+
+        Reviewed by Hyatt.
+
+        Fix for http://bugzilla.opendarwin.org/show_bug.cgi?id=10842
+        REGRESSION (r15418): contenteditable div truncates rightmost Japanese character
+        
+        Make sure we only break after a space (and not any other valid line-break) if
+        the style is -webkit-line-break: after-white-space (e.g. for a contentEditable div).
+        I also did a logic shuffle at Mitz's request to prevent doing an if on the same expression
+        twice in quick succession.
+
+        * rendering/bidi.cpp:
+        (WebCore::RenderBlock::findNextLineBreak): 
+
 2006-10-01  Alexey Proskuryakov  <ap@nypop.com>
 
         Reviewed by Maciej and Darin.
index 0bbac5554141021a66406d21fdb4f74715ca906c..e31aa3256d2014942b08a664fb667de60f66aa30 100644 (file)
@@ -2262,28 +2262,29 @@ BidiIterator RenderBlock::findNextLineBreak(BidiIterator &start, BidiState &bidi
                     if (o->style()->autoWrap() || breakWords) {
                         // If we break only after white-space, consider the current character
                         // as candidate width for this line.
-                        int charWidth = o->style()->breakOnlyAfterWhiteSpace() && !midWordBreak ?
-                                            t->width(pos, 1, f, w + tmpW) + (applyWordSpacing ? wordSpacing : 0) : 0;
-                        if (w + tmpW + charWidth > width) {
-                            if (o->style()->breakOnlyAfterWhiteSpace() && !midWordBreak) {
-                                // Check if line is too big even without the extra space
-                                // at the end of the line. If it is not, do nothing. 
-                                // If the line needs the extra whitespace to be too long, 
-                                // then move the line break to the space and skip all 
-                                // additional whitespace.
-                                if (w + tmpW <= width) {
-                                    lBreak.obj = o;
-                                    lBreak.pos = pos;
-                                    if (pos > 0) {
-                                        // Separate the trailing space into its own box, which we will
-                                        // resize to fit on the line in computeHorizontalPositionsForLine().
-                                        BidiIterator midpoint(0, o, pos);
-                                        addMidpoint(BidiIterator(0, o, pos-1)); // Stop
-                                        addMidpoint(BidiIterator(0, o, pos)); // Start
-                                    }
-                                    skipWhitespace(lBreak, bidi);
+                        bool lineWasTooWide = false;
+                        if (w + tmpW <= width && currentCharacterIsWS && o->style()->breakOnlyAfterWhiteSpace() && !midWordBreak) {
+                            int charWidth = t->width(pos, 1, f, w + tmpW) + (applyWordSpacing ? wordSpacing : 0);
+                            // Check if line is too big even without the extra space
+                            // at the end of the line. If it is not, do nothing. 
+                            // If the line needs the extra whitespace to be too long, 
+                            // then move the line break to the space and skip all 
+                            // additional whitespace.
+                            if (w + tmpW + charWidth > width) {
+                                lineWasTooWide = true;
+                                lBreak.obj = o;
+                                lBreak.pos = pos;
+                                if (pos > 0) {
+                                    // Separate the trailing space into its own box, which we will
+                                    // resize to fit on the line in computeHorizontalPositionsForLine().
+                                    BidiIterator midpoint(0, o, pos);
+                                    addMidpoint(BidiIterator(0, o, pos-1)); // Stop
+                                    addMidpoint(BidiIterator(0, o, pos)); // Start
                                 }
+                                skipWhitespace(lBreak, bidi);
                             }
+                        }
+                        if (lineWasTooWide || w + tmpW > width) {
                             if (lBreak.obj && lBreak.obj->style()->preserveNewline() && lBreak.obj->isText() && static_cast<RenderText*>(lBreak.obj)->text()[lBreak.pos] == '\n') {
                                 if (!stoppedIgnoringSpaces && pos > 0) {
                                     // We need to stop right before the newline and then start up again.