haikuwebkit/LayoutTests/fast/shadow-dom/css-scoping-host-class-and-...

131 lines
2.4 KiB
HTML
Raw Permalink Normal View History

Updating class name of a shadow host does not update the style applied by descendants of :host() https://bugs.webkit.org/show_bug.cgi?id=170762 <rdar://problem/31572668> Reviewed by Ryosuke Niwa. Source/WebCore: We need to invalidate shadow tree style when host classes or attributes change if it may be affected by host rules. Test: fast/shadow-dom/css-scoping-host-class-and-attribute-mutation.html * css/RuleSet.cpp: (WebCore::isHostSelectorMatchingInShadowTree): (WebCore::RuleSet::addRule): Check if we have :host selectors that affect shadow tree. * css/RuleSet.h: (WebCore::RuleSet::hasHostPseudoClassRulesMatchingInShadowTree): * style/AttributeChangeInvalidation.cpp: (WebCore::Style::mayBeAffectedByHostRules): (WebCore::Style::AttributeChangeInvalidation::invalidateStyle): Invalidate the whole subtree if there is a class change that may affect shadow tree style. * style/ClassChangeInvalidation.cpp: (WebCore::Style::mayBeAffectedByHostRules): (WebCore::Style::ClassChangeInvalidation::invalidateStyle): * style/IdChangeInvalidation.cpp: (WebCore::Style::mayBeAffectedByHostRules): (WebCore::Style::IdChangeInvalidation::invalidateStyle): Same for classes and ids. This should be refactored at some point to reduce copy-code. LayoutTests: * fast/shadow-dom/css-scoping-host-class-and-attribute-mutation-expected.html: Added. * fast/shadow-dom/css-scoping-host-class-and-attribute-mutation.html: Added. Canonical link: https://commits.webkit.org/188965@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@216761 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-05-12 12:31:49 +00:00
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>Test passes if you see a single 100px by 100px green box below.</p>
<div id=host1></div>
<div id=host2 class="red"></div>
<div id=host3></div>
<div id=host4></div>
<div id=host5></div>
<template id=shadow1>
<style>
:host(.green) div {
background-color: green;
}
div {
width: 100px;
height: 20px;
background-color: red;
}
</style>
<nav><div></div></nav>
</template>
<template id=shadow2>
<style>
:host(.red) > div {
background-color: red;
}
div {
width: 100px;
height: 20px;
background-color: green;
}
</style>
<div></div>
</template>
<template id=shadow3>
<style>
:host([color=green]) div {
background-color: green;
}
div {
width: 100px;
height: 20px;
background-color: red;
}
</style>
<div></div>
</template>
<template id=shadow4>
<style>
:host(#green) div {
background-color: green;
}
div {
width: 100px;
height: 20px;
background-color: red;
}
</style>
<div></div>
</template>
<template id=shadow5>
<style>
:host div.green {
background-color: green;
}
div {
width: 100px;
height: 20px;
background-color: red;
}
</style>
<div></div>
</template>
<div id=log></div>
<script>
function checkColor(host, expected)
{
const div = host.shadowRoot.querySelector("div");
const color = getComputedStyle(div).backgroundColor;
const width = getComputedStyle(div).width;
if (color != expected)
log.innerHTML += `FAIL: unexpected background color ${color}<br>`;
if (width != "100px")
log.innerHTML += `FAIL: unexpected width ${width}<br>`;
}
function test(hostselector, shadowselector, mutation) {
const host = document.querySelector(hostselector);
const shadowTemplate = document.querySelector(shadowselector);
host.attachShadow({ mode: 'open' });
host.shadowRoot.appendChild(shadowTemplate.content.cloneNode(true));
checkColor(host, "rgb(255, 0, 0)");
mutation(host);
checkColor(host, "rgb(0, 128, 0)");
}
test("#host1", "#shadow1", (host) => {
host.classList.add('green');
});
test("#host2", "#shadow2", (host) => {
host.classList.remove('red');
});
test("#host3", "#shadow3", (host) => {
host.setAttribute('color','green');
});
test("#host4", "#shadow4", (host) => {
host.setAttribute('id','green');
});
test("#host5", "#shadow5", (host) => {
host.shadowRoot.querySelector('div').classList.add('green');
});
</script>
</body>
</html>