Ignore:
Timestamp:
Aug 28, 2013, 9:48:53 AM (12 years ago)
Author:
[email protected]
Message:

[CSS Grid Layout] Handle 'span' positions during layout
https://bugs.webkit.org/show_bug.cgi?id=119756

Reviewed by Andreas Kling.

From Blink r149133 by <[email protected]>

Source/WebCore:

Properly handle the 'span' keyword during layout. We only had
parsing support so far but with this change we are able to
recognize these positions and act accordingly.

  • rendering/RenderGrid.cpp:

(WebCore::RenderGrid::resolveGridPositionsFromStyle):
(WebCore::RenderGrid::resolveGridPositionAgainstOppositePosition):

  • rendering/RenderGrid.h:
  • rendering/style/GridPosition.h:

(WebCore::GridPosition::shouldBeResolvedAgainstOppositePosition):

LayoutTests:

Added some new test cases to verify that we properly resolve
'span' positions.

  • fast/css-grid-layout/grid-item-negative-position-resolution-expected.txt:
  • fast/css-grid-layout/grid-item-negative-position-resolution.html:
  • fast/css-grid-layout/grid-item-spanning-resolution-expected.txt:
  • fast/css-grid-layout/grid-item-spanning-resolution.html:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/rendering/RenderGrid.cpp

    r154731 r154753  
    721721    const GridPositionSide finalPositionSide = (direction == ForColumns) ? ColumnEndSide : RowEndSide;
    722722
     723    // We should NEVER see both spans as they should have been handled during style resolve.
     724    ASSERT(!initialPosition.isSpan() || !finalPosition.isSpan());
     725
    723726    if (initialPosition.isAuto() && finalPosition.isAuto()) {
    724727        if (style()->gridAutoFlow() == AutoFlowNone)
     
    729732    }
    730733
    731     if (initialPosition.isAuto()) {
    732         // Infer the position from the final position ('auto / 1' case).
     734    if (initialPosition.shouldBeResolvedAgainstOppositePosition()) {
     735        // Infer the position from the final position ('auto / 1' or 'span 2 / 3' case).
    733736        const size_t finalResolvedPosition = resolveGridPositionFromStyle(finalPosition, finalPositionSide);
    734         return adoptPtr(new GridSpan(finalResolvedPosition, finalResolvedPosition));
    735     }
    736 
    737     if (finalPosition.isAuto()) {
    738         // Infer our position from the initial position ('1 / auto' case).
     737        return resolveGridPositionAgainstOppositePosition(finalResolvedPosition, initialPosition, initialPositionSide);
     738    }
     739
     740    if (finalPosition.shouldBeResolvedAgainstOppositePosition()) {
     741        // Infer our position from the initial position ('1 / auto' or '3 / span 2' case).
    739742        const size_t initialResolvedPosition = resolveGridPositionFromStyle(initialPosition, initialPositionSide);
    740         return adoptPtr(new GridSpan(initialResolvedPosition, initialResolvedPosition));
     743        return resolveGridPositionAgainstOppositePosition(initialResolvedPosition, finalPosition, finalPositionSide);
    741744    }
    742745
     
    789792    ASSERT_NOT_REACHED();
    790793    return 0;
     794}
     795
     796PassOwnPtr<RenderGrid::GridSpan> RenderGrid::resolveGridPositionAgainstOppositePosition(size_t resolvedOppositePosition, const GridPosition& position, GridPositionSide side) const
     797{
     798    if (position.isAuto())
     799        return GridSpan::create(resolvedOppositePosition, resolvedOppositePosition);
     800
     801    ASSERT(position.isSpan());
     802    ASSERT(position.spanPosition() > 0);
     803
     804    // 'span 1' is contained inside a single grid track regardless of the direction.
     805    // That's why the CSS span value is one more than the offset we apply.
     806    size_t positionOffset = position.spanPosition() - 1;
     807    if (side == ColumnStartSide || side == RowStartSide) {
     808        size_t initialResolvedPosition = std::max<int>(0, resolvedOppositePosition - positionOffset);
     809        return GridSpan::create(initialResolvedPosition, resolvedOppositePosition);
     810    }
     811
     812    return GridSpan::create(resolvedOppositePosition, resolvedOppositePosition + positionOffset);
    791813}
    792814
Note: See TracChangeset for help on using the changeset viewer.