Changeset 195284 in webkit


Ignore:
Timestamp:
Jan 19, 2016 3:36:11 AM (8 years ago)
Author:
jfernandez@igalia.com
Message:

[css-grid][css-align] justify-self stretch is not applied for img elements
https://bugs.webkit.org/show_bug.cgi?id=153206

Reviewed by Darin Adler.

Source/WebCore:

When computing the logical height, we check first if there is an override
height value set as a consequence of the stretching logic, so we use it
directly for any kind of element. However, in the case of the width
computation, we don't use such override value because it's the default
behavior of block-level boxes.

However, we consider some special cases which have to be treated as
replaced elements. Theses cases are evaluated first, so we don't let the
regular width computation logic to be executed, which is what we want
to implement the stretch behavior.

In order to let replaced elements, such images, to be stretched as a
consequence of the CSS alignment properties, we need to exclude grid
items from the cases to be treated as replaced elements during the width
computation.

Test: fast/css-grid-layout/grid-align-stretching-replaced-items.html

  • rendering/RenderBox.cpp:

(WebCore::RenderBox::computeLogicalWidthInRegion):
(WebCore::RenderBox::hasStretchedLogicalWidth):
(WebCore::RenderBox::sizesLogicalWidthToFitContent):

  • rendering/RenderBox.h:

LayoutTests:

Test to verify Replaced Elements, like images, are stretched in the inline
axis, when fulfilling the Box Alignment restrictions on this regard.

  • fast/css-grid-layout/grid-align-stretching-replaced-items-expected.txt: Added.
  • fast/css-grid-layout/grid-align-stretching-replaced-items.html: Added.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r195281 r195284  
     12016-01-19  Javier Fernandez  <jfernandez@igalia.com>
     2
     3        [css-grid][css-align] justify-self stretch is not applied for img elements
     4        https://bugs.webkit.org/show_bug.cgi?id=153206
     5
     6        Reviewed by Darin Adler.
     7
     8        Test to verify Replaced Elements, like images, are stretched in the inline
     9        axis, when fulfilling the Box Alignment restrictions on this regard.
     10
     11        * fast/css-grid-layout/grid-align-stretching-replaced-items-expected.txt: Added.
     12        * fast/css-grid-layout/grid-align-stretching-replaced-items.html: Added.
     13
    1142016-01-19  Ryosuke Niwa  <rniwa@webkit.org>
    215
  • trunk/Source/WebCore/ChangeLog

    r195281 r195284  
     12016-01-19  Javier Fernandez  <jfernandez@igalia.com>
     2
     3        [css-grid][css-align] justify-self stretch is not applied for img elements
     4        https://bugs.webkit.org/show_bug.cgi?id=153206
     5
     6        Reviewed by Darin Adler.
     7
     8        When computing the logical height, we check first if there is an override
     9        height value set as a consequence of the stretching logic, so we use it
     10        directly for any kind of element. However, in the case of the width
     11        computation, we don't use such override value because it's the default
     12        behavior of block-level boxes.
     13
     14        However, we consider some special cases which have to be treated as
     15        replaced elements. Theses cases are evaluated first, so we don't let the
     16        regular width computation logic to be executed, which is what we want
     17        to implement the stretch behavior.
     18
     19        In order to let replaced elements, such images, to be stretched as a
     20        consequence of the CSS alignment properties, we need to exclude grid
     21        items from the cases to be treated as replaced elements during the width
     22        computation.
     23
     24        Test: fast/css-grid-layout/grid-align-stretching-replaced-items.html
     25
     26        * rendering/RenderBox.cpp:
     27        (WebCore::RenderBox::computeLogicalWidthInRegion):
     28        (WebCore::RenderBox::hasStretchedLogicalWidth):
     29        (WebCore::RenderBox::sizesLogicalWidthToFitContent):
     30        * rendering/RenderBox.h:
     31
    1322016-01-19  Ryosuke Niwa  <rniwa@webkit.org>
    233
  • trunk/Source/WebCore/rendering/RenderBox.cpp

    r194710 r195284  
    23702370    bool inVerticalBox = parent()->isDeprecatedFlexibleBox() && (parent()->style().boxOrient() == VERTICAL);
    23712371    bool stretching = (parent()->style().boxAlign() == BSTRETCH);
     2372    // FIXME: Stretching is the only reason why we don't want the box to be treated as a replaced element, so we could perhaps
     2373    // refactor all this logic, not only for flex and grid since alignment is intended to be applied to any block.
    23722374    bool treatAsReplaced = shouldComputeSizeAsReplaced() && (!inVerticalBox || !stretching);
     2375#if ENABLE(CSS_GRID_LAYOUT)
     2376    treatAsReplaced = treatAsReplaced && (!isGridItem() || !hasStretchedLogicalWidth());
     2377#endif
    23732378
    23742379    const RenderStyle& styleToUse = style();
     
    25182523}
    25192524
     2525// FIXME: Can/Should we move this inside specific layout classes (flex. grid)? Can we refactor columnFlexItemHasStretchAlignment logic?
     2526bool RenderBox::hasStretchedLogicalWidth() const
     2527{
     2528    auto& style = this->style();
     2529    if (!style.logicalWidth().isAuto() || style.marginStart().isAuto() || style.marginEnd().isAuto())
     2530        return false;
     2531    RenderBlock* containingBlock = this->containingBlock();
     2532    if (!containingBlock) {
     2533        // We are evaluating align-self/justify-self, which default to 'normal' for the root element.
     2534        // The 'normal' value behaves like 'start' except for Flexbox Items, which obviously should have a container.
     2535        return false;
     2536    }
     2537    if (containingBlock->isHorizontalWritingMode() != isHorizontalWritingMode())
     2538        return RenderStyle::resolveAlignment(containingBlock->style(), style, ItemPositionStretch) == ItemPositionStretch;
     2539    return RenderStyle::resolveJustification(containingBlock->style(), style, ItemPositionStretch) == ItemPositionStretch;
     2540}
     2541
    25202542bool RenderBox::sizesLogicalWidthToFitContent(SizeType widthType) const
    25212543{
     
    25302552
    25312553#if ENABLE(CSS_GRID_LAYOUT)
    2532     if (parent()->isRenderGrid()) {
    2533         bool allowedToStretchChildAlongRowAxis = style().logicalWidth().isAuto() && !style().marginStartUsing(&parent()->style()).isAuto() && !style().marginEndUsing(&parent()->style()).isAuto();
    2534         return !allowedToStretchChildAlongRowAxis || RenderStyle::resolveJustification(parent()->style(), style(), ItemPositionStretch) != ItemPositionStretch;
    2535     }
     2554    if (isGridItem())
     2555        return !hasStretchedLogicalWidth();
    25362556#endif
    25372557
  • trunk/Source/WebCore/rendering/RenderBox.h

    r194417 r195284  
    424424    bool sizesLogicalWidthToFitContent(SizeType) const;
    425425
     426    bool hasStretchedLogicalWidth() const;
     427
    426428    LayoutUnit shrinkLogicalWidthToAvoidFloats(LayoutUnit childMarginStart, LayoutUnit childMarginEnd, const RenderBlock* cb, RenderRegion*) const;
    427429
Note: See TracChangeset for help on using the changeset viewer.