gecko-dev/testing/web-platform/tests/css/css-cascade/revert-val-005.html
Anders Hartvoll Ruud 19a871f7ce Bug 1626700 [wpt PR 22614] - Support reverting to/from css-logical properties, a=testonly
Automatic update from web-platform-tests
Support reverting to/from css-logical properties

The properties defined by css-logical (and more generally surrogates)
pose a hard problem for 'revert' in the StyleCascade, because
declarations such as 'margin-bottom:revert' may actually need to revert
to a different property in the previous origin (e.g. margin-block-end).

An example is the h1 element, which is styled by html.css using
css-logical properties. When the author then reverts using a
corresponding physical property, we can't simply look up the cascaded
value for that same physical property in the UA origin: we must be
aware that the css-logical property won the cascade _at that level_.

So when we we're applying an author declaration 'margin-bottom:revert',
we have to find the *target property* for the revert, which is either
margin-bottom (if that property won the cascade at the target origin),
or the corresponding css-logical property. However, to find the target
property, we need to know during the application of margin-bottom that
a corresponding logical property (surrogate) needs to be taken into
account. AutoSurrogateScope was created for this purpose, which sets
(and resets) a "current surrogate" field on CascadeResolver. This
current surrogate is used when resolving reverts, in order to find
the correct target property.

Also, we don't control the order in which physical/logical properties
are applied. This means we could be applying the physical property
first, which is unaware of any logical properties that should have been
taken into account for revert. In other words, if we apply
'margin-bottom:revert' without the context of a "current surrogate" set,
we'll fall back to unconditionally using margin-bottom as the target
property, which may be incorrect if there also exists a logical
property we'll get to later. This is why the force-reapply code exists:
when both the physical and logical property exists in the cascade,
the physical property must be applied (or re-applied) during
AutoSurrogateScope, otherwise revert will not behave correctly.

Bug: 579788
Change-Id: I864a4c9afdd94f130c42635d28d45c843d5fb617
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2130850
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Reviewed-by: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756419}

--

wpt-commits: a7b84565335bd31cbb265feca05cbef9cb4e999a
wpt-pr: 22614
2020-04-09 10:35:40 +00:00

40 lines
1.3 KiB
HTML

<!DOCTYPE html>
<title>CSS Cascade: 'revert' in css-logical properties</title>
<link rel="help" href="https://drafts.csswg.org/css-cascade/#default">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
#h1_physical {
margin: 0px;
margin: revert;
}
#h1_logical {
margin: 0px;
margin-inline-start: revert;
margin-inline-end: revert;
margin-block-start: revert;
margin-block-end: revert;
}
</style>
<h1 id=h1_physical></h1>
<h1 id=h1_logical></h1>
<h1 id=ref></h1>
<script>
test(function() {
let actual = getComputedStyle(h1_physical).marginTop;
let expected = getComputedStyle(ref).marginTop;
// This test assumes that the UA style sheet sets a non-0px value on
// <h1> elements:
assert_not_equals(expected, '0px');
assert_equals(actual, expected);
}, 'The revert keyword works with physical properties');
test(function() {
let actual = getComputedStyle(h1_logical).marginTop;
let expected = getComputedStyle(ref).marginTop;
// This test assumes that the UA style sheet sets a non-0px value on
// <h1> elements:
assert_not_equals(expected, '0px');
assert_equals(actual, expected);
}, 'The revert keyword works with logical properties');
</script>