Bug 160076 - [css-grid] Stretch alignment doesn't work for orthogonal flows
Summary: [css-grid] Stretch alignment doesn't work for orthogonal flows
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Javier Fernandez
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-22 00:12 PDT by Javier Fernandez
Modified: 2016-08-22 13:13 PDT (History)
10 users (show)

See Also:


Attachments
Patch (16.66 KB, patch)
2016-07-27 06:35 PDT, Javier Fernandez
no flags Details | Formatted Diff | Diff
Patch (18.45 KB, patch)
2016-08-22 12:12 PDT, Javier Fernandez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Javier Fernandez 2016-07-22 00:12:06 PDT
We are progressively adding support on grid for orthogonal flows, however, stretching is not possible yet in these cases.
Comment 1 Javier Fernandez 2016-07-27 06:35:12 PDT
Created attachment 284691 [details]
Patch
Comment 2 Darin Adler 2016-07-28 16:20:12 PDT
Comment on attachment 284691 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=284691&action=review

> Source/WebCore/rendering/RenderGrid.cpp:2190
> +    bool childHasAutoSizeInColumnAxis = isHorizontalMode ? childStyle.height().isAuto() : childStyle.width().isAuto();
> +    bool childHasAutoSizeInRowAxis = isHorizontalMode ? childStyle.width().isAuto() : childStyle.height().isAuto();
> +    bool allowedToStretchChildAlongColumnAxis = childHasAutoSizeInColumnAxis && !hasAutoMarginsInColumnAxis(child);
> +    bool allowedToStretchChildAlongRowAxis = childHasAutoSizeInRowAxis && !hasAutoMarginsInRowAxis(child);
> +    bool stretchingAlongRowAxis = childStyle.resolvedJustifySelf(gridStyle, selfAlignmentNormalBehavior).position() == ItemPositionStretch;
> +    bool stretchingAlongColumnAxis = childStyle.resolvedAlignSelf(gridStyle, selfAlignmentNormalBehavior).position() == ItemPositionStretch;

Inefficient to compute both axes and then only use the one that is needed below. Maybe these can be functions instead of booleans so we can call only the one that is needed.

Also inefficient to compute stretchingAlongAxis when allowedToStretchChildAlongAxis is already false. Early return style would work for that.

> Source/WebCore/rendering/RenderGrid.cpp:2203
> +    if (allowedToStretchChildBlockSize) {
> +        LayoutUnit stretchedLogicalHeight = availableAlignmentSpaceForChildBeforeStretching(overrideContainingBlockContentSizeForChild(child, childBlockDirection).value(), child);
> +        LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinMax(stretchedLogicalHeight, LayoutUnit(-1));
> +        child.setOverrideLogicalContentHeight(desiredLogicalHeight - child.borderAndPaddingLogicalHeight());
> +        if (desiredLogicalHeight != child.logicalHeight()) {
> +            // FIXME: Can avoid laying out here in some cases. See https://webkit.org/b/87905.
> +            child.setLogicalHeight(LayoutUnit());
> +            child.setNeedsLayout();
>          }
>      }

Could be redone to use early exit instead of nesting the having he main function flow go into two nested if statements.
Comment 3 Javier Fernandez 2016-07-29 05:49:04 PDT
Comment on attachment 284691 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=284691&action=review

>> Source/WebCore/rendering/RenderGrid.cpp:2190
>> +    bool stretchingAlongColumnAxis = childStyle.resolvedAlignSelf(gridStyle, selfAlignmentNormalBehavior).position() == ItemPositionStretch;
> 
> Inefficient to compute both axes and then only use the one that is needed below. Maybe these can be functions instead of booleans so we can call only the one that is needed.
> 
> Also inefficient to compute stretchingAlongAxis when allowedToStretchChildAlongAxis is already false. Early return style would work for that.

I understand, I was aiming for a clearer code but it's true we can improve in the points you made. 
Thanks for the review, I'll apply the suggested chances in the patch for landing.

>> Source/WebCore/rendering/RenderGrid.cpp:2203
>>      }
> 
> Could be redone to use early exit instead of nesting the having he main function flow go into two nested if statements.

Yeah, I'll do that.
Comment 4 Javier Fernandez 2016-08-22 12:12:05 PDT
Created attachment 286611 [details]
Patch
Comment 5 WebKit Commit Bot 2016-08-22 13:13:02 PDT
Comment on attachment 286611 [details]
Patch

Clearing flags on attachment: 286611

Committed r204734: <http://trac.webkit.org/changeset/204734>
Comment 6 WebKit Commit Bot 2016-08-22 13:13:05 PDT
All reviewed patches have been landed.  Closing bug.