Changeset 199156 in webkit


Ignore:
Timestamp:
Apr 7, 2016 7:55:54 AM (8 years ago)
Author:
Alan Bujtas
Message:

REGRESSION (197987): Ingredient lists on smittenkitchen.com are full justified instead of left justified.
https://bugs.webkit.org/show_bug.cgi?id=156326
<rdar://problem/25519393>

Reviewed by Antti Koivisto.

According to the spec (https://drafts.csswg.org/css-text-3/#text-align-property)
unless otherwise specified by text-align-last, the last line before
a forced break or the end of the block is start-aligned.

In this patch we check if a forced break is present and we apply text alignment accordingly.

Test: fast/css3-text/css3-text-justify/text-justify-last-line-simple-line-layout.html

Source/WebCore:

  • rendering/SimpleLineLayout.cpp:

(WebCore::SimpleLineLayout::LineState::lastFragment): Make it optional so that we don't just check against a default fragment.
(WebCore::SimpleLineLayout::createLineRuns):
(WebCore::SimpleLineLayout::justifyRuns): Do not compute first run index on the current line twice.
(WebCore::SimpleLineLayout::textAlignForLine):
(WebCore::SimpleLineLayout::closeLineEndingAndAdjustRuns):

LayoutTests:

  • fast/css3-text/css3-text-justify/text-justify-last-line-simple-line-layout-expected.html: Added.
  • fast/css3-text/css3-text-justify/text-justify-last-line-simple-line-layout.html: Added.
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r199154 r199156  
     12016-04-07  Zalan Bujtas  <zalan@apple.com>
     2
     3        REGRESSION (197987): Ingredient lists on smittenkitchen.com are full justified instead of left justified.
     4        https://bugs.webkit.org/show_bug.cgi?id=156326
     5        <rdar://problem/25519393>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        According to the spec (https://drafts.csswg.org/css-text-3/#text-align-property)
     10        unless otherwise specified by text-align-last, the last line before
     11        a forced break or the end of the block is start-aligned.
     12
     13        In this patch we check if a forced break is present and we apply text alignment accordingly.
     14
     15        Test: fast/css3-text/css3-text-justify/text-justify-last-line-simple-line-layout.html
     16
     17        * fast/css3-text/css3-text-justify/text-justify-last-line-simple-line-layout-expected.html: Added.
     18        * fast/css3-text/css3-text-justify/text-justify-last-line-simple-line-layout.html: Added.
     19
    1202016-04-07  Antti Koivisto  <antti@apple.com>
    221
  • trunk/Source/WebCore/ChangeLog

    r199155 r199156  
     12016-04-07  Zalan Bujtas  <zalan@apple.com>
     2
     3        REGRESSION (197987): Ingredient lists on smittenkitchen.com are full justified instead of left justified.
     4        https://bugs.webkit.org/show_bug.cgi?id=156326
     5        <rdar://problem/25519393>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        According to the spec (https://drafts.csswg.org/css-text-3/#text-align-property)
     10        unless otherwise specified by text-align-last, the last line before
     11        a forced break or the end of the block is start-aligned.
     12
     13        In this patch we check if a forced break is present and we apply text alignment accordingly.
     14
     15        Test: fast/css3-text/css3-text-justify/text-justify-last-line-simple-line-layout.html
     16
     17        * rendering/SimpleLineLayout.cpp:
     18        (WebCore::SimpleLineLayout::LineState::lastFragment): Make it optional so that we don't just check against a default fragment.
     19        (WebCore::SimpleLineLayout::createLineRuns):
     20        (WebCore::SimpleLineLayout::justifyRuns): Do not compute first run index on the current line twice.
     21        (WebCore::SimpleLineLayout::textAlignForLine):
     22        (WebCore::SimpleLineLayout::closeLineEndingAndAdjustRuns):
     23
    1242016-04-07  Antti Koivisto  <antti@apple.com>
    225
  • trunk/Source/WebCore/rendering/SimpleLineLayout.cpp

    r198074 r199156  
    403403    const TextFragmentIterator::TextFragment& overflowedFragment() const { return m_overflowedFragment; }
    404404    bool hasTrailingWhitespace() const { return m_trailingWhitespaceLength; }
    405     TextFragmentIterator::TextFragment lastFragment() const { return m_fragments.last(); }
     405    Optional<TextFragmentIterator::TextFragment> lastFragment() const
     406    {
     407        if (m_fragments.size())
     408            return m_fragments.last();
     409        return Nullopt;
     410    }
    406411    bool isWhitespaceOnly() const { return m_trailingWhitespaceWidth && m_runsWidth == m_trailingWhitespaceWidth; }
    407412    bool fits(float extra) const { return m_availableWidth >= m_runsWidth + extra; }
     
    734739            }
    735740            // Non-breakable non-whitespace fragment when there's already content on the line. Push it to the next line.
    736             if (line.lastFragment().overlapsToNextRenderer()) {
     741            ASSERT(line.lastFragment());
     742            if (line.lastFragment().value().overlapsToNextRenderer()) {
    737743                // Check if this fragment is a continuation of a previous segment. In such cases, we need to remove them all.
    738744                const auto& lastCompleteFragment = line.revertToLastCompleteFragment(runs);
     
    758764}
    759765
    760 static void justifyRuns(const LineState& line, Layout::RunVector& runs, Optional<unsigned> lastRunIndexOfPreviousLine)
     766static void justifyRuns(const LineState& line, Layout::RunVector& runs, unsigned firstRunIndex)
    761767{
    762768    ASSERT(runs.size());
     
    765771        return;
    766772
    767     auto firstRunIndex = lastRunIndexOfPreviousLine ? lastRunIndexOfPreviousLine.value() + 1 : 0;
    768773    auto lastRunIndex = runs.size() - 1;
    769774    ASSERT(firstRunIndex <= lastRunIndex);
     
    795800}
    796801
     802static ETextAlign textAlignForLine(const TextFragmentIterator::Style& style, bool lastLine)
     803{
     804    // Fallback to LEFT (START) alignment for non-collapsable content and for the last line before a forced break or the end of the block.
     805    auto textAlign = style.textAlign;
     806    if (textAlign == JUSTIFY && (!style.collapseWhitespace || lastLine))
     807        textAlign = LEFT;
     808    return textAlign;
     809}
     810
    797811static void closeLineEndingAndAdjustRuns(LineState& line, Layout::RunVector& runs, Optional<unsigned> lastRunIndexOfPreviousLine, unsigned& lineCount,
    798     const TextFragmentIterator& textFragmentIterator, bool lastLine)
     812    const TextFragmentIterator& textFragmentIterator, bool lastLineInFlow)
    799813{
    800814    if (!runs.size() || (lastRunIndexOfPreviousLine && runs.size() - 1 == lastRunIndexOfPreviousLine.value()))
     
    805819    // Adjust runs' position by taking line's alignment into account.
    806820    const auto& style = textFragmentIterator.style();
    807     auto textAlign = style.textAlign;
    808     // Fallback to LEFT alignment both for non-collapsable content and for the last line.
    809     if (textAlign == JUSTIFY && (!style.collapseWhitespace || lastLine))
    810         textAlign = LEFT;
    811 
     821    auto firstRunIndex = lastRunIndexOfPreviousLine ? lastRunIndexOfPreviousLine.value() + 1 : 0;
    812822    auto lineLogicalLeft = line.logicalLeftOffset();
     823    auto textAlign = textAlignForLine(style, lastLineInFlow || (line.lastFragment() && line.lastFragment().value().type() == TextFragmentIterator::TextFragment::HardLineBreak));
    813824    if (textAlign == JUSTIFY)
    814         justifyRuns(line, runs, lastRunIndexOfPreviousLine);
     825        justifyRuns(line, runs, firstRunIndex);
    815826    else
    816827        lineLogicalLeft = computeLineLeft(textAlign, line.availableWidth(), line.width(), line.logicalLeftOffset());
    817     auto firstRunIndex = lastRunIndexOfPreviousLine ? lastRunIndexOfPreviousLine.value() + 1 : 0;
    818828    for (auto i = firstRunIndex; i < runs.size(); ++i) {
    819829        runs[i].logicalLeft += lineLogicalLeft;
Note: See TracChangeset for help on using the changeset viewer.