Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@container] Traverse shadow-including ancestors for container units #34055

Merged
merged 1 commit into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 1 addition & 11 deletions css/css-contain/container-queries/container-for-shadow-dom.html
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,7 @@
<script>
setup(() => {
assert_implements_container_queries();

// Fallback for browsers not supporting declarative Shadow DOM
(function attachShadowRoots(root) {
root.querySelectorAll("template[shadowroot]").forEach(template => {
const mode = template.getAttribute("shadowroot");
const shadowRoot = template.parentNode.attachShadow({ mode });
shadowRoot.appendChild(template.content);
template.remove();
attachShadowRoots(shadowRoot);
});
})(document);
polyfill_declarative_shadow_dom(document);
});

const green = "rgb(0, 128, 0)";
Expand Down
64 changes: 64 additions & 0 deletions css/css-contain/container-queries/container-units-shadow.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!doctype html>
<title>Container Relative Units: Shadow DOM</title>
<link rel="help" href="https://drafts.csswg.org/css-contain-3/#container-lengths">
<link rel="help" href="https://drafts.csswg.org/css-contain-3/#container-queries">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/cq-testcommon.js"></script>
<style>
#outer {
container-type: size;
width: 200px;
height: 200px;
}
#direct {
container-type: inline-size;
width: 50cqw;
height: 50cqh;
}
#nondirect {
width: 10cqw;
height: 10cqh;
background: green;
}
</style>
<div id=outer>
<div>
<template shadowroot="open">
<style>
#inner {
container-type: size;
width: 30px;
height: 30px;
}
</style>
<div id=inner>
<slot></slot>
</div>
</template>
<div>
<div id=direct>
<div id=nondirect>
</div>
</div>
</div>
</div>
</div>
<script>
setup(() => {
assert_implements_container_queries();
polyfill_declarative_shadow_dom(document);
});

test(() => {
let cs = getComputedStyle(direct);
assert_equals(cs.width, '100px');
assert_equals(cs.height, '100px');
}, 'Direct slotted child queries shadow-including ancestors');

test(() => {
let cs = getComputedStyle(nondirect);
assert_equals(cs.width, '10px'); // #direct
assert_equals(cs.height, '20px'); // #outer
}, 'Nondirect slotted child queries shadow-including ancestors');
</script>
10 changes: 10 additions & 0 deletions css/css-contain/container-queries/support/cq-testcommon.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
function assert_implements_container_queries() {
assert_implements(CSS.supports("container-type:size"), "Basic support for container queries required");
}

function polyfill_declarative_shadow_dom(root) {
root.querySelectorAll("template[shadowroot]").forEach(template => {
const mode = template.getAttribute("shadowroot");
const shadowRoot = template.parentNode.attachShadow({ mode });
shadowRoot.appendChild(template.content);
template.remove();
polyfill_declarative_shadow_dom(shadowRoot);
});
}