Title: [271061] trunk
Revision
271061
Author
[email protected]
Date
2020-12-22 12:30:23 -0800 (Tue, 22 Dec 2020)

Log Message

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

Patch by Rob Buis <[email protected]> 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.

* TestExpectations:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (271060 => 271061)


--- trunk/LayoutTests/ChangeLog	2020-12-22 20:00:23 UTC (rev 271060)
+++ trunk/LayoutTests/ChangeLog	2020-12-22 20:30:23 UTC (rev 271061)
@@ -1,3 +1,14 @@
+2020-12-22  Rob Buis  <[email protected]>
+
+        Support aspect-ratio on positioned elements
+        https://bugs.webkit.org/show_bug.cgi?id=219741
+
+        Reviewed by Simon Fraser.
+
+        Enable some tests that pass now.
+
+        * TestExpectations:
+
 2020-12-22  Youenn Fablet  <[email protected]>
 
         MediaStreamTrack.muted value should not change before the corresponding event is fired

Modified: trunk/LayoutTests/TestExpectations (271060 => 271061)


--- trunk/LayoutTests/TestExpectations	2020-12-22 20:00:23 UTC (rev 271060)
+++ trunk/LayoutTests/TestExpectations	2020-12-22 20:30:23 UTC (rev 271061)
@@ -4424,17 +4424,9 @@
 webkit.org/b/214462 imported/w3c/web-platform-tests/css/css-scoping/shadow-directionality-002.tentative.html [ ImageOnlyFailure ]
 webkit.org/b/214462 imported/w3c/web-platform-tests/css/css-scoping/slotted-placeholder.html [ ImageOnlyFailure ]
 
-webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-001.html [ ImageOnlyFailure ]
-webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-002.html [ ImageOnlyFailure ]
-webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-003.html [ ImageOnlyFailure ]
-webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-004.html [ ImageOnlyFailure ]
-webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-005.html [ ImageOnlyFailure ]
-webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-006.html [ ImageOnlyFailure ]
-webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-007.html [ ImageOnlyFailure ]
 webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-008.html [ ImageOnlyFailure ]
-webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-009.html [ ImageOnlyFailure ]
-webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-010.html [ ImageOnlyFailure ]
-webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-011.html [ ImageOnlyFailure ]
+webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-012.html [ ImageOnlyFailure ]
+webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-013.html [ ImageOnlyFailure ]
 webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-014.html [ ImageOnlyFailure ]
 webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/block-aspect-ratio-009.html [ ImageOnlyFailure ]
 webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/block-aspect-ratio-014.html [ ImageOnlyFailure ]

Modified: trunk/Source/WebCore/ChangeLog (271060 => 271061)


--- trunk/Source/WebCore/ChangeLog	2020-12-22 20:00:23 UTC (rev 271060)
+++ trunk/Source/WebCore/ChangeLog	2020-12-22 20:30:23 UTC (rev 271061)
@@ -1,3 +1,26 @@
+2020-12-22  Rob Buis  <[email protected]>
+
+        Support aspect-ratio on positioned elements
+        https://bugs.webkit.org/show_bug.cgi?id=219741
+
+        Reviewed by Simon Fraser.
+
+        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:
+
 2020-12-22  Youenn Fablet  <[email protected]>
 
         MediaStreamTrack.muted value should not change before the corresponding event is fired

Modified: trunk/Source/WebCore/rendering/RenderBox.cpp (271060 => 271061)


--- trunk/Source/WebCore/rendering/RenderBox.cpp	2020-12-22 20:00:23 UTC (rev 271060)
+++ trunk/Source/WebCore/rendering/RenderBox.cpp	2020-12-22 20:30:23 UTC (rev 271061)
@@ -3715,6 +3715,8 @@
     auto originalLogicalWidthType = logicalWidth.type();
     if (widthType == MinSize && logicalWidth.isAuto())
         logicalWidth = Length(0, Fixed);
+    else if (widthType == MainOrPreferredSize && logicalWidth.isAuto() && shouldComputeLogicalWidthFromAspectRatio())
+        logicalWidth = Length(computeLogicalWidthFromAspectRatio(), Fixed);
     else if (logicalWidth.isIntrinsic())
         logicalWidth = Length(computeIntrinsicLogicalWidthUsing(logicalWidth, containerLogicalWidth, bordersPlusPadding) - bordersPlusPadding, Fixed);
 
@@ -3726,7 +3728,7 @@
 
     const LayoutUnit containerRelativeLogicalWidth = containingBlockLogicalWidthForPositioned(containerBlock, nullptr, false);
 
-    bool logicalWidthIsAuto = logicalWidth.isIntrinsicOrAuto();
+    bool logicalWidthIsAuto = logicalWidth.isIntrinsicOrAuto() && !shouldComputeLogicalWidthFromAspectRatio();
     bool logicalLeftIsAuto = logicalLeft.isAuto();
     bool logicalRightIsAuto = logicalRight.isAuto();
     LayoutUnit& marginLogicalLeftValue = style().isLeftToRightDirection() ? computedValues.m_margins.m_start : computedValues.m_margins.m_end;
@@ -4063,7 +4065,8 @@
 
     LayoutUnit logicalTopValue;
 
-    bool logicalHeightIsAuto = logicalHeightLength.isAuto();
+    bool fromAspectRatio = heightType == MainOrPreferredSize && shouldComputeLogicalHeightFromAspectRatio();
+    bool logicalHeightIsAuto = logicalHeightLength.isAuto() && !fromAspectRatio;
     bool logicalTopIsAuto = logicalTop.isAuto();
     bool logicalBottomIsAuto = logicalBottom.isAuto();
 
@@ -4075,7 +4078,10 @@
     } else {
         if (logicalHeightLength.isIntrinsic())
             resolvedLogicalHeight = computeIntrinsicLogicalContentHeightUsing(logicalHeightLength, contentLogicalHeight, bordersPlusPadding).value();
-        else
+        else if (fromAspectRatio) {
+            resolvedLogicalHeight = blockSizeFromAspectRatio(horizontalBorderAndPaddingExtent(), verticalBorderAndPaddingExtent(), style().logicalAspectRatio() , style().boxSizing(), logicalWidth());
+            resolvedLogicalHeight = std::max(LayoutUnit(), resolvedLogicalHeight - bordersPlusPadding);
+        } else
             resolvedLogicalHeight = adjustContentBoxLogicalHeightForBoxSizing(valueForLength(logicalHeightLength, containerLogicalHeight));
     }
 
@@ -4997,10 +5003,46 @@
     if (!style().hasAspectRatio())
         return false;
 
+    if (shouldComputeLogicalWidthFromAspectRatioAndInsets())
+        return false;
+
     auto h = style().logicalHeight();
     return h.isAuto() || (!isOutOfFlowPositioned() && h.isPercentOrCalculated() && percentageLogicalHeightIsResolvable());
 }
 
+bool RenderBox::shouldComputeLogicalWidthFromAspectRatio() const
+{
+    if (!style().hasAspectRatio())
+        return false;
+
+    if (!shouldComputeLogicalWidthFromAspectRatioAndInsets() && !style().logicalHeight().isFixed() && !style().logicalHeight().isPercentOrCalculated())
+        return false;
+
+    return true;
+}
+
+bool RenderBox::shouldComputeLogicalWidthFromAspectRatioAndInsets() const
+{
+    if (!isOutOfFlowPositioned())
+        return false;
+    // FIXME: see if this can become a helper on RenderStyle.
+    if (style().width().isAuto() && style().height().isAuto() && !style().top().isAuto() && !style().bottom().isAuto() && (style().left().isAuto() || style().right().isAuto()))
+        return true;
+    return false;
+}
+
+LayoutUnit RenderBox::computeLogicalWidthFromAspectRatio(RenderFragmentContainer* fragment) const
+{
+    ASSERT(shouldComputeLogicalWidthFromAspectRatio());
+    auto computedValues = computeLogicalHeight(logicalHeight(), logicalTop());
+    LayoutUnit logicalHeightforAspectRatio = computedValues.m_extent;
+
+    auto logicalWidth = inlineSizeFromAspectRatio(horizontalBorderAndPaddingExtent(), verticalBorderAndPaddingExtent(), style().logicalAspectRatio(), style().boxSizing(), logicalHeightforAspectRatio);
+
+    LayoutUnit containerWidthInInlineDirection = std::max<LayoutUnit>(0, containingBlockLogicalWidthForContentInFragment(fragment));
+    return constrainLogicalWidthInFragmentByMinMax(logicalWidth, containerWidthInInlineDirection, *containingBlock(), fragment);
+}
+
 bool RenderBox::hasRelativeDimensions() const
 {
     return style().height().isPercentOrCalculated() || style().width().isPercentOrCalculated()

Modified: trunk/Source/WebCore/rendering/RenderBox.h (271060 => 271061)


--- trunk/Source/WebCore/rendering/RenderBox.h	2020-12-22 20:00:23 UTC (rev 271060)
+++ trunk/Source/WebCore/rendering/RenderBox.h	2020-12-22 20:30:23 UTC (rev 271061)
@@ -745,6 +745,9 @@
     void applyTopLeftLocationOffsetWithFlipping(LayoutPoint&) const;
 
     bool shouldComputeLogicalHeightFromAspectRatio() const;
+    bool shouldComputeLogicalWidthFromAspectRatio() const;
+    bool shouldComputeLogicalWidthFromAspectRatioAndInsets() const;
+    LayoutUnit computeLogicalWidthFromAspectRatio(RenderFragmentContainer* = nullptr) const;
 
 private:
     // The width/height of the contents + borders + padding.  The x/y location is relative to our container (which is not always our parent).
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to