Changeset 279108 in webkit
- Timestamp:
- Jun 22, 2021 1:06:05 AM (13 months ago)
- Location:
- trunk
- Files:
-
- 19 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/TestExpectations (modified) (1 diff)
-
LayoutTests/imported/w3c/ChangeLog (modified) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/picture-aspect-ratio-expected.txt (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/dom/ElementData.h (modified) (1 diff)
-
Source/WebCore/dom/StyledElement.cpp (modified) (3 diffs)
-
Source/WebCore/dom/StyledElement.h (modified) (1 diff)
-
Source/WebCore/html/HTMLElement.cpp (modified) (1 diff)
-
Source/WebCore/html/HTMLElement.h (modified) (1 diff)
-
Source/WebCore/html/HTMLImageElement.cpp (modified) (6 diffs)
-
Source/WebCore/html/HTMLImageElement.h (modified) (3 diffs)
-
Source/WebCore/html/HTMLInputElement.cpp (modified) (1 diff)
-
Source/WebCore/html/HTMLPictureElement.cpp (modified) (1 diff)
-
Source/WebCore/html/HTMLPictureElement.h (modified) (1 diff)
-
Source/WebCore/html/HTMLSourceElement.cpp (modified) (1 diff)
-
Source/WebCore/html/HTMLSourceElement.h (modified) (1 diff)
-
Source/WebCore/html/HTMLSourceElement.idl (modified) (1 diff)
-
Source/WebCore/html/HTMLVideoElement.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r279100 r279108 1 2021-06-22 Cathie Chen <cathiechen@igalia.com> 2 3 Implement width and height attributes on source elements of <picture> 4 https://bugs.webkit.org/show_bug.cgi?id=222368 5 6 Reviewed by Darin Adler. 7 8 * TestExpectations: 9 1 10 2021-06-21 Carlos Alberto Lopez Perez <clopez@igalia.com> 2 11 -
trunk/LayoutTests/TestExpectations
r279055 r279108 1434 1434 imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/sizes/parse-a-sizes-attribute-standards-mode.html [ Failure Pass ] 1435 1435 imported/w3c/web-platform-tests/html/semantics/embedded-content/the-object-element/object-fallback-failed-cross-origin-navigation.sub.html [ Failure Pass ] 1436 1437 # Newly importing aspect ratio test is flaky.1438 imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/picture-aspect-ratio.html [ Failure Pass ]1439 1436 1440 1437 # Newly importing W3C tests needed support for reftest-wait. -
trunk/LayoutTests/imported/w3c/ChangeLog
r279099 r279108 1 2021-06-22 Cathie Chen <cathiechen@igalia.com> 2 3 Implement width and height attributes on source elements of <picture> 4 https://bugs.webkit.org/show_bug.cgi?id=222368 5 6 Reviewed by Darin Adler. 7 8 * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/picture-aspect-ratio-expected.txt: 9 1 10 2021-06-21 Chris Dumez <cdumez@apple.com> 2 11 -
trunk/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/picture-aspect-ratio-expected.txt
r276498 r279108 1 2 3 1 4 2 5 3 PASS source width and height attributes are used to infer aspect-ratio in <picture> 6 FAIL Computed style for width/height/aspect-ratio assert_approx_equals: expected 1 +/- 0.001 but got Infinity 7 FAIL Source width/height should take precedence over img attributes. assert_approx_equals: expected 2 +/- 0.001 but got 5 8 FAIL Make sure style gets invalidated correctly when the source gets removed. assert_equals: expected "auto 250 / 50" but got "auto" 9 FAIL If the <source> has only one of width/height, we don't get an aspect ratio, even if the <img> has both. assert_equals: expected "100px" but got "200px" 10 FAIL If we don't have width/height on the source, we fall back to width/height on the <img>. assert_equals: expected "auto 200 / 100" but got "auto" 11 FAIL If we only have one width attribute, we should get width mapped but no aspect ratio, even if <img> has attributes. assert_equals: expected "100px" but got "200px" 12 FAIL If we only have height attribute, we should get height mapped but no aspect ratio, even if <img> has attributes. assert_equals: expected "auto" but got "200px" 13 FAIL Dynamically changing width/height should change computed style assert_equals: expected "auto 100 / 100" but got "auto" 14 FAIL Changing which <source> matches should change computed style assert_equals: expected "auto 100 / 100" but got "auto" 15 FAIL Percentages on source should be ignored for aspect-ratio but used for width/height. assert_equals: expected 100 but got 0 16 FAIL Trailing garbage should be ignored but not make the attribute invalid assert_equals: expected 100 but got 0 4 PASS Computed style for width/height/aspect-ratio 5 PASS Source width/height should take precedence over img attributes. 6 PASS Make sure style gets invalidated correctly when the source gets removed. 7 PASS If the <source> has only one of width/height, we don't get an aspect ratio, even if the <img> has both. 8 PASS If we don't have width/height on the source, we fall back to width/height on the <img>. 9 PASS If we only have one width attribute, we should get width mapped but no aspect ratio, even if <img> has attributes. 10 PASS If we only have height attribute, we should get height mapped but no aspect ratio, even if <img> has attributes. 11 PASS Dynamically changing width/height should change computed style 12 PASS Changing which <source> matches should change computed style 13 PASS Percentages on source should be ignored for aspect-ratio but used for width/height. 14 PASS Trailing garbage should be ignored but not make the attribute invalid 17 15 PASS Loaded picture test: Both <source> and <img> are without width and height attributes 18 FAIL Loaded picture test: <source> with width and height attributes, <img> without width and height attributes assert_equals: expected "auto 100 / 100" but got "auto" 19 FAIL Loaded picture test: Both <source> and <img> are with width and height attributes assert_equals: expected "auto 100 / 100" but got "auto" 16 PASS Loaded picture test: <source> with width and height attributes, <img> without width and height attributes 17 PASS Loaded picture test: Both <source> and <img> are with width and height attributes 20 18 -
trunk/Source/WebCore/ChangeLog
r279103 r279108 1 2021-06-22 Cathie Chen <cathiechen@igalia.com> 2 3 Implement width and height attributes on source elements of <picture> 4 https://bugs.webkit.org/show_bug.cgi?id=222368 5 6 Reviewed by Darin Adler. 7 8 According to [1], the source element supports dimension attributes. The img element can use the width 9 and height attributes of the source element to determine its rendered dimensions and aspect-ratio. 10 In order to implement this, add m_sourceElement to HTMLImageElement to indicate the source element that 11 is selected. Also add invalidateAttributeMapping() to synchronize with the changes of source's attributes 12 to the img element. Then add collectExtraStyleForPresentationalHints() to collect style from source attributes. 13 14 [1] https://html.spec.whatwg.org/#the-source-element 15 16 * dom/ElementData.h: 17 * dom/StyledElement.cpp: 18 (WebCore::StyledElement::rebuildPresentationalHintStyle): collectExtraStyleForPresentationalHints() when rebuild. 19 * dom/StyledElement.h: 20 (WebCore::StyledElement::collectExtraStyleForPresentationalHints): Add an interface to collect extra style from other elements. 21 * html/HTMLElement.cpp: 22 (WebCore::HTMLElement::applyAspectRatioFromWidthAndHeightAttributesToStyle): Add width and height attributes as input variables. 23 * html/HTMLElement.h: 24 * html/HTMLImageElement.cpp: 25 (WebCore::HTMLImageElement::collectPresentationalHintsForAttribute): 26 (WebCore::HTMLImageElement::collectExtraStyleForPresentationalHints): If source element has width or height attributes, apply them 27 to width, height and aspect-ratio of the style. 28 (WebCore::HTMLImageElement::bestFitSourceFromPictureElement): Keep the source element. 29 (WebCore::HTMLImageElement::selectImageSource): Reset the source element to null if no candidate is found. 30 (WebCore::HTMLImageElement::sourceElement const): 31 (WebCore::HTMLImageElement::setSourceElement): 32 (WebCore::HTMLImageElement::invalidateAttributeMapping): Invalidate the presentationalHintStyle. 33 * html/HTMLImageElement.h: 34 * html/HTMLInputElement.cpp: 35 (WebCore::HTMLInputElement::collectPresentationalHintsForAttribute): 36 * html/HTMLPictureElement.cpp: 37 (WebCore::HTMLPictureElement::sourceDimensionAttributesChanged): Call invalidateAttributeMapping if source element's attributes are changed. 38 * html/HTMLPictureElement.h: 39 * html/HTMLSourceElement.cpp: 40 (WebCore::HTMLSourceElement::attributeChanged): Call sourceDimensionAttributesChanged if width or height attributes are changed. 41 * html/HTMLSourceElement.h: 42 * html/HTMLSourceElement.idl: 43 * html/HTMLVideoElement.cpp: 44 (WebCore::HTMLVideoElement::collectPresentationalHintsForAttribute): 45 1 46 2021-06-21 Jean-Yves Avenard <jya@apple.com> 2 47 -
trunk/Source/WebCore/dom/ElementData.h
r278277 r279108 171 171 friend class UniqueElementData; 172 172 friend class SVGElement; 173 friend class HTMLImageElement; 173 174 174 175 void destroy(); -
trunk/Source/WebCore/dom/StyledElement.cpp
r278669 r279108 38 38 #include "ElementRareData.h" 39 39 #include "HTMLElement.h" 40 #include "HTMLImageElement.h" 40 41 #include "HTMLParserIdioms.h" 41 42 #include "InspectorInstrumentation.h" … … 293 294 void StyledElement::rebuildPresentationalHintStyle() 294 295 { 295 RefPtr<StyleProperties>style = MutableStyleProperties::create(isSVGElement() ? SVGAttributeMode : HTMLQuirksMode);296 auto style = MutableStyleProperties::create(isSVGElement() ? SVGAttributeMode : HTMLQuirksMode); 296 297 for (const Attribute& attribute : attributesIterator()) 297 collectPresentationalHintsForAttribute(attribute.name(), attribute.value(), static_cast<MutableStyleProperties&>(*style)); 298 collectPresentationalHintsForAttribute(attribute.name(), attribute.value(), style); 299 300 if (is<HTMLImageElement>(*this)) 301 collectExtraStyleForPresentationalHints(style); 298 302 299 303 // ShareableElementData doesn't store presentation attribute style, so make sure we have a UniqueElementData. … … 301 305 302 306 elementData.setPresentationalHintStyleIsDirty(false); 303 elementData.m_presentationalHintStyle = style->isEmpty() ? nullptr : WTFMove(style); 307 if (style->isEmpty()) 308 elementData.m_presentationalHintStyle = nullptr; 309 else 310 elementData.m_presentationalHintStyle = WTFMove(style); 304 311 } 305 312 -
trunk/Source/WebCore/dom/StyledElement.h
r278277 r279108 65 65 virtual void collectPresentationalHintsForAttribute(const QualifiedName&, const AtomString&, MutableStyleProperties&) { } 66 66 virtual const StyleProperties* additionalPresentationalHintStyle() const { return nullptr; } 67 virtual void collectExtraStyleForPresentationalHints(MutableStyleProperties&) { } 67 68 68 69 protected: -
trunk/Source/WebCore/html/HTMLElement.cpp
r278834 r279108 626 626 } 627 627 628 void HTMLElement::applyAspectRatioFromWidthAndHeightAttributesToStyle( MutableStyleProperties& style)628 void HTMLElement::applyAspectRatioFromWidthAndHeightAttributesToStyle(StringView widthAttribute, StringView heightAttribute, MutableStyleProperties& style) 629 629 { 630 630 if (!document().settings().aspectRatioOfImgFromWidthAndHeightEnabled()) 631 631 return; 632 632 633 auto dimensionWidth = parseHTMLDimension( attributeWithoutSynchronization(widthAttr));633 auto dimensionWidth = parseHTMLDimension(widthAttribute); 634 634 if (!dimensionWidth || dimensionWidth->type != HTMLDimension::Type::Pixel) 635 635 return; 636 auto dimensionHeight = parseHTMLDimension( attributeWithoutSynchronization(heightAttr));636 auto dimensionHeight = parseHTMLDimension(heightAttribute); 637 637 if (!dimensionHeight || dimensionHeight->type != HTMLDimension::Type::Pixel) 638 638 return; -
trunk/Source/WebCore/html/HTMLElement.h
r278765 r279108 158 158 void addHTMLColorToStyle(MutableStyleProperties&, CSSPropertyID, const String& color); 159 159 160 void applyAspectRatioFromWidthAndHeightAttributesToStyle( MutableStyleProperties&);160 void applyAspectRatioFromWidthAndHeightAttributesToStyle(StringView widthAttribute, StringView heightAttribute, MutableStyleProperties&); 161 161 void applyAlignmentAttributeToStyle(const AtomString&, MutableStyleProperties&); 162 162 void applyBorderAttributeToStyle(const AtomString&, MutableStyleProperties&); -
trunk/Source/WebCore/html/HTMLImageElement.cpp
r278765 r279108 38 38 #include "HTMLFormElement.h" 39 39 #include "HTMLImageLoader.h" 40 #include "HTMLMapElement.h" 40 41 #include "HTMLParserIdioms.h" 41 42 #include "HTMLPictureElement.h" 42 #include "HTMLMapElement.h"43 43 #include "HTMLSourceElement.h" 44 44 #include "HTMLSrcsetParser.h" … … 118 118 if (name == widthAttr) { 119 119 addHTMLMultiLengthToStyle(style, CSSPropertyWidth, value); 120 applyAspectRatioFromWidthAndHeightAttributesToStyle( style);120 applyAspectRatioFromWidthAndHeightAttributesToStyle(value, attributeWithoutSynchronization(heightAttr), style); 121 121 } else if (name == heightAttr) { 122 122 addHTMLMultiLengthToStyle(style, CSSPropertyHeight, value); 123 applyAspectRatioFromWidthAndHeightAttributesToStyle( style);123 applyAspectRatioFromWidthAndHeightAttributesToStyle(attributeWithoutSynchronization(widthAttr), value, style); 124 124 } else if (name == borderAttr) 125 125 applyBorderAttributeToStyle(value, style); … … 138 138 } 139 139 140 void HTMLImageElement::collectExtraStyleForPresentationalHints(MutableStyleProperties& style) 141 { 142 if (!sourceElement()) 143 return; 144 auto& widthAttrFromSource = sourceElement()->attributeWithoutSynchronization(widthAttr); 145 auto& heightAttrFromSource = sourceElement()->attributeWithoutSynchronization(heightAttr); 146 // If both width and height attributes of <source> is undefined, the style's value should not 147 // be overwritten. Otherwise, <souce> will overwrite it. I.e., if <source> only has one attribute 148 // defined, the other one and aspect-ratio shouldn't be set to auto. 149 if (widthAttrFromSource.isNull() && heightAttrFromSource.isNull()) 150 return; 151 152 if (!widthAttrFromSource.isNull()) 153 addHTMLLengthToStyle(style, CSSPropertyWidth, widthAttrFromSource); 154 else 155 addPropertyToPresentationalHintStyle(style, CSSPropertyWidth, CSSValueAuto); 156 157 if (!heightAttrFromSource.isNull()) 158 addHTMLLengthToStyle(style, CSSPropertyHeight, heightAttrFromSource); 159 else 160 addPropertyToPresentationalHintStyle(style, CSSPropertyHeight, CSSValueAuto); 161 162 if (!widthAttrFromSource.isNull() && !heightAttrFromSource.isNull()) 163 applyAspectRatioFromWidthAndHeightAttributesToStyle(widthAttrFromSource, heightAttrFromSource, style); 164 else 165 addPropertyToPresentationalHintStyle(style, CSSPropertyAspectRatio, CSSValueAuto); 166 } 167 140 168 const AtomString& HTMLImageElement::imageSourceURL() const 141 169 { … … 192 220 193 221 candidate = bestFitSourceForImageAttributes(document().deviceScaleFactor(), nullAtom(), srcset, sourceSize); 194 if (!candidate.isEmpty()) 222 if (!candidate.isEmpty()) { 223 setSourceElement(&source); 195 224 break; 225 } 196 226 } 197 227 … … 218 248 ImageCandidate candidate = bestFitSourceFromPictureElement(); 219 249 if (candidate.isEmpty()) { 250 setSourceElement(nullptr); 220 251 // If we don't have a <picture> or didn't find a source, then we use our own attributes. 221 252 SizesAttributeParser sizesParser(attributeWithoutSynchronization(sizesAttr).string(), document(), &m_mediaQueryDynamicResults); … … 800 831 } 801 832 802 } 833 HTMLSourceElement* HTMLImageElement::sourceElement() const 834 { 835 return m_sourceElement.get(); 836 } 837 838 void HTMLImageElement::setSourceElement(HTMLSourceElement* sourceElement) 839 { 840 if (m_sourceElement == sourceElement) 841 return; 842 m_sourceElement = makeWeakPtr(sourceElement); 843 invalidateAttributeMapping(); 844 } 845 846 void HTMLImageElement::invalidateAttributeMapping() 847 { 848 ensureUniqueElementData().setPresentationalHintStyleIsDirty(true); 849 invalidateStyle(); 850 } 851 852 } -
trunk/Source/WebCore/html/HTMLImageElement.h
r278277 r279108 151 151 bool hasPresentationalHintsForAttribute(const QualifiedName&) const override; 152 152 void collectPresentationalHintsForAttribute(const QualifiedName&, const AtomString&, MutableStyleProperties&) override; 153 void collectExtraStyleForPresentationalHints(MutableStyleProperties&) override; 154 void invalidateAttributeMapping(); 153 155 154 156 void didAttachRenderers() override; … … 183 185 184 186 float effectiveImageDevicePixelRatio() const; 187 188 HTMLSourceElement* sourceElement() const; 189 void setSourceElement(HTMLSourceElement*); 185 190 186 191 std::unique_ptr<HTMLImageLoader> m_imageLoader; … … 197 202 198 203 WeakPtr<HTMLPictureElement> m_pictureElement; 204 // The source element that was selected to provide the source URL. 205 WeakPtr<HTMLSourceElement> m_sourceElement; 199 206 MediaQueryDynamicResults m_mediaQueryDynamicResults; 200 207 -
trunk/Source/WebCore/html/HTMLInputElement.cpp
r279054 r279108 715 715 addHTMLLengthToStyle(style, CSSPropertyWidth, value); 716 716 if (isImageButton()) 717 applyAspectRatioFromWidthAndHeightAttributesToStyle( style);717 applyAspectRatioFromWidthAndHeightAttributesToStyle(value, attributeWithoutSynchronization(heightAttr), style); 718 718 } else if (name == heightAttr) { 719 719 if (m_inputType->shouldRespectHeightAndWidthAttributes()) 720 720 addHTMLLengthToStyle(style, CSSPropertyHeight, value); 721 721 if (isImageButton()) 722 applyAspectRatioFromWidthAndHeightAttributesToStyle( style);722 applyAspectRatioFromWidthAndHeightAttributesToStyle(attributeWithoutSynchronization(widthAttr), value, style); 723 723 } else if (name == borderAttr && isImageButton()) 724 724 applyBorderAttributeToStyle(value, style); -
trunk/Source/WebCore/html/HTMLPictureElement.cpp
r266360 r279108 65 65 } 66 66 67 void HTMLPictureElement::sourceDimensionAttributesChanged(const HTMLSourceElement& sourceElement) 68 { 69 for (auto& element : childrenOfType<HTMLImageElement>(*this)) { 70 if (&sourceElement == element.sourceElement()) 71 element.invalidateAttributeMapping(); 72 } 73 } 74 67 75 #if USE(SYSTEM_PREVIEW) 68 76 bool HTMLPictureElement::isSystemPreviewImage() -
trunk/Source/WebCore/html/HTMLPictureElement.h
r264789 r279108 37 37 38 38 void sourcesChanged(); 39 void sourceDimensionAttributesChanged(const HTMLSourceElement&); 39 40 40 41 #if USE(SYSTEM_PREVIEW) -
trunk/Source/WebCore/html/HTMLSourceElement.cpp
r278185 r279108 206 206 } 207 207 208 } 208 void HTMLSourceElement::attributeChanged(const QualifiedName& name, const AtomString& oldValue, const AtomString& newValue, AttributeModificationReason reason) 209 { 210 if (name == widthAttr || name == heightAttr) { 211 if (RefPtr parent = parentNode(); is<HTMLPictureElement>(parent)) 212 downcast<HTMLPictureElement>(*parent).sourceDimensionAttributesChanged(*this); 213 } 214 HTMLElement::attributeChanged(name, oldValue, newValue, reason); 215 } 216 217 } -
trunk/Source/WebCore/html/HTMLSourceElement.h
r278253 r279108 59 59 void parseAttribute(const QualifiedName&, const AtomString&) final; 60 60 61 void attributeChanged(const QualifiedName&, const AtomString& oldValue, const AtomString& newValue, AttributeModificationReason) final; 62 61 63 void errorEventTimerFired(); 62 64 -
trunk/Source/WebCore/html/HTMLSourceElement.idl
r267813 r279108 33 33 [CEReactions=NotNeeded, Reflect] attribute DOMString sizes; 34 34 [CEReactions=NotNeeded, Reflect] attribute DOMString media; 35 [CEReactions=NotNeeded, Reflect] attribute unsigned long width; 36 [CEReactions=NotNeeded, Reflect] attribute unsigned long height; 35 37 }; -
trunk/Source/WebCore/html/HTMLVideoElement.cpp
r278277 r279108 116 116 if (name == widthAttr) { 117 117 addHTMLLengthToStyle(style, CSSPropertyWidth, value); 118 applyAspectRatioFromWidthAndHeightAttributesToStyle( style);118 applyAspectRatioFromWidthAndHeightAttributesToStyle(value, attributeWithoutSynchronization(heightAttr), style); 119 119 } else if (name == heightAttr) { 120 120 addHTMLLengthToStyle(style, CSSPropertyHeight, value); 121 applyAspectRatioFromWidthAndHeightAttributesToStyle( style);121 applyAspectRatioFromWidthAndHeightAttributesToStyle(attributeWithoutSynchronization(widthAttr), value, style); 122 122 } else 123 123 HTMLMediaElement::collectPresentationalHintsForAttribute(name, value, style);
Note: See TracChangeset
for help on using the changeset viewer.