-
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
Use width and height as intrinsic aspect ratio for various non-img elements #4961
Comments
VIDEO should definitely be included here, and also INPUT type=image. EMBED and OBJECT are sometimes used for things which do not have an intrinsic aspect ratio, so they probably should not get this behavior. |
As suggested, I made a new proposal for aspect-ratio in regards to art-direction with multiple sources, each having their own aspect-ratio. |
This should apply to It should not apply to any element that does not have an intrinsic aspect ratio — like Needing a way to easily set an aspect ratio on TL;DR — this should apply to all elements that have an intrinsic aspect ratio, and none of the ones that do not. |
|
If any element, including embed or object, is getting its sizing from a parent container, or children content, then that will be part of the layout calculation in CSS. But the elements themselves do not have an intrinsic aspect ratio. https://www.w3.org/TR/css-sizing-3/#intrinsic-sizes |
They do have an intrinsic aspect ratio in all engines, as far as I can tell. Trivial example:
|
Yeah, |
…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
…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
Actually they don't. @cbiesinger where is it defined that |
The rendering section has:
As you note in #6527 that leaves something to be desired, but it's probably sufficient to close this issue? |
Although I guess one weird thing is that for |
Indeed. That's related to #6527, we don't really want to parse the attribute twice. |
Yes, what Anne said. |
Also map <canvas width height> to aspect-ratio consistently with how the attributes are parsed. Tests: web-platform-tests/wpt#28229. Follow-up: #6528. Closes #4961 and closes #6527.
Also map <canvas width height> to aspect-ratio consistently with how the attributes are parsed and clean up some wording. Tests: web-platform-tests/wpt#28229 & web-platform-tests/wpt#28932. Follow-up: #6528. Closes #4961 and closes #6527.
#4952 added support for a fallback aspect ratio for
<img>
, but as noted there by @cbiesinger @emilio @fantasai it might be good to also support<video>
,<input type=image>
, and perhaps other elements.#3090 has a similar suggestion for
<video>
that should probably be resolved while fixing this.The text was updated successfully, but these errors were encountered: