Changeset 136465 in webkit


Ignore:
Timestamp:
Dec 3, 2012 6:24:23 PM (11 years ago)
Author:
jchaffraix@webkit.org
Message:

Source/WebCore: [CSS Grid Layout] Support paddings and margins on grid items
https://bugs.webkit.org/show_bug.cgi?id=103677

Reviewed by Tony Chang.

After bug 102968, we properly resolve grid items' width and height against the
grid areas' sizes. However we didn't check for paddings and margins, which is
what this change fixes..

Test: fast/css-grid-layout/percent-padding-margin-resolution-grid-item.html

  • rendering/RenderBox.cpp:

(WebCore::RenderBox::computeLogicalWidthInRegion):
Don't stretch the end margin to match the containing block's extent.
The fix is similar to what was done for flex-box in bug 65887.

  • rendering/RenderBoxModelObject.cpp:

(WebCore::RenderBoxModelObject::computeStickyPositionConstraints):
Added a comment about not using containingBlockLogicalWidthForContent.

(WebCore::RenderBoxModelObject::computedCSSPaddingTop):
(WebCore::RenderBoxModelObject::computedCSSPaddingBottom):
(WebCore::RenderBoxModelObject::computedCSSPaddingLeft):
(WebCore::RenderBoxModelObject::computedCSSPaddingRight):
(WebCore::RenderBoxModelObject::computedCSSPaddingBefore):
(WebCore::RenderBoxModelObject::computedCSSPaddingAfter):
(WebCore::RenderBoxModelObject::computedCSSPaddingStart):
(WebCore::RenderBoxModelObject::computedCSSPaddingEnd):
Updated these functions to use containingBlockLogicalWidthForContent.

  • rendering/RenderGrid.h:
  • rendering/RenderObject.h:

(WebCore::RenderObject::isRenderGrid):
Added isRenderGrid.

LayoutTests: [CSS Grid Layout] Support percentage paddings and margins on grid items
https://bugs.webkit.org/show_bug.cgi?id=103677

Reviewed by Tony Chang.

  • resources/check-layout.js:

Extended check-layout to be able to query paddings and margins. Note that in order to compare,
the attribute with the returned value from getComputedStyle, we need to trim the unit ("px")
from the actual values. This trick also works in FireFox and Opera.

  • fast/css-grid-layout/percent-padding-margin-resolution-grid-item-expected.txt: Added.
  • fast/css-grid-layout/percent-padding-margin-resolution-grid-item.html: Added.
Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r136463 r136465  
     12012-12-03  Julien Chaffraix  <jchaffraix@webkit.org>
     2
     3        [CSS Grid Layout] Support percentage paddings and margins on grid items
     4        https://bugs.webkit.org/show_bug.cgi?id=103677
     5
     6        Reviewed by Tony Chang.
     7
     8        * resources/check-layout.js:
     9        Extended check-layout to be able to query paddings and margins. Note that in order to compare,
     10        the attribute with the returned value from getComputedStyle, we need to trim the unit ("px")
     11        from the actual values. This trick also works in FireFox and Opera.
     12
     13        * fast/css-grid-layout/percent-padding-margin-resolution-grid-item-expected.txt: Added.
     14        * fast/css-grid-layout/percent-padding-margin-resolution-grid-item.html: Added.
     15
    1162012-12-03  Roger Fong  <roger_fong@apple.com>
    217
  • trunk/LayoutTests/resources/check-layout.js

    r130979 r136465  
    7878            failures.push("Expected " + expectedDisplay + " for display, but got " + actualDisplay + ". ");
    7979    }
     80
     81    var expectedPaddingTop = node.getAttribute && node.getAttribute("data-expected-padding-top");
     82    if (expectedPaddingTop) {
     83        var actualPaddingTop = getComputedStyle(node).paddingTop;
     84        // Trim the unit "px" from the output.
     85        actualPaddingTop = actualPaddingTop.substring(0, actualPaddingTop.length - 2);
     86        if (actualPaddingTop != expectedPaddingTop)
     87            failures.push("Expected " + expectedPaddingTop + " for padding-top, but got " + actualPaddingTop + ". ");
     88    }
     89
     90    var expectedPaddingBottom = node.getAttribute && node.getAttribute("data-expected-padding-bottom");
     91    if (expectedPaddingBottom) {
     92        var actualPaddingBottom = getComputedStyle(node).paddingBottom;
     93        // Trim the unit "px" from the output.
     94        actualPaddingBottom = actualPaddingBottom.substring(0, actualPaddingBottom.length - 2);
     95        if (actualPaddingBottom != expectedPaddingBottom)
     96            failures.push("Expected " + expectedPaddingBottom + " for padding-bottom, but got " + actualPaddingBottom + ". ");
     97    }
     98
     99    var expectedPaddingLeft = node.getAttribute && node.getAttribute("data-expected-padding-left");
     100    if (expectedPaddingLeft) {
     101        var actualPaddingLeft = getComputedStyle(node).paddingLeft;
     102        // Trim the unit "px" from the output.
     103        actualPaddingLeft = actualPaddingLeft.substring(0, actualPaddingLeft.length - 2);
     104        if (actualPaddingLeft != expectedPaddingLeft)
     105            failures.push("Expected " + expectedPaddingLeft + " for padding-left, but got " + actualPaddingLeft + ". ");
     106    }
     107
     108    var expectedPaddingRight = node.getAttribute && node.getAttribute("data-expected-padding-right");
     109    if (expectedPaddingRight) {
     110        var actualPaddingRight = getComputedStyle(node).paddingRight;
     111        // Trim the unit "px" from the output.
     112        actualPaddingRight = actualPaddingRight.substring(0, actualPaddingRight.length - 2);
     113        if (actualPaddingRight != expectedPaddingRight)
     114            failures.push("Expected " + expectedPaddingRight + " for padding-right, but got " + actualPaddingRight + ". ");
     115    }
     116
     117    var expectedMarginTop = node.getAttribute && node.getAttribute("data-expected-margin-top");
     118    if (expectedMarginTop) {
     119        var actualMarginTop = getComputedStyle(node).marginTop;
     120        // Trim the unit "px" from the output.
     121        actualMarginTop = actualMarginTop.substring(0, actualMarginTop.length - 2);
     122        if (actualMarginTop != expectedMarginTop)
     123            failures.push("Expected " + expectedMarginTop + " for margin-top, but got " + actualMarginTop + ". ");
     124    }
     125
     126    var expectedMarginBottom = node.getAttribute && node.getAttribute("data-expected-margin-bottom");
     127    if (expectedMarginBottom) {
     128        var actualMarginBottom = getComputedStyle(node).marginBottom;
     129        // Trim the unit "px" from the output.
     130        actualMarginBottom = actualMarginBottom.substring(0, actualMarginBottom.length - 2);
     131        if (actualMarginBottom != expectedMarginBottom)
     132            failures.push("Expected " + expectedMarginBottom + " for margin-bottom, but got " + actualMarginBottom + ". ");
     133    }
     134
     135    var expectedMarginLeft = node.getAttribute && node.getAttribute("data-expected-margin-left");
     136    if (expectedMarginLeft) {
     137        var actualMarginLeft = getComputedStyle(node).marginLeft;
     138        // Trim the unit "px" from the output.
     139        actualMarginLeft = actualMarginLeft.substring(0, actualMarginLeft.length - 2);
     140        if (actualMarginLeft != expectedMarginLeft)
     141            failures.push("Expected " + expectedMarginLeft + " for margin-left, but got " + actualMarginLeft + ". ");
     142    }
     143
     144    var expectedMarginRight = node.getAttribute && node.getAttribute("data-expected-margin-right");
     145    if (expectedMarginRight) {
     146        var actualMarginRight = getComputedStyle(node).marginRight;
     147        // Trim the unit "px" from the output.
     148        actualMarginRight = actualMarginRight.substring(0, actualMarginRight.length - 2);
     149        if (actualMarginRight != expectedMarginRight)
     150            failures.push("Expected " + expectedMarginRight + " for margin-right, but got " + actualMarginRight + ". ");
     151    }
    80152}
    81153
  • trunk/Source/WebCore/ChangeLog

    r136460 r136465  
     12012-12-03  Julien Chaffraix  <jchaffraix@webkit.org>
     2
     3        [CSS Grid Layout] Support paddings and margins on grid items
     4        https://bugs.webkit.org/show_bug.cgi?id=103677
     5
     6        Reviewed by Tony Chang.
     7
     8        After bug 102968, we properly resolve grid items' width and height against the
     9        grid areas' sizes. However we didn't check for paddings and margins, which is
     10        what this change fixes..
     11
     12        Test: fast/css-grid-layout/percent-padding-margin-resolution-grid-item.html
     13
     14        * rendering/RenderBox.cpp:
     15        (WebCore::RenderBox::computeLogicalWidthInRegion):
     16        Don't stretch the end margin to match the containing block's extent.
     17        The fix is similar to what was done for flex-box in bug 65887.
     18
     19        * rendering/RenderBoxModelObject.cpp:
     20        (WebCore::RenderBoxModelObject::computeStickyPositionConstraints):
     21        Added a comment about not using containingBlockLogicalWidthForContent.
     22
     23        (WebCore::RenderBoxModelObject::computedCSSPaddingTop):
     24        (WebCore::RenderBoxModelObject::computedCSSPaddingBottom):
     25        (WebCore::RenderBoxModelObject::computedCSSPaddingLeft):
     26        (WebCore::RenderBoxModelObject::computedCSSPaddingRight):
     27        (WebCore::RenderBoxModelObject::computedCSSPaddingBefore):
     28        (WebCore::RenderBoxModelObject::computedCSSPaddingAfter):
     29        (WebCore::RenderBoxModelObject::computedCSSPaddingStart):
     30        (WebCore::RenderBoxModelObject::computedCSSPaddingEnd):
     31        Updated these functions to use containingBlockLogicalWidthForContent.
     32
     33        * rendering/RenderGrid.h:
     34        * rendering/RenderObject.h:
     35        (WebCore::RenderObject::isRenderGrid):
     36        Added isRenderGrid.
     37
    1382012-12-03  Scott Violet  <sky@chromium.org>
    239
  • trunk/Source/WebCore/rendering/RenderBox.cpp

    r136326 r136465  
    18301830   
    18311831    if (!hasPerpendicularContainingBlock && containerLogicalWidth && containerLogicalWidth != (computedValues.m_extent + computedValues.m_margins.m_start + computedValues.m_margins.m_end)
    1832             && !isFloating() && !isInline() && !cb->isFlexibleBoxIncludingDeprecated()) {
     1832        && !isFloating() && !isInline() && !cb->isFlexibleBoxIncludingDeprecated() && !cb->isRenderGrid()) {
    18331833        LayoutUnit newMargin = containerLogicalWidth - computedValues.m_extent - cb->marginStartForChild(this);
    18341834        bool hasInvertedDirection = cb->style()->isLeftToRightDirection() != style()->isLeftToRightDirection();
  • trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp

    r136378 r136465  
    462462    LayoutRect containerContentRect = containingBlock->contentBoxRect();
    463463
     464    // Sticky positioned element ignore any override logical width on the containing block (as they don't call
     465    // containingBlockLogicalWidthForContent). It's unclear whether this is totally fine.
    464466    LayoutUnit minLeftMargin = minimumValueForLength(style()->marginLeft(), containingBlock->availableLogicalWidth(), view());
    465467    LayoutUnit minTopMargin = minimumValueForLength(style()->marginTop(), containingBlock->availableLogicalWidth(), view());
     
    556558    Length padding = style()->paddingTop();
    557559    if (padding.isPercent())
    558         w = containingBlock()->availableLogicalWidth();
     560        w = containingBlockLogicalWidthForContent();
    559561    else if (padding.isViewportPercentage())
    560562        renderView = view();
     
    568570    Length padding = style()->paddingBottom();
    569571    if (padding.isPercent())
    570         w = containingBlock()->availableLogicalWidth();
     572        w = containingBlockLogicalWidthForContent();
    571573    else if (padding.isViewportPercentage())
    572574        renderView = view();
     
    580582    Length padding = style()->paddingLeft();
    581583    if (padding.isPercent())
    582         w = containingBlock()->availableLogicalWidth();
     584        w = containingBlockLogicalWidthForContent();
    583585    else if (padding.isViewportPercentage())
    584586        renderView = view();
     
    592594    Length padding = style()->paddingRight();
    593595    if (padding.isPercent())
    594         w = containingBlock()->availableLogicalWidth();
     596        w = containingBlockLogicalWidthForContent();
    595597    else if (padding.isViewportPercentage())
    596598        renderView = view();
     
    604606    Length padding = style()->paddingBefore();
    605607    if (padding.isPercent())
    606         w = containingBlock()->availableLogicalWidth();
     608        w = containingBlockLogicalWidthForContent();
    607609    else if (padding.isViewportPercentage())
    608610        renderView = view();
     
    616618    Length padding = style()->paddingAfter();
    617619    if (padding.isPercent())
    618         w = containingBlock()->availableLogicalWidth();
     620        w = containingBlockLogicalWidthForContent();
    619621    else if (padding.isViewportPercentage())
    620622        renderView = view();
     
    628630    Length padding = style()->paddingStart();
    629631    if (padding.isPercent())
    630         w = containingBlock()->availableLogicalWidth();
     632        w = containingBlockLogicalWidthForContent();
    631633    else if (padding.isViewportPercentage())
    632634        renderView = view();
     
    640642    Length padding = style()->paddingEnd();
    641643    if (padding.isPercent())
    642         w = containingBlock()->availableLogicalWidth();
     644        w = containingBlockLogicalWidthForContent();
    643645    else if (padding.isViewportPercentage())
    644646        renderView = view();
  • trunk/Source/WebCore/rendering/RenderGrid.h

    r135164 r136465  
    4545
    4646private:
     47    virtual bool isRenderGrid() const OVERRIDE { return true; }
     48
    4749    class GridTrack;
    4850    enum TrackSizingDirection { ForColumns, ForRows };
  • trunk/Source/WebCore/rendering/RenderObject.h

    r136107 r136465  
    396396    virtual bool isRenderFullScreenPlaceholder() const { return false; }
    397397#endif
     398
     399    virtual bool isRenderGrid() const { return false; }
    398400
    399401    virtual bool isRenderFlowThread() const { return false; }
Note: See TracChangeset for help on using the changeset viewer.