⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 237456 in webkit


Ignore:
Timestamp:
Oct 26, 2018, 7:42:06 AM (8 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] Layout floats as part of the inline content
​https://bugs.webkit.org/show_bug.cgi?id=190942

Reviewed by Antti Koivisto.

Source/WebCore:

Add float handling to InlineFormattingContext::layoutInlineContent.
Note that floats don't actually generate inline runs.

Test: fast/block/basic/inline-content-with-floating-image.html

  • layout/blockformatting/BlockFormattingContext.cpp:

(WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot const):

  • layout/floats/FloatAvoider.cpp:

(WebCore::Layout::FloatAvoider::FloatAvoider): Check if any mapping is needed.

  • layout/inlineformatting/InlineFormattingContext.cpp:

(WebCore::Layout::isTrimmableContent):
(WebCore::Layout::InlineFormattingContext::layoutInlineContent const):
(WebCore::Layout::trimLeadingRun): Deleted.

  • layout/inlineformatting/InlineFormattingContext.h:

(WebCore::Layout::InlineFormattingContext::Line::isClosed const):

  • layout/inlineformatting/Line.cpp:

(WebCore::Layout::InlineFormattingContext::Line::init):
(WebCore::Layout::InlineFormattingContext::Line::adjustLogicalLeft):
(WebCore::Layout::InlineFormattingContext::Line::adjustLogicalRight):
(WebCore::Layout::InlineFormattingContext::Line::appendContent):
(WebCore::Layout::InlineFormattingContext::Line::close):

Tools:

  • LayoutReloaded/misc/LFC-passing-tests.txt:

LayoutTests:

  • fast/block/basic/inline-content-with-floating-image-expected.txt: Added.
  • fast/block/basic/inline-content-with-floating-image.html: Added.
Location:
trunk
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r237450 r237456  
     12018-10-26  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Layout floats as part of the inline content
     4        https://bugs.webkit.org/show_bug.cgi?id=190942
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * fast/block/basic/inline-content-with-floating-image-expected.txt: Added.
     9        * fast/block/basic/inline-content-with-floating-image.html: Added.
     10
    1112018-10-26  Alicia Boya García  <aboya@igalia.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r237455 r237456  
     12018-10-26  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Layout floats as part of the inline content
     4        https://bugs.webkit.org/show_bug.cgi?id=190942
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Add float handling to InlineFormattingContext::layoutInlineContent.
     9        Note that floats don't actually generate inline runs.
     10
     11        Test: fast/block/basic/inline-content-with-floating-image.html
     12
     13        * layout/blockformatting/BlockFormattingContext.cpp:
     14        (WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot const):
     15        * layout/floats/FloatAvoider.cpp:
     16        (WebCore::Layout::FloatAvoider::FloatAvoider): Check if any mapping is needed.
     17        * layout/inlineformatting/InlineFormattingContext.cpp:
     18        (WebCore::Layout::isTrimmableContent):
     19        (WebCore::Layout::InlineFormattingContext::layoutInlineContent const):
     20        (WebCore::Layout::trimLeadingRun): Deleted.
     21        * layout/inlineformatting/InlineFormattingContext.h:
     22        (WebCore::Layout::InlineFormattingContext::Line::isClosed const):
     23        * layout/inlineformatting/Line.cpp:
     24        (WebCore::Layout::InlineFormattingContext::Line::init):
     25        (WebCore::Layout::InlineFormattingContext::Line::adjustLogicalLeft):
     26        (WebCore::Layout::InlineFormattingContext::Line::adjustLogicalRight):
     27        (WebCore::Layout::InlineFormattingContext::Line::appendContent):
     28        (WebCore::Layout::InlineFormattingContext::Line::close):
     29
    1302018-10-26  Zalan Bujtas  <zalan@apple.com>
    231
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp

    r237320 r237456  
    146146        computeFloatingPosition(layoutContext, floatingContext, layoutBox);
    147147        floatingContext.floatingState().append(layoutBox);
    148     }
    149     else if (layoutBox.hasFloatClear())
     148    } else if (layoutBox.hasFloatClear())
    150149        computeVerticalPositionForFloatClear(layoutContext, floatingContext, layoutBox);
    151150    else if (layoutBox.establishesBlockFormattingContext())
  • trunk/Source/WebCore/layout/floats/FloatAvoider.cpp

    r235735 r237456  
    4343    , m_floatingState(floatingState)
    4444    , m_absoluteDisplayBox(FormattingContext::mapBoxToAncestor(layoutContext, layoutBox, downcast<Container>(floatingState.root())))
    45     , m_containingBlockAbsoluteDisplayBox(FormattingContext::mapBoxToAncestor(layoutContext, *layoutBox.containingBlock(), downcast<Container>(floatingState.root())))
     45    , m_containingBlockAbsoluteDisplayBox(layoutBox.containingBlock() == &floatingState.root() ? Display::Box(layoutContext.displayBoxForLayoutBox(*layoutBox.containingBlock())) : FormattingContext::mapBoxToAncestor(layoutContext, *layoutBox.containingBlock(), downcast<Container>(floatingState.root())))
    4646    , m_initialVerticalPosition(m_absoluteDisplayBox.top())
    4747{
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp

    r237455 r237456  
    9292}
    9393
    94 static bool trimLeadingRun(const InlineLineBreaker::Run& run)
    95 {
    96     ASSERT(run.position == InlineLineBreaker::Run::Position::LineBegin);
    97 
    98     if (!run.content.isWhitespace())
    99         return false;
    100 
    101     return run.content.style().collapseWhiteSpace();
     94static bool isTrimmableContent(const InlineLineBreaker::Run& run)
     95{
     96    return run.content.isWhitespace() && run.content.style().collapseWhiteSpace();
    10297}
    10398
    … …  
    147142void InlineFormattingContext::layoutInlineContent(const LayoutContext& layoutContext, InlineFormattingState& inlineFormattingState, const InlineRunProvider& inlineRunProvider) const
    148143{
    149     auto previousRunPositionIsLineEnd = false;
     144    auto floatingContext = FloatingContext { inlineFormattingState.floatingState() };
    150145
    151146    Line line(inlineFormattingState, root());
    … …  
    154149    InlineLineBreaker lineBreaker(layoutContext, inlineFormattingState.inlineContent(), inlineRunProvider.runs());
    155150    while (auto run = lineBreaker.nextRun(line.contentLogicalRight(), line.availableWidth(), !line.hasContent())) {
    156 
    157         if (run->position == InlineLineBreaker::Run::Position::LineBegin) {
    158             // First run on line.
    159 
    160             // Previous run ended up being at the line end. Adjust the line accordingly.
    161             if (!previousRunPositionIsLineEnd) {
    162                 line.close();
     151        auto isFirstRun = run->position == InlineLineBreaker::Run::Position::LineBegin;
     152        auto isLastRun = run->position == InlineLineBreaker::Run::Position::LineEnd;
     153        auto generatesInlineRun = true;
     154
     155        // Position float and adjust the runs on line.
     156        if (run->content.isFloat()) {
     157            auto& floatBox = run->content.inlineItem().layoutBox();
     158            computeFloatPosition(layoutContext, floatingContext, line, floatBox);
     159            inlineFormattingState.floatingState().append(floatBox);
     160
     161            auto floatBoxWidth = layoutContext.displayBoxForLayoutBox(floatBox).width();
     162            // Shrink availble space for current line and move existing inline runs.
     163            floatBox.isLeftFloatingPositioned() ? line.adjustLogicalLeft(floatBoxWidth) : line.adjustLogicalRight(floatBoxWidth);
     164
     165            generatesInlineRun = false;
     166        }
     167
     168        // 1. Initialize new line if needed.
     169        // 2. Append inline run unless it is skipped.
     170        // 3. Close current line if needed.
     171        if (isFirstRun) {
     172            // When the first run does not generate an actual inline run, the next run comes in first-run as well.
     173            // No need to spend time on closing/initializing.
     174            // Skip leading whitespace.
     175            if (!generatesInlineRun || isTrimmableContent(*run))
     176                continue;
     177
     178            if (line.hasContent()) {
     179                // Previous run ended up being at the line end. Adjust the line accordingly.
     180                if (!line.isClosed())
     181                    line.close(Line::LastLine::No);
    163182                initializeNewLine(layoutContext, inlineFormattingState, line);
    164183            }
    165             // Skip leading whitespace.
    166             if (!trimLeadingRun(*run))
    167                 line.appendContent(*run);
    168             continue;
    169         }
    170 
    171         if (run->position == InlineLineBreaker::Run::Position::LineEnd) {
    172             // Last run on line.
    173             previousRunPositionIsLineEnd = true;
    174             line.appendContent(*run);
    175             // Move over to the next line.
    176             line.close();
    177             initializeNewLine(layoutContext, inlineFormattingState, line);
    178             continue;
    179         }
    180 
    181         // This may or may not be the last run on line -but definitely not the first one.
    182         line.appendContent(*run);
    183     }
     184         }
     185
     186        if (generatesInlineRun)
     187             line.appendContent(*run);
     188
     189        if (isLastRun)
     190            line.close(Line::LastLine::No);
     191    }
     192
    184193    line.close(Line::LastLine::Yes);
    185194}
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h

    r237455 r237456  
    6464
    6565        bool hasContent() const { return m_firstRunIndex.has_value(); }
     66        bool isClosed() const { return m_closed; }
    6667        bool isFirstLine() const { return m_isFirstLine; }
    6768        LayoutUnit contentLogicalRight();
    … …  
    9293        bool m_alignmentIsJustify { false };
    9394        bool m_isFirstLine { true };
     95        bool m_closed { true };
    9496    };
    9597
  • trunk/Source/WebCore/layout/inlineformatting/Line.cpp

    r237455 r237456  
    5050    m_lastRunCanExpand = false;
    5151    m_trailingTrimmableContent = { };
     52    m_closed = false;
    5253}
    5354
    5455void InlineFormattingContext::Line::adjustLogicalLeft(LayoutUnit delta)
    5556{
     57    ASSERT(delta > 0);
     58
    5659    m_availableWidth -= delta;
    5760    m_logicalRect.shiftLeftTo(m_logicalRect.left() + delta);
    … …  
    6770void InlineFormattingContext::Line::adjustLogicalRight(LayoutUnit delta)
    6871{
     72    ASSERT(delta > 0);
     73
    6974    m_availableWidth -= delta;
    7075    m_logicalRect.shiftRightTo(m_logicalRect.right() - delta);
    … …  
    133138void InlineFormattingContext::Line::appendContent(const InlineLineBreaker::Run& run)
    134139{
     140    ASSERT(!isClosed());
     141
    135142    auto& content = run.content;
    136143
    … …  
    259266    alignRuns(textAlignment);
    260267    m_isFirstLine = false;
     268    m_closed = true;
    261269}
    262270
  • trunk/Tools/ChangeLog

    r237450 r237456  
     12018-10-26  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Layout floats as part of the inline content
     4        https://bugs.webkit.org/show_bug.cgi?id=190942
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * LayoutReloaded/misc/LFC-passing-tests.txt:
     9
    1102018-10-26  Alicia Boya García  <aboya@igalia.com>
    211
  • trunk/Tools/LayoutReloaded/misc/LFC-passing-tests.txt

    r235773 r237456  
    6363fast/block/block-only/float-min-max-height.html
    6464fast/block/block-only/min-max-height-percentage.html
     65fast/block/basic/inline-content-with-floating-image.html
Note: See TracChangeset for help on using the changeset viewer.