Bug 150443

Summary: <img>.naturalWidth should return the density-corrected intrinsic width
Product: WebKit Reporter: Simon Pieters (:zcorpan) <zcorpan>
Component: ImagesAssignee: Noam Rosenthal <noam>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, commit-queue, dbates, dino, don.olmstead, e, esprehn+autocc, ews-feeder, ews-watchlist, gyuyoung.kim, japhet, noam, sabouhallawa, simon.fraser, webkit-bug-importer, yoav
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=144095
Attachments:
Description Flags
Patch
none
Patch
none
Patch none

Description Simon Pieters (:zcorpan) 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>