RenderText’s minimum preferred width is incorrect when soft hyphens are used
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Jun 2012 20:06:54 +0000 (20:06 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Jun 2012 20:06:54 +0000 (20:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=89775

Reviewed by Simon Fraser.

Source/WebCore:

Test: fast/text/soft-hyphen-min-preferred-width.html

* rendering/RenderText.cpp:
(WebCore::hyphenWidth): Added this helper function.
(WebCore::RenderText::computePreferredLogicalWidths): In places where this function tests
for the soft hyphen character, added a check that the 'hyphens' style property is not set
to 'none', because in that case soft hyphens are not break opportunities. Also added an
explicit check to suppress break opportunities from isBreakable() if the occur after a
soft hyphen and 'hyphens' is set to 'none'. Finally, when measuring text up to a potential
line break, added the width of the hyphen string when needed.

LayoutTests:

* fast/text/soft-hyphen-min-preferred-width-expected.html: Added.
* fast/text/soft-hyphen-min-preferred-width.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/text/soft-hyphen-min-preferred-width-expected.html [new file with mode: 0644]
LayoutTests/fast/text/soft-hyphen-min-preferred-width.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderText.cpp

index ccd88aa..00999a5 100644 (file)
@@ -1,3 +1,13 @@
+2012-06-22  Dan Bernstein  <mitz@apple.com>
+
+        RenderText’s minimum preferred width is incorrect when soft hyphens are used
+        https://bugs.webkit.org/show_bug.cgi?id=89775
+
+        Reviewed by Simon Fraser.
+
+        * fast/text/soft-hyphen-min-preferred-width-expected.html: Added.
+        * fast/text/soft-hyphen-min-preferred-width.html: Added.
+
 2012-06-22  Jan Keromnes  <janx@linux.com>
 
         Web Inspector: ExtensionPanel.onSearch listener doesn't work
diff --git a/LayoutTests/fast/text/soft-hyphen-min-preferred-width-expected.html b/LayoutTests/fast/text/soft-hyphen-min-preferred-width-expected.html
new file mode 100644 (file)
index 0000000..9847126
--- /dev/null
@@ -0,0 +1,29 @@
+<style>
+    div {
+        outline: dashed thin lightblue;
+         -webkit-hyphenate-character: "-";
+    }
+</style>
+<p>
+    There should be a hyphen at the end of the first line, and it should not
+    overflow the box.
+</p>
+<table cellspacing=0 cellpadding=0>
+    <tr>
+        <td>
+            <div>extraordinar<span>-</span><br>ily</div>
+        </td>
+        <td style="width: 100%"></td>
+    </tr>
+</table>
+<p>
+    The text should not overflow the box.
+</p>
+<table cellspacing=0 cellpadding=0>
+    <tr>
+        <td>
+            <div>extraordinar<span></span>ily</div>
+        </td>
+        <td style="width: 100%"></td>
+    </tr>
+</table>
diff --git a/LayoutTests/fast/text/soft-hyphen-min-preferred-width.html b/LayoutTests/fast/text/soft-hyphen-min-preferred-width.html
new file mode 100644 (file)
index 0000000..de8b1ca
--- /dev/null
@@ -0,0 +1,29 @@
+<style>
+    div {
+        outline: dashed thin lightblue;
+         -webkit-hyphenate-character: "-";
+    }
+</style>
+<p>
+    There should be a hyphen at the end of the first line, and it should not
+    overflow the box.
+</p>
+<table cellspacing=0 cellpadding=0>
+    <tr>
+        <td>
+            <div style="-webkit-hyphens: manual;">extraordinar&shy;ily</div>
+        </td>
+        <td style="width: 100%"></td>
+    </tr>
+</table>
+<p>
+    The text should not overflow the box.
+</p>
+<table cellspacing=0 cellpadding=0>
+    <tr>
+        <td>
+            <div style="-webkit-hyphens: none;">extraordinar&shy;ily</div>
+        </td>
+        <td style="width: 100%"></td>
+    </tr>
+</table>
index 9030577..5d8b653 100644 (file)
@@ -1,3 +1,21 @@
+2012-06-22  Dan Bernstein  <mitz@apple.com>
+
+        RenderText’s minimum preferred width is incorrect when soft hyphens are used
+        https://bugs.webkit.org/show_bug.cgi?id=89775
+
+        Reviewed by Simon Fraser.
+
+        Test: fast/text/soft-hyphen-min-preferred-width.html
+
+        * rendering/RenderText.cpp:
+        (WebCore::hyphenWidth): Added this helper function.
+        (WebCore::RenderText::computePreferredLogicalWidths): In places where this function tests
+        for the soft hyphen character, added a check that the 'hyphens' style property is not set
+        to 'none', because in that case soft hyphens are not break opportunities. Also added an
+        explicit check to suppress break opportunities from isBreakable() if the occur after a
+        soft hyphen and 'hyphens' is set to 'none'. Finally, when measuring text up to a potential
+        line break, added the width of the hyphen string when needed.
+
 2012-06-22  Dean Jackson  <dino@apple.com>
 
         BitmapImage duplicates code to calculate size
index 7ea7d7b..0ff8fd7 100644 (file)
@@ -882,6 +882,12 @@ void RenderText::computePreferredLogicalWidths(float leadWidth)
         m_knownToHaveNoOverflowAndNoFallbackFonts = true;
 }
 
+static inline float hyphenWidth(RenderText* renderer, const Font& font)
+{
+    RenderStyle* style = renderer->style();
+    return font.width(RenderBlock::constructTextRun(renderer, font, style->hyphenString().string(), style));
+}
+
 void RenderText::computePreferredLogicalWidths(float leadWidth, HashSet<const SimpleFontData*>& fallbackFonts, GlyphOverflow& glyphOverflow)
 {
     ASSERT(m_hasTab || preferredLogicalWidthsDirty() || !m_knownToHaveNoOverflowAndNoFallbackFonts);
@@ -963,7 +969,7 @@ void RenderText::computePreferredLogicalWidths(float leadWidth, HashSet<const Si
             ASSERT(lastWordBoundary == i);
             lastWordBoundary++;
             continue;
-        } else if (c == softHyphen) {
+        } else if (c == softHyphen && styleToUse->hyphens() != HyphensNone) {
             currMaxWidth += widthFromCache(f, lastWordBoundary, i - lastWordBoundary, leadWidth + currMaxWidth, &fallbackFonts, &glyphOverflow);
             if (firstGlyphLeftOverflow < 0)
                 firstGlyphLeftOverflow = glyphOverflow.left;
@@ -974,12 +980,12 @@ void RenderText::computePreferredLogicalWidths(float leadWidth, HashSet<const Si
         bool hasBreak = breakAll || isBreakable(breakIterator, i, nextBreakable, breakNBSP);
         bool betweenWords = true;
         int j = i;
-        while (c != '\n' && !isSpaceAccordingToStyle(c, styleToUse) && c != '\t' && c != softHyphen) {
+        while (c != '\n' && !isSpaceAccordingToStyle(c, styleToUse) && c != '\t' && (c != softHyphen || styleToUse->hyphens() == HyphensNone)) {
             j++;
             if (j == len)
                 break;
             c = txt[j];
-            if (isBreakable(breakIterator, j, nextBreakable, breakNBSP))
+            if (isBreakable(breakIterator, j, nextBreakable, breakNBSP) && txt[j - 1] != softHyphen)
                 break;
             if (breakAll) {
                 betweenWords = false;
@@ -993,8 +999,11 @@ void RenderText::computePreferredLogicalWidths(float leadWidth, HashSet<const Si
             float w;
             if (wordTrailingSpaceWidth && isSpace)
                 w = widthFromCache(f, i, wordLen + 1, leadWidth + currMaxWidth, &fallbackFonts, &glyphOverflow) - wordTrailingSpaceWidth;
-            else
+            else {
                 w = widthFromCache(f, i, wordLen, leadWidth + currMaxWidth, &fallbackFonts, &glyphOverflow);
+                if (c == softHyphen && styleToUse->hyphens() != HyphensNone)
+                    currMinWidth += hyphenWidth(this, f);
+            }
 
             if (firstGlyphLeftOverflow < 0)
                 firstGlyphLeftOverflow = glyphOverflow.left;