LibWeb: Allow setting shorthand CSS properties via CSSStyleDeclaration

We now expand shorthands into their respective longhand values when
assigning to a shorthand named property on a CSSStyleDeclaration.

We also make sure that shorthands can be round-tripped by correctly
routing named property access through the getPropertyValue() AO,
and expanding it to handle shorthands as well.

A lot of WPT tests for CSS parsing rely on these mechanisms and should
now start working. :^)

Note that multi-level recursive shorthands like `border` don't work
100% correctly yet. We're going to need a bunch more logic to properly
serialize e.g `border-width` or `border` itself.
This commit is contained in:
Andreas Kling 2024-09-21 20:11:03 +02:00 committed by Andreas Kling
commit e40ad73ae7
Notes: github-actions[bot] 2024-09-22 07:46:48 +00:00
3 changed files with 138 additions and 13 deletions

View file

@ -0,0 +1,38 @@
<script src="../include.js"></script>
<script>
function testFlexValue(value) {
let e = document.createElement("div");
e.style.flex = value;
println("Setting flex: '" + value + "'; becomes...");
println(" flex-basis: '" + e.style.flexBasis + "'");
println(" flex-grow: '" + e.style.flexGrow + "'");
println(" flex-shrink: '" + e.style.flexShrink + "'");
println(" flex: '" + e.style.flex + "'");
println(" e.style.length: " + e.style.length);
for (let p = 0; p < e.style.length; ++p) {
println(" > [" + p + "] " + e.style[p]);
}
println("");
}
function testBorderValue(value) {
let e = document.createElement("div");
e.style.border = value;
println("Setting border: '" + value + "'; becomes...");
println(" border-width: '" + e.style.getPropertyValue('border-width') + "'");
println(" border-style: '" + e.style.borderStyle + "'");
println(" border-color: '" + e.style.borderColor + "'");
println(" border: '" + e.style.border + "'");
println(" e.style.length: " + e.style.length);
for (let p = 0; p < e.style.length; ++p) {
println(" > [" + p + "] " + e.style[p]);
}
println("");
}
test(() => {
testFlexValue("none");
testFlexValue("auto 1 2");
testFlexValue("");
testBorderValue("1px solid red");
});
</script>