Title: [199818] trunk
Revision
199818
Author
hy...@apple.com
Date
2016-04-21 09:25:13 -0700 (Thu, 21 Apr 2016)

Log Message

Don't hyphenate the last word in a paragraph of text.
https://bugs.webkit.org/show_bug.cgi?id=156803

Reviewed by Simon Fraser.

Source/WebCore:

Added fast/text/hyphenate-avoid-orphaned-word.html

* rendering/RenderText.h:
* rendering/line/BreakingContext.h:
(WebCore::BreakingContext::handleText):

LayoutTests:

* fast/text/hyphenate-avoid-orphaned-word.html: Added.
* platform/mac/fast/text/hyphenate-avoid-orphaned-word-expected.txt: Added.
* platform/mac/fast/text/hyphenate-limit-before-after-expected.txt:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (199817 => 199818)


--- trunk/LayoutTests/ChangeLog	2016-04-21 16:07:18 UTC (rev 199817)
+++ trunk/LayoutTests/ChangeLog	2016-04-21 16:25:13 UTC (rev 199818)
@@ -1,3 +1,14 @@
+2016-04-21  Dave Hyatt  <hy...@apple.com>
+
+        Don't hyphenate the last word in a paragraph of text.
+        https://bugs.webkit.org/show_bug.cgi?id=156803
+
+        Reviewed by Simon Fraser.
+
+        * fast/text/hyphenate-avoid-orphaned-word.html: Added.
+        * platform/mac/fast/text/hyphenate-avoid-orphaned-word-expected.txt: Added.
+        * platform/mac/fast/text/hyphenate-limit-before-after-expected.txt:
+
 2016-04-21  Carlos Garcia Campos  <cgar...@igalia.com>
 
         Unreviewed GTK+ gardening. Update expectations for some editing tests that are slow on Debug.

Added: trunk/LayoutTests/fast/text/hyphenate-avoid-orphaned-word.html (0 => 199818)


--- trunk/LayoutTests/fast/text/hyphenate-avoid-orphaned-word.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/hyphenate-avoid-orphaned-word.html	2016-04-21 16:25:13 UTC (rev 199818)
@@ -0,0 +1,76 @@
+<style>
+    html {
+        -webkit-locale: "en_US";
+    }
+
+    .text-box {
+        border: solid;
+        padding: 4px;
+        width: 330px;
+        font-size: 18px;
+        text-align: justify;
+        -webkit-hyphens: auto;
+    }
+
+    .float {
+        width: 75px;
+        height: 5em;
+        background-color: aliceblue;
+        float: right;
+        margin-left: 10px;
+    }
+
+    .hyphenate-character-auto {
+        -webkit-hyphenate-character: auto;
+    }
+
+    .hyphenate-character-bullet {
+        -webkit-hyphenate-character: "\2022";
+    }
+
+    .hyphenate-character-tilde-dot {
+        -webkit-hyphenate-character: "\B7~";
+    }
+
+    .test {
+        float: left;
+        margin: 0 4px;
+    }
+</style>
+<div class="test">
+    <p>The initial value (should be like <tt>auto</tt>)</p>
+    <div class="text-box">
+        <div class="float"></div>
+        The chief difficulty Alice found at first was in managing her
+        flamingo: she succeeded in getting its body tucked away,
+        comfortably enough, under her arm, with its legs hanging down,
+        but generally, just as she had got its neck nicely straightened.</div>
+</div>
+<div class="test">
+    <p>The default (<tt>hyphenate-character: auto</tt>)</p>
+    <div class="text-box hyphenate-character-auto">
+        <div class="float"></div>
+        The chief difficulty Alice found at first was in managing her
+        flamingo: she succeeded in getting its body tucked away,
+        comfortably enough, under her arm, with its legs hanging down,
+        but generally, just as she had got its neck nicely straightened.
+    </div>
+</div>
+<div class="test">
+    <p>Bullet (<tt>hyphenate-character: "\2022"</tt>)</p>
+    <div class="text-box hyphenate-character-bullet">
+        <div class="float"></div>
+        The chief difficulty Alice found at first was in managing her
+        flamingo: she succeeded in getting its body tucked away,
+        comfortably enough, under her arm, with its legs hanging down,
+        but generally, just as she had got its neck nicely straightened.    </div>
+</div>
+<div class="test">
+    <p>Middle dot and tilde (<tt>hyphenate-character: "\B7~"</tt>)</p>
+    <div class="text-box hyphenate-character-tilde-dot">
+        <div class="float"></div>
+        The chief difficulty Alice found at first was in managing her
+        flamingo: she succeeded in getting its body tucked away,
+        comfortably enough, under her arm, with its legs hanging down,
+        but generally, just as she had got its neck nicely straightened.    </div>
+</div>

Added: trunk/LayoutTests/platform/mac/fast/text/hyphenate-avoid-orphaned-word-expected.txt (0 => 199818)


--- trunk/LayoutTests/platform/mac/fast/text/hyphenate-avoid-orphaned-word-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/fast/text/hyphenate-avoid-orphaned-word-expected.txt	2016-04-21 16:25:13 UTC (rev 199818)
@@ -0,0 +1,93 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock (floating) {DIV} at (4,0) size 344x240
+        RenderBlock {P} at (0,16) size 344x18
+          RenderText {#text} at (0,0) size 208x18
+            text run at (0,0) width 208: "The initial value (should be like "
+          RenderInline {TT} at (0,0) size 33x15
+            RenderText {#text} at (207,2) size 33x15
+              text run at (207,2) width 33: "auto"
+          RenderText {#text} at (239,0) size 6x18
+            text run at (239,0) width 6: ")"
+        RenderBlock {DIV} at (0,50) size 344x190 [border: (3px solid #000000)]
+          RenderBlock (floating) {DIV} at (262,7) size 75x90 [bgcolor=#F0F8FF]
+          RenderText {#text} at (7,7) size 330x176
+            text run at (7,7) width 245: "The chief difficulty Alice found"
+            text run at (7,29) width 245: "at first was in managing her"
+            text run at (7,51) width 245: "flamingo: she succeeded in get" + hyphen string "-"
+            text run at (7,73) width 209: "ting its body tucked away, "
+            text run at (215,73) width 37: "com" + hyphen string "-"
+            text run at (7,95) width 245: "fortably enough, under her arm,"
+            text run at (7,117) width 228: "with its legs hanging down, "
+            text run at (234,117) width 103: "but generally,"
+            text run at (7,139) width 330: "just as she had got its neck nicely"
+            text run at (7,161) width 93: "straightened."
+      RenderBlock (floating) {DIV} at (356,0) size 344x240
+        RenderBlock {P} at (0,16) size 344x18
+          RenderText {#text} at (0,0) size 83x18
+            text run at (0,0) width 83: "The default ("
+          RenderInline {TT} at (0,0) size 196x15
+            RenderText {#text} at (82,2) size 196x15
+              text run at (82,2) width 196: "hyphenate-character: auto"
+          RenderText {#text} at (277,0) size 6x18
+            text run at (277,0) width 6: ")"
+        RenderBlock {DIV} at (0,50) size 344x190 [border: (3px solid #000000)]
+          RenderBlock (floating) {DIV} at (262,7) size 75x90 [bgcolor=#F0F8FF]
+          RenderText {#text} at (7,7) size 330x176
+            text run at (7,7) width 245: "The chief difficulty Alice found"
+            text run at (7,29) width 245: "at first was in managing her"
+            text run at (7,51) width 245: "flamingo: she succeeded in get" + hyphen string "-"
+            text run at (7,73) width 209: "ting its body tucked away, "
+            text run at (215,73) width 37: "com" + hyphen string "-"
+            text run at (7,95) width 245: "fortably enough, under her arm,"
+            text run at (7,117) width 228: "with its legs hanging down, "
+            text run at (234,117) width 103: "but generally,"
+            text run at (7,139) width 330: "just as she had got its neck nicely"
+            text run at (7,161) width 93: "straightened."
+      RenderBlock (floating) {DIV} at (4,240) size 344x240
+        RenderBlock {P} at (0,16) size 344x18
+          RenderText {#text} at (0,0) size 49x18
+            text run at (0,0) width 49: "Bullet ("
+          RenderInline {TT} at (0,0) size 219x15
+            RenderText {#text} at (48,2) size 219x15
+              text run at (48,2) width 219: "hyphenate-character: \"\\2022\""
+          RenderText {#text} at (266,0) size 7x18
+            text run at (266,0) width 7: ")"
+        RenderBlock {DIV} at (0,50) size 344x190 [border: (3px solid #000000)]
+          RenderBlock (floating) {DIV} at (262,7) size 75x90 [bgcolor=#F0F8FF]
+          RenderText {#text} at (7,7) size 330x176
+            text run at (7,7) width 245: "The chief difficulty Alice found"
+            text run at (7,29) width 245: "at first was in managing her"
+            text run at (7,51) width 245: "flamingo: she succeeded in get" + hyphen string "\x{2022}"
+            text run at (7,73) width 208: "ting its body tucked away, "
+            text run at (214,73) width 38: "com" + hyphen string "\x{2022}"
+            text run at (7,95) width 245: "fortably enough, under her arm,"
+            text run at (7,117) width 228: "with its legs hanging down, "
+            text run at (234,117) width 103: "but generally,"
+            text run at (7,139) width 330: "just as she had got its neck nicely"
+            text run at (7,161) width 93: "straightened."
+      RenderBlock (floating) {DIV} at (356,240) size 356x240
+        RenderBlock {P} at (0,16) size 356x18
+          RenderText {#text} at (0,0) size 140x18
+            text run at (0,0) width 140: "Middle dot and tilde ("
+          RenderInline {TT} at (0,0) size 212x15
+            RenderText {#text} at (139,2) size 212x15
+              text run at (139,2) width 212: "hyphenate-character: \"\\B7~\""
+          RenderText {#text} at (350,0) size 6x18
+            text run at (350,0) width 6: ")"
+        RenderBlock {DIV} at (0,50) size 344x190 [border: (3px solid #000000)]
+          RenderBlock (floating) {DIV} at (262,7) size 75x90 [bgcolor=#F0F8FF]
+          RenderText {#text} at (7,7) size 330x176
+            text run at (7,7) width 245: "The chief difficulty Alice found"
+            text run at (7,29) width 245: "at first was in managing her"
+            text run at (7,51) width 245: "flamingo: she succeeded in get" + hyphen string "\x{B7}~"
+            text run at (7,73) width 200: "ting its body tucked away, "
+            text run at (206,73) width 46: "com" + hyphen string "\x{B7}~"
+            text run at (7,95) width 245: "fortably enough, under her arm,"
+            text run at (7,117) width 228: "with its legs hanging down, "
+            text run at (234,117) width 103: "but generally,"
+            text run at (7,139) width 330: "just as she had got its neck nicely"
+            text run at (7,161) width 93: "straightened."

Modified: trunk/LayoutTests/platform/mac/fast/text/hyphenate-limit-before-after-expected.txt (199817 => 199818)


--- trunk/LayoutTests/platform/mac/fast/text/hyphenate-limit-before-after-expected.txt	2016-04-21 16:07:18 UTC (rev 199817)
+++ trunk/LayoutTests/platform/mac/fast/text/hyphenate-limit-before-after-expected.txt	2016-04-21 16:25:13 UTC (rev 199818)
@@ -53,15 +53,15 @@
       RenderText {#text} at (434,123) size 4x18
         text run at (434,123) width 4: " "
       RenderBlock {DIV} at (446,84) size 126x60 [border: (3px solid #000000)]
-        RenderText {#text} at (3,3) size 89x54
+        RenderText {#text} at (3,3) size 74x54
           text run at (3,3) width 74: "There is re" + hyphen string "-"
-          text run at (3,21) width 89: "markable evi" + hyphen string "-"
-          text run at (3,39) width 42: "dence."
+          text run at (3,21) width 60: "markable"
+          text run at (3,39) width 61: "evidence."
       RenderText {#text} at (580,123) size 4x18
         text run at (580,123) width 4: " "
       RenderBlock {DIV} at (592,84) size 126x60 [border: (3px solid #000000)]
-        RenderText {#text} at (3,3) size 101x54
+        RenderText {#text} at (3,3) size 72x54
           text run at (3,3) width 52: "There is"
-          text run at (3,21) width 101: "remarkable evi" + hyphen string "-"
-          text run at (3,39) width 42: "dence."
+          text run at (3,21) width 72: "remarkable"
+          text run at (3,39) width 61: "evidence."
       RenderText {#text} at (0,0) size 0x0

Modified: trunk/Source/WebCore/ChangeLog (199817 => 199818)


--- trunk/Source/WebCore/ChangeLog	2016-04-21 16:07:18 UTC (rev 199817)
+++ trunk/Source/WebCore/ChangeLog	2016-04-21 16:25:13 UTC (rev 199818)
@@ -1,3 +1,16 @@
+2016-04-21  Dave Hyatt  <hy...@apple.com>
+
+        Don't hyphenate the last word in a paragraph of text.
+        https://bugs.webkit.org/show_bug.cgi?id=156803
+
+        Reviewed by Simon Fraser.
+
+        Added fast/text/hyphenate-avoid-orphaned-word.html
+
+        * rendering/RenderText.h:
+        * rendering/line/BreakingContext.h:
+        (WebCore::BreakingContext::handleText):
+
 2016-04-21  Chris Dumez  <cdu...@apple.com>
 
         Drop [UsePointersEvenForNonNullableObjectArguments] from Range

Modified: trunk/Source/WebCore/rendering/RenderText.h (199817 => 199818)


--- trunk/Source/WebCore/rendering/RenderText.h	2016-04-21 16:07:18 UTC (rev 199817)
+++ trunk/Source/WebCore/rendering/RenderText.h	2016-04-21 16:25:13 UTC (rev 199818)
@@ -170,6 +170,8 @@
     StringView stringView(int start = 0, int stop = -1) const;
 
     LayoutUnit topOfFirstText() const;
+    
+    bool containsOnlyWhitespace(unsigned from, unsigned len) const;
 
 protected:
     virtual void computePreferredLogicalWidths(float leadWidth);
@@ -194,7 +196,6 @@
 
     bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation&, const LayoutPoint&, HitTestAction) final { ASSERT_NOT_REACHED(); return false; }
 
-    bool containsOnlyWhitespace(unsigned from, unsigned len) const;
     float widthFromCache(const FontCascade&, int start, int len, float xPos, HashSet<const Font*>* fallbackFonts, GlyphOverflow*, const RenderStyle&) const;
     bool isAllASCII() const { return m_isAllASCII; }
     bool computeUseBackslashAsYenSymbol() const;

Modified: trunk/Source/WebCore/rendering/line/BreakingContext.h (199817 => 199818)


--- trunk/Source/WebCore/rendering/line/BreakingContext.h	2016-04-21 16:07:18 UTC (rev 199817)
+++ trunk/Source/WebCore/rendering/line/BreakingContext.h	2016-04-21 16:25:13 UTC (rev 199818)
@@ -794,6 +794,7 @@
     bool keepAllWords = m_currentStyle->wordBreak() == KeepAllWordBreak;
     float hyphenWidth = 0;
     bool isLooseCJKMode = false;
+    bool isLineEmpty = m_lineInfo.isEmpty();
 
     if (isSVGText) {
         breakWords = false;
@@ -937,7 +938,10 @@
                     }
                 }
                 if ((lineWasTooWide || !m_width.fitsOnLine()) && !m_hangsAtEnd) {
-                    if (canHyphenate && !m_width.fitsOnLine()) {
+                    // Don't try to hyphenate at the final break of a block, since this means there is
+                    // no more content, and a hyphenated single word would end up on a line by itself. This looks
+                    // bad so just don't allow it.
+                    if (canHyphenate && !m_width.fitsOnLine() && (m_nextObject || !renderText.containsOnlyWhitespace(m_current.offset(), renderText.textLength() - m_current.offset()) || isLineEmpty)) {
                         m_lineBreakHistory.push([&](InlineIterator& modifyMe) {
                             tryHyphenating(renderText, font, style.locale(), consecutiveHyphenatedLines, m_blockStyle.hyphenationLimitLines(), style.hyphenationLimitBefore(), style.hyphenationLimitAfter(), lastSpace, m_current.offset(), m_width.currentWidth() - additionalTempWidth, m_width.availableWidth(), isFixedPitch, m_collapseWhiteSpace, lastSpaceWordSpacing, modifyMe, m_current.nextBreakablePosition(), m_lineBreaker.m_hyphenated);
                         });
@@ -1045,6 +1049,8 @@
                     m_trailingObjects.updateWhitespaceCollapsingTransitionsForTrailingBoxes(m_lineWhitespaceCollapsingState, InlineIterator(), TrailingObjects::DoNotCollapseFirstSpace);
                 }
             }
+            
+            isLineEmpty = m_lineInfo.isEmpty();
         } else {
             if (m_ignoringSpaces) {
                 // Stop ignoring spaces and begin at this new point.
@@ -1120,7 +1126,10 @@
     m_includeEndWidth = false;
 
     if (!fitsOnLineOrHangsAtEnd()) {
-        if (canHyphenate) {
+        // Don't try to hyphenate at the final break of a block, since this means there is
+        // no more content, and a hyphenated single word would end up on a line by itself. This looks
+        // bad so just don't allow it.
+        if (canHyphenate && (m_nextObject || isLineEmpty)) {
             m_lineBreakHistory.push([&](InlineIterator& modifyMe) {
                 tryHyphenating(renderText, font, style.locale(), consecutiveHyphenatedLines, m_blockStyle.hyphenationLimitLines(), style.hyphenationLimitBefore(), style.hyphenationLimitAfter(), lastSpace, m_current.offset(), m_width.currentWidth() - additionalTempWidth, m_width.availableWidth(), isFixedPitch, m_collapseWhiteSpace, lastSpaceWordSpacing, modifyMe, m_current.nextBreakablePosition(), m_lineBreaker.m_hyphenated);
             });
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to