From 4481e38af645d3bac270241c50053345a9962d8a Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Sun, 9 Oct 2022 14:14:32 -0700 Subject: [PATCH] [cssom] Serialize the 'all' shorthand in cssText https://bugs.webkit.org/show_bug.cgi?id=190753 Reviewed by Darin Adler. Test: imported/w3c/web-platform-tests/css/cssom/cssstyledeclaration-csstext-all-shorthand.html * LayoutTests/imported/w3c/web-platform-tests/css/cssom/cssstyledeclaration-csstext-all-shorthand-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/css/cssom/cssstyledeclaration-csstext-all-shorthand.html: Added. * Source/WebCore/css/StyleProperties.cpp: (WebCore::StyleProperties::asTextInternal const): Canonical link: https://commits.webkit.org/255329@main --- ...aration-csstext-all-shorthand-expected.txt | 7 ++++ ...tyledeclaration-csstext-all-shorthand.html | 38 +++++++++++++++++++ Source/WebCore/css/StyleProperties.cpp | 15 ++++++++ 3 files changed, 60 insertions(+) create mode 100644 LayoutTests/imported/w3c/web-platform-tests/css/cssom/cssstyledeclaration-csstext-all-shorthand-expected.txt create mode 100644 LayoutTests/imported/w3c/web-platform-tests/css/cssom/cssstyledeclaration-csstext-all-shorthand.html diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/cssom/cssstyledeclaration-csstext-all-shorthand-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/css/cssom/cssstyledeclaration-csstext-all-shorthand-expected.txt new file mode 100644 index 000000000000..0247e6338f89 --- /dev/null +++ b/LayoutTests/imported/w3c/web-platform-tests/css/cssom/cssstyledeclaration-csstext-all-shorthand-expected.txt @@ -0,0 +1,7 @@ + +PASS 'all' shorthand alone +PASS 'all' shorthand with 'width' and 'height' +PASS 'all' shorthand with 'direction' and 'unicode-bidi' +PASS 'all' shorthand with 'width', 'height' and custom properties +PASS 'all' shorthand with all longhands + diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/cssom/cssstyledeclaration-csstext-all-shorthand.html b/LayoutTests/imported/w3c/web-platform-tests/css/cssom/cssstyledeclaration-csstext-all-shorthand.html new file mode 100644 index 000000000000..6619538cf109 --- /dev/null +++ b/LayoutTests/imported/w3c/web-platform-tests/css/cssom/cssstyledeclaration-csstext-all-shorthand.html @@ -0,0 +1,38 @@ + +CSSOM test: serialization of the 'all' shorthand in cssText + + + + + diff --git a/Source/WebCore/css/StyleProperties.cpp b/Source/WebCore/css/StyleProperties.cpp index eaf1d081ef75..223b5ca73ad2 100644 --- a/Source/WebCore/css/StyleProperties.cpp +++ b/Source/WebCore/css/StyleProperties.cpp @@ -1680,6 +1680,19 @@ StringBuilder StyleProperties::asTextInternal() const shorthands.append(substitutionValue.shorthandPropertyId()); value = substitutionValue.shorthandValue().cssText(); } else { + // FIXME: could probably use matchingShorthandsForLonghand() instead of populating 'shorthands' manually. + switch (propertyID) { + case CSSPropertyCustom: + case CSSPropertyDirection: + case CSSPropertyUnicodeBidi: + // These are the only longhands not included in the 'all' shorthand. + break; + default: + ASSERT(propertyID >= firstCSSProperty); + ASSERT(propertyID < firstShorthandProperty); + shorthands.append(CSSPropertyAll); + } + switch (propertyID) { case CSSPropertyAnimationName: case CSSPropertyAnimationDuration: @@ -1968,6 +1981,8 @@ StringBuilder StyleProperties::asTextInternal() const // In 2007 we decided this was required because background-position-x/y are non-standard properties and WebKit generated output would not work in Firefox (). // FIXME: This can probably be cleaned up now that background-position-x/y are standardized. auto appendPositionOrProperty = [&] (int xIndex, int yIndex, const char* name, const StylePropertyShorthand& shorthand) { + if (shorthandPropertyUsed[CSSPropertyAll - firstShorthandProperty]) + return; if (xIndex != -1 && yIndex != -1 && propertyAt(xIndex).isImportant() == propertyAt(yIndex).isImportant()) { String value; auto xProperty = propertyAt(xIndex);