[webkit-changes] [WebKit/WebKit] 036e53: Replaced elements with aspect ratio and size in on...

Sammy Gill noreply at github.com
Tue Dec 6 14:29:52 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 036e53a548a5852a4a59f49298cb45e8c8e0a2ce
      https://github.com/WebKit/WebKit/commit/036e53a548a5852a4a59f49298cb45e8c8e0a2ce
  Author: Sammy Gill <sammy.gill at apple.com>
  Date:   2022-12-06 (Tue, 06 Dec 2022)

  Changed paths:
    A LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/replaced-element-039-expected.html
    A LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/replaced-element-039.html
    A LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/replaced-element-040-expected.html
    A LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/replaced-element-040.html
    M Source/WebCore/rendering/RenderBlock.cpp
    M Source/WebCore/rendering/RenderBox.cpp
    M Source/WebCore/rendering/RenderBox.h
    M Source/WebCore/rendering/RenderObject.h
    M Source/WebCore/rendering/RenderReplaced.cpp
    M Source/WebCore/rendering/RenderReplaced.h
    M Source/WebCore/rendering/svg/LegacyRenderSVGRoot.cpp
    M Source/WebCore/rendering/svg/LegacyRenderSVGRoot.h
    M Source/WebCore/rendering/svg/RenderSVGRoot.cpp
    M Source/WebCore/rendering/svg/RenderSVGRoot.h

  Log Message:
  -----------
  Replaced elements with aspect ratio and size in one dimension should respect min-max constraints in opposite dimension.
https://bugs.webkit.org/show_bug.cgi?id=247507
rdar://101979495

Reviewed by Alan Baradlay.

There are certain scenarios where a replaced element may have a
specified aspect ratio, but will not have intrinsic sizes in both
dimensions. One such examples is a SVG with only a specified width
and aspect ratio.

To help facilitate this, the logic in
RenderReplaced::computeAspectRatioInformationForRenderBox has been
separated out since it was doing too much before. It was both computing
the intrinsic size/ratio and constraining the intrinsic size. The logic
for constraining the intrinsic size has been refactored out into a new
method called
RenderReplaced::computeIntrinsicSizesConstrainedByTransferredMinMaxSizes.
This method will call

In these scenarios, we must use the specified aspect ratio to do any
sort of sizing since it is not possible to compute it from the
dimensions of the box. computeAspectRatioInformationForRenderBox to get
the intrinsic size/ratio and then constrain it. This new method will
also constrain the sizes in each dimension by the transferred sizes.
This size may be then potentially constrained even further in
RenderReplaced::computeReplacedLogicalWidthRespectingMinMaxWidth (and
height) by any definite min/max sizes in that dimension. There was an
attempt to consolidate all constraining logic into that method, but
that was causing some unexpected results. That may need to be done in
a future patch.

A few of the CSS aspect ratio methods have also been modified to help
with this logic. Since a lot of the logic is shared, these methods
can determine if a replaced element is being used and use the correct
aspect ratio in that case.

A new member variable to RenderReplaced has been added:
m_intrinsicRatioSize. This is used to keep track of the width and height
sizes associated with the aspect ratio. This is because there were some
precision issues that this patch exposed. Certain tests were starting
to fail because the computed width/height from the aspect ratio was
slightly off. To help with this, we can store the intrinsic ratio sizes
until we actually need to use them to compute the width/height. The
goal here is to hopefully reduce the number of floating point operations
that are needed to compute a size. It may be possible to replace all
instances where the computed intrinsicRatio double is being used, but
that is probably a little too risky for this patch. Instead, this patch
only uses it in the call to resolveHeightForRatio within
RenderReplaced::computeReplacedLogicalHeight. It is probably best
to update all uses of intrinsicRatio to m_intrinsicRatioSize in another
patch. To compute the intrinsic ratio size we needed to keep track of
a new variable inside the computeIntrinsicRatioInformation logic and
then update the member variable once it was computed.

Spec references:
https://www.w3.org/TR/CSS22/visudet.html#min-max-widths
https://www.w3.org/TR/CSS22/visudet.html#min-max-heights
https://w3c.github.io/csswg-drafts/css-sizing-4/#aspect-ratio

* LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/replaced-element-039-expected.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/replaced-element-039.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/replaced-element-040-expected.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/replaced-element-040.html: Added.
* Source/WebCore/rendering/RenderBlock.cpp:
(WebCore::RenderBlock::computeChildPreferredLogicalWidths const):
(WebCore::RenderBlock::availableLogicalHeightForPercentageComputation const):
* Source/WebCore/rendering/RenderBox.cpp:
(WebCore::RenderBox::constrainLogicalMinMaxSizesByAspectRatio const):
(WebCore::RenderBox::constrainLogicalHeightByMinMax const):
(WebCore::inlineSizeFromAspectRatio):
Two extra arguments have been added to provide some context when
determining the box type to use (content box or border box). These
arguments are the aspect-ratio type being used for the box along with
whether or not the box is a replaced element with an intrinsic ratio.
css-sizing-4 specifies which box type to use depending on whether the
aspect-ratio property is auto, <ratio>, or auto && <ratio>. If the item
is a replaced element, then it should always work with the content box.

(WebCore::RenderBox::computeLogicalHeight const):
(WebCore::RenderBox::availableLogicalHeightUsing const):
(WebCore::RenderBox::computePositionedLogicalHeightUsing const):
(WebCore::RenderBox::computeLogicalWidthFromAspectRatioInternal const):
(WebCore::RenderBox::isRenderReplacedWithIntrinsicRatio const):
(WebCore::RenderBox::resolveAspectRatio const):
A new helper method to determine which aspect ratio to use depending on
the type of the box. Since RenderReplaced objects have slightly
different logic to compute their aspect ratio, this method does the
work of finding on the aspect ratio that needs to be used and performs
the appropriate calls to compute it. If the object is a RenderReplaced
object, then we need the compute its aspect ratio, otherwise we should
be able to get the box's aspect ratio from its style.

(WebCore::RenderBox::computeMinMaxLogicalWidthFromAspectRatio const):
(WebCore::RenderBox::computeMinMaxLogicalHeightFromAspectRatio const):
horizontalBorderAndPaddingExtent and verticalBorderAndPaddingExtent
were replaced with borderAndPaddingLogicalWidth and
borderAndPaddingLogicalHeight since both blockSizeFromAspectRatio and
inlineSizeFromAspectRatio were expecting the inline and block sizes.
Before, these methods were being passed in the values for the physical
directions and were causing certain tests to fail (e.g.
css/css-flexbox/flex-aspect-ratio-img-column-008.html and
css/css-flexbox/image-as-flexitem-size-007v.html).

* Source/WebCore/rendering/RenderBox.h:
(WebCore::RenderBox::blockSizeFromAspectRatio):
* Source/WebCore/rendering/RenderObject.h:
(WebCore::RenderObject::hasIntrinsicAspectRatio const):
This method was made virtual because it was difficult to provide a valid
answer for SVG elements at this high of an abstraction. Since SVG
elements may not have an aspect ratio, we need those elements to
override this method and provide the answer themselves.

* Source/WebCore/rendering/RenderReplaced.cpp:
(WebCore::RenderReplaced::computeAspectRatioInformationForRenderBox const):
(WebCore::RenderReplaced::computeIntrinsicSizesConstrainedByTransferredMinMaxSizes const):
(WebCore::RenderReplaced::computeIntrinsicRatioInformation const):
(WebCore::RenderReplaced::computeReplacedLogicalWidth const):
(WebCore::RenderReplaced::computeReplacedLogicalHeight const):
* Source/WebCore/rendering/RenderReplaced.h:
* Source/WebCore/rendering/svg/LegacyRenderSVGRoot.cpp:
(WebCore::LegacyRenderSVGRoot::hasIntrinsicAspectRatio const):
* Source/WebCore/rendering/svg/LegacyRenderSVGRoot.h:
* Source/WebCore/rendering/svg/RenderSVGRoot.cpp:
(WebCore::RenderSVGRoot::hasIntrinsicAspectRatio const):
* Source/WebCore/rendering/svg/RenderSVGRoot.h:

Canonical link: https://commits.webkit.org/257434@main




More information about the webkit-changes mailing list