Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
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
- Loading branch information
Showing
8 changed files
with
97 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters