Changeset 190633 in webkit


Ignore:
Timestamp:
Oct 6, 2015 12:23:52 PM (9 years ago)
Author:
jfernandez@igalia.com
Message:

[CSS Grid Layout] Don't need to reset auto-margins during grid items layout
https://bugs.webkit.org/show_bug.cgi?id=149764

Reviewed by Darin Adler.

Source/WebCore:

This patch implements a refactoring of the auto-margin alignment code for grid
items so it uses start/end and before/after margin logic terms.

I addition, it avoids resetting the auto-margin values, which requires an extra
layout, before applying the alignment logic.

No new tests because there is no behavior change.

  • rendering/RenderGrid.cpp:

(WebCore::RenderGrid::computeMarginLogicalHeightForChild): Computing margins if child needs layout.
(WebCore::RenderGrid::availableAlignmentSpaceForChildBeforeStretching):
(WebCore::RenderGrid::updateAutoMarginsInRowAxisIfNeeded): Using start/end logical margins.
(WebCore::RenderGrid::updateAutoMarginsInColumnAxisIfNeeded): Using before/after logical margins.
(WebCore::RenderGrid::columnAxisOffsetForChild): Just added comment.
(WebCore::RenderGrid::rowAxisOffsetForChild): Just added comment.

LayoutTests:

Removed a duplicated layout tests.

  • fast/css-grid-layout/grid-item-should-not-be-stretched-when-height-or-margin-change-expected.txt: Removed.
  • fast/css-grid-layout/grid-item-should-not-be-stretched-when-height-or-margin-change.html: Removed.
Location:
trunk
Files:
2 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r190629 r190633  
     12015-10-06  Javier Fernandez  <jfernandez@igalia.com>
     2
     3        [CSS Grid Layout] Don't need to reset auto-margins during grid items layout
     4        https://bugs.webkit.org/show_bug.cgi?id=149764
     5
     6        Reviewed by Darin Adler.
     7
     8        Removed a duplicated layout tests.
     9
     10        * fast/css-grid-layout/grid-item-should-not-be-stretched-when-height-or-margin-change-expected.txt: Removed.
     11        * fast/css-grid-layout/grid-item-should-not-be-stretched-when-height-or-margin-change.html: Removed.
     12
    1132015-10-02  Jon Honeycutt  <jhoneycutt@apple.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r190628 r190633  
     12015-10-06  Javier Fernandez  <jfernandez@igalia.com>
     2
     3        [CSS Grid Layout] Don't need to reset auto-margins during grid items layout
     4        https://bugs.webkit.org/show_bug.cgi?id=149764
     5
     6        Reviewed by Darin Adler.
     7
     8        This patch implements a refactoring of the auto-margin alignment code for grid
     9        items so it uses start/end and before/after margin logic terms.
     10
     11        I addition, it avoids resetting the auto-margin values, which requires an extra
     12        layout, before applying the alignment logic.
     13
     14        No new tests because there is no behavior change.
     15
     16        * rendering/RenderGrid.cpp:
     17        (WebCore::RenderGrid::computeMarginLogicalHeightForChild): Computing margins if child needs layout.
     18        (WebCore::RenderGrid::availableAlignmentSpaceForChildBeforeStretching):
     19        (WebCore::RenderGrid::updateAutoMarginsInRowAxisIfNeeded): Using start/end logical margins.
     20        (WebCore::RenderGrid::updateAutoMarginsInColumnAxisIfNeeded): Using before/after logical margins.
     21        (WebCore::RenderGrid::columnAxisOffsetForChild): Just added comment.
     22        (WebCore::RenderGrid::rowAxisOffsetForChild): Just added comment.
     23
    1242015-10-06  Tim Horton  <timothy_horton@apple.com>
    225
  • trunk/Source/WebCore/rendering/RenderGrid.cpp

    r190484 r190633  
    12711271                && child->hasRelativeLogicalHeight()))
    12721272            child->setNeedsLayout(MarkOnlyThis);
    1273         else
    1274             resetAutoMarginsAndLogicalTopInColumnAxis(*child);
    12751273
    12761274        child->setOverrideContainingBlockContentLogicalWidth(overrideContainingBlockContentLogicalWidth);
     
    14131411}
    14141412
     1413LayoutUnit RenderGrid::computeMarginLogicalHeightForChild(const RenderBox& child) const
     1414{
     1415    if (!child.style().hasMargin())
     1416        return 0;
     1417
     1418    LayoutUnit marginBefore;
     1419    LayoutUnit marginAfter;
     1420    child.computeBlockDirectionMargins(this, marginBefore, marginAfter);
     1421
     1422    return marginBefore + marginAfter;
     1423}
     1424
    14151425LayoutUnit RenderGrid::availableAlignmentSpaceForChildBeforeStretching(LayoutUnit gridAreaBreadthForChild, const RenderBox& child) const
    14161426{
    1417     return gridAreaBreadthForChild - marginLogicalHeightForChild(child);
     1427    // Because we want to avoid multiple layouts, stretching logic might be performed before
     1428    // children are laid out, so we can't use the child cached values. Hence, we need to
     1429    // compute margins in order to determine the available height before stretching.
     1430    return gridAreaBreadthForChild - (child.needsLayout() ? computeMarginLogicalHeightForChild(child) : marginLogicalHeightForChild(child));
    14181431}
    14191432
     
    14821495
    14831496// FIXME: This logic is shared by RenderFlexibleBox, so it should be moved to RenderBox.
    1484 void RenderGrid::resetAutoMarginsAndLogicalTopInColumnAxis(RenderBox& child)
    1485 {
    1486     if (hasAutoMarginsInColumnAxis(child) || child.needsLayout()) {
    1487         child.clearOverrideLogicalContentHeight();
    1488         child.updateLogicalHeight();
    1489         if (isHorizontalWritingMode()) {
    1490             if (child.style().marginTop().isAuto())
    1491                 child.setMarginTop(0);
    1492             if (child.style().marginBottom().isAuto())
    1493                 child.setMarginBottom(0);
    1494         } else {
    1495             if (child.style().marginLeft().isAuto())
    1496                 child.setMarginLeft(0);
    1497             if (child.style().marginRight().isAuto())
    1498                 child.setMarginRight(0);
    1499         }
    1500 
    1501     }
    1502 }
    1503 
    1504 // FIXME: This logic is shared by RenderFlexibleBox, so it should be moved to RenderBox.
    15051497void RenderGrid::updateAutoMarginsInRowAxisIfNeeded(RenderBox& child)
    15061498{
    15071499    ASSERT(!child.isOutOfFlowPositioned());
    1508     ASSERT(child.overrideContainingBlockContentLogicalWidth());
    15091500
    15101501    LayoutUnit availableAlignmentSpace = child.overrideContainingBlockContentLogicalWidth().value() - child.logicalWidth();
     
    15121503        return;
    15131504
    1514     bool isHorizontal = isHorizontalWritingMode();
    1515     Length topOrLeft = isHorizontal ? child.style().marginLeft() : child.style().marginTop();
    1516     Length bottomOrRight = isHorizontal ? child.style().marginRight() : child.style().marginBottom();
    1517     if (topOrLeft.isAuto() && bottomOrRight.isAuto()) {
    1518         if (isHorizontal) {
    1519             child.setMarginLeft(availableAlignmentSpace / 2);
    1520             child.setMarginRight(availableAlignmentSpace / 2);
    1521         } else {
    1522             child.setMarginTop(availableAlignmentSpace / 2);
    1523             child.setMarginBottom(availableAlignmentSpace / 2);
    1524         }
    1525     } else if (topOrLeft.isAuto()) {
    1526         if (isHorizontal)
    1527             child.setMarginLeft(availableAlignmentSpace);
    1528         else
    1529             child.setMarginTop(availableAlignmentSpace);
    1530     } else if (bottomOrRight.isAuto()) {
    1531         if (isHorizontal)
    1532             child.setMarginRight(availableAlignmentSpace);
    1533         else
    1534             child.setMarginBottom(availableAlignmentSpace);
     1505    const RenderStyle& parentStyle = style();
     1506    Length marginStart = child.style().marginStartUsing(&parentStyle);
     1507    Length marginEnd = child.style().marginEndUsing(&parentStyle);
     1508    if (marginStart.isAuto() && marginEnd.isAuto()) {
     1509        child.setMarginStart(availableAlignmentSpace / 2, &parentStyle);
     1510        child.setMarginEnd(availableAlignmentSpace / 2, &parentStyle);
     1511    } else if (marginStart.isAuto()) {
     1512        child.setMarginStart(availableAlignmentSpace, &parentStyle);
     1513    } else if (marginEnd.isAuto()) {
     1514        child.setMarginEnd(availableAlignmentSpace, &parentStyle);
    15351515    }
    15361516}
     
    15401520{
    15411521    ASSERT(!child.isOutOfFlowPositioned());
    1542     ASSERT(child.overrideContainingBlockContentLogicalHeight());
    15431522
    15441523    LayoutUnit availableAlignmentSpace = child.overrideContainingBlockContentLogicalHeight().value() - child.logicalHeight();
     
    15461525        return;
    15471526
    1548     bool isHorizontal = isHorizontalWritingMode();
    1549     Length topOrLeft = isHorizontal ? child.style().marginTop() : child.style().marginLeft();
    1550     Length bottomOrRight = isHorizontal ? child.style().marginBottom() : child.style().marginRight();
    1551     if (topOrLeft.isAuto() && bottomOrRight.isAuto()) {
    1552         if (isHorizontal) {
    1553             child.setMarginTop(availableAlignmentSpace / 2);
    1554             child.setMarginBottom(availableAlignmentSpace / 2);
    1555         } else {
    1556             child.setMarginLeft(availableAlignmentSpace / 2);
    1557             child.setMarginRight(availableAlignmentSpace / 2);
    1558         }
    1559     } else if (topOrLeft.isAuto()) {
    1560         if (isHorizontal)
    1561             child.setMarginTop(availableAlignmentSpace);
    1562         else
    1563             child.setMarginLeft(availableAlignmentSpace);
    1564     } else if (bottomOrRight.isAuto()) {
    1565         if (isHorizontal)
    1566             child.setMarginBottom(availableAlignmentSpace);
    1567         else
    1568             child.setMarginRight(availableAlignmentSpace);
     1527    const RenderStyle& parentStyle = style();
     1528    Length marginBefore = child.style().marginBeforeUsing(&parentStyle);
     1529    Length marginAfter = child.style().marginAfterUsing(&parentStyle);
     1530    if (marginBefore.isAuto() && marginAfter.isAuto()) {
     1531        child.setMarginBefore(availableAlignmentSpace / 2, &parentStyle);
     1532        child.setMarginAfter(availableAlignmentSpace / 2, &parentStyle);
     1533    } else if (marginBefore.isAuto()) {
     1534        child.setMarginBefore(availableAlignmentSpace, &parentStyle);
     1535    } else if (marginAfter.isAuto()) {
     1536        child.setMarginAfter(availableAlignmentSpace, &parentStyle);
    15691537    }
    15701538}
     
    16821650        LayoutUnit endOfRow = m_rowPositions[childEndLine];
    16831651        LayoutUnit childBreadth = child.logicalHeight() + child.marginLogicalHeight();
     1652        // In order to properly adjust the Self Alignment values we need to consider the offset between tracks.
    16841653        if (childEndLine - childStartLine > 1 && childEndLine < m_rowPositions.size() - 1)
    16851654            endOfRow -= offsetBetweenTracks(style().resolvedAlignContentDistribution(), m_rowPositions, childBreadth);
     
    17111680        LayoutUnit endOfColumn = m_columnPositions[childEndLine];
    17121681        LayoutUnit childBreadth = child.logicalWidth() + child.marginLogicalWidth();
     1682        // In order to properly adjust the Self Alignment values we need to consider the offset between tracks.
    17131683        if (childEndLine - childStartLine > 1 && childEndLine < m_columnPositions.size() - 1)
    17141684            endOfColumn -= offsetBetweenTracks(style().resolvedJustifyContentDistribution(), m_columnPositions, childBreadth);
Note: See TracChangeset for help on using the changeset viewer.