Title: [254648] branches/safari-609-branch
Revision
254648
Author
alanc...@apple.com
Date
2020-01-15 15:07:41 -0800 (Wed, 15 Jan 2020)

Log Message

Cherry-pick r254229. rdar://problem/58605950

    <img>.naturalWidth should return the density-corrected intrinsic width
    https://bugs.webkit.org/show_bug.cgi?id=150443

    Patch by Noam Rosenthal <n...@webkit.org> on 2020-01-08
    Reviewed by Simon Fraser.

    LayoutTests/imported/w3c:

    Updated expected results.

    * web-platform-tests/html/semantics/embedded-content/the-img-element/current-pixel-density/basic-expected.txt:
            All tests now pass.

    * web-platform-tests/html/semantics/embedded-content/the-img-element/intrinsicsize/intrinsicsize-with-responsive-images.tentative-expected.txt:
            Still fails but failure values are different.

    Source/WebCore:

    Take image's density into account when requesting naturalWidth/naturalHeight, not in SVG.

    This now complies with the standard (https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-naturalwidth)
    It also matches the behavior on Chrome and on Firefox.

    Test: imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/current-pixel-density/basic.html
            Updaded expected results

    * html/HTMLImageElement.cpp:
    (WebCore::HTMLImageElement::effectiveImageDevicePixelRatio const):
    (WebCore::HTMLImageElement::naturalWidth const):
    (WebCore::HTMLImageElement::naturalHeight const):
    * html/HTMLImageElement.h:
            Use effective image devicePixelRatio for naturalWidth/height calculation

    * loader/cache/CachedImage.cpp:
    (WebCore::CachedImage::unclampedImageSizeForRenderer const):
    (WebCore::CachedImage::imageSizeForRenderer const):
    * loader/cache/CachedImage.h:
            Don't clamp to 1 when calculating naturalWidth/naturalHeight, as this has
            nothing to do with zoomed images. Zoomed images behavior remains the same.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254229 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Property Changed

Diff

Modified: branches/safari-609-branch/LayoutTests/imported/w3c/ChangeLog (254647 => 254648)


--- branches/safari-609-branch/LayoutTests/imported/w3c/ChangeLog	2020-01-15 23:07:36 UTC (rev 254647)
+++ branches/safari-609-branch/LayoutTests/imported/w3c/ChangeLog	2020-01-15 23:07:41 UTC (rev 254648)
@@ -1,5 +1,66 @@
 2020-01-15  Alan Coon  <alanc...@apple.com>
 
+        Cherry-pick r254229. rdar://problem/58605950
+
+    <img>.naturalWidth should return the density-corrected intrinsic width
+    https://bugs.webkit.org/show_bug.cgi?id=150443
+    
+    Patch by Noam Rosenthal <n...@webkit.org> on 2020-01-08
+    Reviewed by Simon Fraser.
+    
+    LayoutTests/imported/w3c:
+    
+    Updated expected results.
+    
+    * web-platform-tests/html/semantics/embedded-content/the-img-element/current-pixel-density/basic-expected.txt:
+            All tests now pass.
+    
+    * web-platform-tests/html/semantics/embedded-content/the-img-element/intrinsicsize/intrinsicsize-with-responsive-images.tentative-expected.txt:
+            Still fails but failure values are different.
+    
+    Source/WebCore:
+    
+    Take image's density into account when requesting naturalWidth/naturalHeight, not in SVG.
+    
+    This now complies with the standard (https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-naturalwidth)
+    It also matches the behavior on Chrome and on Firefox.
+    
+    Test: imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/current-pixel-density/basic.html
+            Updaded expected results
+    
+    * html/HTMLImageElement.cpp:
+    (WebCore::HTMLImageElement::effectiveImageDevicePixelRatio const):
+    (WebCore::HTMLImageElement::naturalWidth const):
+    (WebCore::HTMLImageElement::naturalHeight const):
+    * html/HTMLImageElement.h:
+            Use effective image devicePixelRatio for naturalWidth/height calculation
+    
+    * loader/cache/CachedImage.cpp:
+    (WebCore::CachedImage::unclampedImageSizeForRenderer const):
+    (WebCore::CachedImage::imageSizeForRenderer const):
+    * loader/cache/CachedImage.h:
+            Don't clamp to 1 when calculating naturalWidth/naturalHeight, as this has
+            nothing to do with zoomed images. Zoomed images behavior remains the same.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254229 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-01-08  Noam Rosenthal  <n...@webkit.org>
+
+            <img>.naturalWidth should return the density-corrected intrinsic width
+            https://bugs.webkit.org/show_bug.cgi?id=150443
+
+            Reviewed by Simon Fraser.
+
+            Updated expected results.
+
+            * web-platform-tests/html/semantics/embedded-content/the-img-element/current-pixel-density/basic-expected.txt:
+                    All tests now pass.
+
+            * web-platform-tests/html/semantics/embedded-content/the-img-element/intrinsicsize/intrinsicsize-with-responsive-images.tentative-expected.txt:
+                    Still fails but failure values are different.
+
+2020-01-15  Alan Coon  <alanc...@apple.com>
+
         Cherry-pick r254187. rdar://problem/58605950
 
     Implement css3-images image-orientation

Modified: branches/safari-609-branch/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/current-pixel-density/basic-expected.txt (254647 => 254648)


--- branches/safari-609-branch/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/current-pixel-density/basic-expected.txt	2020-01-15 23:07:36 UTC (rev 254647)
+++ branches/safari-609-branch/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/current-pixel-density/basic-expected.txt	2020-01-15 23:07:41 UTC (rev 254648)
@@ -1,15 +1,15 @@
 
 PASS <img src="" data-expect="256"> 
 PASS <img srcset="/images/green-256x256.png 1x" data-expect="256"> 
-FAIL <img srcset="/images/green-256x256.png 1.6x" data-expect="160"> assert_equals: naturalWidth expected 160 but got 256
-FAIL <img srcset="/images/green-256x256.png 2x" data-expect="128"> assert_equals: naturalWidth expected 128 but got 256
-FAIL <img srcset="/images/green-256x256.png 10000x" data-expect="0"> assert_equals: naturalWidth expected 0 but got 256
+PASS <img srcset="/images/green-256x256.png 1.6x" data-expect="160"> 
+PASS <img srcset="/images/green-256x256.png 2x" data-expect="128"> 
+PASS <img srcset="/images/green-256x256.png 10000x" data-expect="0"> 
 PASS <img srcset="/images/green-256x256.png 9e99999999999999999999999x" data-expect="0"> 
 PASS <img srcset="/images/green-256x256.png 256w" sizes="256px" data-expect="256"> 
-FAIL <img srcset="/images/green-256x256.png 512w" sizes="256px" data-expect="128"> assert_equals: naturalWidth expected 128 but got 256
-FAIL <img srcset="/images/green-256x256.png 256w" sizes="512px" data-expect="512"> assert_equals: naturalWidth expected 512 but got 256
-FAIL <img srcset="/images/green-256x256.png 256w" sizes="1px" data-expect="1"> assert_equals: naturalWidth expected 1 but got 256
-FAIL <img srcset="/images/green-256x256.png 256w" sizes="0px" data-expect="0"> assert_equals: naturalWidth expected 0 but got 256
+PASS <img srcset="/images/green-256x256.png 512w" sizes="256px" data-expect="128"> 
+PASS <img srcset="/images/green-256x256.png 256w" sizes="512px" data-expect="512"> 
+PASS <img srcset="/images/green-256x256.png 256w" sizes="1px" data-expect="1"> 
+PASS <img srcset="/images/green-256x256.png 256w" sizes="0px" data-expect="0"> 
 PASS <img srcset="data:image/svg+xml,<svg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='-1%20-1%202%202'%20width='20'%20height='20'><circle%20r='1'/></svg> 2x" data-expect="10"> 
 PASS <img srcset="data:image/svg+xml,<svg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='-1%20-1%202%202'%20width='20'><circle%20r='1'/></svg> 2x" data-expect="10"> 
 PASS <img srcset="data:image/svg+xml,<svg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='-1%20-1%202%202'%20height='20'><circle%20r='1'/></svg> 2x" data-expect="10"> 

Modified: branches/safari-609-branch/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/intrinsicsize/intrinsicsize-with-responsive-images.tentative-expected.txt (254647 => 254648)


--- branches/safari-609-branch/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/intrinsicsize/intrinsicsize-with-responsive-images.tentative-expected.txt	2020-01-15 23:07:36 UTC (rev 254647)
+++ branches/safari-609-branch/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/intrinsicsize/intrinsicsize-with-responsive-images.tentative-expected.txt	2020-01-15 23:07:41 UTC (rev 254648)
@@ -5,6 +5,6 @@
 FAIL Test image /images/green.svg with width = 800, height = 800, and no specified sizes assert_equals: naturalWidth expected 400 but got 800
 FAIL Test image /images/green.png with no specified sizes, width, or height assert_equals: width expected 400 but got 33
 FAIL Test image /images/green.png with width = 800, no specified sizes, or height assert_equals: height expected 1000 but got 400
-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
 FAIL Test image (32 x 32) with sizes = 100 and srcset descriptor = 32w assert_equals: height expected 125 but got 100
 

Modified: branches/safari-609-branch/Source/WebCore/ChangeLog (254647 => 254648)


--- branches/safari-609-branch/Source/WebCore/ChangeLog	2020-01-15 23:07:36 UTC (rev 254647)
+++ branches/safari-609-branch/Source/WebCore/ChangeLog	2020-01-15 23:07:41 UTC (rev 254648)
@@ -1,5 +1,80 @@
 2020-01-15  Alan Coon  <alanc...@apple.com>
 
+        Cherry-pick r254229. rdar://problem/58605950
+
+    <img>.naturalWidth should return the density-corrected intrinsic width
+    https://bugs.webkit.org/show_bug.cgi?id=150443
+    
+    Patch by Noam Rosenthal <n...@webkit.org> on 2020-01-08
+    Reviewed by Simon Fraser.
+    
+    LayoutTests/imported/w3c:
+    
+    Updated expected results.
+    
+    * web-platform-tests/html/semantics/embedded-content/the-img-element/current-pixel-density/basic-expected.txt:
+            All tests now pass.
+    
+    * web-platform-tests/html/semantics/embedded-content/the-img-element/intrinsicsize/intrinsicsize-with-responsive-images.tentative-expected.txt:
+            Still fails but failure values are different.
+    
+    Source/WebCore:
+    
+    Take image's density into account when requesting naturalWidth/naturalHeight, not in SVG.
+    
+    This now complies with the standard (https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-naturalwidth)
+    It also matches the behavior on Chrome and on Firefox.
+    
+    Test: imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/current-pixel-density/basic.html
+            Updaded expected results
+    
+    * html/HTMLImageElement.cpp:
+    (WebCore::HTMLImageElement::effectiveImageDevicePixelRatio const):
+    (WebCore::HTMLImageElement::naturalWidth const):
+    (WebCore::HTMLImageElement::naturalHeight const):
+    * html/HTMLImageElement.h:
+            Use effective image devicePixelRatio for naturalWidth/height calculation
+    
+    * loader/cache/CachedImage.cpp:
+    (WebCore::CachedImage::unclampedImageSizeForRenderer const):
+    (WebCore::CachedImage::imageSizeForRenderer const):
+    * loader/cache/CachedImage.h:
+            Don't clamp to 1 when calculating naturalWidth/naturalHeight, as this has
+            nothing to do with zoomed images. Zoomed images behavior remains the same.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254229 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-01-08  Noam Rosenthal  <n...@webkit.org>
+
+            <img>.naturalWidth should return the density-corrected intrinsic width
+            https://bugs.webkit.org/show_bug.cgi?id=150443
+
+            Reviewed by Simon Fraser.
+
+            Take image's density into account when requesting naturalWidth/naturalHeight, not in SVG.
+
+            This now complies with the standard (https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-naturalwidth)
+            It also matches the behavior on Chrome and on Firefox.
+
+            Test: imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/current-pixel-density/basic.html
+                    Updaded expected results
+
+            * html/HTMLImageElement.cpp:
+            (WebCore::HTMLImageElement::effectiveImageDevicePixelRatio const):
+            (WebCore::HTMLImageElement::naturalWidth const):
+            (WebCore::HTMLImageElement::naturalHeight const):
+            * html/HTMLImageElement.h:
+                    Use effective image devicePixelRatio for naturalWidth/height calculation
+
+            * loader/cache/CachedImage.cpp:
+            (WebCore::CachedImage::unclampedImageSizeForRenderer const):
+            (WebCore::CachedImage::imageSizeForRenderer const):
+            * loader/cache/CachedImage.h:
+                    Don't clamp to 1 when calculating naturalWidth/naturalHeight, as this has
+                    nothing to do with zoomed images. Zoomed images behavior remains the same.
+
+2020-01-15  Alan Coon  <alanc...@apple.com>
+
         Cherry-pick r254187. rdar://problem/58605950
 
     Implement css3-images image-orientation

Modified: branches/safari-609-branch/Source/WebCore/html/HTMLImageElement.cpp (254647 => 254648)


--- branches/safari-609-branch/Source/WebCore/html/HTMLImageElement.cpp	2020-01-15 23:07:36 UTC (rev 254647)
+++ branches/safari-609-branch/Source/WebCore/html/HTMLImageElement.cpp	2020-01-15 23:07:41 UTC (rev 254648)
@@ -531,12 +531,25 @@
     return adjustForAbsoluteZoom(snappedIntRect(contentRect).height(), *box);
 }
 
+float HTMLImageElement::effectiveImageDevicePixelRatio() const
+{
+    if (!m_imageLoader->image())
+        return 1.0f;
+
+    auto* image = m_imageLoader->image()->image();
+
+    if (image && image->isSVGImage())
+        return 1.0f;
+
+    return m_imageDevicePixelRatio;
+}
+
 int HTMLImageElement::naturalWidth() const
 {
     if (!m_imageLoader->image())
         return 0;
 
-    return m_imageLoader->image()->imageSizeForRenderer(renderer(), 1.0f).width();
+    return m_imageLoader->image()->unclampedImageSizeForRenderer(renderer(), effectiveImageDevicePixelRatio()).width();
 }
 
 int HTMLImageElement::naturalHeight() const
@@ -544,7 +557,7 @@
     if (!m_imageLoader->image())
         return 0;
 
-    return m_imageLoader->image()->imageSizeForRenderer(renderer(), 1.0f).height();
+    return m_imageLoader->image()->unclampedImageSizeForRenderer(renderer(), effectiveImageDevicePixelRatio()).height();
 }
 
 bool HTMLImageElement::isURLAttribute(const Attribute& attribute) const
Property changes on: branches/safari-609-branch/Source/WebCore/html/HTMLImageElement.cpp
___________________________________________________________________

Added: svn:executable

+* \ No newline at end of property

Modified: branches/safari-609-branch/Source/WebCore/html/HTMLImageElement.h (254647 => 254648)


--- branches/safari-609-branch/Source/WebCore/html/HTMLImageElement.h	2020-01-15 23:07:36 UTC (rev 254647)
+++ branches/safari-609-branch/Source/WebCore/html/HTMLImageElement.h	2020-01-15 23:07:41 UTC (rev 254648)
@@ -178,6 +178,8 @@
 
     void copyNonAttributePropertiesFromElement(const Element&) final;
 
+    float effectiveImageDevicePixelRatio() const;
+
 #if ENABLE(SERVICE_CONTROLS)
     void updateImageControls();
     void tryCreateImageControls();

Modified: branches/safari-609-branch/Source/WebCore/loader/cache/CachedImage.cpp (254647 => 254648)


--- branches/safari-609-branch/Source/WebCore/loader/cache/CachedImage.cpp	2020-01-15 23:07:36 UTC (rev 254647)
+++ branches/safari-609-branch/Source/WebCore/loader/cache/CachedImage.cpp	2020-01-15 23:07:41 UTC (rev 254648)
@@ -286,18 +286,29 @@
     return m_image->size(renderer ? renderer->imageOrientation() : ImageOrientation(ImageOrientation::FromImage));
 }
 
-LayoutSize CachedImage::imageSizeForRenderer(const RenderElement* renderer, float multiplier, SizeType sizeType) const
+
+LayoutSize CachedImage::unclampedImageSizeForRenderer(const RenderElement* renderer, float multiplier, SizeType sizeType) const
 {
     LayoutSize imageSize = LayoutSize(imageSizeForRenderer(renderer, sizeType));
     if (imageSize.isEmpty() || multiplier == 1.0f)
         return imageSize;
 
-    // Don't let images that have a width/height >= 1 shrink below 1 when zoomed.
     float widthScale = m_image->hasRelativeWidth() ? 1.0f : multiplier;
     float heightScale = m_image->hasRelativeHeight() ? 1.0f : multiplier;
+    imageSize.scale(widthScale, heightScale);
+    return imageSize;    
+}
+
+LayoutSize CachedImage::imageSizeForRenderer(const RenderElement* renderer, float multiplier, SizeType sizeType) const
+{
+    auto imageSize = unclampedImageSizeForRenderer(renderer, multiplier, sizeType);
+    if (imageSize.isEmpty() || multiplier == 1.0f)
+        return imageSize;
+
+    // Don't let images that have a width/height >= 1 shrink below 1 when zoomed.
     LayoutSize minimumSize(imageSize.width() > 0 ? 1 : 0, imageSize.height() > 0 ? 1 : 0);
-    imageSize.scale(widthScale, heightScale);
     imageSize.clampToMinimumSize(minimumSize);
+
     ASSERT(multiplier != 1.0f || (imageSize.width().fraction() == 0.0f && imageSize.height().fraction() == 0.0f));
     return imageSize;
 }

Modified: branches/safari-609-branch/Source/WebCore/loader/cache/CachedImage.h (254647 => 254648)


--- branches/safari-609-branch/Source/WebCore/loader/cache/CachedImage.h	2020-01-15 23:07:36 UTC (rev 254647)
+++ branches/safari-609-branch/Source/WebCore/loader/cache/CachedImage.h	2020-01-15 23:07:41 UTC (rev 254648)
@@ -78,6 +78,7 @@
     WEBCORE_EXPORT FloatSize imageSizeForRenderer(const RenderElement* renderer, SizeType = UsedSize) const;
     // This method takes a zoom multiplier that can be used to increase the natural size of the image by the zoom.
     LayoutSize imageSizeForRenderer(const RenderElement*, float multiplier, SizeType = UsedSize) const; // returns the size of the complete image.
+    LayoutSize unclampedImageSizeForRenderer(const RenderElement* renderer, float multiplier, SizeType = UsedSize) const;
     void computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio);
 
     bool isManuallyCached() const { return m_isManuallyCached; }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to