Commit 1fb36415 authored by rune@opera.com's avatar rune@opera.com

Invalidate style from shadow host, not root, to apply :host rules.

This is a regression from r201058. We incorrectly marked the shadow root
node for style recalc instead of the host. Marking the host is necessary
to apply new :host rules.

R=esprehn@chromium.org
BUG=525280

Review URL: https://codereview.chromium.org/1311463004

git-svn-id: svn://svn.chromium.org/blink/trunk@201311 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent fc4a759a
...@@ -4,7 +4,7 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE ...@@ -4,7 +4,7 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
PASS getComputedStyle(outerSpan).color is "rgb(255, 0, 0)" PASS getComputedStyle(outerSpan).color is "rgb(255, 0, 0)"
PASS internals.updateStyleAndReturnAffectedElementCount() is 9 PASS internals.updateStyleAndReturnAffectedElementCount() is 5
PASS getComputedStyle(outerSpan).color is "rgb(0, 128, 0)" PASS getComputedStyle(outerSpan).color is "rgb(0, 128, 0)"
PASS successfullyParsed is true PASS successfullyParsed is true
......
...@@ -32,12 +32,13 @@ ...@@ -32,12 +32,13 @@
shouldBeEqualToString("getComputedStyle(outerSpan).color", "rgb(255, 0, 0)"); shouldBeEqualToString("getComputedStyle(outerSpan).color", "rgb(255, 0, 0)");
document.body.offsetTop;
var sheet = document.createElement("style"); var sheet = document.createElement("style");
sheet.appendChild(document.createTextNode("::content #outerSpan { color: green }")); sheet.appendChild(document.createTextNode("::content #outerSpan { color: green }"));
root2.appendChild(sheet); root2.appendChild(sheet);
if (window.internals) if (window.internals)
shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "9"); shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "5");
shouldBeEqualToString("getComputedStyle(outerSpan).color", "rgb(0, 128, 0)"); shouldBeEqualToString("getComputedStyle(outerSpan).color", "rgb(0, 128, 0)");
</script> </script>
Insert a style element into a shadow tree affecting the host.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS getComputedStyle(host2).color is "rgb(255, 0, 0)"
PASS internals.updateStyleAndReturnAffectedElementCount() is 2
PASS getComputedStyle(host2).color is "rgb(0, 128, 0)"
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<script src="../../../resources/js-test.js"></script>
<style>
#outerHost { color: red }
</style>
<div>
<div id="outerHost"></div>
<div></div>
<div></div>
</div>
<script>
description("Insert a style element into a shadow tree affecting the host.");
var outerRoot = outerHost.createShadowRoot();
outerRoot.innerHTML = "<div><div id='host1'></div></div><div></div>";
var host1 = outerRoot.querySelector("#host1");
var root1 = host1.createShadowRoot();
root1.innerHTML = "<div><div id='host2'></div></div><div></div>";
var host2 = root1.querySelector("#host2");
var root2 = host2.createShadowRoot();
root2.innerHTML = "This text should be green";
shouldBeEqualToString("getComputedStyle(host2).color", "rgb(255, 0, 0)");
document.body.offsetTop;
var sheet = document.createElement("style");
sheet.appendChild(document.createTextNode(":host { color: green }"));
root2.appendChild(sheet);
if (window.internals)
shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "2");
shouldBeEqualToString("getComputedStyle(host2).color", "rgb(0, 128, 0)");
</script>
...@@ -177,12 +177,12 @@ static bool elementMatchesSelectorScopes(const Element* element, const HashSet<S ...@@ -177,12 +177,12 @@ static bool elementMatchesSelectorScopes(const Element* element, const HashSet<S
return false; return false;
} }
static ContainerNode* outermostShadowHost(const ShadowRoot& root) static ContainerNode* outermostShadowHost(ContainerNode& host)
{ {
ContainerNode* host = root.host(); ContainerNode* outerHost = &host;
while (host->isInShadowTree()) while (outerHost->isInShadowTree())
host = host->containingShadowRoot()->host(); outerHost = outerHost->containingShadowRoot()->host();
return host; return outerHost;
} }
void StyleSheetInvalidationAnalysis::invalidateStyle() void StyleSheetInvalidationAnalysis::invalidateStyle()
...@@ -190,9 +190,9 @@ void StyleSheetInvalidationAnalysis::invalidateStyle() ...@@ -190,9 +190,9 @@ void StyleSheetInvalidationAnalysis::invalidateStyle()
ASSERT(!m_dirtiesAllStyle); ASSERT(!m_dirtiesAllStyle);
if (m_treeScope->rootNode().isShadowRoot()) { if (m_treeScope->rootNode().isShadowRoot()) {
ContainerNode* invalidationRoot = &m_treeScope->rootNode(); ContainerNode* invalidationRoot = toShadowRoot(m_treeScope->rootNode()).host();
if (m_hasDistributedRules) if (m_hasDistributedRules)
invalidationRoot = outermostShadowHost(*toShadowRoot(invalidationRoot)); invalidationRoot = outermostShadowHost(*invalidationRoot);
invalidationRoot->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create(StyleChangeReason::StyleSheetChange)); invalidationRoot->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create(StyleChangeReason::StyleSheetChange));
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment