Changeset 276521 in webkit
- Timestamp:
- Apr 23, 2021 3:00:12 PM (15 months ago)
- Location:
- trunk
- Files:
-
- 7 edited
-
LayoutTests/imported/w3c/ChangeLog (modified) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/img-aspect-ratio-expected.txt (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/rendering/RenderImage.cpp (modified) (2 diffs)
-
Source/WebCore/rendering/RenderImage.h (modified) (1 diff)
-
Source/WebCore/rendering/RenderReplaced.cpp (modified) (2 diffs)
-
Source/WebCore/rendering/RenderReplaced.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/imported/w3c/ChangeLog
r276498 r276521 1 2021-04-23 Cathie Chen <cathiechen@igalia.com> 2 3 Not computing image aspect ratios from width and height attributes for lazy loaded images 4 https://bugs.webkit.org/show_bug.cgi?id=224197 5 6 Reviewed by Darin Adler. 7 8 The test cases for error images and images without src in img-aspect-ratio.html are passed. This patch 9 doesn't change the behavior of the original aspect ratio case, so it's failed like before. 10 11 * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/img-aspect-ratio-expected.txt: 12 1 13 2021-04-23 Cathie Chen <cathiechen@igalia.com> 2 14 -
trunk/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/img-aspect-ratio-expected.txt
r276498 r276521 37 37 PASS Loaded images test: <img> without width height attributes 38 38 PASS Loaded images test: <img> with width and height attributes, but conflicting to the original aspect ratio 39 FAIL Loaded images test: <img> with width, height and empty src attributes assert_approx_equals: aspect-ratio should override intrinsic size of images that don't have any src. expected 0.8 +/- 0.001 but got Infinity 40 FAIL Loaded images test: Error image with width and height attributes assert_approx_equals: aspect-ratio should affect the size of error images. expected 0.8 +/- 0.001 but got 1 39 PASS Loaded images test: <img> with width, height and empty src attributes 40 PASS Loaded images test: Error image with width and height attributes 41 41 PASS Loaded images test: Error image with width, height and alt attributes 42 42 FAIL Loaded images test: <img> with width and height attributes, but not equal to the original aspect ratio assert_approx_equals: The original aspect ratio of blue.png expected 1.2547169811320755 +/- 0.001 but got 1.25 -
trunk/Source/WebCore/ChangeLog
r276513 r276521 1 2021-04-23 Cathie Chen <cathiechen@igalia.com> 2 3 Not computing image aspect ratios from width and height attributes for lazy loaded images 4 https://bugs.webkit.org/show_bug.cgi?id=224197 5 6 Reviewed by Darin Adler. 7 8 This patch supports error images and lazy loaded images (without src attribute) to compute 9 implicit aspect ratios from width and height attributes. Refactor the code a bit. Added 10 intrinsicAspectRatioFromWidthHeight() to compute aspect ratio from width and height attributes when 11 the object is allowed to which is decided by canMapWidthHeightToAspectRatio(). 12 Remove `!downcast<RenderImage>(*this).cachedImage()` constraint, so that images without src attributes 13 is allowed. As to error images, compute the aspect ratio when the image shouldDisplayBrokenImageIcon(). 14 15 * rendering/RenderImage.cpp: 16 (WebCore::RenderImage::canMapWidthHeightToAspectRatio const): To indicate that the object is allowed 17 to compute aspect ratio from width and height attributes. 18 (WebCore::RenderImage::computeIntrinsicRatioInformation const): When shouldDisplayBrokenImageIcon(), 19 try to compute the aspect ratio from attributes width and height. 20 * rendering/RenderImage.h: 21 * rendering/RenderReplaced.cpp: 22 (WebCore::RenderReplaced::intrinsicAspectRatioFromWidthHeight const): Compute the aspect ratio from attributes width and height. 23 (WebCore::RenderReplaced::computeIntrinsicRatioInformation const): 24 * rendering/RenderReplaced.h: 25 (WebCore::RenderReplaced::canMapWidthHeightToAspectRatio const): Ditto. 26 1 27 2021-04-23 Michael Catanzaro <mcatanzaro@igalia.com> 2 28 -
trunk/Source/WebCore/rendering/RenderImage.cpp
r276388 r276521 843 843 } 844 844 845 bool RenderImage::canMapWidthHeightToAspectRatio() const 846 { 847 // The aspectRatioOfImgFromWidthAndHeight only applies to <img>. 848 return is<HTMLImageElement>(element()) && !isShowingAltText(); 849 } 850 845 851 void RenderImage::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio) const 846 852 { … … 859 865 // Don't compute an intrinsic ratio to preserve historical WebKit behavior if we're painting alt text and/or a broken image. 860 866 if (shouldDisplayBrokenImageIcon()) { 867 if (!style().hasAspectRatio()) { 868 intrinsicRatio = intrinsicAspectRatioFromWidthHeight().valueOr(1); 869 return; 870 } 861 871 intrinsicRatio = 1; 862 872 return; -
trunk/Source/WebCore/rendering/RenderImage.h
r276331 r276521 104 104 } 105 105 106 bool canMapWidthHeightToAspectRatio() const override; 107 106 108 private: 107 109 const char* renderName() const override { return "RenderImage"; } -
trunk/Source/WebCore/rendering/RenderReplaced.cpp
r276228 r276521 475 475 } 476 476 477 Optional<double> RenderReplaced::intrinsicAspectRatioFromWidthHeight() const 478 { 479 if (!settings().aspectRatioOfImgFromWidthAndHeightEnabled()) 480 return Optional<double>(); 481 482 if (!canMapWidthHeightToAspectRatio()) 483 return Optional<double>(); 484 485 ASSERT(element()); 486 double attributeWidth = parseValidHTMLFloatingPointNumber(element()->getAttribute(HTMLNames::widthAttr)).valueOr(0); 487 double attributeHeight = parseValidHTMLFloatingPointNumber(element()->getAttribute(HTMLNames::heightAttr)).valueOr(0); 488 if (attributeWidth > 0 && attributeHeight > 0) 489 return attributeWidth / attributeHeight; 490 491 return Optional<double>(); 492 } 493 477 494 void RenderReplaced::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio) const 478 495 { … … 491 508 492 509 if (intrinsicSize.isEmpty()) { 493 if (!settings().aspectRatioOfImgFromWidthAndHeightEnabled()) 494 return; 495 496 auto* node = element(); 497 // The aspectRatioOfImgFromWidthAndHeight only applies to <img>. 498 if (!node || !is<HTMLImageElement>(*node) || !node->hasAttribute(HTMLNames::widthAttr) || !node->hasAttribute(HTMLNames::heightAttr)) 499 return; 500 501 // We shouldn't override the aspect-ratio when the <img> element has an empty src attribute. 502 if (!is<RenderImage>(*this) || !downcast<RenderImage>(*this).cachedImage()) 503 return; 504 505 double attributeWidth = parseValidHTMLFloatingPointNumber(node->getAttribute(HTMLNames::widthAttr)).valueOr(0); 506 double attributeHeight = parseValidHTMLFloatingPointNumber(node->getAttribute(HTMLNames::heightAttr)).valueOr(0); 507 if (attributeWidth > 0 && attributeHeight > 0) 508 intrinsicRatio = attributeWidth / attributeHeight; 510 intrinsicRatio = intrinsicAspectRatioFromWidthHeight().valueOr(0); 509 511 return; 510 512 } -
trunk/Source/WebCore/rendering/RenderReplaced.h
r272711 r276521 59 59 void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const final; 60 60 61 // This function determines if the object is allowed to compute aspect ratio from attributes width and height. 62 virtual bool canMapWidthHeightToAspectRatio() const { return false; } 63 Optional<double> intrinsicAspectRatioFromWidthHeight() const; 64 61 65 virtual LayoutUnit minimumReplacedHeight() const { return 0_lu; } 62 66
Note: See TracChangeset
for help on using the changeset viewer.