-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Utilizing Aspect-Ratio with Art Direction (Multiple Sources with various Aspect Ratios known) #4968
Comments
As I suggested on WICG/intrinsicsize-attribute#16 (comment), I think we can update the update the image data algorithm to pick the aspect ratio from the selected source. For consistency, it seems like it would be better to add |
@yoavweiss One question regarding changing the algorithm of update the image data: |
I agree that the best solution is to have Authors put I would not apply this to the @AndresInSpace This should apply to the first layout calculation. In the moment when the browser decides which image to use, it should grab the width & height data, and use it in the first paint. Skipping over any other ideas of what layout should be. Once the height & width data is transferred to |
Nope, |
@jensimmons Perfect. |
…img> https://bugs.webkit.org/show_bug.cgi?id=201641 Reviewed by Frédéric Wang LayoutTests/imported/w3c: assert_ratio(images[5], 133/106) in img-aspect-ratio.html still fails because of bug 206161. * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/canvas-aspect-ratio.html: * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/content-aspect-ratio.html: * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/img-aspect-ratio-expected.txt: * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/img-aspect-ratio.html: * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/video-aspect-ratio.html: Source/WebCore: According to [1], if HTML width and height attributes have valid values, not a percentage, and non-zero, the value width/height is the default intrinsic aspect ratio for an <img> element. This will help to calculate img element's layout size before loading. The value will be overridden if img is loaded. Also see [2]. This is currently limited in <img> element. Other elements like <canvas>, <video> and <input type=image>, currently their aspect-ratio won't be affected.[3] While <picture> is still under discuss.[4] [1]: https://html.spec.whatwg.org/multipage/rendering.html#attributes-for-embedded-content-and-images [2]: WICG/intrinsicsize-attribute#16 [3]: whatwg/html#4961 [4]: whatwg/html#4968 Tests: imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/canvas-aspect-ratio.html imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/img-aspect-ratio.html imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/video-aspect-ratio.html imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/content-aspect-ratio.html * page/Settings.yaml: * rendering/RenderReplaced.cpp: (WebCore::RenderReplaced::computeIntrinsicRatioInformation const): Source/WebKit: Add experimental flag: AspectRatioOfImgFromWidthAndHeightEnabled. * Shared/WebPreferences.yaml: Source/WebKitLegacy/mac: Add experimental flag: AspectRatioOfImgFromWidthAndHeightEnabled. * WebView/WebPreferenceKeysPrivate.h: * WebView/WebPreferences.mm: ([WebPreferences initialize]): (-[WebPreferences aspectRatioOfImgFromWidthAndHeightEnabled]): (-[WebPreferences setAspectRatioOfImgFromWidthAndHeightEnabled:]): * WebView/WebPreferencesPrivate.h: * WebView/WebView.mm: (-[WebView _preferencesChanged:]): Source/WebKitLegacy/win: Add experimental flag: AspectRatioOfImgFromWidthAndHeightEnabled. * Interfaces/IWebPreferencesPrivate.idl: * WebPreferenceKeysPrivate.h: * WebPreferences.cpp: (WebPreferences::initializeDefaultSettings): (WebPreferences::aspectRatioOfImgFromWidthAndHeightEnabled): (WebPreferences::setAspectRatioOfImgFromWidthAndHeightEnabled): * WebPreferences.h: * WebView.cpp: (WebView::notifyPreferencesChanged): Tools: Add experimental flag: AspectRatioOfImgFromWidthAndHeightEnabled. (enableExperimentalFeatures): (setWebPreferencesForTestOptions): * DumpRenderTree/win/DumpRenderTree.cpp: (enableExperimentalFeatures): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@254669 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Does this also handle image formats like HEIF which, as far as I understand, can have multiple pictures inside that do not need to have all the same dimensions and ratios (though usually do)? |
<picture> does not currently let you specify an aspect ratio per source: w3c/csswg-drafts#5212 whatwg/html#4968 So this just tests setting a single aspect-ratio on the <img> element for now. Bug: 1045668 Change-Id: I89f5132322f8131bf346ea663b889e3b1d740e7c
<picture> does not currently let you specify an aspect ratio per source: w3c/csswg-drafts#5212 whatwg/html#4968 So this just tests setting a single aspect-ratio on the <img> element for now. Bug: 1045668 Change-Id: I89f5132322f8131bf346ea663b889e3b1d740e7c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2254454 Auto-Submit: Christian Biesinger <[email protected]> Commit-Queue: Ian Kilpatrick <[email protected]> Reviewed-by: Ian Kilpatrick <[email protected]> Cr-Commit-Position: refs/heads/master@{#780870}
<picture> does not currently let you specify an aspect ratio per source: w3c/csswg-drafts#5212 whatwg/html#4968 So this just tests setting a single aspect-ratio on the <img> element for now. Bug: 1045668 Change-Id: I89f5132322f8131bf346ea663b889e3b1d740e7c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2254454 Auto-Submit: Christian Biesinger <[email protected]> Commit-Queue: Ian Kilpatrick <[email protected]> Reviewed-by: Ian Kilpatrick <[email protected]> Cr-Commit-Position: refs/heads/master@{#780870}
<picture> does not currently let you specify an aspect ratio per source: w3c/csswg-drafts#5212 whatwg/html#4968 So this just tests setting a single aspect-ratio on the <img> element for now. Bug: 1045668 Change-Id: I89f5132322f8131bf346ea663b889e3b1d740e7c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2254454 Auto-Submit: Christian Biesinger <[email protected]> Commit-Queue: Ian Kilpatrick <[email protected]> Reviewed-by: Ian Kilpatrick <[email protected]> Cr-Commit-Position: refs/heads/master@{#780870}
…a=testonly Automatic update from web-platform-tests [AspectRatio] Add a test for <picture> <picture> does not currently let you specify an aspect ratio per source: w3c/csswg-drafts#5212 whatwg/html#4968 So this just tests setting a single aspect-ratio on the <img> element for now. Bug: 1045668 Change-Id: I89f5132322f8131bf346ea663b889e3b1d740e7c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2254454 Auto-Submit: Christian Biesinger <[email protected]> Commit-Queue: Ian Kilpatrick <[email protected]> Reviewed-by: Ian Kilpatrick <[email protected]> Cr-Commit-Position: refs/heads/master@{#780870} -- wpt-commits: 0c5883bd05b5d962ae68998b450510582e6ef6ca wpt-pr: 24256
…a=testonly Automatic update from web-platform-tests [AspectRatio] Add a test for <picture> <picture> does not currently let you specify an aspect ratio per source: w3c/csswg-drafts#5212 whatwg/html#4968 So this just tests setting a single aspect-ratio on the <img> element for now. Bug: 1045668 Change-Id: I89f5132322f8131bf346ea663b889e3b1d740e7c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2254454 Auto-Submit: Christian Biesinger <[email protected]> Commit-Queue: Ian Kilpatrick <[email protected]> Reviewed-by: Ian Kilpatrick <[email protected]> Cr-Commit-Position: refs/heads/master@{#780870} -- wpt-commits: 0c5883bd05b5d962ae68998b450510582e6ef6ca wpt-pr: 24256
…img> https://bugs.webkit.org/show_bug.cgi?id=201641 Reviewed by Frédéric Wang LayoutTests/imported/w3c: assert_ratio(images[5], 133/106) in img-aspect-ratio.html still fails because of bug 206161. * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/canvas-aspect-ratio.html: * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/content-aspect-ratio.html: * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/img-aspect-ratio-expected.txt: * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/img-aspect-ratio.html: * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/video-aspect-ratio.html: Source/WebCore: According to [1], if HTML width and height attributes have valid values, not a percentage, and non-zero, the value width/height is the default intrinsic aspect ratio for an <img> element. This will help to calculate img element's layout size before loading. The value will be overridden if img is loaded. Also see [2]. This is currently limited in <img> element. Other elements like <canvas>, <video> and <input type=image>, currently their aspect-ratio won't be affected.[3] While <picture> is still under discuss.[4] [1]: https://html.spec.whatwg.org/multipage/rendering.html#attributes-for-embedded-content-and-images [2]: WICG/intrinsicsize-attribute#16 [3]: whatwg/html#4961 [4]: whatwg/html#4968 Tests: imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/canvas-aspect-ratio.html imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/img-aspect-ratio.html imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/video-aspect-ratio.html imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/content-aspect-ratio.html * page/Settings.yaml: * rendering/RenderReplaced.cpp: (WebCore::RenderReplaced::computeIntrinsicRatioInformation const): Source/WebKit: Add experimental flag: AspectRatioOfImgFromWidthAndHeightEnabled. * Shared/WebPreferences.yaml: Source/WebKitLegacy/mac: Add experimental flag: AspectRatioOfImgFromWidthAndHeightEnabled. * WebView/WebPreferenceKeysPrivate.h: * WebView/WebPreferences.mm: ([WebPreferences initialize]): (-[WebPreferences aspectRatioOfImgFromWidthAndHeightEnabled]): (-[WebPreferences setAspectRatioOfImgFromWidthAndHeightEnabled:]): * WebView/WebPreferencesPrivate.h: * WebView/WebView.mm: (-[WebView _preferencesChanged:]): Source/WebKitLegacy/win: Add experimental flag: AspectRatioOfImgFromWidthAndHeightEnabled. * Interfaces/IWebPreferencesPrivate.idl: * WebPreferenceKeysPrivate.h: * WebPreferences.cpp: (WebPreferences::initializeDefaultSettings): (WebPreferences::aspectRatioOfImgFromWidthAndHeightEnabled): (WebPreferences::setAspectRatioOfImgFromWidthAndHeightEnabled): * WebPreferences.h: * WebView.cpp: (WebView::notifyPreferencesChanged): Tools: Add experimental flag: AspectRatioOfImgFromWidthAndHeightEnabled. (enableExperimentalFeatures): (setWebPreferencesForTestOptions): * DumpRenderTree/win/DumpRenderTree.cpp: (enableExperimentalFeatures): Canonical link: https://commits.webkit.org/219419@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254669 268f45cc-cd09-0410-ab3c-d52691b4dbfc
For reference, this is now documented at (via PR #5894): Thank you for adding this to the spec! 🎉 |
It will also ship in Chrome 90! I believe Firefox is also working on it, don't know about their schedule. |
This is in Safari 15 |
For those looking for FF support, this seems to be the Firefox tracking for this: https://bugzilla.mozilla.org/show_bug.cgi?id=1694741 |
<picture> does not currently let you specify an aspect ratio per source: w3c/csswg-drafts#5212 whatwg/html#4968 So this just tests setting a single aspect-ratio on the <img> element for now. Bug: 1045668 Change-Id: I89f5132322f8131bf346ea663b889e3b1d740e7c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2254454 Auto-Submit: Christian Biesinger <[email protected]> Commit-Queue: Ian Kilpatrick <[email protected]> Reviewed-by: Ian Kilpatrick <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#780870} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 6e558e21d4240c7d676e049f9ae2d7691356decd
This has landed on Firefox 108 Developer Edition |
Problem:
Implementing aspect ratios during the first layout calculation for when various aspect ratios are utilized, such as with art direction.
Avoid any extra layout calculation's after initial layout. (avoiding page jumps!)
Avoid writing any CSS for the aspect ratio.
Avoid needing custom JS to do any of this.
Use Case:
Using multiple
<source>
's within<picture>
or<video>
Requirements:
Aspect-ratio MUST be known for each source.
(ideally it should match the intrinsic ratio of source asset, otherwise when the asset loads the intrinsic ratio changes and may cause layout recalc? which we want to avoid!)
New attributes(s) for
<source>
:width="1600" height="900"
(16/9 ratio)Both
width and height
of the source must be supplied for a ratio to be calculated.e.g.
<source srcset="https://via.placeholder.com/600x279" media="(max-width: 599px)" width="600" height="279">
My thoughts on implementation for
<picture>
Either the
<img>
inside<picture>
or the<picture>
element itself will have the aspect ratio applied to it.The text was updated successfully, but these errors were encountered: