Title: [95030] trunk
Revision
95030
Author
commit-qu...@webkit.org
Date
2011-09-13 09:44:15 -0700 (Tue, 13 Sep 2011)

Log Message

Patch by Xianzhu Wang <wangxian...@chromium.org> on 2011-09-13
Reviewed by Darin Adler.

Source/WebCore:

Webkit wraps between hyphen-minus and numeric characters
https://bugs.webkit.org/show_bug.cgi?id=20677

Disallow wrapping between a hyphen-minus and a digit if the hyphen-minus
is not directly after a digit or a letter.

Test: fast/text/line-breaks-after-hyphen-before-number.html

* rendering/break_lines.cpp:
(WebCore::asciiLineBreakTable): Disabled line-breaking after '-' and before '.', '0'-'9'. Note: the change for '0'-'9' doesn't really matter because the case is handled hard-coded in shouldBreakAfter().
(WebCore::shouldBreakAfter): Changed line-breaking behavior after '-'.
(WebCore::nextBreakablePosition): Passes lastLastCh to shouldBreakAfter.

LayoutTests:

Webkit wraps between hyphen-minus and numeric characters
https://bugs.webkit.org/show_bug.cgi?id=20677

Disallow wrapping between a hyphen-minus and a digit if the hyphen-minus
is not directly after a digit or a letter.

* fast/text/line-breaks-after-hyphen-before-number-expected.txt: Added.
* fast/text/line-breaks-after-hyphen-before-number.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (95029 => 95030)


--- trunk/LayoutTests/ChangeLog	2011-09-13 16:23:49 UTC (rev 95029)
+++ trunk/LayoutTests/ChangeLog	2011-09-13 16:44:15 UTC (rev 95030)
@@ -1,3 +1,16 @@
+2011-09-13  Xianzhu Wang  <wangxian...@chromium.org>
+
+        Reviewed by Darin Adler.
+
+        Webkit wraps between hyphen-minus and numeric characters
+        https://bugs.webkit.org/show_bug.cgi?id=20677
+
+        Disallow wrapping between a hyphen-minus and a digit if the hyphen-minus
+        is not directly after a digit or a letter.
+
+        * fast/text/line-breaks-after-hyphen-before-number-expected.txt: Added.
+        * fast/text/line-breaks-after-hyphen-before-number.html: Added.
+
 2011-09-12  Sam Weinig  <s...@webkit.org>
 
         Object.getPrototypeOf should use JSValue::get()

Added: trunk/LayoutTests/fast/text/line-breaks-after-hyphen-before-number-expected.txt (0 => 95030)


--- trunk/LayoutTests/fast/text/line-breaks-after-hyphen-before-number-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/text/line-breaks-after-hyphen-before-number-expected.txt	2011-09-13 16:44:15 UTC (rev 95030)
@@ -0,0 +1,40 @@
+Test 1:
+$-1111111
+Expected:
+$-1111111
+PASS
+
+Test 2:
+-2222.2222
+Expected:
+-2222.2222
+PASS
+
+Test 3:
+-.33333333
+Expected:
+-.33333333
+PASS
+
+Test 4:
+4444444-4444444
+Expected:
+4444444-
+4444444
+PASS
+
+Test 5:
+5555555-abcdefg
+Expected:
+5555555-
+abcdefg
+PASS
+
+Test 6:
+abcdefg-6666666
+Expected:
+abcdefg-
+6666666
+PASS
+
+Summary: PASS

Added: trunk/LayoutTests/fast/text/line-breaks-after-hyphen-before-number.html (0 => 95030)


--- trunk/LayoutTests/fast/text/line-breaks-after-hyphen-before-number.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/line-breaks-after-hyphen-before-number.html	2011-09-13 16:44:15 UTC (rev 95030)
@@ -0,0 +1,47 @@
+<html>
+<head>
+<title>Line breaks after hyphen before number</title>
+<style>
+.test { width: 1px; }
+</style>
+</head>
+<body>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+var tests = [
+    "$-1111111",
+    "-2222.2222",
+    "-.33333333",
+    "4444444-4444444",
+    "5555555-abcdefg",
+    "abcdefg-6666666"
+];
+
+// Each of the above tests should look like corresponding expectation below.
+var expected = [
+    "$-1111111",
+    "-2222.2222",
+    "-.33333333",
+    "4444444-<br>4444444",
+    "5555555-<br>abcdefg",
+    "abcdefg-<br>6666666"
+];
+
+var allSuccess = true;
+for (var i = 1; i <= tests.length; ++i) {
+    document.write("Test " + i + ":");
+    document.write("<div class='test' id='test" + i + "'>" + tests[i - 1] + "</div>");
+    document.write("Expected:<div id='expected" + i + "'>" + expected[i - 1] + "</div>");
+    var success = getComputedStyle(document.getElementById("test" + i, "")).height
+         == getComputedStyle(document.getElementById("expected" + i, "")).height;
+    document.write(success ? "PASS" : "FAIL");
+    document.write("<br><br>");
+    allSuccess = allSuccess && success;
+}
+
+document.write("Summary: " + (allSuccess ? "PASS" : "FAIL")); 
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (95029 => 95030)


--- trunk/Source/WebCore/ChangeLog	2011-09-13 16:23:49 UTC (rev 95029)
+++ trunk/Source/WebCore/ChangeLog	2011-09-13 16:44:15 UTC (rev 95030)
@@ -1,3 +1,20 @@
+2011-09-13  Xianzhu Wang  <wangxian...@chromium.org>
+
+        Reviewed by Darin Adler.
+
+        Webkit wraps between hyphen-minus and numeric characters 
+        https://bugs.webkit.org/show_bug.cgi?id=20677
+
+        Disallow wrapping between a hyphen-minus and a digit if the hyphen-minus
+        is not directly after a digit or a letter.
+
+        Test: fast/text/line-breaks-after-hyphen-before-number.html
+
+        * rendering/break_lines.cpp:
+        (WebCore::asciiLineBreakTable): Disabled line-breaking after '-' and before '.', '0'-'9'. Note: the change for '0'-'9' doesn't really matter because the case is handled hard-coded in shouldBreakAfter().
+        (WebCore::shouldBreakAfter): Changed line-breaking behavior after '-'.
+        (WebCore::nextBreakablePosition): Passes lastLastCh to shouldBreakAfter. 
+
 2011-09-13  Erik Wright  <erikwri...@chromium.org>
 
         platform/graphics/gtk/FontGtk.cpp was renamed to platform/graphics/pango/FontPango.cpp . Reflect this change in WebCore.gypi to fix a Chromium build breakage.

Modified: trunk/Source/WebCore/rendering/break_lines.cpp (95029 => 95030)


--- trunk/Source/WebCore/rendering/break_lines.cpp	2011-09-13 16:23:49 UTC (rev 95029)
+++ trunk/Source/WebCore/rendering/break_lines.cpp	2011-09-13 16:44:15 UTC (rev 95030)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2005, 2007, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2011 Google Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -27,6 +28,7 @@
 #include "break_lines.h"
 
 #include "TextBreakIterator.h"
+#include <wtf/ASCIICType.h>
 #include <wtf/StdLibExtras.h>
 #include <wtf/unicode/CharacterNames.h>
 
@@ -66,7 +68,7 @@
 #define F 0xFF
 
 // Line breaking table for printable ASCII characters. Line breaking opportunities in this table are as below:
-// - before openning punctuations such as '(', '<', '[', '{' after certain characters (compatible with Firefox 3.6);
+// - before opening punctuations such as '(', '<', '[', '{' after certain characters (compatible with Firefox 3.6);
 // - after '-' and '?' (backward-compatible, and compatible with Internet Explorer).
 // Please refer to <https://bugs.webkit.org/show_bug.cgi?id=37698> for line breaking matrixes of different browsers
 // and the ICU standard.
@@ -84,7 +86,7 @@
     { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // *
     { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // +
     { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // ,
-    { B(1, 1, 1, 1, 1, 1, 1, 1), B(1, 1, 1, 1, 1, 1, 1, 1), F, B(1, 1, 1, 1, 1, 1, 1, 1), F, F, F, B(1, 1, 1, 1, 1, 1, 1, 1), F, F, F, B(1, 1, 1, 1, 1, 1, 1, 1) }, // -
+    { B(1, 1, 1, 1, 1, 1, 1, 1), B(1, 1, 1, 1, 1, 0, 1, 0), 0, B(0, 1, 1, 1, 1, 1, 1, 1), F, F, F, B(1, 1, 1, 1, 1, 1, 1, 1), F, F, F, B(1, 1, 1, 1, 1, 1, 1, 1) }, // - Note: breaking before '0'-'9' is handled hard-coded in shouldBreakAfter().
     { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // .
     { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // /
     DI,  DI,  DI,  DI,  DI,  DI,  DI,  DI,  DI,  DI, // 0-9
@@ -117,7 +119,7 @@
 
 COMPILE_ASSERT(WTF_ARRAY_LENGTH(asciiLineBreakTable) == asciiLineBreakTableLastChar - asciiLineBreakTableFirstChar + 1, TestLineBreakTableConsistency);
 
-static inline bool shouldBreakAfter(UChar ch, UChar nextCh)
+static inline bool shouldBreakAfter(UChar lastCh, UChar ch, UChar nextCh)
 {
     switch (ch) {
     case ideographicComma:
@@ -126,6 +128,13 @@
         // which is likely to be resolved in Unicode 5.1 <http://bugs.webkit.org/show_bug.cgi?id=17411>.
         // We may want to remove or conditionalize this workaround at some point.
         return true;
+    case '-':
+        if (isASCIIDigit(nextCh)) {
+            // Don't allow line breaking between '-' and a digit if the '-' may mean a minus sign in the context,
+            // while allow breaking in 'ABCD-1234' and '1234-5678' which may be in long URLs.
+            return isASCIIAlphanumeric(lastCh);
+        }
+        // Fall through
     default:
         // If both ch and nextCh are ASCII characters, use a lookup table for enhanced speed and for compatibility
         // with other browsers (see comments for asciiLineBreakTable for details).
@@ -151,11 +160,12 @@
     int len = lazyBreakIterator.length();
     int nextBreak = -1;
 
+    UChar lastLastCh = pos > 1 ? str[pos - 2] : 0;
     UChar lastCh = pos > 0 ? str[pos - 1] : 0;
     for (int i = pos; i < len; i++) {
         UChar ch = str[i];
 
-        if (isBreakableSpace(ch, treatNoBreakSpaceAsBreak) || shouldBreakAfter(lastCh, ch))
+        if (isBreakableSpace(ch, treatNoBreakSpaceAsBreak) || shouldBreakAfter(lastLastCh, lastCh, ch))
             return i;
 
         if (needsLineBreakIterator(ch) || needsLineBreakIterator(lastCh)) {
@@ -168,6 +178,7 @@
                 return i;
         }
 
+        lastLastCh = lastCh;
         lastCh = ch;
     }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to