Bug 150443 - <img>.naturalWidth should return the density-corrected intrinsic width
Summary: <img>.naturalWidth should return the density-corrected intrinsic width
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Images (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Noam Rosenthal
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-10-22 03:39 PDT by Simon Pieters
Modified: 2020-01-08 15:39 PST (History)
16 users (show)

See Also:


Attachments
Patch (4.96 KB, patch)
2019-12-25 06:53 PST, Noam Rosenthal
no flags Details | Formatted Diff | Diff
Patch (12.26 KB, patch)
2019-12-25 13:58 PST, Noam Rosenthal
no flags Details | Formatted Diff | Diff
Patch (12.25 KB, patch)
2020-01-08 10:32 PST, Noam Rosenthal
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Pieters 2015-10-22 03:39:04 PDT
Consider

   <img srcset="http://placehold.it/240 2x" onload="alert(this.naturalWidth)">

Per spec it should alert 120. WebKit alerts 240. Gecko and Blink match the spec, I don't know about Edge.

https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-naturalwidth

I would recommend waiting with fixing this bug until .currentSrc is implemented, since exploiting this bug can be a poor man's .currentSrc; see http://stackoverflow.com/questions/33231426/get-the-currentsrc-of-responsive-image-on-safari/33278821
Comment 1 Noam Rosenthal 2019-12-25 06:53:24 PST
Created attachment 386408 [details]
Patch
Comment 2 Noam Rosenthal 2019-12-25 13:58:43 PST
Created attachment 386412 [details]
Patch
Comment 3 Simon Fraser (smfr) 2020-01-08 10:05:40 PST
Comment on attachment 386412 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=386412&action=review

> Source/WebCore/html/HTMLImageElement.cpp:534
> +float HTMLImageElement::effectiveImageDevicePixelRatio() const

The "device" in the name is confusing, but I guess we already have m_imageDevicePixelRatio.

> Source/WebCore/loader/cache/CachedImage.h:81
> +    LayoutSize nonClampedImageSizeForRenderer(const RenderElement* renderer, float multiplier, SizeType = UsedSize) const;

Maybe unclamped

> LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/intrinsicsize/intrinsicsize-with-responsive-images.tentative-expected.txt:8
> -FAIL Test image /images/green.png with width = 800, height = 800, and no specified sizes assert_equals: naturalWidth expected 400 but got 100
> +FAIL Test image /images/green.png with width = 800, height = 800, and no specified sizes assert_equals: naturalWidth expected 400 but got 33

Do you understand this behavior change?
Comment 4 Noam Rosenthal 2020-01-08 10:17:14 PST
> Maybe unclamped
OKEY

>> +FAIL Test image /images/green.png with width = 800, height = 800, and no specified sizes assert_equals: naturalWidth expected 400 but got 33

> Do you understand this behavior change?
Yes, it's the expected behavior change. That test happens to have images with srcset, and it's asking for their natural width/height.
Comment 5 Noam Rosenthal 2020-01-08 10:32:59 PST
Created attachment 387112 [details]
Patch
Comment 6 EWS 2020-01-08 11:55:48 PST
Comment on attachment 387112 [details]
Patch

Rejecting attachment 387112 [details] from commit-queue.

noam@webkit.org does not have committer permissions according to https://trac.webkit.org/browser/trunk/Tools/Scripts/webkitpy/common/config/contributors.json.

- If you do not have committer rights please read http://webkit.org/coding/contributing.html for instructions on how to use bugzilla flags.

- If you have committer rights please correct the error in Tools/Scripts/webkitpy/common/config/contributors.json by adding yourself to the file (no review needed).  The commit-queue restarts itself every 2 hours.  After restart the commit-queue will correctly respect your committer rights.
Comment 7 WebKit Commit Bot 2020-01-08 15:38:55 PST
Comment on attachment 387112 [details]
Patch

Clearing flags on attachment: 387112

Committed r254229: <https://trac.webkit.org/changeset/254229>
Comment 8 WebKit Commit Bot 2020-01-08 15:38:57 PST
All reviewed patches have been landed.  Closing bug.
Comment 9 Radar WebKit Bug Importer 2020-01-08 15:39:24 PST
<rdar://problem/58424497>