Skip to content

Commit 37dc10d

Browse files
[scope-vt] Fix crash with display:inline and friends
Skip the view transition when attempting a scoped-VT on an element that has an inline display type. Display type inline-block is an exception since it has block characteristics in addition to inline. Also skip the VT when the display type inline's its children like ruby-text, or content. These display types do not create a layout box. A console warning is triggered to indicate why the transition was skipped. Once resolved in the spec, we can revisit how these display types are handled. Bug: 434891109, 436804019 Change-Id: I8ef4375b8805a788bc55ae30e90e2201c1bb83b7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6819008 Commit-Queue: Kevin Ellis <[email protected]> Reviewed-by: Steve Kobes <[email protected]> Cr-Commit-Position: refs/heads/main@{#1497618}
1 parent dc5b1fa commit 37dc10d

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html class="test-wait">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>Scoped VT on display:inline element</title>
7+
</head>
8+
<style>
9+
#scope {
10+
view-transition-name: scope;
11+
}
12+
</style>
13+
<body>
14+
<p><span id="scope">Hello</span> world</p>
15+
</body>
16+
<script>
17+
async function testDisplayProperty(type) {
18+
scope.style = `display: ${type}`;
19+
const vt = scope.startViewTransition();
20+
await vt.finished;
21+
}
22+
23+
async function runTests() {
24+
const tests = [
25+
// Inline display types:
26+
'inline',
27+
'inline-flex',
28+
'inline flow',
29+
'math',
30+
'ruby',
31+
// No box, and children are inline:
32+
'ruby-text',
33+
'content'
34+
];
35+
tests.forEach(async display => {
36+
await testDisplayProperty(display);
37+
});
38+
document.documentElement.classList.remove('test-wait');
39+
}
40+
41+
window.onload = runTests;
42+
</script>
43+
</html>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<!-- TODO update link -->
6+
<link rel="help" href="https://drafts.csswg.org/css-view-transitions-2/">
7+
<meta name="viewport" content="width=device-width, initial-scale=1">
8+
<title>Scoped view transition with inline block</title>
9+
</head>
10+
<style>
11+
#target {
12+
display: inline-block;
13+
view-transition-name: target;
14+
}
15+
16+
::view-transition-group(target),
17+
::view-transition-old(target) {
18+
animation: unset;
19+
}
20+
21+
@keyframes colorize {
22+
to { opacity: 0.5; }
23+
}
24+
25+
::view-transition-new(target) {
26+
animation: colorize 1s paused steps(1, jump-start);
27+
}
28+
</style>
29+
<script src="/web-animations/testcommon.js"></script>
30+
<script src="/resources/testharness.js"></script>
31+
<script src="/resources/testharnessreport.js"></script>
32+
<body>
33+
<p><span id="target">Hello</span> World</p>
34+
</body>
35+
<script>
36+
promise_test(async t => {
37+
const vt = target.startViewTransition();
38+
await vt.ready;
39+
await Promise.all(document.getAnimations().map(a => a.ready));
40+
const style =
41+
getComputedStyle(target, '::view-transition-new(target)');
42+
assert_equals(style.opacity, '0.5', 'Opacity animation is in effect');
43+
}, 'Scoped view transition on an inline-block element');
44+
</script>
45+
</html>

0 commit comments

Comments
 (0)