Changeset 271061 in webkit


Ignore:
Timestamp:
Dec 22, 2020 12:30:23 PM (3 years ago)
Author:
commit-queue@webkit.org
Message:

Support aspect-ratio on positioned elements
https://bugs.webkit.org/show_bug.cgi?id=219741

Patch by Rob Buis <rbuis@igalia.com> on 2020-12-22
Reviewed by Simon Fraser.

Source/WebCore:

Support aspect-ratio on positioned elements taking into account
insets in the case where no width/height is specified.

  • rendering/RenderBox.cpp:

(WebCore::RenderBox::computePositionedLogicalWidthUsing const):
(WebCore::RenderBox::computePositionedLogicalHeightUsing const):
(WebCore::RenderBox::shouldComputeLogicalHeightFromAspectRatio const): We should not compute
the logical height if there is an implied height due to top/bottom.
(WebCore::RenderBox::shouldComputeLogicalWidthFromAspectRatio const):
(WebCore::RenderBox::shouldComputeLogicalWidthFromAspectRatioAndInsets const): Helper method
to determine whether logical width can be computed from inset information in the case where
no width/height are specified.
(WebCore::RenderBox::computeLogicalWidthFromAspectRatio const): compute logical width
from the computed logical height constriaining it by min max.

  • rendering/RenderBox.h:

LayoutTests:

Enable some tests that pass now.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r271060 r271061  
     12020-12-22  Rob Buis  <rbuis@igalia.com>
     2
     3        Support aspect-ratio on positioned elements
     4        https://bugs.webkit.org/show_bug.cgi?id=219741
     5
     6        Reviewed by Simon Fraser.
     7
     8        Enable some tests that pass now.
     9
     10        * TestExpectations:
     11
    1122020-12-22  Youenn Fablet  <youenn@apple.com>
    213
  • trunk/LayoutTests/TestExpectations

    r270955 r271061  
    44254425webkit.org/b/214462 imported/w3c/web-platform-tests/css/css-scoping/slotted-placeholder.html [ ImageOnlyFailure ]
    44264426
    4427 webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-001.html [ ImageOnlyFailure ]
    4428 webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-002.html [ ImageOnlyFailure ]
    4429 webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-003.html [ ImageOnlyFailure ]
    4430 webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-004.html [ ImageOnlyFailure ]
    4431 webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-005.html [ ImageOnlyFailure ]
    4432 webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-006.html [ ImageOnlyFailure ]
    4433 webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-007.html [ ImageOnlyFailure ]
    44344427webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-008.html [ ImageOnlyFailure ]
    4435 webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-009.html [ ImageOnlyFailure ]
    4436 webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-010.html [ ImageOnlyFailure ]
    4437 webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-011.html [ ImageOnlyFailure ]
     4428webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-012.html [ ImageOnlyFailure ]
     4429webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-013.html [ ImageOnlyFailure ]
    44384430webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-014.html [ ImageOnlyFailure ]
    44394431webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/block-aspect-ratio-009.html [ ImageOnlyFailure ]
  • trunk/Source/WebCore/ChangeLog

    r271060 r271061  
     12020-12-22  Rob Buis  <rbuis@igalia.com>
     2
     3        Support aspect-ratio on positioned elements
     4        https://bugs.webkit.org/show_bug.cgi?id=219741
     5
     6        Reviewed by Simon Fraser.
     7
     8        Support aspect-ratio on positioned elements taking into account
     9        insets in the case where no width/height is specified.
     10
     11        * rendering/RenderBox.cpp:
     12        (WebCore::RenderBox::computePositionedLogicalWidthUsing const):
     13        (WebCore::RenderBox::computePositionedLogicalHeightUsing const):
     14        (WebCore::RenderBox::shouldComputeLogicalHeightFromAspectRatio const): We should not compute
     15        the logical height if there is an implied height due to top/bottom.
     16        (WebCore::RenderBox::shouldComputeLogicalWidthFromAspectRatio const):
     17        (WebCore::RenderBox::shouldComputeLogicalWidthFromAspectRatioAndInsets const): Helper method
     18        to determine whether logical width can be computed from inset information in the case where
     19        no width/height are specified.
     20        (WebCore::RenderBox::computeLogicalWidthFromAspectRatio const): compute logical width
     21        from the computed logical height constriaining it by min max.
     22        * rendering/RenderBox.h:
     23
    1242020-12-22  Youenn Fablet  <youenn@apple.com>
    225
  • trunk/Source/WebCore/rendering/RenderBox.cpp

    r271003 r271061  
    37163716    if (widthType == MinSize && logicalWidth.isAuto())
    37173717        logicalWidth = Length(0, Fixed);
     3718    else if (widthType == MainOrPreferredSize && logicalWidth.isAuto() && shouldComputeLogicalWidthFromAspectRatio())
     3719        logicalWidth = Length(computeLogicalWidthFromAspectRatio(), Fixed);
    37183720    else if (logicalWidth.isIntrinsic())
    37193721        logicalWidth = Length(computeIntrinsicLogicalWidthUsing(logicalWidth, containerLogicalWidth, bordersPlusPadding) - bordersPlusPadding, Fixed);
     
    37273729    const LayoutUnit containerRelativeLogicalWidth = containingBlockLogicalWidthForPositioned(containerBlock, nullptr, false);
    37283730
    3729     bool logicalWidthIsAuto = logicalWidth.isIntrinsicOrAuto();
     3731    bool logicalWidthIsAuto = logicalWidth.isIntrinsicOrAuto() && !shouldComputeLogicalWidthFromAspectRatio();
    37303732    bool logicalLeftIsAuto = logicalLeft.isAuto();
    37313733    bool logicalRightIsAuto = logicalRight.isAuto();
     
    40644066    LayoutUnit logicalTopValue;
    40654067
    4066     bool logicalHeightIsAuto = logicalHeightLength.isAuto();
     4068    bool fromAspectRatio = heightType == MainOrPreferredSize && shouldComputeLogicalHeightFromAspectRatio();
     4069    bool logicalHeightIsAuto = logicalHeightLength.isAuto() && !fromAspectRatio;
    40674070    bool logicalTopIsAuto = logicalTop.isAuto();
    40684071    bool logicalBottomIsAuto = logicalBottom.isAuto();
     
    40764079        if (logicalHeightLength.isIntrinsic())
    40774080            resolvedLogicalHeight = computeIntrinsicLogicalContentHeightUsing(logicalHeightLength, contentLogicalHeight, bordersPlusPadding).value();
    4078         else
     4081        else if (fromAspectRatio) {
     4082            resolvedLogicalHeight = blockSizeFromAspectRatio(horizontalBorderAndPaddingExtent(), verticalBorderAndPaddingExtent(), style().logicalAspectRatio() , style().boxSizing(), logicalWidth());
     4083            resolvedLogicalHeight = std::max(LayoutUnit(), resolvedLogicalHeight - bordersPlusPadding);
     4084        } else
    40794085            resolvedLogicalHeight = adjustContentBoxLogicalHeightForBoxSizing(valueForLength(logicalHeightLength, containerLogicalHeight));
    40804086    }
     
    49985004        return false;
    49995005
     5006    if (shouldComputeLogicalWidthFromAspectRatioAndInsets())
     5007        return false;
     5008
    50005009    auto h = style().logicalHeight();
    50015010    return h.isAuto() || (!isOutOfFlowPositioned() && h.isPercentOrCalculated() && percentageLogicalHeightIsResolvable());
     5011}
     5012
     5013bool RenderBox::shouldComputeLogicalWidthFromAspectRatio() const
     5014{
     5015    if (!style().hasAspectRatio())
     5016        return false;
     5017
     5018    if (!shouldComputeLogicalWidthFromAspectRatioAndInsets() && !style().logicalHeight().isFixed() && !style().logicalHeight().isPercentOrCalculated())
     5019        return false;
     5020
     5021    return true;
     5022}
     5023
     5024bool RenderBox::shouldComputeLogicalWidthFromAspectRatioAndInsets() const
     5025{
     5026    if (!isOutOfFlowPositioned())
     5027        return false;
     5028    // FIXME: see if this can become a helper on RenderStyle.
     5029    if (style().width().isAuto() && style().height().isAuto() && !style().top().isAuto() && !style().bottom().isAuto() && (style().left().isAuto() || style().right().isAuto()))
     5030        return true;
     5031    return false;
     5032}
     5033
     5034LayoutUnit RenderBox::computeLogicalWidthFromAspectRatio(RenderFragmentContainer* fragment) const
     5035{
     5036    ASSERT(shouldComputeLogicalWidthFromAspectRatio());
     5037    auto computedValues = computeLogicalHeight(logicalHeight(), logicalTop());
     5038    LayoutUnit logicalHeightforAspectRatio = computedValues.m_extent;
     5039
     5040    auto logicalWidth = inlineSizeFromAspectRatio(horizontalBorderAndPaddingExtent(), verticalBorderAndPaddingExtent(), style().logicalAspectRatio(), style().boxSizing(), logicalHeightforAspectRatio);
     5041
     5042    LayoutUnit containerWidthInInlineDirection = std::max<LayoutUnit>(0, containingBlockLogicalWidthForContentInFragment(fragment));
     5043    return constrainLogicalWidthInFragmentByMinMax(logicalWidth, containerWidthInInlineDirection, *containingBlock(), fragment);
    50025044}
    50035045
  • trunk/Source/WebCore/rendering/RenderBox.h

    r271003 r271061  
    746746
    747747    bool shouldComputeLogicalHeightFromAspectRatio() const;
     748    bool shouldComputeLogicalWidthFromAspectRatio() const;
     749    bool shouldComputeLogicalWidthFromAspectRatioAndInsets() const;
     750    LayoutUnit computeLogicalWidthFromAspectRatio(RenderFragmentContainer* = nullptr) const;
    748751
    749752private:
Note: See TracChangeset for help on using the changeset viewer.