Skip to content


Browse files Browse the repository at this point in the history
[aspect-ratio] Use correct box-sizing when calculating block size

Reviewed by Darin Adler.

When calculating block size and having both box-sizing and "auto && <ratio>" aspect ratio
specified use the specified box-sizing and not the box-sizing implied by "auto && <ratio>".

* LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/block-aspect-ratio-033.html:
* Source/WebCore/rendering/RenderBox.cpp:
(WebCore::RenderBox::computeLogicalHeight const):

Canonical link:
  • Loading branch information
rwlbuis committed Aug 3, 2022
1 parent a9c8a56 commit 871d8bc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
@@ -0,0 +1,19 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="">
<title>CSS Reftest Reference</title>
<link rel="author" title="Gérard Talbot" href="" />
<style type="text/css"><![CDATA[
background-color: green;
height: 100px;
width: 100px;
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<title>CSS aspect-ratio: Use correct box-sizing when calculating block size</title>
<link rel="help" href="">
<link rel="help" href="">
<link rel="match" href="../../reference/ref-filled-green-100px-square.xht" />
<meta name="assert" content="CSS aspect-ratio: Use correct box-sizing when calculating block size.">

<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>

<div style="background: green; width: 100px; aspect-ratio: auto 1/1; box-sizing: border-box; padding-top:10px; padding-left: 50px">
<div style="height: 90px"></div>
2 changes: 1 addition & 1 deletion Source/WebCore/rendering/RenderBox.cpp
Expand Up @@ -3189,7 +3189,7 @@ RenderBox::LogicalExtentComputedValues RenderBox::computeLogicalHeight(LayoutUni
if (computedValues.m_extent != LayoutUnit::max())
intrinsicHeight = computedValues.m_extent;
if (shouldComputeLogicalHeightFromAspectRatio()) {
if (intrinsicHeight && style().boxSizingForAspectRatio() == BoxSizing::ContentBox)
if (intrinsicHeight && style().boxSizing() == BoxSizing::ContentBox)
*intrinsicHeight -= RenderBox::borderBefore() + RenderBox::paddingBefore() + RenderBox::borderAfter() + RenderBox::paddingAfter();
heightResult = blockSizeFromAspectRatio(horizontalBorderAndPaddingExtent(), verticalBorderAndPaddingExtent(), style().logicalAspectRatio(), style().boxSizingForAspectRatio(), logicalWidth());
} else {
Expand Down

0 comments on commit 871d8bc

Please sign in to comment.