LibWeb/CSS: Correct behavior of revert inside a @layer

`revert` is supposed to revert to the previous cascade origin, but we
previously had it reverting to the previous layer. To support both,
track them separately during the cascade.

As part of this, we make `set_property_expanding_shorthands()` fall back
to `initial` if it can't find a previous value to revert to. Previously
we would just shrug and do nothing if that happened, which only works
if the value you want to revert to is whatever is currently in `style`.
That's no longer the case, because `revert` should skip over any layer
styles that have been applied since the previous origin.
This commit is contained in:
Sam Atkins 2024-09-25 14:22:50 +01:00 committed by Andreas Kling
commit bea47a2554
Notes: github-actions[bot] 2024-09-26 06:09:32 +00:00
4 changed files with 88 additions and 30 deletions

View file

@ -0,0 +1,35 @@
<!DOCTYPE html>
<style>
@layer A, B, C;
@layer A {
#target {
color: red;
}
}
@layer B {
#target {
color: blue;
}
}
@layer C {
#target {
color: revert;
}
}
</style>
<script src="../include.js"></script>
<div id="target"></div>
<div id="initial"></div>
<script>
test(() => {
const target = document.getElementById("target");
const initial = document.getElementById("target");
const expected = getComputedStyle(initial).color;
const actual = getComputedStyle(target).color;
if (expected === actual) {
println('PASS, revert skipped the layers');
} else {
println(`FAIL: got ${actual}, expected ${expected}`);
}
});
</script>