Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 2c67cb17aa9c83a86e3882206ecf8ad5aeea49c9
https://github.com/WebKit/WebKit/commit/2c67cb17aa9c83a86e3882206ecf8ad5aeea49c9
Author: Anne van Kesteren <[email protected]>
Date: 2026-09-15 (Tue, 15 Sep 2026)
Changed paths:
M
LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/naturalWidth-naturalHeight-width-height.html
M
LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/w3c-import.log
A
LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/width-height-attribute-parsing-expected.txt
A
LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/width-height-attribute-parsing.html
A
LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-input-element/image-width-height-expected.txt
A
LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-input-element/image-width-height.html
M
LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-input-element/w3c-import.log
M Source/WebCore/html/HTMLImageElement.cpp
M Source/WebCore/html/HTMLImageElement.h
Log Message:
-----------
<img>.width and .height are not density-corrected when the image is not being
rendered
https://bugs.webkit.org/show_bug.cgi?id=323210
Reviewed by Said Abou-Hallawa.
HTMLImageElement::width() and height() fall back to the image's natural
size when the element is not being rendered, but did not pass the image's
device pixel ratio. I.e., for <img srcset="100x100.png 2x">, width
returned 50 while the image was being rendered and 100 once it was not,
and naturalWidth returned 50 throughout.
The HTML standard requires the density-corrected natural width and height
here as of https://github.com/whatwg/html/pull/12840
So we pass m_imageDevicePixelRatio, and move the computation into
naturalSize() so all four getters ask CachedImage the same question.
imageSizeForRenderer() and unclampedImageSizeForRenderer() only differ
when the multiplier is not 1, so this does not change naturalWidth or
naturalHeight.
Tests:
imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/width-height-attribute-parsing.html
imported/w3c/web-platform-tests/html/semantics/forms/the-input-element/image-width-height.html
Tests upstream: https://github.com/web-platform-tests/wpt/pull/61080
https://github.com/web-platform-tests/wpt/pull/62710
(The input test failures will be addressed in their own change.)
Canonical link: https://commits.webkit.org/321226@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications