Skip to content

Commit

Permalink
[@container] Traverse shadow-including ancestors for container units
Browse files Browse the repository at this point in the history
Fixed: 1325047
Change-Id: I69c381111b9d89f71fbb575cfcc25b58e12a546f
  • Loading branch information
andruud authored and chromium-wpt-export-bot committed May 13, 2022
1 parent c95ef3b commit b7375f3
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 11 deletions.
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);
});
}

0 comments on commit b7375f3

Please sign in to comment.