Skip to content
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

Closed
AndresInSpace opened this issue Oct 3, 2019 · 11 comments
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: img topic: rendering

Comments

@AndresInSpace
Copy link

AndresInSpace commented Oct 3, 2019

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.

<picture>
  <source srcset="https://via.placeholder.com/600x279" media="(max-width: 599px)" width="600" height="279">
  <source srcset="https://via.placeholder.com/1500x300" media="(max-width: 991px)" width="1500" height="300">
  <img src="https://via.placeholder.com/1500x300" width="1500" height="300">
</picture>
@AndresInSpace AndresInSpace changed the title Utilizing Aspect-Ratio for Art Direction (Multiple Sources with various Aspect Ratios known) Utilizing Aspect-Ratio with Art Direction (Multiple Sources with various Aspect Ratios known) Oct 3, 2019
@yoavweiss
Copy link
Contributor

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 width and height attributes.

@AndresInSpace
Copy link
Author

AndresInSpace commented Oct 3, 2019

@yoavweiss
I agree on utilizing width="" height="" instead of ratio="" for consistency.
I will update my post to reflect this.

One question regarding changing the algorithm of update the image data:
Would this cause a re-calc of layout or would this pick the proper source before the first layout calc? I am unsure of the order of things here.

@annevk annevk added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: img topic: rendering labels Oct 6, 2019
@jensimmons
Copy link

I agree that the best solution is to have Authors put width and height attributes on each source inside <picture> (and video and anyplace else source is used for visual media) — and have the browser act as if the width and height attributes are being swapped into the <img> element in exactly the same way the src attribute is swapped.

I would not apply this to the picture element. (Which reminds me @fantasai and @emilio of that conversation we had when we discovered all the CSS being applied to picture that should be removed... that picture should have display: contents applied instead — we should find & file that issue).

@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 img, along with src — everything else should happen just as if the IMG only had one URL, one height, one width, and there were no other sources.

@zcorpan
Copy link
Member

zcorpan commented Oct 8, 2019

(and video and anyplace else source is used for visual media)

Nope, video doesn't do art direction. #4544

@AndresInSpace
Copy link
Author

@jensimmons Perfect.
@zcorpan I think the arguments for it carries more weight than the argument against it. I've posted my thoughts over in #4544

bertogg pushed a commit to Igalia/webkit that referenced this issue Jan 16, 2020
…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
@Crissov
Copy link

Crissov commented Jun 16, 2020

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)?

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jun 19, 2020
<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
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jun 22, 2020
<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 <cbiesinger@chromium.org>
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780870}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jun 22, 2020
<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 <cbiesinger@chromium.org>
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780870}
blueboxd pushed a commit to blueboxd/chromium-legacy that referenced this issue Jun 22, 2020
<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 <cbiesinger@chromium.org>
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780870}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Jun 24, 2020
…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 <cbiesinger@chromium.org>
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780870}

--

wpt-commits: 0c5883bd05b5d962ae68998b450510582e6ef6ca
wpt-pr: 24256
xeonchen pushed a commit to xeonchen/gecko that referenced this issue Jun 26, 2020
…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 <cbiesinger@chromium.org>
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780870}

--

wpt-commits: 0c5883bd05b5d962ae68998b450510582e6ef6ca
wpt-pr: 24256
ryanhaddad pushed a commit to WebKit/WebKit that referenced this issue Dec 22, 2020
…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
@patricknelson
Copy link

For reference, this is now documented at (via PR #5894):
https://html.spec.whatwg.org/multipage/embedded-content.html#the-source-element

Thank you for adding this to the spec! 🎉

@cbiesinger
Copy link

It will also ship in Chrome 90! I believe Firefox is also working on it, don't know about their schedule.

@hecktarzuli
Copy link

This is in Safari 15

@hecktarzuli
Copy link

For those looking for FF support, this seems to be the Firefox tracking for this: https://bugzilla.mozilla.org/show_bug.cgi?id=1694741

mjfroman pushed a commit to mjfroman/moz-libwebrtc-third-party that referenced this issue Oct 14, 2022
<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 <cbiesinger@chromium.org>
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#780870}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 6e558e21d4240c7d676e049f9ae2d7691356decd
@y-commit69
Copy link

For those looking for FF support, this seems to be the Firefox tracking for this: https://bugzilla.mozilla.org/show_bug.cgi?id=1694741

This has landed on Firefox 108 Developer Edition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: img topic: rendering
Development

No branches or pull requests

10 participants