Changeset 211222 in webkit


Ignore:
Timestamp:
Jan 26, 2017 11:36:27 AM (7 years ago)
Author:
Alan Bujtas
Message:

Simple line layout: Add support for -webkit-hyphenate-limit-after and -webkit-hyphenate-limit-before
https://bugs.webkit.org/show_bug.cgi?id=167439
<rdar://problem/30180184>

Reviewed by Antti Koivisto.

Source/WebCore:

Implement pre and post hyphen length constrains for simple line layout.

Tests: fast/text/simple-line-layout-hyphen-limit-after.html

fast/text/simple-line-layout-hyphen-limit-before.html

  • rendering/SimpleLineLayout.cpp:

(WebCore::SimpleLineLayout::canUseForStyle):
(WebCore::SimpleLineLayout::printReason):

  • rendering/SimpleLineLayoutTextFragmentIterator.cpp:

(WebCore::SimpleLineLayout::TextFragmentIterator::Style::Style): Same as normal line layout default values.
(WebCore::SimpleLineLayout::TextFragmentIterator::lastHyphenPosition):

  • rendering/SimpleLineLayoutTextFragmentIterator.h:

LayoutTests:

  • fast/text/simple-line-layout-hyphen-limit-after.html: Added.
  • fast/text/simple-line-layout-hyphen-limit-before-expected.html: Added.
  • fast/text/simple-line-layout-hyphen-limit-before.html: Added.
  • platform/mac/fast/text/hyphenate-limit-before-after-expected.txt: progression.
Location:
trunk
Files:
4 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r211219 r211222  
     12017-01-26  Zalan Bujtas  <zalan@apple.com>
     2
     3        Simple line layout: Add support for -webkit-hyphenate-limit-after and -webkit-hyphenate-limit-before
     4        https://bugs.webkit.org/show_bug.cgi?id=167439
     5        <rdar://problem/30180184>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        * fast/text/simple-line-layout-hyphen-limit-after.html: Added.
     10        * fast/text/simple-line-layout-hyphen-limit-before-expected.html: Added.
     11        * fast/text/simple-line-layout-hyphen-limit-before.html: Added.
     12        * platform/mac/fast/text/hyphenate-limit-before-after-expected.txt: progression.
     13
    1142017-01-26  Ryan Haddad  <ryanhaddad@apple.com>
    215
  • trunk/LayoutTests/platform/mac/fast/text/hyphenate-limit-before-after-expected.txt

    r199818 r211222  
    5454        text run at (434,123) width 4: " "
    5555      RenderBlock {DIV} at (446,84) size 126x60 [border: (3px solid #000000)]
    56         RenderText {#text} at (3,3) size 74x54
     56        RenderText {#text} at (3,3) size 89x54
    5757          text run at (3,3) width 74: "There is re" + hyphen string "-"
    58           text run at (3,21) width 60: "markable"
    59           text run at (3,39) width 61: "evidence."
     58          text run at (3,21) width 89: "markable evi" + hyphen string "-"
     59          text run at (3,39) width 42: "dence."
    6060      RenderText {#text} at (580,123) size 4x18
    6161        text run at (580,123) width 4: " "
    6262      RenderBlock {DIV} at (592,84) size 126x60 [border: (3px solid #000000)]
    63         RenderText {#text} at (3,3) size 72x54
     63        RenderText {#text} at (3,3) size 101x54
    6464          text run at (3,3) width 52: "There is"
    65           text run at (3,21) width 72: "remarkable"
    66           text run at (3,39) width 61: "evidence."
     65          text run at (3,21) width 101: "remarkable evi" + hyphen string "-"
     66          text run at (3,39) width 42: "dence."
    6767      RenderText {#text} at (0,0) size 0x0
  • trunk/Source/WebCore/ChangeLog

    r211220 r211222  
     12017-01-26  Zalan Bujtas  <zalan@apple.com>
     2
     3        Simple line layout: Add support for -webkit-hyphenate-limit-after and -webkit-hyphenate-limit-before
     4        https://bugs.webkit.org/show_bug.cgi?id=167439
     5        <rdar://problem/30180184>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        Implement pre and post hyphen length constrains for simple line layout.
     10
     11        Tests: fast/text/simple-line-layout-hyphen-limit-after.html
     12               fast/text/simple-line-layout-hyphen-limit-before.html
     13
     14        * rendering/SimpleLineLayout.cpp:
     15        (WebCore::SimpleLineLayout::canUseForStyle):
     16        (WebCore::SimpleLineLayout::printReason):
     17        * rendering/SimpleLineLayoutTextFragmentIterator.cpp:
     18        (WebCore::SimpleLineLayout::TextFragmentIterator::Style::Style): Same as normal line layout default values.
     19        (WebCore::SimpleLineLayout::TextFragmentIterator::lastHyphenPosition):
     20        * rendering/SimpleLineLayoutTextFragmentIterator.h:
     21
    1222017-01-26  Brady Eidson  <beidson@apple.com>
    223
  • trunk/Source/WebCore/rendering/SimpleLineLayout.cpp

    r211108 r211222  
    8787    FlowHasLineAlignEdges                 = 1LLU  << 21,
    8888    FlowHasLineSnap                       = 1LLU  << 22,
    89     FlowHasHypensLimit                    = 1LLU  << 23,
     89    FlowHasHypensLineLimit                = 1LLU  << 23,
    9090    FlowHasTextEmphasisFillOrMark         = 1LLU  << 24,
    9191    FlowHasTextShadow                     = 1LLU  << 25,
     
    238238    if (style.lineSnap() != LineSnapNone)
    239239        SET_REASON_AND_RETURN_IF_NEEDED(FlowHasLineSnap, reasons, includeReasons);
    240     if (style.hyphenationLimitBefore() != RenderStyle::initialHyphenationLimitBefore()
    241         || style.hyphenationLimitAfter() != RenderStyle::initialHyphenationLimitAfter()
    242         || style.hyphenationLimitLines() != RenderStyle::initialHyphenationLimitLines())
    243         SET_REASON_AND_RETURN_IF_NEEDED(FlowHasHypensLimit, reasons, includeReasons);
     240    if (style.hyphenationLimitLines() != RenderStyle::initialHyphenationLimitLines())
     241        SET_REASON_AND_RETURN_IF_NEEDED(FlowHasHypensLineLimit, reasons, includeReasons);
    244242    if (style.textEmphasisFill() != TextEmphasisFillFilled || style.textEmphasisMark() != TextEmphasisMarkNone)
    245243        SET_REASON_AND_RETURN_IF_NEEDED(FlowHasTextEmphasisFillOrMark, reasons, includeReasons);
     
    992990        stream << "-webkit-line-snap property";
    993991        break;
    994     case FlowHasHypensLimit:
    995         stream << "hyphen-limit-* property";
     992    case FlowHasHypensLineLimit:
     993        stream << "-webkit-hyphenate-limit-lines property";
    996994        break;
    997995    case FlowHasTextEmphasisFillOrMark:
  • trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.cpp

    r211108 r211222  
    5050    , shouldHyphenate(style.hyphens() == HyphensAuto && canHyphenate(style.locale()))
    5151    , hyphenStringWidth(shouldHyphenate ? font.width(TextRun(style.hyphenString())) : 0)
     52    , hyphenLimitBefore(style.hyphenationLimitBefore() < 0 ? 2 : style.hyphenationLimitBefore())
     53    , hyphenLimitAfter(style.hyphenationLimitAfter() < 0 ? 2 : style.hyphenationLimitAfter())
    5254    , locale(style.locale())
    5355{
     
    177179}
    178180
    179 std::optional<unsigned> TextFragmentIterator::lastHyphenPosition(const TextFragmentIterator::TextFragment& run, unsigned beforeIndex) const
    180 {
    181     ASSERT(run.start() < beforeIndex);
     181std::optional<unsigned> TextFragmentIterator::lastHyphenPosition(const TextFragmentIterator::TextFragment& run, unsigned before) const
     182{
     183    ASSERT(run.start() < before);
    182184    auto& segment = *m_currentSegment;
    183     ASSERT(segment.start <= beforeIndex && beforeIndex <= segment.end);
     185    ASSERT(segment.start <= before && before <= segment.end);
    184186    ASSERT(is<RenderText>(segment.renderer));
    185187    if (!m_style.shouldHyphenate || run.type() != TextFragment::NonWhitespace)
    186188        return std::nullopt;
    187    
     189    // Check if there are enough characters in the run.
     190    unsigned runLength = run.end() - run.start();
     191    if (m_style.hyphenLimitBefore >= runLength || m_style.hyphenLimitAfter >= runLength || m_style.hyphenLimitBefore + m_style.hyphenLimitAfter > runLength)
     192        return std::nullopt;
    188193    auto runStart = segment.toSegmentPosition(run.start());
    189     auto before = segment.toSegmentPosition(beforeIndex) - runStart;
     194    auto beforeIndex = segment.toSegmentPosition(before) - runStart;
     195    if (beforeIndex <= m_style.hyphenLimitBefore)
     196        return std::nullopt;
     197    // Adjust before index to accommodate the limit-after value (this is the last potential hyphen location).
     198    beforeIndex = std::min(beforeIndex, runLength - m_style.hyphenLimitAfter + 1);
    190199    auto substringForHyphenation = StringView(segment.text).substring(runStart, run.end() - run.start());
    191     auto hyphenLocation = lastHyphenLocation(substringForHyphenation, before, m_style.locale);
    192     if (hyphenLocation)
     200    auto hyphenLocation = lastHyphenLocation(substringForHyphenation, beforeIndex, m_style.locale);
     201    // Check if there are enough characters before and after the hyphen.
     202    if (hyphenLocation && hyphenLocation >= m_style.hyphenLimitBefore && m_style.hyphenLimitAfter <= (runLength - hyphenLocation))
    193203        return segment.toRenderPosition(hyphenLocation + runStart);
    194204    return std::nullopt;
  • trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.h

    r211108 r211222  
    119119        bool shouldHyphenate;
    120120        float hyphenStringWidth;
     121        unsigned hyphenLimitBefore;
     122        unsigned hyphenLimitAfter;
    121123        AtomicString locale;
    122124    };
Note: See TracChangeset for help on using the changeset viewer.