Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (277996 => 277997)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2021-05-25 04:13:26 UTC (rev 277996)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2021-05-25 05:39:12 UTC (rev 277997)
@@ -1,3 +1,15 @@
+2021-05-24 Cathie Chen <cathiec...@igalia.com>
+
+ Use the parsed width and height attributes as a presentational hint for aspect-ratio CSS property
+ https://bugs.webkit.org/show_bug.cgi?id=217529
+
+ Reviewed by Antti Koivisto.
+
+ Update the expected results of test_computed_style which are passed now.
+
+ * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/img-aspect-ratio-expected.txt:
+ * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/video-aspect-ratio-expected.txt:
+
2021-05-24 Cameron McCormack <hey...@apple.com>
Add missing operators.woff that a few WPTs reference.
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/img-aspect-ratio-expected.txt (277996 => 277997)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/img-aspect-ratio-expected.txt 2021-05-25 04:13:26 UTC (rev 277996)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/img-aspect-ratio-expected.txt 2021-05-25 05:39:12 UTC (rev 277997)
@@ -4,20 +4,20 @@
PASS Create, append and test immediately: <img> with attributes width=250, height=100
PASS Create, append and test immediately: <img> with attributes width=0.8, height=0.2
PASS Create, append and test immediately: <img> with attributes width=50% height=25%
-FAIL Computed style test: img with {"width":"10","height":"20"} assert_equals: expected "auto 10 / 20" but got "auto"
-FAIL Computed style test: input with {"type":"image","width":"10","height":"20"} assert_equals: expected "auto 10 / 20" but got "auto"
+PASS Computed style test: img with {"width":"10","height":"20"}
+PASS Computed style test: input with {"type":"image","width":"10","height":"20"}
PASS Computed style test: input with {"type":"submit","width":"10","height":"20"}
-FAIL Computed style test: img with {"width":"0","height":"1"} assert_equals: expected "auto 0 / 1" but got "auto"
-FAIL Computed style test: input with {"type":"image","width":"0","height":"1"} assert_equals: expected "auto 0 / 1" but got "auto"
+PASS Computed style test: img with {"width":"0","height":"1"}
+PASS Computed style test: input with {"type":"image","width":"0","height":"1"}
PASS Computed style test: input with {"type":"submit","width":"0","height":"1"}
-FAIL Computed style test: img with {"width":"1","height":"0"} assert_equals: expected "auto 1 / 0" but got "auto"
-FAIL Computed style test: input with {"type":"image","width":"1","height":"0"} assert_equals: expected "auto 1 / 0" but got "auto"
+PASS Computed style test: img with {"width":"1","height":"0"}
+PASS Computed style test: input with {"type":"image","width":"1","height":"0"}
PASS Computed style test: input with {"type":"submit","width":"1","height":"0"}
-FAIL Computed style test: img with {"width":"0","height":"0"} assert_equals: expected "auto 0 / 0" but got "auto"
-FAIL Computed style test: input with {"type":"image","width":"0","height":"0"} assert_equals: expected "auto 0 / 0" but got "auto"
+PASS Computed style test: img with {"width":"0","height":"0"}
+PASS Computed style test: input with {"type":"image","width":"0","height":"0"}
PASS Computed style test: input with {"type":"submit","width":"0","height":"0"}
-FAIL Computed style test: img with {"width":"0.5","height":"1.5"} assert_equals: expected "auto 0.5 / 1.5" but got "auto"
-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"
+PASS Computed style test: img with {"width":"0.5","height":"1.5"}
+PASS Computed style test: input with {"type":"image","width":"0.5","height":"1.5"}
PASS Computed style test: input with {"type":"submit","width":"0.5","height":"1.5"}
PASS Computed style test: img with {"width":null,"height":null}
PASS Computed style test: input with {"type":"image","width":null,"height":null}
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/video-aspect-ratio-expected.txt (277996 => 277997)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/video-aspect-ratio-expected.txt 2021-05-25 04:13:26 UTC (rev 277996)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/video-aspect-ratio-expected.txt 2021-05-25 05:39:12 UTC (rev 277997)
@@ -1,8 +1,8 @@
-FAIL Video width and height attributes are not used to infer aspect-ratio assert_approx_equals: expected 2.5 +/- 0.001 but got Infinity
-FAIL Computed style test: video with {"width":"10","height":"20"} assert_equals: expected "auto 10 / 20" but got "auto"
-FAIL Computed style test: video with {"width":"0.5","height":"1.5"} assert_equals: expected "auto 0.5 / 1.5" but got "auto"
+PASS Video width and height attributes are not used to infer aspect-ratio
+PASS Computed style test: video with {"width":"10","height":"20"}
+PASS Computed style test: video with {"width":"0.5","height":"1.5"}
PASS Computed style test: video with {"width":"0","height":"1"}
PASS Computed style test: video with {"width":"1","height":"0"}
PASS Computed style test: video with {"width":"0","height":"0"}
Modified: trunk/Source/WebCore/ChangeLog (277996 => 277997)
--- trunk/Source/WebCore/ChangeLog 2021-05-25 04:13:26 UTC (rev 277996)
+++ trunk/Source/WebCore/ChangeLog 2021-05-25 05:39:12 UTC (rev 277997)
@@ -1,3 +1,37 @@
+2021-05-24 Cathie Chen <cathiec...@igalia.com>
+
+ Use the parsed width and height attributes as a presentational hint for aspect-ratio CSS property
+ https://bugs.webkit.org/show_bug.cgi?id=217529
+
+ Reviewed by Antti Koivisto.
+
+ The feature "mapping attributes width and height to aspect ratio" currently is handled by RenderReplaced::computeIntrinsicRatioInformation.
+ However, per [1], the non-negative width and height attributes are expected to be used as a presentational hint for the aspect-ratio property.
+ This patch addes HTMLElement::applyAspectRatioFromWidthAndHeightAttributesToStyle to apply the attributes to m_presentationAttributeStyle.
+ Also this patch supports the feature for <video> and <input> with type="image".
+
+ [1] https://html.spec.whatwg.org/#map-to-the-aspect-ratio-property-(using-dimension-rules)
+
+ * html/HTMLElement.cpp:
+ (WebCore::HTMLElement::applyAspectRatioFromWidthAndHeightAttributesToStyle): Apply attributes width / height to aspectRatio of style if they aren't negative.
+ * html/HTMLElement.h:
+ * html/HTMLImageElement.cpp:
+ (WebCore::HTMLImageElement::collectStyleForPresentationAttribute): Use attributes width and height as a presentational hint for aspect-ratio.
+ * html/HTMLInputElement.cpp:
+ (WebCore::HTMLInputElement::collectStyleForPresentationAttribute): If isImageButton(), collect attributes width and height as aspect-ratio of m_presentationAttributeStyle.
+ * html/HTMLVideoElement.cpp:
+ (WebCore::HTMLVideoElement::collectStyleForPresentationAttribute): Ditto.
+ * rendering/RenderImage.cpp:
+ (WebCore::RenderImage::computeIntrinsicRatioInformation const): The intrinsicRatio is logicalAspectRatio()
+ if error image is not showing alt text.
+ (WebCore::RenderImage::canMapWidthHeightToAspectRatio const): Deleted. Remove the legacy code.
+ * rendering/RenderImage.h:
+ * rendering/RenderReplaced.cpp:
+ (WebCore::RenderReplaced::computeIntrinsicRatioInformation const): Ditto.
+ (WebCore::RenderReplaced::intrinsicAspectRatioFromWidthHeight const): Deleted. Ditto.
+ * rendering/RenderReplaced.h:
+ (WebCore::RenderReplaced::canMapWidthHeightToAspectRatio const): Deleted. Ditto.
+
2021-05-24 Commit Queue <commit-qu...@webkit.org>
Unreviewed, reverting r277867.
Modified: trunk/Source/WebCore/html/HTMLElement.cpp (277996 => 277997)
--- trunk/Source/WebCore/html/HTMLElement.cpp 2021-05-25 04:13:26 UTC (rev 277996)
+++ trunk/Source/WebCore/html/HTMLElement.cpp 2021-05-25 05:39:12 UTC (rev 277997)
@@ -28,6 +28,7 @@
#include "CSSMarkup.h"
#include "CSSPropertyNames.h"
#include "CSSValueKeywords.h"
+#include "CSSValueList.h"
#include "CSSValuePool.h"
#include "Chrome.h"
#include "ChromeClient.h"
@@ -620,6 +621,28 @@
return { };
}
+void HTMLElement::applyAspectRatioFromWidthAndHeightAttributesToStyle(MutableStyleProperties& style)
+{
+ if (!document().settings().aspectRatioOfImgFromWidthAndHeightEnabled())
+ return;
+
+ double width = parseValidHTMLFloatingPointNumber(attributeWithoutSynchronization(widthAttr)).valueOr(-1);
+ if (width < 0)
+ return;
+ double height = parseValidHTMLFloatingPointNumber(attributeWithoutSynchronization(heightAttr)).valueOr(-1);
+ if (height < 0)
+ return;
+
+ auto ratioList = CSSValueList::createSlashSeparated();
+ ratioList->append(CSSValuePool::singleton().createValue(width, CSSUnitType::CSS_NUMBER));
+ ratioList->append(CSSValuePool::singleton().createValue(height, CSSUnitType::CSS_NUMBER));
+ auto list = CSSValueList::createSpaceSeparated();
+ list->append(CSSValuePool::singleton().createIdentifierValue(CSSValueAuto));
+ list->append(ratioList);
+
+ style.setProperty(CSSPropertyAspectRatio, RefPtr<CSSValue>(WTFMove(list)));
+}
+
void HTMLElement::applyAlignmentAttributeToStyle(const AtomString& alignment, MutableStyleProperties& style)
{
// Vertical alignment with respect to the current baseline of the text
Modified: trunk/Source/WebCore/html/HTMLElement.h (277996 => 277997)
--- trunk/Source/WebCore/html/HTMLElement.h 2021-05-25 04:13:26 UTC (rev 277996)
+++ trunk/Source/WebCore/html/HTMLElement.h 2021-05-25 05:39:12 UTC (rev 277997)
@@ -154,6 +154,7 @@
void addHTMLLengthToStyle(MutableStyleProperties&, CSSPropertyID, const String& value);
void addHTMLColorToStyle(MutableStyleProperties&, CSSPropertyID, const String& color);
+ void applyAspectRatioFromWidthAndHeightAttributesToStyle(MutableStyleProperties&);
void applyAlignmentAttributeToStyle(const AtomString&, MutableStyleProperties&);
void applyBorderAttributeToStyle(const AtomString&, MutableStyleProperties&);
Modified: trunk/Source/WebCore/html/HTMLImageElement.cpp (277996 => 277997)
--- trunk/Source/WebCore/html/HTMLImageElement.cpp 2021-05-25 04:13:26 UTC (rev 277996)
+++ trunk/Source/WebCore/html/HTMLImageElement.cpp 2021-05-25 05:39:12 UTC (rev 277997)
@@ -115,11 +115,13 @@
void HTMLImageElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomString& value, MutableStyleProperties& style)
{
- if (name == widthAttr)
+ if (name == widthAttr) {
addHTMLLengthToStyle(style, CSSPropertyWidth, value);
- else if (name == heightAttr)
+ applyAspectRatioFromWidthAndHeightAttributesToStyle(style);
+ } else if (name == heightAttr) {
addHTMLLengthToStyle(style, CSSPropertyHeight, value);
- else if (name == borderAttr)
+ applyAspectRatioFromWidthAndHeightAttributesToStyle(style);
+ } else if (name == borderAttr)
applyBorderAttributeToStyle(value, style);
else if (name == vspaceAttr) {
addHTMLLengthToStyle(style, CSSPropertyMarginTop, value);
Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (277996 => 277997)
--- trunk/Source/WebCore/html/HTMLInputElement.cpp 2021-05-25 04:13:26 UTC (rev 277996)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp 2021-05-25 05:39:12 UTC (rev 277997)
@@ -707,9 +707,13 @@
} else if (name == widthAttr) {
if (m_inputType->shouldRespectHeightAndWidthAttributes())
addHTMLLengthToStyle(style, CSSPropertyWidth, value);
+ if (isImageButton())
+ applyAspectRatioFromWidthAndHeightAttributesToStyle(style);
} else if (name == heightAttr) {
if (m_inputType->shouldRespectHeightAndWidthAttributes())
addHTMLLengthToStyle(style, CSSPropertyHeight, value);
+ if (isImageButton())
+ applyAspectRatioFromWidthAndHeightAttributesToStyle(style);
} else if (name == borderAttr && isImageButton())
applyBorderAttributeToStyle(value, style);
else
Modified: trunk/Source/WebCore/html/HTMLVideoElement.cpp (277996 => 277997)
--- trunk/Source/WebCore/html/HTMLVideoElement.cpp 2021-05-25 04:13:26 UTC (rev 277996)
+++ trunk/Source/WebCore/html/HTMLVideoElement.cpp 2021-05-25 05:39:12 UTC (rev 277997)
@@ -113,11 +113,13 @@
void HTMLVideoElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomString& value, MutableStyleProperties& style)
{
- if (name == widthAttr)
+ if (name == widthAttr) {
addHTMLLengthToStyle(style, CSSPropertyWidth, value);
- else if (name == heightAttr)
+ applyAspectRatioFromWidthAndHeightAttributesToStyle(style);
+ } else if (name == heightAttr) {
addHTMLLengthToStyle(style, CSSPropertyHeight, value);
- else
+ applyAspectRatioFromWidthAndHeightAttributesToStyle(style);
+ } else
HTMLMediaElement::collectStyleForPresentationAttribute(name, value, style);
}
Modified: trunk/Source/WebCore/rendering/RenderImage.cpp (277996 => 277997)
--- trunk/Source/WebCore/rendering/RenderImage.cpp 2021-05-25 04:13:26 UTC (rev 277996)
+++ trunk/Source/WebCore/rendering/RenderImage.cpp 2021-05-25 05:39:12 UTC (rev 277997)
@@ -842,12 +842,6 @@
clearChildNeedsLayout();
}
-bool RenderImage::canMapWidthHeightToAspectRatio() const
-{
- // The aspectRatioOfImgFromWidthAndHeight only applies to <img>.
- return is<HTMLImageElement>(element()) && !isShowingAltText();
-}
-
void RenderImage::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio) const
{
ASSERT(!shouldApplySizeContainment(*this));
@@ -865,11 +859,11 @@
// Don't compute an intrinsic ratio to preserve historical WebKit behavior if we're painting alt text and/or a broken image.
if (shouldDisplayBrokenImageIcon()) {
- if (!style().hasAspectRatio()) {
- intrinsicRatio = intrinsicAspectRatioFromWidthHeight().valueOr(1);
- return;
- }
- intrinsicRatio = 1;
+ if (settings().aspectRatioOfImgFromWidthAndHeightEnabled()
+ && style().aspectRatioType() == AspectRatioType::AutoAndRatio && !isShowingAltText())
+ intrinsicRatio = style().logicalAspectRatio();
+ else
+ intrinsicRatio = 1;
return;
}
}
Modified: trunk/Source/WebCore/rendering/RenderImage.h (277996 => 277997)
--- trunk/Source/WebCore/rendering/RenderImage.h 2021-05-25 04:13:26 UTC (rev 277996)
+++ trunk/Source/WebCore/rendering/RenderImage.h 2021-05-25 05:39:12 UTC (rev 277997)
@@ -103,8 +103,6 @@
imageChanged(imageResource().imagePtr());
}
- bool canMapWidthHeightToAspectRatio() const override;
-
private:
const char* renderName() const override { return "RenderImage"; }
Modified: trunk/Source/WebCore/rendering/RenderReplaced.cpp (277996 => 277997)
--- trunk/Source/WebCore/rendering/RenderReplaced.cpp 2021-05-25 04:13:26 UTC (rev 277996)
+++ trunk/Source/WebCore/rendering/RenderReplaced.cpp 2021-05-25 05:39:12 UTC (rev 277997)
@@ -478,23 +478,6 @@
borderLeft() + paddingLeft(), borderRight() + paddingRight());
}
-Optional<double> RenderReplaced::intrinsicAspectRatioFromWidthHeight() const
-{
- if (!settings().aspectRatioOfImgFromWidthAndHeightEnabled())
- return Optional<double>();
-
- if (!canMapWidthHeightToAspectRatio())
- return Optional<double>();
-
- ASSERT(element());
- double attributeWidth = parseValidHTMLFloatingPointNumber(element()->getAttribute(HTMLNames::widthAttr)).valueOr(0);
- double attributeHeight = parseValidHTMLFloatingPointNumber(element()->getAttribute(HTMLNames::heightAttr)).valueOr(0);
- if (attributeWidth > 0 && attributeHeight > 0)
- return attributeWidth / attributeHeight;
-
- return Optional<double>();
-}
-
void RenderReplaced::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio) const
{
// If there's an embeddedContentBox() of a remote, referenced document available, this code-path should never be used.
@@ -510,10 +493,8 @@
if (!hasIntrinsicAspectRatio())
return;
- if (intrinsicSize.isEmpty()) {
- intrinsicRatio = intrinsicAspectRatioFromWidthHeight().valueOr(0);
+ if (intrinsicSize.isEmpty())
return;
- }
intrinsicRatio = intrinsicSize.width() / intrinsicSize.height();
}
Modified: trunk/Source/WebCore/rendering/RenderReplaced.h (277996 => 277997)
--- trunk/Source/WebCore/rendering/RenderReplaced.h 2021-05-25 04:13:26 UTC (rev 277996)
+++ trunk/Source/WebCore/rendering/RenderReplaced.h 2021-05-25 05:39:12 UTC (rev 277997)
@@ -63,10 +63,6 @@
void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const final;
- // This function determines if the object is allowed to compute aspect ratio from attributes width and height.
- virtual bool canMapWidthHeightToAspectRatio() const { return false; }
- Optional<double> intrinsicAspectRatioFromWidthHeight() const;
-
virtual LayoutUnit minimumReplacedHeight() const { return 0_lu; }
bool isSelected() const;