Changeset 277997 in webkit
- Timestamp:
- May 24, 2021, 10:39:12 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 13 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)
-
LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/video-aspect-ratio-expected.txt (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/html/HTMLElement.cpp (modified) (2 diffs)
-
Source/WebCore/html/HTMLElement.h (modified) (1 diff)
-
Source/WebCore/html/HTMLImageElement.cpp (modified) (1 diff)
-
Source/WebCore/html/HTMLInputElement.cpp (modified) (1 diff)
-
Source/WebCore/html/HTMLVideoElement.cpp (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
r277970 r277997 1 2021-05-24 Cathie Chen <cathiechen@igalia.com> 2 3 Use the parsed width and height attributes as a presentational hint for aspect-ratio CSS property 4 https://bugs.webkit.org/show_bug.cgi?id=217529 5 6 Reviewed by Antti Koivisto. 7 8 Update the expected results of test_computed_style which are passed now. 9 10 * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/img-aspect-ratio-expected.txt: 11 * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/video-aspect-ratio-expected.txt: 12 1 13 2021-05-24 Cameron McCormack <heycam@apple.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
r276521 r277997 5 5 PASS Create, append and test immediately: <img> with attributes width=0.8, height=0.2 6 6 PASS Create, append and test immediately: <img> with attributes width=50% height=25% 7 FAIL Computed style test: img with {"width":"10","height":"20"} assert_equals: expected "auto 10 / 20" but got "auto" 8 FAIL Computed style test: input with {"type":"image","width":"10","height":"20"} assert_equals: expected "auto 10 / 20" but got "auto" 7 PASS Computed style test: img with {"width":"10","height":"20"} 8 PASS Computed style test: input with {"type":"image","width":"10","height":"20"} 9 9 PASS Computed style test: input with {"type":"submit","width":"10","height":"20"} 10 FAIL Computed style test: img with {"width":"0","height":"1"} assert_equals: expected "auto 0 / 1" but got "auto" 11 FAIL Computed style test: input with {"type":"image","width":"0","height":"1"} assert_equals: expected "auto 0 / 1" but got "auto" 10 PASS Computed style test: img with {"width":"0","height":"1"} 11 PASS Computed style test: input with {"type":"image","width":"0","height":"1"} 12 12 PASS Computed style test: input with {"type":"submit","width":"0","height":"1"} 13 FAIL Computed style test: img with {"width":"1","height":"0"} assert_equals: expected "auto 1 / 0" but got "auto" 14 FAIL Computed style test: input with {"type":"image","width":"1","height":"0"} assert_equals: expected "auto 1 / 0" but got "auto" 13 PASS Computed style test: img with {"width":"1","height":"0"} 14 PASS Computed style test: input with {"type":"image","width":"1","height":"0"} 15 15 PASS Computed style test: input with {"type":"submit","width":"1","height":"0"} 16 FAIL Computed style test: img with {"width":"0","height":"0"} assert_equals: expected "auto 0 / 0" but got "auto" 17 FAIL Computed style test: input with {"type":"image","width":"0","height":"0"} assert_equals: expected "auto 0 / 0" but got "auto" 16 PASS Computed style test: img with {"width":"0","height":"0"} 17 PASS Computed style test: input with {"type":"image","width":"0","height":"0"} 18 18 PASS Computed style test: input with {"type":"submit","width":"0","height":"0"} 19 FAIL Computed style test: img with {"width":"0.5","height":"1.5"} assert_equals: expected "auto 0.5 / 1.5" but got "auto" 20 FAIL Computed style test: input with {"type":"image","width":"0.5","height":"1.5"} assert_equals: expected "auto 0.5 / 1.5" but got "auto" 19 PASS Computed style test: img with {"width":"0.5","height":"1.5"} 20 PASS Computed style test: input with {"type":"image","width":"0.5","height":"1.5"} 21 21 PASS Computed style test: input with {"type":"submit","width":"0.5","height":"1.5"} 22 22 PASS Computed style test: img with {"width":null,"height":null} -
trunk/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/video-aspect-ratio-expected.txt
r277321 r277997 1 1 2 2 3 FAIL Video width and height attributes are not used to infer aspect-ratio assert_approx_equals: expected 2.5 +/- 0.001 but got Infinity 4 FAIL Computed style test: video with {"width":"10","height":"20"} assert_equals: expected "auto 10 / 20" but got "auto" 5 FAIL Computed style test: video with {"width":"0.5","height":"1.5"} assert_equals: expected "auto 0.5 / 1.5" but got "auto" 3 PASS Video width and height attributes are not used to infer aspect-ratio 4 PASS Computed style test: video with {"width":"10","height":"20"} 5 PASS Computed style test: video with {"width":"0.5","height":"1.5"} 6 6 PASS Computed style test: video with {"width":"0","height":"1"} 7 7 PASS Computed style test: video with {"width":"1","height":"0"} -
trunk/Source/WebCore/ChangeLog
r277996 r277997 1 2021-05-24 Cathie Chen <cathiechen@igalia.com> 2 3 Use the parsed width and height attributes as a presentational hint for aspect-ratio CSS property 4 https://bugs.webkit.org/show_bug.cgi?id=217529 5 6 Reviewed by Antti Koivisto. 7 8 The feature "mapping attributes width and height to aspect ratio" currently is handled by RenderReplaced::computeIntrinsicRatioInformation. 9 However, per [1], the non-negative width and height attributes are expected to be used as a presentational hint for the aspect-ratio property. 10 This patch addes HTMLElement::applyAspectRatioFromWidthAndHeightAttributesToStyle to apply the attributes to m_presentationAttributeStyle. 11 Also this patch supports the feature for <video> and <input> with type="image". 12 13 [1] https://html.spec.whatwg.org/#map-to-the-aspect-ratio-property-(using-dimension-rules) 14 15 * html/HTMLElement.cpp: 16 (WebCore::HTMLElement::applyAspectRatioFromWidthAndHeightAttributesToStyle): Apply attributes width / height to aspectRatio of style if they aren't negative. 17 * html/HTMLElement.h: 18 * html/HTMLImageElement.cpp: 19 (WebCore::HTMLImageElement::collectStyleForPresentationAttribute): Use attributes width and height as a presentational hint for aspect-ratio. 20 * html/HTMLInputElement.cpp: 21 (WebCore::HTMLInputElement::collectStyleForPresentationAttribute): If isImageButton(), collect attributes width and height as aspect-ratio of m_presentationAttributeStyle. 22 * html/HTMLVideoElement.cpp: 23 (WebCore::HTMLVideoElement::collectStyleForPresentationAttribute): Ditto. 24 * rendering/RenderImage.cpp: 25 (WebCore::RenderImage::computeIntrinsicRatioInformation const): The intrinsicRatio is logicalAspectRatio() 26 if error image is not showing alt text. 27 (WebCore::RenderImage::canMapWidthHeightToAspectRatio const): Deleted. Remove the legacy code. 28 * rendering/RenderImage.h: 29 * rendering/RenderReplaced.cpp: 30 (WebCore::RenderReplaced::computeIntrinsicRatioInformation const): Ditto. 31 (WebCore::RenderReplaced::intrinsicAspectRatioFromWidthHeight const): Deleted. Ditto. 32 * rendering/RenderReplaced.h: 33 (WebCore::RenderReplaced::canMapWidthHeightToAspectRatio const): Deleted. Ditto. 34 1 35 2021-05-24 Commit Queue <commit-queue@webkit.org> 2 36 -
trunk/Source/WebCore/html/HTMLElement.cpp
r277527 r277997 29 29 #include "CSSPropertyNames.h" 30 30 #include "CSSValueKeywords.h" 31 #include "CSSValueList.h" 31 32 #include "CSSValuePool.h" 32 33 #include "Chrome.h" … … 621 622 } 622 623 624 void HTMLElement::applyAspectRatioFromWidthAndHeightAttributesToStyle(MutableStyleProperties& style) 625 { 626 if (!document().settings().aspectRatioOfImgFromWidthAndHeightEnabled()) 627 return; 628 629 double width = parseValidHTMLFloatingPointNumber(attributeWithoutSynchronization(widthAttr)).valueOr(-1); 630 if (width < 0) 631 return; 632 double height = parseValidHTMLFloatingPointNumber(attributeWithoutSynchronization(heightAttr)).valueOr(-1); 633 if (height < 0) 634 return; 635 636 auto ratioList = CSSValueList::createSlashSeparated(); 637 ratioList->append(CSSValuePool::singleton().createValue(width, CSSUnitType::CSS_NUMBER)); 638 ratioList->append(CSSValuePool::singleton().createValue(height, CSSUnitType::CSS_NUMBER)); 639 auto list = CSSValueList::createSpaceSeparated(); 640 list->append(CSSValuePool::singleton().createIdentifierValue(CSSValueAuto)); 641 list->append(ratioList); 642 643 style.setProperty(CSSPropertyAspectRatio, RefPtr<CSSValue>(WTFMove(list))); 644 } 645 623 646 void HTMLElement::applyAlignmentAttributeToStyle(const AtomString& alignment, MutableStyleProperties& style) 624 647 { -
trunk/Source/WebCore/html/HTMLElement.h
r276746 r277997 155 155 void addHTMLColorToStyle(MutableStyleProperties&, CSSPropertyID, const String& color); 156 156 157 void applyAspectRatioFromWidthAndHeightAttributesToStyle(MutableStyleProperties&); 157 158 void applyAlignmentAttributeToStyle(const AtomString&, MutableStyleProperties&); 158 159 void applyBorderAttributeToStyle(const AtomString&, MutableStyleProperties&); -
trunk/Source/WebCore/html/HTMLImageElement.cpp
r277967 r277997 116 116 void HTMLImageElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomString& value, MutableStyleProperties& style) 117 117 { 118 if (name == widthAttr) 118 if (name == widthAttr) { 119 119 addHTMLLengthToStyle(style, CSSPropertyWidth, value); 120 else if (name == heightAttr) 120 applyAspectRatioFromWidthAndHeightAttributesToStyle(style); 121 } else if (name == heightAttr) { 121 122 addHTMLLengthToStyle(style, CSSPropertyHeight, value); 122 else if (name == borderAttr) 123 applyAspectRatioFromWidthAndHeightAttributesToStyle(style); 124 } else if (name == borderAttr) 123 125 applyBorderAttributeToStyle(value, style); 124 126 else if (name == vspaceAttr) { -
trunk/Source/WebCore/html/HTMLInputElement.cpp
r277269 r277997 708 708 if (m_inputType->shouldRespectHeightAndWidthAttributes()) 709 709 addHTMLLengthToStyle(style, CSSPropertyWidth, value); 710 if (isImageButton()) 711 applyAspectRatioFromWidthAndHeightAttributesToStyle(style); 710 712 } else if (name == heightAttr) { 711 713 if (m_inputType->shouldRespectHeightAndWidthAttributes()) 712 714 addHTMLLengthToStyle(style, CSSPropertyHeight, value); 715 if (isImageButton()) 716 applyAspectRatioFromWidthAndHeightAttributesToStyle(style); 713 717 } else if (name == borderAttr && isImageButton()) 714 718 applyBorderAttributeToStyle(value, style); -
trunk/Source/WebCore/html/HTMLVideoElement.cpp
r277986 r277997 114 114 void HTMLVideoElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomString& value, MutableStyleProperties& style) 115 115 { 116 if (name == widthAttr) 116 if (name == widthAttr) { 117 117 addHTMLLengthToStyle(style, CSSPropertyWidth, value); 118 else if (name == heightAttr) 118 applyAspectRatioFromWidthAndHeightAttributesToStyle(style); 119 } else if (name == heightAttr) { 119 120 addHTMLLengthToStyle(style, CSSPropertyHeight, value); 120 else 121 applyAspectRatioFromWidthAndHeightAttributesToStyle(style); 122 } else 121 123 HTMLMediaElement::collectStyleForPresentationAttribute(name, value, style); 122 124 } -
trunk/Source/WebCore/rendering/RenderImage.cpp
r277321 r277997 843 843 } 844 844 845 bool RenderImage::canMapWidthHeightToAspectRatio() const846 {847 // The aspectRatioOfImgFromWidthAndHeight only applies to <img>.848 return is<HTMLImageElement>(element()) && !isShowingAltText();849 }850 851 845 void RenderImage::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio) const 852 846 { … … 866 860 // Don't compute an intrinsic ratio to preserve historical WebKit behavior if we're painting alt text and/or a broken image. 867 861 if (shouldDisplayBrokenImageIcon()) { 868 if ( !style().hasAspectRatio()) {869 intrinsicRatio = intrinsicAspectRatioFromWidthHeight().valueOr(1);870 return;871 }872 intrinsicRatio = 1;862 if (settings().aspectRatioOfImgFromWidthAndHeightEnabled() 863 && style().aspectRatioType() == AspectRatioType::AutoAndRatio && !isShowingAltText()) 864 intrinsicRatio = style().logicalAspectRatio(); 865 else 866 intrinsicRatio = 1; 873 867 return; 874 868 } -
trunk/Source/WebCore/rendering/RenderImage.h
r276521 r277997 104 104 } 105 105 106 bool canMapWidthHeightToAspectRatio() const override;107 108 106 private: 109 107 const char* renderName() const override { return "RenderImage"; } -
trunk/Source/WebCore/rendering/RenderReplaced.cpp
r277802 r277997 479 479 } 480 480 481 Optional<double> RenderReplaced::intrinsicAspectRatioFromWidthHeight() const482 {483 if (!settings().aspectRatioOfImgFromWidthAndHeightEnabled())484 return Optional<double>();485 486 if (!canMapWidthHeightToAspectRatio())487 return Optional<double>();488 489 ASSERT(element());490 double attributeWidth = parseValidHTMLFloatingPointNumber(element()->getAttribute(HTMLNames::widthAttr)).valueOr(0);491 double attributeHeight = parseValidHTMLFloatingPointNumber(element()->getAttribute(HTMLNames::heightAttr)).valueOr(0);492 if (attributeWidth > 0 && attributeHeight > 0)493 return attributeWidth / attributeHeight;494 495 return Optional<double>();496 }497 498 481 void RenderReplaced::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio) const 499 482 { … … 511 494 return; 512 495 513 if (intrinsicSize.isEmpty()) { 514 intrinsicRatio = intrinsicAspectRatioFromWidthHeight().valueOr(0); 496 if (intrinsicSize.isEmpty()) 515 497 return; 516 }517 498 518 499 intrinsicRatio = intrinsicSize.width() / intrinsicSize.height(); -
trunk/Source/WebCore/rendering/RenderReplaced.h
r277802 r277997 64 64 void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const final; 65 65 66 // This function determines if the object is allowed to compute aspect ratio from attributes width and height.67 virtual bool canMapWidthHeightToAspectRatio() const { return false; }68 Optional<double> intrinsicAspectRatioFromWidthHeight() const;69 70 66 virtual LayoutUnit minimumReplacedHeight() const { return 0_lu; } 71 67
Note:
See TracChangeset
for help on using the changeset viewer.