-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[@container] Traverse shadow-including ancestors for container units
Fixed: 1325047 Change-Id: I69c381111b9d89f71fbb575cfcc25b58e12a546f
- Loading branch information
1 parent
c95ef3b
commit b7375f3
Showing
3 changed files
with
75 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
css/css-contain/container-queries/container-units-shadow.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
css/css-contain/container-queries/support/cq-testcommon.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} |