Title: [279108] trunk
Revision
279108
Author
[email protected]
Date
2021-06-22 01:06:05 -0700 (Tue, 22 Jun 2021)

Log Message

Implement width and height attributes on source elements of <picture>
https://bugs.webkit.org/show_bug.cgi?id=222368

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

* web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/picture-aspect-ratio-expected.txt:

Source/WebCore:

According to [1], the source element supports dimension attributes. The img element can use the width
and height attributes of the source element to determine its rendered dimensions and aspect-ratio.
In order to implement this, add m_sourceElement to HTMLImageElement to indicate the source element that
is selected. Also add invalidateAttributeMapping() to synchronize with the changes of source's attributes
to the img element. Then add collectExtraStyleForPresentationalHints() to collect style from source attributes.

[1] https://html.spec.whatwg.org/#the-source-element

* dom/ElementData.h:
* dom/StyledElement.cpp:
(WebCore::StyledElement::rebuildPresentationalHintStyle): collectExtraStyleForPresentationalHints() when rebuild.
* dom/StyledElement.h:
(WebCore::StyledElement::collectExtraStyleForPresentationalHints): Add an interface to collect extra style from other elements.
* html/HTMLElement.cpp:
(WebCore::HTMLElement::applyAspectRatioFromWidthAndHeightAttributesToStyle): Add width and height attributes as input variables.
* html/HTMLElement.h:
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::collectPresentationalHintsForAttribute):
(WebCore::HTMLImageElement::collectExtraStyleForPresentationalHints): If source element has width or height attributes, apply them
to width, height and aspect-ratio of the style.
(WebCore::HTMLImageElement::bestFitSourceFromPictureElement): Keep the source element.
(WebCore::HTMLImageElement::selectImageSource): Reset the source element to null if no candidate is found.
(WebCore::HTMLImageElement::sourceElement const):
(WebCore::HTMLImageElement::setSourceElement):
(WebCore::HTMLImageElement::invalidateAttributeMapping): Invalidate the presentationalHintStyle.
* html/HTMLImageElement.h:
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::collectPresentationalHintsForAttribute):
* html/HTMLPictureElement.cpp:
(WebCore::HTMLPictureElement::sourceDimensionAttributesChanged): Call invalidateAttributeMapping if source element's attributes are changed.
* html/HTMLPictureElement.h:
* html/HTMLSourceElement.cpp:
(WebCore::HTMLSourceElement::attributeChanged): Call sourceDimensionAttributesChanged if width or height attributes are changed.
* html/HTMLSourceElement.h:
* html/HTMLSourceElement.idl:
* html/HTMLVideoElement.cpp:
(WebCore::HTMLVideoElement::collectPresentationalHintsForAttribute):

LayoutTests:

* TestExpectations:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (279107 => 279108)


--- trunk/LayoutTests/ChangeLog	2021-06-22 07:56:27 UTC (rev 279107)
+++ trunk/LayoutTests/ChangeLog	2021-06-22 08:06:05 UTC (rev 279108)
@@ -1,3 +1,12 @@
+2021-06-22  Cathie Chen  <[email protected]>
+
+        Implement width and height attributes on source elements of <picture>
+        https://bugs.webkit.org/show_bug.cgi?id=222368
+
+        Reviewed by Darin Adler.
+
+        * TestExpectations:
+
 2021-06-21  Carlos Alberto Lopez Perez  <[email protected]>
 
         [GLIB] Gardening of test failures.

Modified: trunk/LayoutTests/TestExpectations (279107 => 279108)


--- trunk/LayoutTests/TestExpectations	2021-06-22 07:56:27 UTC (rev 279107)
+++ trunk/LayoutTests/TestExpectations	2021-06-22 08:06:05 UTC (rev 279108)
@@ -1434,9 +1434,6 @@
 imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/sizes/parse-a-sizes-attribute-standards-mode.html [ Failure Pass ]
 imported/w3c/web-platform-tests/html/semantics/embedded-content/the-object-element/object-fallback-failed-cross-origin-navigation.sub.html [ Failure Pass ]
 
-# Newly importing aspect ratio test is flaky.
-imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/picture-aspect-ratio.html [ Failure Pass ]
-
 # Newly importing W3C tests needed support for reftest-wait.
 webkit.org/b/186045 imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/track/track-element/track-cue-rendering-after-controls-added.html [ Skip ]
 webkit.org/b/186045 imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/track/track-element/track-cue-rendering-after-controls-removed.html [ Skip ]

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (279107 => 279108)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-06-22 07:56:27 UTC (rev 279107)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-06-22 08:06:05 UTC (rev 279108)
@@ -1,3 +1,12 @@
+2021-06-22  Cathie Chen  <[email protected]>
+
+        Implement width and height attributes on source elements of <picture>
+        https://bugs.webkit.org/show_bug.cgi?id=222368
+
+        Reviewed by Darin Adler.
+
+        * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/picture-aspect-ratio-expected.txt:
+
 2021-06-21  Chris Dumez  <[email protected]>
 
         Adjust `fetch` port blocking for ports 990, 989

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/picture-aspect-ratio-expected.txt (279107 => 279108)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/picture-aspect-ratio-expected.txt	2021-06-22 07:56:27 UTC (rev 279107)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/picture-aspect-ratio-expected.txt	2021-06-22 08:06:05 UTC (rev 279108)
@@ -1,20 +1,18 @@
 
 
-
-
 PASS source width and height attributes are used to infer aspect-ratio in <picture>
-FAIL Computed style for width/height/aspect-ratio assert_approx_equals: expected 1 +/- 0.001 but got Infinity
-FAIL Source width/height should take precedence over img attributes. assert_approx_equals: expected 2 +/- 0.001 but got 5
-FAIL Make sure style gets invalidated correctly when the source gets removed. assert_equals: expected "auto 250 / 50" but got "auto"
-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"
-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"
-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"
-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"
-FAIL Dynamically changing width/height should change computed style assert_equals: expected "auto 100 / 100" but got "auto"
-FAIL Changing which <source> matches should change computed style assert_equals: expected "auto 100 / 100" but got "auto"
-FAIL Percentages on source should be ignored for aspect-ratio but used for width/height. assert_equals: expected 100 but got 0
-FAIL Trailing garbage should be ignored but not make the attribute invalid assert_equals: expected 100 but got 0
+PASS Computed style for width/height/aspect-ratio
+PASS Source width/height should take precedence over img attributes.
+PASS Make sure style gets invalidated correctly when the source gets removed.
+PASS If the <source> has only one of width/height, we don't get an aspect ratio, even if the <img> has both.
+PASS If we don't have width/height on the source, we fall back to width/height on the <img>.
+PASS If we only have one width attribute, we should get width mapped but no aspect ratio, even if <img> has attributes.
+PASS If we only have height attribute, we should get height mapped but no aspect ratio, even if <img> has attributes.
+PASS Dynamically changing width/height should change computed style
+PASS Changing which <source> matches should change computed style
+PASS Percentages on source should be ignored for aspect-ratio but used for width/height.
+PASS Trailing garbage should be ignored but not make the attribute invalid
 PASS Loaded picture test: Both <source> and <img> are without width and height attributes
-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"
-FAIL Loaded picture test: Both <source> and <img> are with width and height attributes assert_equals: expected "auto 100 / 100" but got "auto"
+PASS Loaded picture test: <source> with width and height attributes, <img> without width and height attributes
+PASS Loaded picture test: Both <source> and <img> are with width and height attributes
 

Modified: trunk/Source/WebCore/ChangeLog (279107 => 279108)


--- trunk/Source/WebCore/ChangeLog	2021-06-22 07:56:27 UTC (rev 279107)
+++ trunk/Source/WebCore/ChangeLog	2021-06-22 08:06:05 UTC (rev 279108)
@@ -1,3 +1,48 @@
+2021-06-22  Cathie Chen  <[email protected]>
+
+        Implement width and height attributes on source elements of <picture>
+        https://bugs.webkit.org/show_bug.cgi?id=222368
+
+        Reviewed by Darin Adler.
+
+        According to [1], the source element supports dimension attributes. The img element can use the width
+        and height attributes of the source element to determine its rendered dimensions and aspect-ratio.
+        In order to implement this, add m_sourceElement to HTMLImageElement to indicate the source element that
+        is selected. Also add invalidateAttributeMapping() to synchronize with the changes of source's attributes
+        to the img element. Then add collectExtraStyleForPresentationalHints() to collect style from source attributes.
+
+        [1] https://html.spec.whatwg.org/#the-source-element
+
+        * dom/ElementData.h:
+        * dom/StyledElement.cpp:
+        (WebCore::StyledElement::rebuildPresentationalHintStyle): collectExtraStyleForPresentationalHints() when rebuild.
+        * dom/StyledElement.h:
+        (WebCore::StyledElement::collectExtraStyleForPresentationalHints): Add an interface to collect extra style from other elements.
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::applyAspectRatioFromWidthAndHeightAttributesToStyle): Add width and height attributes as input variables.
+        * html/HTMLElement.h:
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::collectPresentationalHintsForAttribute):
+        (WebCore::HTMLImageElement::collectExtraStyleForPresentationalHints): If source element has width or height attributes, apply them
+        to width, height and aspect-ratio of the style.
+        (WebCore::HTMLImageElement::bestFitSourceFromPictureElement): Keep the source element.
+        (WebCore::HTMLImageElement::selectImageSource): Reset the source element to null if no candidate is found.
+        (WebCore::HTMLImageElement::sourceElement const):
+        (WebCore::HTMLImageElement::setSourceElement):
+        (WebCore::HTMLImageElement::invalidateAttributeMapping): Invalidate the presentationalHintStyle.
+        * html/HTMLImageElement.h:
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::collectPresentationalHintsForAttribute):
+        * html/HTMLPictureElement.cpp:
+        (WebCore::HTMLPictureElement::sourceDimensionAttributesChanged): Call invalidateAttributeMapping if source element's attributes are changed.
+        * html/HTMLPictureElement.h:
+        * html/HTMLSourceElement.cpp:
+        (WebCore::HTMLSourceElement::attributeChanged): Call sourceDimensionAttributesChanged if width or height attributes are changed.
+        * html/HTMLSourceElement.h:
+        * html/HTMLSourceElement.idl:
+        * html/HTMLVideoElement.cpp:
+        (WebCore::HTMLVideoElement::collectPresentationalHintsForAttribute):
+
 2021-06-21  Jean-Yves Avenard  <[email protected]>
 
         Safari 15 breaks all Web Audio content using WebM Opus

Modified: trunk/Source/WebCore/dom/ElementData.h (279107 => 279108)


--- trunk/Source/WebCore/dom/ElementData.h	2021-06-22 07:56:27 UTC (rev 279107)
+++ trunk/Source/WebCore/dom/ElementData.h	2021-06-22 08:06:05 UTC (rev 279108)
@@ -170,6 +170,7 @@
     friend class ShareableElementData;
     friend class UniqueElementData;
     friend class SVGElement;
+    friend class HTMLImageElement;
 
     void destroy();
 

Modified: trunk/Source/WebCore/dom/StyledElement.cpp (279107 => 279108)


--- trunk/Source/WebCore/dom/StyledElement.cpp	2021-06-22 07:56:27 UTC (rev 279107)
+++ trunk/Source/WebCore/dom/StyledElement.cpp	2021-06-22 08:06:05 UTC (rev 279108)
@@ -37,6 +37,7 @@
 #include "DOMTokenList.h"
 #include "ElementRareData.h"
 #include "HTMLElement.h"
+#include "HTMLImageElement.h"
 #include "HTMLParserIdioms.h"
 #include "InspectorInstrumentation.h"
 #include "PropertySetCSSStyleDeclaration.h"
@@ -292,15 +293,21 @@
 
 void StyledElement::rebuildPresentationalHintStyle()
 {
-    RefPtr<StyleProperties> style = MutableStyleProperties::create(isSVGElement() ? SVGAttributeMode : HTMLQuirksMode);
+    auto style = MutableStyleProperties::create(isSVGElement() ? SVGAttributeMode : HTMLQuirksMode);
     for (const Attribute& attribute : attributesIterator())
-        collectPresentationalHintsForAttribute(attribute.name(), attribute.value(), static_cast<MutableStyleProperties&>(*style));
+        collectPresentationalHintsForAttribute(attribute.name(), attribute.value(), style);
 
+    if (is<HTMLImageElement>(*this))
+        collectExtraStyleForPresentationalHints(style);
+
     // ShareableElementData doesn't store presentation attribute style, so make sure we have a UniqueElementData.
     UniqueElementData& elementData = ensureUniqueElementData();
 
     elementData.setPresentationalHintStyleIsDirty(false);
-    elementData.m_presentationalHintStyle = style->isEmpty() ? nullptr : WTFMove(style);
+    if (style->isEmpty())
+        elementData.m_presentationalHintStyle = nullptr;
+    else
+        elementData.m_presentationalHintStyle = WTFMove(style);
 }
 
 void StyledElement::addPropertyToPresentationalHintStyle(MutableStyleProperties& style, CSSPropertyID propertyID, CSSValueID identifier)

Modified: trunk/Source/WebCore/dom/StyledElement.h (279107 => 279108)


--- trunk/Source/WebCore/dom/StyledElement.h	2021-06-22 07:56:27 UTC (rev 279107)
+++ trunk/Source/WebCore/dom/StyledElement.h	2021-06-22 08:06:05 UTC (rev 279108)
@@ -64,6 +64,7 @@
     const StyleProperties* presentationalHintStyle() const;
     virtual void collectPresentationalHintsForAttribute(const QualifiedName&, const AtomString&, MutableStyleProperties&) { }
     virtual const StyleProperties* additionalPresentationalHintStyle() const { return nullptr; }
+    virtual void collectExtraStyleForPresentationalHints(MutableStyleProperties&) { }
 
 protected:
     StyledElement(const QualifiedName& name, Document& document, ConstructionType type)

Modified: trunk/Source/WebCore/html/HTMLElement.cpp (279107 => 279108)


--- trunk/Source/WebCore/html/HTMLElement.cpp	2021-06-22 07:56:27 UTC (rev 279107)
+++ trunk/Source/WebCore/html/HTMLElement.cpp	2021-06-22 08:06:05 UTC (rev 279108)
@@ -625,15 +625,15 @@
     return { };
 }
 
-void HTMLElement::applyAspectRatioFromWidthAndHeightAttributesToStyle(MutableStyleProperties& style)
+void HTMLElement::applyAspectRatioFromWidthAndHeightAttributesToStyle(StringView widthAttribute, StringView heightAttribute, MutableStyleProperties& style)
 {
     if (!document().settings().aspectRatioOfImgFromWidthAndHeightEnabled())
         return;
 
-    auto dimensionWidth = parseHTMLDimension(attributeWithoutSynchronization(widthAttr));
+    auto dimensionWidth = parseHTMLDimension(widthAttribute);
     if (!dimensionWidth || dimensionWidth->type != HTMLDimension::Type::Pixel)
         return;
-    auto dimensionHeight = parseHTMLDimension(attributeWithoutSynchronization(heightAttr));
+    auto dimensionHeight = parseHTMLDimension(heightAttribute);
     if (!dimensionHeight || dimensionHeight->type != HTMLDimension::Type::Pixel)
         return;
 

Modified: trunk/Source/WebCore/html/HTMLElement.h (279107 => 279108)


--- trunk/Source/WebCore/html/HTMLElement.h	2021-06-22 07:56:27 UTC (rev 279107)
+++ trunk/Source/WebCore/html/HTMLElement.h	2021-06-22 08:06:05 UTC (rev 279108)
@@ -157,7 +157,7 @@
 
     void addHTMLColorToStyle(MutableStyleProperties&, CSSPropertyID, const String& color);
 
-    void applyAspectRatioFromWidthAndHeightAttributesToStyle(MutableStyleProperties&);
+    void applyAspectRatioFromWidthAndHeightAttributesToStyle(StringView widthAttribute, StringView heightAttribute, MutableStyleProperties&);
     void applyAlignmentAttributeToStyle(const AtomString&, MutableStyleProperties&);
     void applyBorderAttributeToStyle(const AtomString&, MutableStyleProperties&);
 

Modified: trunk/Source/WebCore/html/HTMLImageElement.cpp (279107 => 279108)


--- trunk/Source/WebCore/html/HTMLImageElement.cpp	2021-06-22 07:56:27 UTC (rev 279107)
+++ trunk/Source/WebCore/html/HTMLImageElement.cpp	2021-06-22 08:06:05 UTC (rev 279108)
@@ -37,9 +37,9 @@
 #include "HTMLDocument.h"
 #include "HTMLFormElement.h"
 #include "HTMLImageLoader.h"
+#include "HTMLMapElement.h"
 #include "HTMLParserIdioms.h"
 #include "HTMLPictureElement.h"
-#include "HTMLMapElement.h"
 #include "HTMLSourceElement.h"
 #include "HTMLSrcsetParser.h"
 #include "LazyLoadImageObserver.h"
@@ -117,10 +117,10 @@
 {
     if (name == widthAttr) {
         addHTMLMultiLengthToStyle(style, CSSPropertyWidth, value);
-        applyAspectRatioFromWidthAndHeightAttributesToStyle(style);
+        applyAspectRatioFromWidthAndHeightAttributesToStyle(value, attributeWithoutSynchronization(heightAttr), style);
     } else if (name == heightAttr) {
         addHTMLMultiLengthToStyle(style, CSSPropertyHeight, value);
-        applyAspectRatioFromWidthAndHeightAttributesToStyle(style);
+        applyAspectRatioFromWidthAndHeightAttributesToStyle(attributeWithoutSynchronization(widthAttr), value, style);
     } else if (name == borderAttr)
         applyBorderAttributeToStyle(value, style);
     else if (name == vspaceAttr) {
@@ -137,6 +137,34 @@
         HTMLElement::collectPresentationalHintsForAttribute(name, value, style);
 }
 
+void HTMLImageElement::collectExtraStyleForPresentationalHints(MutableStyleProperties& style)
+{
+    if (!sourceElement())
+        return;
+    auto& widthAttrFromSource = sourceElement()->attributeWithoutSynchronization(widthAttr);
+    auto& heightAttrFromSource = sourceElement()->attributeWithoutSynchronization(heightAttr);
+    // If both width and height attributes of <source> is undefined, the style's value should not
+    // be overwritten. Otherwise, <souce> will overwrite it. I.e., if <source> only has one attribute
+    // defined, the other one and aspect-ratio shouldn't be set to auto.
+    if (widthAttrFromSource.isNull() && heightAttrFromSource.isNull())
+        return;
+
+    if (!widthAttrFromSource.isNull())
+        addHTMLLengthToStyle(style, CSSPropertyWidth, widthAttrFromSource);
+    else
+        addPropertyToPresentationalHintStyle(style, CSSPropertyWidth, CSSValueAuto);
+
+    if (!heightAttrFromSource.isNull())
+        addHTMLLengthToStyle(style, CSSPropertyHeight, heightAttrFromSource);
+    else
+        addPropertyToPresentationalHintStyle(style, CSSPropertyHeight, CSSValueAuto);
+
+    if (!widthAttrFromSource.isNull() && !heightAttrFromSource.isNull())
+        applyAspectRatioFromWidthAndHeightAttributesToStyle(widthAttrFromSource, heightAttrFromSource, style);
+    else
+        addPropertyToPresentationalHintStyle(style, CSSPropertyAspectRatio, CSSValueAuto);
+}
+
 const AtomString& HTMLImageElement::imageSourceURL() const
 {
     return m_bestFitImageURL.isEmpty() ? attributeWithoutSynchronization(srcAttr) : m_bestFitImageURL;
@@ -191,8 +219,10 @@
         auto sourceSize = sizesParser.length();
 
         candidate = bestFitSourceForImageAttributes(document().deviceScaleFactor(), nullAtom(), srcset, sourceSize);
-        if (!candidate.isEmpty())
+        if (!candidate.isEmpty()) {
+            setSourceElement(&source);
             break;
+        }
     }
 
     return candidate;
@@ -217,6 +247,7 @@
     // First look for the best fit source from our <picture> parent if we have one.
     ImageCandidate candidate = bestFitSourceFromPictureElement();
     if (candidate.isEmpty()) {
+        setSourceElement(nullptr);
         // If we don't have a <picture> or didn't find a source, then we use our own attributes.
         SizesAttributeParser sizesParser(attributeWithoutSynchronization(sizesAttr).string(), document(), &m_mediaQueryDynamicResults);
         auto sourceSize = sizesParser.length();
@@ -799,4 +830,23 @@
     return ReferrerPolicy::EmptyString;
 }
 
+HTMLSourceElement* HTMLImageElement::sourceElement() const
+{
+    return m_sourceElement.get();
 }
+
+void HTMLImageElement::setSourceElement(HTMLSourceElement* sourceElement)
+{
+    if (m_sourceElement == sourceElement)
+        return;
+    m_sourceElement = makeWeakPtr(sourceElement);
+    invalidateAttributeMapping();
+}
+
+void HTMLImageElement::invalidateAttributeMapping()
+{
+    ensureUniqueElementData().setPresentationalHintStyleIsDirty(true);
+    invalidateStyle();
+}
+
+}

Modified: trunk/Source/WebCore/html/HTMLImageElement.h (279107 => 279108)


--- trunk/Source/WebCore/html/HTMLImageElement.h	2021-06-22 07:56:27 UTC (rev 279107)
+++ trunk/Source/WebCore/html/HTMLImageElement.h	2021-06-22 08:06:05 UTC (rev 279108)
@@ -150,6 +150,8 @@
     void parseAttribute(const QualifiedName&, const AtomString&) override;
     bool hasPresentationalHintsForAttribute(const QualifiedName&) const override;
     void collectPresentationalHintsForAttribute(const QualifiedName&, const AtomString&, MutableStyleProperties&) override;
+    void collectExtraStyleForPresentationalHints(MutableStyleProperties&) override;
+    void invalidateAttributeMapping();
 
     void didAttachRenderers() override;
     RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override;
@@ -183,6 +185,9 @@
 
     float effectiveImageDevicePixelRatio() const;
 
+    HTMLSourceElement* sourceElement() const;
+    void setSourceElement(HTMLSourceElement*);
+
     std::unique_ptr<HTMLImageLoader> m_imageLoader;
     WeakPtr<HTMLFormElement> m_form;
     WeakPtr<HTMLFormElement> m_formSetByParser;
@@ -196,6 +201,8 @@
     bool m_isDroppedImagePlaceholder { false };
 
     WeakPtr<HTMLPictureElement> m_pictureElement;
+    // The source element that was selected to provide the source URL.
+    WeakPtr<HTMLSourceElement> m_sourceElement;
     MediaQueryDynamicResults m_mediaQueryDynamicResults;
 
 #if ENABLE(ATTACHMENT_ELEMENT)

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (279107 => 279108)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2021-06-22 07:56:27 UTC (rev 279107)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2021-06-22 08:06:05 UTC (rev 279108)
@@ -714,12 +714,12 @@
         if (m_inputType->shouldRespectHeightAndWidthAttributes())
             addHTMLLengthToStyle(style, CSSPropertyWidth, value);
         if (isImageButton())
-            applyAspectRatioFromWidthAndHeightAttributesToStyle(style);
+            applyAspectRatioFromWidthAndHeightAttributesToStyle(value, attributeWithoutSynchronization(heightAttr), style);
     } else if (name == heightAttr) {
         if (m_inputType->shouldRespectHeightAndWidthAttributes())
             addHTMLLengthToStyle(style, CSSPropertyHeight, value);
         if (isImageButton())
-            applyAspectRatioFromWidthAndHeightAttributesToStyle(style);
+            applyAspectRatioFromWidthAndHeightAttributesToStyle(attributeWithoutSynchronization(widthAttr), value, style);
     } else if (name == borderAttr && isImageButton())
         applyBorderAttributeToStyle(value, style);
     else

Modified: trunk/Source/WebCore/html/HTMLPictureElement.cpp (279107 => 279108)


--- trunk/Source/WebCore/html/HTMLPictureElement.cpp	2021-06-22 07:56:27 UTC (rev 279107)
+++ trunk/Source/WebCore/html/HTMLPictureElement.cpp	2021-06-22 08:06:05 UTC (rev 279108)
@@ -64,6 +64,14 @@
         element.selectImageSource(RelevantMutation::Yes);
 }
 
+void HTMLPictureElement::sourceDimensionAttributesChanged(const HTMLSourceElement& sourceElement)
+{
+    for (auto& element : childrenOfType<HTMLImageElement>(*this)) {
+        if (&sourceElement == element.sourceElement())
+            element.invalidateAttributeMapping();
+    }
+}
+
 #if USE(SYSTEM_PREVIEW)
 bool HTMLPictureElement::isSystemPreviewImage()
 {

Modified: trunk/Source/WebCore/html/HTMLPictureElement.h (279107 => 279108)


--- trunk/Source/WebCore/html/HTMLPictureElement.h	2021-06-22 07:56:27 UTC (rev 279107)
+++ trunk/Source/WebCore/html/HTMLPictureElement.h	2021-06-22 08:06:05 UTC (rev 279108)
@@ -36,6 +36,7 @@
     virtual ~HTMLPictureElement();
 
     void sourcesChanged();
+    void sourceDimensionAttributesChanged(const HTMLSourceElement&);
 
 #if USE(SYSTEM_PREVIEW)
     WEBCORE_EXPORT bool isSystemPreviewImage();

Modified: trunk/Source/WebCore/html/HTMLSourceElement.cpp (279107 => 279108)


--- trunk/Source/WebCore/html/HTMLSourceElement.cpp	2021-06-22 07:56:27 UTC (rev 279107)
+++ trunk/Source/WebCore/html/HTMLSourceElement.cpp	2021-06-22 08:06:05 UTC (rev 279108)
@@ -205,4 +205,13 @@
     return m_cachedParsedMediaAttribute.value().get();
 }
 
+void HTMLSourceElement::attributeChanged(const QualifiedName& name, const AtomString& oldValue, const AtomString& newValue, AttributeModificationReason reason)
+{
+    if (name == widthAttr || name == heightAttr) {
+        if (RefPtr parent = parentNode(); is<HTMLPictureElement>(parent))
+            downcast<HTMLPictureElement>(*parent).sourceDimensionAttributesChanged(*this);
+    }
+    HTMLElement::attributeChanged(name, oldValue, newValue, reason);
 }
+
+}

Modified: trunk/Source/WebCore/html/HTMLSourceElement.h (279107 => 279108)


--- trunk/Source/WebCore/html/HTMLSourceElement.h	2021-06-22 07:56:27 UTC (rev 279107)
+++ trunk/Source/WebCore/html/HTMLSourceElement.h	2021-06-22 08:06:05 UTC (rev 279108)
@@ -58,6 +58,8 @@
 
     void parseAttribute(const QualifiedName&, const AtomString&) final;
 
+    void attributeChanged(const QualifiedName&, const AtomString& oldValue, const AtomString& newValue, AttributeModificationReason) final;
+
     void errorEventTimerFired();
 
     Timer m_errorEventTimer;

Modified: trunk/Source/WebCore/html/HTMLSourceElement.idl (279107 => 279108)


--- trunk/Source/WebCore/html/HTMLSourceElement.idl	2021-06-22 07:56:27 UTC (rev 279107)
+++ trunk/Source/WebCore/html/HTMLSourceElement.idl	2021-06-22 08:06:05 UTC (rev 279108)
@@ -32,4 +32,6 @@
     [CEReactions=NotNeeded, Reflect] attribute USVString srcset;
     [CEReactions=NotNeeded, Reflect] attribute DOMString sizes;
     [CEReactions=NotNeeded, Reflect] attribute DOMString media;
+    [CEReactions=NotNeeded, Reflect] attribute unsigned long width;
+    [CEReactions=NotNeeded, Reflect] attribute unsigned long height;
 };

Modified: trunk/Source/WebCore/html/HTMLVideoElement.cpp (279107 => 279108)


--- trunk/Source/WebCore/html/HTMLVideoElement.cpp	2021-06-22 07:56:27 UTC (rev 279107)
+++ trunk/Source/WebCore/html/HTMLVideoElement.cpp	2021-06-22 08:06:05 UTC (rev 279108)
@@ -115,10 +115,10 @@
 {
     if (name == widthAttr) {
         addHTMLLengthToStyle(style, CSSPropertyWidth, value);
-        applyAspectRatioFromWidthAndHeightAttributesToStyle(style);
+        applyAspectRatioFromWidthAndHeightAttributesToStyle(value, attributeWithoutSynchronization(heightAttr), style);
     } else if (name == heightAttr) {
         addHTMLLengthToStyle(style, CSSPropertyHeight, value);
-        applyAspectRatioFromWidthAndHeightAttributesToStyle(style);
+        applyAspectRatioFromWidthAndHeightAttributesToStyle(attributeWithoutSynchronization(widthAttr), value, style);
     } else
         HTMLMediaElement::collectPresentationalHintsForAttribute(name, value, style);
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to