Changeset 210792 in webkit


Ignore:
Timestamp:
Jan 16, 2017 3:15:26 PM (7 years ago)
Author:
jfernandez@igalia.com
Message:

[css-grid] Implementing baseline positioning for grid containers
https://bugs.webkit.org/show_bug.cgi?id=165063

Reviewed by Darin Adler and Sergio Villar Senin.

Source/WebCore:

Implementation of the 'first-line' baseline for Grid containers,
according to the CSS Grid Layout spec.
https://drafts.csswg.org/css-grid/#grid-baselines

The self-baseline and content-baseline alignment logic is still
not implemented, hence some cases will be implemented in
future patches.

Tests: fast/css-grid-layout/grid-baseline-margins.html

fast/css-grid-layout/grid-baseline-must-respect-grid-order.html
fast/css-grid-layout/grid-baseline.html

  • rendering/RenderGrid.cpp:

(WebCore::synthesizedBaselineFromBorderBox):
(WebCore::RenderGrid::isInlineBaselineAlignedChild):
(WebCore::RenderGrid::baselinePosition):
(WebCore::RenderGrid::firstLineBaseline):
(WebCore::RenderGrid::inlineBlockBaseline):

  • rendering/RenderGrid.h:

LayoutTests:

Tests to verify the baseline positioning of grid and inline-grid blocks.
Note that two of these new tests are expected to fail because of a Flexbox
bug, since we use Flexbox as reference test.

  • TestExpectations:
  • fast/css-grid-layout/grid-baseline-expected.html: Added.
  • fast/css-grid-layout/grid-baseline-margins-expected.html: Added.
  • fast/css-grid-layout/grid-baseline-margins.html: Added.
  • fast/css-grid-layout/grid-baseline-must-respect-grid-order-expected.txt: Added.
  • fast/css-grid-layout/grid-baseline-must-respect-grid-order.html: Added.
  • fast/css-grid-layout/grid-baseline.html: Added.
  • fast/css-grid-layout/resources/grid-alignment.css:

(.alignSelfBaseline):
(.selfBaseline):

Location:
trunk
Files:
6 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r210780 r210792  
     12017-01-16  Javier Fernandez  <jfernandez@igalia.com>
     2
     3        [css-grid] Implementing baseline positioning for grid containers
     4        https://bugs.webkit.org/show_bug.cgi?id=165063
     5
     6        Reviewed by Darin Adler and Sergio Villar Senin.
     7
     8        Tests to verify the baseline positioning of grid and inline-grid blocks.
     9        Note that two of these new tests are expected to fail because of a Flexbox
     10        bug, since we use Flexbox as reference test.
     11
     12        * TestExpectations:
     13        * fast/css-grid-layout/grid-baseline-expected.html: Added.
     14        * fast/css-grid-layout/grid-baseline-margins-expected.html: Added.
     15        * fast/css-grid-layout/grid-baseline-margins.html: Added.
     16        * fast/css-grid-layout/grid-baseline-must-respect-grid-order-expected.txt: Added.
     17        * fast/css-grid-layout/grid-baseline-must-respect-grid-order.html: Added.
     18        * fast/css-grid-layout/grid-baseline.html: Added.
     19        * fast/css-grid-layout/resources/grid-alignment.css:
     20        (.alignSelfBaseline):
     21        (.selfBaseline):
     22
    1232017-01-15  Sam Weinig  <sam@webkit.org>
    224
  • trunk/LayoutTests/TestExpectations

    r210538 r210792  
    262262webkit.org/b/136754 css3/flexbox/csswg/ttwf-reftest-flex-wrap-reverse.html [ ImageOnlyFailure ]
    263263webkit.org/b/136754 css3/flexbox/csswg/ttwf-reftest-flex-wrap.html [ ImageOnlyFailure ]
     264
     265# grid layout tests
     266webkit.org/b/165062 fast/css-grid-layout/grid-baseline.html [ ImageOnlyFailure ]
     267webkit.org/b/165062 fast/css-grid-layout/grid-baseline-margins.html [ ImageOnlyFailure ]
    264268
    265269# nth-child tests takes long time and Debug build sometimes timeouts because there are many test cases.
  • trunk/LayoutTests/fast/css-grid-layout/resources/grid-alignment.css

    r203771 r210792  
    1818.alignSelfEndSafe { align-self: end safe; }
    1919.alignSelfEndUnsafe { align-self: end unsafe; }
     20
     21.alignSelfBaseline { align-self: baseline; }
    2022
    2123/* align-items */
     
    127129}
    128130
     131.selfBaseline {
     132    align-self: baseline;
     133    justify-self: baseline;
     134}
     135
    129136/* Both align-self and justify-self */
    130137.selfStretch {
  • trunk/Source/WebCore/ChangeLog

    r210791 r210792  
     12017-01-16  Javier Fernandez  <jfernandez@igalia.com>
     2
     3        [css-grid] Implementing baseline positioning for grid containers
     4        https://bugs.webkit.org/show_bug.cgi?id=165063
     5
     6        Reviewed by Darin Adler and Sergio Villar Senin.
     7
     8        Implementation of the 'first-line' baseline for Grid containers,
     9        according to the CSS Grid Layout spec.
     10        https://drafts.csswg.org/css-grid/#grid-baselines
     11
     12        The self-baseline and content-baseline alignment logic is still
     13        not implemented, hence some cases will be implemented in
     14        future patches.
     15
     16        Tests: fast/css-grid-layout/grid-baseline-margins.html
     17               fast/css-grid-layout/grid-baseline-must-respect-grid-order.html
     18               fast/css-grid-layout/grid-baseline.html
     19
     20        * rendering/RenderGrid.cpp:
     21        (WebCore::synthesizedBaselineFromBorderBox):
     22        (WebCore::RenderGrid::isInlineBaselineAlignedChild):
     23        (WebCore::RenderGrid::baselinePosition):
     24        (WebCore::RenderGrid::firstLineBaseline):
     25        (WebCore::RenderGrid::inlineBlockBaseline):
     26        * rendering/RenderGrid.h:
     27
    1282017-01-16  Andy Estes  <aestes@apple.com>
    229
  • trunk/Source/WebCore/rendering/RenderGrid.cpp

    r210758 r210792  
    24982498        child.setMarginAfter(availableAlignmentSpace, &parentStyle);
    24992499    }
     2500}
     2501
     2502// FIXME: This logic could be refactored somehow and defined in RenderBox.
     2503static int synthesizedBaselineFromBorderBox(const RenderBox& box, LineDirectionMode direction)
     2504{
     2505    return (direction == HorizontalLine ? box.size().height() : box.size().width()).toInt();
     2506}
     2507
     2508bool RenderGrid::isInlineBaselineAlignedChild(const RenderBox& child) const
     2509{
     2510    return alignSelfForChild(child).position() == ItemPositionBaseline && !isOrthogonalChild(child) && !hasAutoMarginsInColumnAxis(child);
     2511}
     2512
     2513// FIXME: This logic is shared by RenderFlexibleBox, so it might be refactored somehow.
     2514int RenderGrid::baselinePosition(FontBaseline, bool, LineDirectionMode direction, LinePositionMode mode) const
     2515{
     2516#if ENABLE(ASSERT)
     2517    ASSERT(mode == PositionOnContainingLine);
     2518#else
     2519    UNUSED_PARAM(mode);
     2520#endif
     2521    int baseline = firstLineBaseline().value_or(synthesizedBaselineFromBorderBox(*this, direction));
     2522
     2523    int marginSize = direction == HorizontalLine ? verticalMarginExtent() : horizontalMarginExtent();
     2524    return baseline + marginSize;
     2525}
     2526
     2527std::optional<int> RenderGrid::firstLineBaseline() const
     2528{
     2529    if (isWritingModeRoot() || !m_grid.hasGridItems())
     2530        return std::nullopt;
     2531
     2532    const RenderBox* baselineChild = nullptr;
     2533    // Finding the first grid item in grid order.
     2534    unsigned numColumns = m_grid.numTracks(ForColumns);
     2535    for (size_t column = 0; column < numColumns; column++) {
     2536        for (const auto* child : m_grid.cell(0, column)) {
     2537            // If an item participates in baseline alignment, we select such item.
     2538            if (isInlineBaselineAlignedChild(*child)) {
     2539                // FIXME: self-baseline and content-baseline alignment not implemented yet.
     2540                baselineChild = child;
     2541                break;
     2542            }
     2543            if (!baselineChild)
     2544                baselineChild = child;
     2545        }
     2546    }
     2547
     2548    if (!baselineChild)
     2549        return std::nullopt;
     2550
     2551    auto baseline = isOrthogonalChild(*baselineChild) ? std::nullopt : baselineChild->firstLineBaseline();
     2552    // We take border-box's bottom if no valid baseline.
     2553    if (!baseline) {
     2554        // FIXME: We should pass |direction| into firstLineBaseline and stop bailing out if we're a writing
     2555        // mode root. This would also fix some cases where the grid is orthogonal to its container.
     2556        LineDirectionMode direction = isHorizontalWritingMode() ? HorizontalLine : VerticalLine;
     2557        return synthesizedBaselineFromBorderBox(*baselineChild, direction) + baselineChild->logicalTop().toInt();
     2558    }
     2559    return baseline.value() + baselineChild->logicalTop().toInt();
     2560}
     2561
     2562std::optional<int> RenderGrid::inlineBlockBaseline(LineDirectionMode direction) const
     2563{
     2564    if (std::optional<int> baseline = firstLineBaseline())
     2565        return baseline;
     2566
     2567    int marginAscent = direction == HorizontalLine ? marginTop() : marginRight();
     2568    return synthesizedBaselineFromBorderBox(*this, direction) + marginAscent;
    25002569}
    25012570
  • trunk/Source/WebCore/rendering/RenderGrid.h

    r210669 r210792  
    183183    void updateAutoMarginsInRowAxisIfNeeded(RenderBox&);
    184184
     185    int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const final;
     186    std::optional<int> firstLineBaseline() const final;
     187    std::optional<int> inlineBlockBaseline(LineDirectionMode) const final;
     188    bool isInlineBaselineAlignedChild(const RenderBox&) const;
     189
    185190#ifndef NDEBUG
    186191    bool tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection, GridSizingData&);
Note: See TracChangeset for help on using the changeset viewer.