[webkit-changes] [WebKit/WebKit] bda70c: Use Aspect Ratio Computed From Presentational Hint...

Sammy Gill noreply at github.com
Wed Oct 19 10:48:59 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: bda70c08fc70def99434a3fb9bc8c8ff43fea239
      https://github.com/WebKit/WebKit/commit/bda70c08fc70def99434a3fb9bc8c8ff43fea239
  Author: Sammy Gill <sammy.gill at apple.com>
  Date:   2022-10-19 (Wed, 19 Oct 2022)

  Changed paths:
    M LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/video-aspect-ratio-expected.txt
    M LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/video-aspect-ratio.html
    A LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/video-intrinsic-width-height-expected.txt
    A LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/video-intrinsic-width-height.html
    R LayoutTests/media/video-intrinsic-width-height-expected.txt
    R LayoutTests/media/video-intrinsic-width-height.html
    M Source/WebCore/rendering/RenderReplaced.cpp
    M Source/WebCore/rendering/RenderReplaced.h
    M Source/WebCore/rendering/RenderVideo.cpp
    M Source/WebCore/rendering/RenderVideo.h

  Log Message:
  -----------
  Use Aspect Ratio Computed From Presentational Hints Before Video Loads.
https://bugs.webkit.org/show_bug.cgi?id=245001
rdar://99755477

Reviewed by Brent Fulgham.

When the width and height attributes are provided to video elements,
those values should contribute to the aspect-ratio property with the
form: auto width x height. This is the aspect-ratio that should be used
when sizing the video before its metadata have been received. Once the
metadata has been received, we should instead use the aspect-ratio
provided by the intrinsic sizes. Another subtle trait about the video
element is that its default object size (300px x 150px) should not
contribute to the aspect-ratio at any point in time.

To help match this behavior, the RenderBox::boxAspectRatio virtual
method was created to help determine the appropriate aspect ratio for
different boxes. The default behavior is to just return
style().logicalAspectRatio(), so that the behavior can remain the same
in RenderBox::computeMinMaxLogicalHeightFromAspectRatio and
RenderBox::computeMinMaxLogicalWidthFromAspectRatio. In scenarios where
this may not be correct, such as with RenderVideo, the subclass can
override the behavior. For RenderVideo's case, we need to determine
whether or not we have received the video metadata. If we have, we
should return the aspect-ratio provided by the intrinsic size of the
video. Otherwise, we can use the aspect ratio provided by either the
CSS property or the presentational hints.

* LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/video-aspect-ratio-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/video-aspect-ratio.html:
Imported most recent WPT test

* LayoutTests/media/video-intrinsic-width-height.html:
The final video element in this test should have a final dimension of
300px x 300px. This is because:

    1.) Since there is not actually any video content, this box will not
        have any intrinsic width/height.
    2.) There is an inline style that overrides the width/height
        attributes, so it will have width and height of auto.
    3.) Even though the width/height style is overridden, the attributes
        still contribute to the aspect ratio, giving it an aspect-ratio
        value of "auto 100/100"
    4.) When computing the automatic width we fall back to the default
        object size value, which is 300px.
    5.) To compute the height we take the aspect-ratio we computed and
        arrive at a height of 300px.

* Source/WebCore/rendering/RenderReplaced.cpp:
(WebCore::RenderReplaced::computeAspectRatioInformationForRenderBox const):
The new code path provides the width and height based on the aspect
ratio for video elements. Even though it seems like this logic should
work for any ReplacedElement, it seems to fail various tests. For now
we may want to just keep this logic separated for RenderVideo objects
specifically.

(WebCore::RenderReplaced::computeIntrinsicRatioInformation const):
We need to make sure we do not override the computed aspect ratio with
the values of the default object size for video elements. This is
because the default object size is not an intrinsic size and should not
contribute to the aspect ratio. Basically, we need to check out if we
have an intrinsic size set and bail out early if we do.
RenderVideo::calculateIntrinsicSize contains logic that decides if the
size needs to be set to the default size, so we can base most off of the
logic off of that.

(WebCore::isVideoWithDefaultObjectSize):
* Source/WebCore/rendering/RenderReplaced.h:
* Source/WebCore/rendering/RenderVideo.cpp:
(WebCore::RenderVideo::calculateIntrinsicSize):
(WebCore::RenderVideo::computeReplacedLogicalWidth const):
(WebCore::RenderVideo::hasVideoMetadata const):
(WebCore::RenderVideo::hasPosterFrameSize const):
(WebCore::RenderVideo::hasDefaultObjectSize const):
* Source/WebCore/rendering/RenderVideo.h:

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




More information about the webkit-changes mailing list