Changeset 213733 in webkit


Ignore:
Timestamp:
Mar 10, 2017 4:33:18 PM (7 years ago)
Author:
Alan Bujtas
Message:

Simple line layout: Check how many orphans needed on the current page before breaking.
https://bugs.webkit.org/show_bug.cgi?id=169477

Reviewed by Antti Koivisto.

Source/WebCore:

Before breaking for the widows we actually need to check for orphans first.

Test: fast/multicol/simple-line-layout-orphans-and-widows.html

  • rendering/SimpleLineLayoutPagination.cpp:

(WebCore::SimpleLineLayout::computeLineBreakIndex):
(WebCore::SimpleLineLayout::adjustLinePositionsForPagination):

LayoutTests:

  • fast/multicol/simple-line-layout-orphans-and-widows-expected.html: Added.
  • fast/multicol/simple-line-layout-orphans-and-widows.html: Added.
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r213729 r213733  
     12017-03-10  Zalan Bujtas  <zalan@apple.com>
     2
     3        Simple line layout: Check how many orphans needed on the current page before breaking.
     4        https://bugs.webkit.org/show_bug.cgi?id=169477
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * fast/multicol/simple-line-layout-orphans-and-widows-expected.html: Added.
     9        * fast/multicol/simple-line-layout-orphans-and-widows.html: Added.
     10
    1112017-03-10  Ryan Haddad  <ryanhaddad@apple.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r213731 r213733  
     12017-03-10  Zalan Bujtas  <zalan@apple.com>
     2
     3        Simple line layout: Check how many orphans needed on the current page before breaking.
     4        https://bugs.webkit.org/show_bug.cgi?id=169477
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Before breaking for the widows we actually need to check for orphans first.
     9
     10        Test: fast/multicol/simple-line-layout-orphans-and-widows.html
     11
     12        * rendering/SimpleLineLayoutPagination.cpp:
     13        (WebCore::SimpleLineLayout::computeLineBreakIndex):
     14        (WebCore::SimpleLineLayout::adjustLinePositionsForPagination):
     15
    1162017-03-10  Dean Jackson  <dino@apple.com>
    217
  • trunk/Source/WebCore/rendering/SimpleLineLayoutPagination.cpp

    r213723 r213733  
    6464}
    6565
    66 static unsigned computeLineBreakIndex(unsigned breakCandidate, unsigned lineCount, unsigned widows, const Layout::SimpleLineStruts& struts)
     66static unsigned computeLineBreakIndex(unsigned breakCandidate, unsigned lineCount, int orphansNeeded, int widowsNeeded,
     67    const Layout::SimpleLineStruts& struts)
    6768{
    6869    // First line does not fit the current page.
     
    7071        return breakCandidate;
    7172   
    72     auto remainingLineCount = lineCount - breakCandidate;
    73     if (widows <= remainingLineCount)
     73    int widowsOnTheNextPage = lineCount - breakCandidate;
     74    if (widowsNeeded <= widowsOnTheNextPage)
    7475        return breakCandidate;
    75    
    7676    // Only break after the first line with widows.
    77     auto lineBreak = std::max<int>(lineCount - widows, 1);
     77    auto lineBreak = std::max<int>(lineCount - widowsNeeded, 1);
     78    if (orphansNeeded > lineBreak)
     79        return breakCandidate;
    7880    // Break on current page only.
    7981    if (struts.isEmpty())
     
    98100    auto remainingLogicalHeight = flow.pageRemainingLogicalHeightForOffset(line.top, RenderBlockFlow::ExcludePageBoundary);
    99101    auto& style = flow.style();
    100     auto firstLineWithDoesNotFit = !lineBreakIndex && line.height < flow.pageLogicalHeightForOffset(line.top);
     102    auto firstLineDoesNotFit = !lineBreakIndex && line.height < flow.pageLogicalHeightForOffset(line.top);
    101103    auto orphanDoesNotFit = !style.hasAutoOrphans() && style.orphans() > (short)lineBreakIndex;
    102     if (firstLineWithDoesNotFit || orphanDoesNotFit) {
     104    if (firstLineDoesNotFit || orphanDoesNotFit) {
    103105        auto firstLine = lines.first();
    104106        auto firstLineOverflowRect = computeOverflow(flow, LayoutRect(0, firstLine.top, 0, firstLine.height));
     
    133135    unsigned lineIndex = 0;
    134136    auto widows = flow.style().hasAutoWidows() ? 1 : std::max<int>(flow.style().widows(), 1);
     137    auto orphans = flow.style().hasAutoOrphans() ? 1 : std::max<int>(flow.style().orphans(), 1);
    135138    PaginatedLines lines;
    136139    for (unsigned runIndex = 0; runIndex < simpleLines.runCount(); ++runIndex) {
     
    144147        auto atTheTopOfColumnOrPage = flow.pageLogicalHeightForOffset(line.top) == remainingHeight;
    145148        if (line.height > remainingHeight || (atTheTopOfColumnOrPage && lineIndex)) {
    146             auto lineBreakIndex = computeLineBreakIndex(lineIndex, lineCount, widows, struts);
     149            auto lineBreakIndex = computeLineBreakIndex(lineIndex, lineCount, orphans, widows, struts);
    147150            // Are we still at the top of the column/page?
    148151            atTheTopOfColumnOrPage = atTheTopOfColumnOrPage ? lineIndex == lineBreakIndex : false;
    149152            setPageBreakForLine(lineBreakIndex, lines, flow, struts, atTheTopOfColumnOrPage);
    150             // Recompute line positions that we already visited but window break pushed them to a new page.
     153            // Recompute line positions that we already visited but widow break pushed them to a new page.
    151154            for (auto i = lineBreakIndex; i < lines.size(); ++i)
    152155                lines.at(i) = computeLineTopAndBottomWithOverflow(flow, i, struts);
Note: See TracChangeset for help on using the changeset viewer.