Skip to content

Commit

Permalink
[cssom] Serialize the 'all' shorthand in cssText
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Loirooriol authored and darinadler committed Oct 9, 2022
1 parent a689335 commit 4481e38
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
@@ -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

@@ -0,0 +1,38 @@
<!DOCTYPE html>
<title>CSSOM test: serialization of the 'all' shorthand in cssText</title>
<link rel="author" title="Oriol Brufau" href="mailto:obrufau@igalia.com">
<link rel="help" href="https://drafts.csswg.org/cssom-1/#dom-cssstyledeclaration-csstext">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
const style = document.createElement("div").style;

test(function() {
style.cssText = "all: inherit";
assert_equals(style.cssText, "all: inherit;");
}, "'all' shorthand alone");

test(function() {
style.cssText = "width: 100px; all: inherit; height: inherit";
assert_equals(style.cssText, "all: inherit;");
}, "'all' shorthand with 'width' and 'height'");

test(function() {
style.cssText = "direction: ltr; all: inherit; unicode-bidi: plaintext";
assert_equals(style.cssText, "direction: ltr; all: inherit; unicode-bidi: plaintext;");
}, "'all' shorthand with 'direction' and 'unicode-bidi'");

test(function() {
style.cssText = "width: 100px; --a: a; all: inherit; --b: b; height: inherit";
assert_equals(style.cssText, "--a: a; all: inherit; --b: b;");
}, "'all' shorthand with 'width', 'height' and custom properties");

test(function() {
let cssText = "all: inherit; ";
for (let longhand of getComputedStyle(document.documentElement)) {
cssText += longhand + ": inherit; ";
}
style.cssText = cssText;
assert_equals(style.cssText, "all: inherit; direction: inherit; unicode-bidi: inherit;");
}, "'all' shorthand with all longhands");
</script>
15 changes: 15 additions & 0 deletions Source/WebCore/css/StyleProperties.cpp
Expand Up @@ -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:
Expand Down Expand Up @@ -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 (<rdar://problem/5143183>).
// 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);
Expand Down

0 comments on commit 4481e38

Please sign in to comment.