Title: [137708] trunk
Revision
137708
Author
ta...@google.com
Date
2012-12-13 20:40:47 -0800 (Thu, 13 Dec 2012)

Log Message

[Shadow DOM]: scoped styles are not applied in the cascade order.
https://bugs.webkit.org/show_bug.cgi?id=103239

Reviewed by Dimitri Glazkov.

Source/WebCore:

If the scoping elements of two declarations have an ancestor/
descendant relationship, the declaration whose scoping element is
the descendant should win.
c.f. http://dev.w3.org/csswg/css3-cascade/#cascade

Test: fast/css/style-scoped/style-scoped-nested.html
      fast/css/style-scoped/style-scoped-with-important-rule.html

* css/RuleSet.cpp:
(WebCore::RuleSet::addRule):
Removed specificity for @host @-rules. Now @host @-rules use the
cascading order instead.
* css/RuleSet.h:
Removed increaseSpecificity. The method is used by only @host @-rules.
* css/StyleResolver.cpp:
(WebCore::StyleResolver::matchScopedAuthorRules):
(WebCore::StyleResolver::matchHostRules):
(WebCore::StyleResolver::matchAuthorRules):
Modified to invoke sortAndTransferMatchedRules per scoping element.
The order of "matchXXXRules" must be the same as the cascading order.
So matchHostRules was invoked after collecting all scoped author rules.
* css/StyleScopeResolver.cpp:
(WebCore::StyleScopeResolver::addHostRule):
Removed RuleIsHostRule. We don't need the flag.
* html/HTMLStyleElement.cpp:
(WebCore::HTMLStyleElement::registerWithScopingNode):
Needs to pass the last test case of style-scoped-nested.html.
When appending some style element to a shadow root, we should recalc
styles of all elements in the shadow dom tree. And if the style
element has @host @-rules, we have to update the host's style.

LayoutTests:

* fast/css/style-scoped/style-scoped-nested-expected.txt: Added.
* fast/css/style-scoped/style-scoped-nested.html: Added.
* fast/css/style-scoped/style-scoped-with-important-rule-expected.txt: Added.
* fast/css/style-scoped/style-scoped-with-important-rule.html: Added.
* fast/regions/style-scoped-in-flow-override-region-styling-expected.html:
* fast/regions/style-scoped-in-flow-override-region-styling.html:
Changed the test's expectation.
Since @region's scoping element is :root but scoped styles' scoping
element is a descendant element of :root, scoped styles should win.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (137707 => 137708)


--- trunk/LayoutTests/ChangeLog	2012-12-14 04:38:20 UTC (rev 137707)
+++ trunk/LayoutTests/ChangeLog	2012-12-14 04:40:47 UTC (rev 137708)
@@ -1,3 +1,20 @@
+2012-12-13  Takashi Sakamoto  <ta...@google.com>
+
+        [Shadow DOM]: scoped styles are not applied in the cascade order.
+        https://bugs.webkit.org/show_bug.cgi?id=103239
+
+        Reviewed by Dimitri Glazkov.
+
+        * fast/css/style-scoped/style-scoped-nested-expected.txt: Added.
+        * fast/css/style-scoped/style-scoped-nested.html: Added.
+        * fast/css/style-scoped/style-scoped-with-important-rule-expected.txt: Added.
+        * fast/css/style-scoped/style-scoped-with-important-rule.html: Added.
+        * fast/regions/style-scoped-in-flow-override-region-styling-expected.html:
+        * fast/regions/style-scoped-in-flow-override-region-styling.html:
+        Changed the test's expectation.
+        Since @region's scoping element is :root but scoped styles' scoping
+        element is a descendant element of :root, scoped styles should win.
+
 2012-12-13  Kentaro Hara  <hara...@chromium.org>
 
         ChildNodesLazySnapshot::nextNode() can crash

Added: trunk/LayoutTests/fast/css/style-scoped/style-scoped-nested-expected.txt (0 => 137708)


--- trunk/LayoutTests/fast/css/style-scoped/style-scoped-nested-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/css/style-scoped/style-scoped-nested-expected.txt	2012-12-14 04:40:47 UTC (rev 137708)
@@ -0,0 +1,17 @@
+Test whether scoped styles are applied in the cascade order or not.
+If this test passes, rules which are declared in descendant scoping element are applied to a target element.
+c.f. https://bugs.webkit.org/show_bug.cgi?id=103239
+Only document.style is applied to the target.
+PASS window.getComputedStyle(target).color is "rgb(255, 0, 0)"
+A new scoped style is inserted into the grandparent node of the target. A class rule in the inserted scoped style wins an id rule in document.style.
+PASS window.getComputedStyle(target).color is "rgb(255, 255, 0)"
+A new scoped style is inserted into the parent node of the target. A tag rule in the inserted scoped style wins an id rule and a class rule in existing styles.
+PASS window.getComputedStyle(target).color is "rgb(0, 0, 255)"
+Test a span in some shadow dom tree. Since the span's host node is the above target, we have to see all inserted scoped styles and an author style to find whether the styles have any matched rules or not.
+PASS window.getComputedStyle(targetInShadow).color is "rgb(0, 0, 255)"
+Append a new style element to the shadow root. The style's scoping element is the shadow root. Rules in the style should override other rules in ascendant (scoped) styles.
+PASS window.getComputedStyle(targetInShadow).color is "rgb(0, 255, 0)"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/css/style-scoped/style-scoped-nested.html (0 => 137708)


--- trunk/LayoutTests/fast/css/style-scoped/style-scoped-nested.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/style-scoped/style-scoped-nested.html	2012-12-14 04:40:47 UTC (rev 137708)
@@ -0,0 +1,64 @@
+<!doctype html>
+<html>
+<head>
+<style>
+#target, #targetInShadow {
+    color: red;
+}
+</style>
+<script src=""
+<script src=""
+<script>
+if (window.testRunner)
+    testRunner.dumpAsText();
+</script>
+</head>
+<body>
+  <div id="grandparent">
+    <div id="parent">
+      <span class="target" id="target"></span>
+    </div>
+  </div>
+</body>
+<script>
+debug("Test whether scoped styles are applied in the cascade order or not.");
+debug("If this test passes, rules which are declared in descendant scoping element are applied to a target element.");
+debug("c.f. https://bugs.webkit.org/show_bug.cgi?id=103239");
+
+var target = document.getElementById("target");
+debug("Only document.style is applied to the target.");
+shouldBe("window.getComputedStyle(target).color", '"rgb(255, 0, 0)"');
+
+var styleForGrandparent = document.createElement("style");
+styleForGrandparent.scoped = true;
+styleForGrandparent.innerHTML = ".target { color: yellow; }";
+document.getElementById("grandparent").appendChild(styleForGrandparent);
+debug("A new scoped style is inserted into the grandparent node of the target. A class rule in the inserted scoped style wins an id rule in document.style.");
+shouldBe("window.getComputedStyle(target).color", '"rgb(255, 255, 0)"');
+
+var styleForParent = document.createElement("style");
+styleForParent.scoped = true;
+styleForParent.innerHTML = "span { color: blue; }";
+document.getElementById("parent").appendChild(styleForParent);
+debug("A new scoped style is inserted into the parent node of the target. A tag rule in the inserted scoped style wins an id rule and a class rule in existing styles.");
+shouldBe("window.getComputedStyle(target).color", '"rgb(0, 0, 255)"');
+
+var shadowRoot = target.webkitCreateShadowRoot();
+shadowRoot.innerHTML = '<span id="targetInShadow" class="target"></span>';
+var targetInShadow = shadowRoot.getElementById("targetInShadow");
+shadowRoot.applyAuthorStyles = true;
+// Disable style-inheritance from its shadow host to check whether rules match
+// the span in the shadow tree or not.
+shadowRoot.resetStyleInheritance = true;
+debug("Test a span in some shadow dom tree. Since the span's host node is the above target, we have to see all inserted scoped styles and an author style to find whether the styles have any matched rules or not.");
+shouldBe("window.getComputedStyle(targetInShadow).color", '"rgb(0, 0, 255)"');
+
+var styleInShadow = document.createElement("style");
+styleInShadow.innerHTML = "span { color: lime; }";
+shadowRoot.appendChild(styleInShadow);
+debug("Append a new style element to the shadow root. The style's scoping element is the shadow root. Rules in the style should override other rules in ascendant (scoped) styles.");
+shouldBe("window.getComputedStyle(targetInShadow).color", '"rgb(0, 255, 0)"');
+
+</script>
+<script src=""
+</html>

Added: trunk/LayoutTests/fast/css/style-scoped/style-scoped-with-important-rule-expected.txt (0 => 137708)


--- trunk/LayoutTests/fast/css/style-scoped/style-scoped-with-important-rule-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/css/style-scoped/style-scoped-with-important-rule-expected.txt	2012-12-14 04:40:47 UTC (rev 137708)
@@ -0,0 +1,27 @@
+Test that rules in an inner scoped stylesheet don't override !important rules declared in an outer scoped stylesheet.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Case1: The target element has any matched important rule declared in an outer scoped stylesheet, and the element also has any matched normal rule declared in an inner scoped stylesheet.
+PASS getComputedStyle(target1).borderColor is "rgb(0, 128, 0)"
+Case2: The target element has any matched important rule declared in an outer scoped stylesheet, and the element also has a matched normal ID rule declared in an inner scoped stylesheet.
+PASS getComputedStyle(target2).borderColor is "rgb(0, 128, 0)"
+Case3: The target element has any matched important rule declared in an outer scoped stylesheet, and the element also has matched normal rules declared in an inner scoped stylesheet and in a STYLE attribute.
+PASS getComputedStyle(target3).borderColor is "rgb(0, 128, 0)"
+Case4: The target element has matched important rules. One is declared in an outer scoped stylesheet and the other is declared in an inner scoped stylesheet.
+PASS getComputedStyle(target4).borderColor is "rgb(0, 0, 255)"
+Case5: The target element has any matched important rule declared in an author stylesheet, and the element also has matched normal rules declared in an inner scoped stylesheet.
+PASS getComputedStyle(target5).borderColor is "rgb(0, 255, 0)"
+Case6: The target element has matched important rules. One is declared in an author stylesheet (not scoped) and the other is declared in a scoped stylesheet.
+PASS getComputedStyle(target6).borderColor is "rgb(0, 0, 255)"
+Case7: The target element has any matched important rule declared in an outer scoped stylesheet. The element is in a shadow dom tree whose shadow root has apply-author-styles true. The shadow dom tree has any other normal rules which match the element.
+PASS getComputedStyle(target7).borderColor is "rgb(0, 128, 0)"
+Case8: The target element in a shadow dom tree has any matched important rule declared in an outer scoped stylesheet in an enclosing shadow dom tree. The target element's shadow root has apply-author-styles true.
+PASS getComputedStyle(target8).borderColor is "rgb(0, 128, 0)"
+Case8': The target element is in a shadow dom tree. An enclosing shadow dom tree has some stylesheet which declares an important rule. The target element's shadow root has apply-author-styles false.
+PASS getComputedStyle(target8).borderColor is "rgb(0, 0, 255)"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/css/style-scoped/style-scoped-with-important-rule.html (0 => 137708)


--- trunk/LayoutTests/fast/css/style-scoped/style-scoped-with-important-rule.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/style-scoped/style-scoped-with-important-rule.html	2012-12-14 04:40:47 UTC (rev 137708)
@@ -0,0 +1,118 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+span { border-color: lime ! important; }
+div { border-color: orange; }
+div#id2 { border-color: yellow; }
+</style>
+<script src=""
+<script src=""
+</head>
+<body>
+<div>
+  <style scoped>
+      div { border-color: green ! important; }
+      div { border-color: red; }
+      div#id2 {border-color: purple; }
+  </style>
+  <div>
+    <style scoped>
+        div { border-color: blue; }
+    </style>
+    <div id="id1"></div>
+  </div>
+  <div>
+    <style scoped>
+        div#id2 { border-color: blue; }
+    </style>
+    <div id="id2"></div>
+  </div>
+  <div>
+    <style scoped>
+        div { border-color: blue; }
+    </style>
+    <div id="id3" style="border-color: red;"></div>
+  </div>
+  <div>
+    <style scoped>
+      div { border-color: blue !important; }
+    </style>
+    <div id="id4"></div>
+  </div>
+  <div id="host1">Shadow Host</div>
+</div>
+<div>
+  <style scoped>
+      span#id5 { border-color: blue; }
+  </style>
+  <span id="id5"></span>
+</div>
+<div>
+  <style scoped>
+      span { border-color: blue !important; }
+  </style>
+  <span id="id6"></span>
+</div>
+<div>
+  <style scoped>
+      div { border-color: red;}
+  </style>
+  <div id="host2">Shadow Host</div>
+</div>
+</body>
+<script>
+description("Test that rules in an inner scoped stylesheet don't override !important rules declared in an outer scoped stylesheet.");
+
+var target1 = document.getElementById("id1");
+debug("Case1: The target element has any matched important rule declared in an outer scoped stylesheet, and the element also has any matched normal rule declared in an inner scoped stylesheet.");
+shouldBe('getComputedStyle(target1).borderColor', '"rgb(0, 128, 0)"');
+
+debug("Case2: The target element has any matched important rule declared in an outer scoped stylesheet, and the element also has a matched normal ID rule declared in an inner scoped stylesheet.");
+var target2 = document.getElementById("id2");
+shouldBe('getComputedStyle(target2).borderColor', '"rgb(0, 128, 0)"');
+
+debug("Case3: The target element has any matched important rule declared in an outer scoped stylesheet, and the element also has matched normal rules declared in an inner scoped stylesheet and in a STYLE attribute.");
+var target3 = document.getElementById("id3");
+shouldBe('getComputedStyle(target3).borderColor', '"rgb(0, 128, 0)"');
+
+debug("Case4: The target element has matched important rules. One is declared in an outer scoped stylesheet and the other is declared in an inner scoped stylesheet.");
+var target4 = document.getElementById("id4");
+shouldBe('getComputedStyle(target4).borderColor', '"rgb(0, 0, 255)"');
+
+debug("Case5: The target element has any matched important rule declared in an author stylesheet, and the element also has matched normal rules declared in an inner scoped stylesheet.");
+var target5 = document.getElementById("id5");
+shouldBe('getComputedStyle(target5).borderColor', '"rgb(0, 255, 0)"');
+
+debug("Case6: The target element has matched important rules. One is declared in an author stylesheet (not scoped) and the other is declared in a scoped stylesheet.");
+var target6 = document.getElementById("id6");
+shouldBe('getComputedStyle(target6).borderColor', '"rgb(0, 0, 255)"');
+
+debug("Case7: The target element has any matched important rule declared in an outer scoped stylesheet. The element is in a shadow dom tree whose shadow root has apply-author-styles true. The shadow dom tree has any other normal rules which match the element.");
+var host1 = document.getElementById("host1");
+var shadowRoot1 = host1.webkitCreateShadowRoot();
+shadowRoot1.applyAuthorStyles = true;
+shadowRoot1.innerHTML = '<style>div#shadow1 { color: blue; }</style><div id="shadow1"></div>';
+var target7 = shadowRoot1.getElementById("shadow1");
+shouldBe('getComputedStyle(target7).borderColor', '"rgb(0, 128, 0)"');
+
+debug("Case8: The target element in a shadow dom tree has any matched important rule declared in an outer scoped stylesheet in an enclosing shadow dom tree. The target element's shadow root has apply-author-styles true.");
+var host2 = document.getElementById("host2");
+var shadowRoot2 = host2.webkitCreateShadowRoot();
+shadowRoot2.applyAuthorStyles = false;
+shadowRoot2.innerHTML = '<style>div { border-color: green !important; }</style><div id="shadow2"></div>';
+
+var hostInShadowTree2 = shadowRoot2.getElementById("shadow2");
+var shadowRoot3 = hostInShadowTree2.webkitCreateShadowRoot();
+shadowRoot3.applyAuthorStyles = true;
+shadowRoot3.innerHTML = '<style>div#shadow3 { border-color: blue; }</style><div id="shadow3"></div>';
+var target8 = shadowRoot3.getElementById("shadow3");
+shouldBe('getComputedStyle(target8).borderColor', '"rgb(0, 128, 0)"');
+
+debug("Case8': The target element is in a shadow dom tree. An enclosing shadow dom tree has some stylesheet which declares an important rule. The target element's shadow root has apply-author-styles false.");
+shadowRoot3.applyAuthorStyles = false;
+shouldBe('getComputedStyle(target8).borderColor', '"rgb(0, 0, 255)"');
+
+</script>
+<script src=""
+</html>

Modified: trunk/LayoutTests/fast/regions/style-scoped-in-flow-override-region-styling-expected.html (137707 => 137708)


--- trunk/LayoutTests/fast/regions/style-scoped-in-flow-override-region-styling-expected.html	2012-12-14 04:38:20 UTC (rev 137707)
+++ trunk/LayoutTests/fast/regions/style-scoped-in-flow-override-region-styling-expected.html	2012-12-14 04:40:47 UTC (rev 137708)
@@ -32,8 +32,8 @@
 	Partial overlap, @region more specific than &lt;style scoped&gt; (@region style has rules for class and id, scoped style has rule for &lt;p&gt;)
 	<div class='container' id='r1'>
 		<p class='light'>Styled line of text</p>
-		<p class='lime'>Styled line of text</p>
-		<p class='green'>Styled line of text</p>
+		<p class='light'>Styled line of text</p>
+		<p class='light'>Styled line of text</p>
 	</div>
 	Partial overlap, &lt;style scoped&gt; more specific than @region (@region style has rule for &lt;p&gt;, scoped style has rules for class and id)
 	<div class='container' id='r2'>

Modified: trunk/LayoutTests/fast/regions/style-scoped-in-flow-override-region-styling.html (137707 => 137708)


--- trunk/LayoutTests/fast/regions/style-scoped-in-flow-override-region-styling.html	2012-12-14 04:38:20 UTC (rev 137707)
+++ trunk/LayoutTests/fast/regions/style-scoped-in-flow-override-region-styling.html	2012-12-14 04:40:47 UTC (rev 137708)
@@ -50,13 +50,13 @@
 	}
 	@-webkit-region #r3 {
 		p {
-			background-color: lightgreen;
+			background-color: yellow;
 		}
 		.c3 {
-			background-color: lime;
+			background-color: orange;
 		}
 		#p3 {
-			background-color: green;
+			background-color: red;
 		}
 	}
 	</style>
@@ -87,15 +87,15 @@
 	</div>
 	<div id='f3'>
 		<style scoped='true'>
-			p {
-				background-color: yellow;
-			}
-			.c3 {
-				background-color: orange;
-			}
-			#p3 {
-				background-color: red;
-			}
+		        p {
+			        background-color: lightgreen;
+    			}
+		        .c3 {
+        			background-color: lime;
+        		}
+        		#p3 {
+        			background-color: green;
+        		}
 		</style>
 		<p>Styled line of text</p>
 		<p class='c3'>Styled line of text</p>

Modified: trunk/Source/WebCore/ChangeLog (137707 => 137708)


--- trunk/Source/WebCore/ChangeLog	2012-12-14 04:38:20 UTC (rev 137707)
+++ trunk/Source/WebCore/ChangeLog	2012-12-14 04:40:47 UTC (rev 137708)
@@ -1,3 +1,41 @@
+2012-12-13  Takashi Sakamoto  <ta...@google.com>
+
+        [Shadow DOM]: scoped styles are not applied in the cascade order.
+        https://bugs.webkit.org/show_bug.cgi?id=103239
+
+        Reviewed by Dimitri Glazkov.
+
+        If the scoping elements of two declarations have an ancestor/
+        descendant relationship, the declaration whose scoping element is
+        the descendant should win.
+        c.f. http://dev.w3.org/csswg/css3-cascade/#cascade
+
+        Test: fast/css/style-scoped/style-scoped-nested.html
+              fast/css/style-scoped/style-scoped-with-important-rule.html
+
+        * css/RuleSet.cpp:
+        (WebCore::RuleSet::addRule):
+        Removed specificity for @host @-rules. Now @host @-rules use the
+        cascading order instead.
+        * css/RuleSet.h:
+        Removed increaseSpecificity. The method is used by only @host @-rules.
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::matchScopedAuthorRules):
+        (WebCore::StyleResolver::matchHostRules):
+        (WebCore::StyleResolver::matchAuthorRules):
+        Modified to invoke sortAndTransferMatchedRules per scoping element.
+        The order of "matchXXXRules" must be the same as the cascading order.
+        So matchHostRules was invoked after collecting all scoped author rules.
+        * css/StyleScopeResolver.cpp:
+        (WebCore::StyleScopeResolver::addHostRule):
+        Removed RuleIsHostRule. We don't need the flag.
+        * html/HTMLStyleElement.cpp:
+        (WebCore::HTMLStyleElement::registerWithScopingNode):
+        Needs to pass the last test case of style-scoped-nested.html.
+        When appending some style element to a shadow root, we should recalc
+        styles of all elements in the shadow dom tree. And if the style
+        element has @host @-rules, we have to update the host's style.
+
 2012-12-13  Filip Pizlo  <fpi...@apple.com>
 
         MediaPlayerPrivateAVFoundation::m_inbandTrackConfigurationPending is unused except when HAVE(AVFOUNDATION_TEXT_TRACK_SUPPORT)

Modified: trunk/Source/WebCore/css/RuleSet.cpp (137707 => 137708)


--- trunk/Source/WebCore/css/RuleSet.cpp	2012-12-14 04:38:20 UTC (rev 137707)
+++ trunk/Source/WebCore/css/RuleSet.cpp	2012-12-14 04:40:47 UTC (rev 137708)
@@ -191,11 +191,7 @@
 void RuleSet::addRule(StyleRule* rule, unsigned selectorIndex, AddRuleFlags addRuleFlags)
 {
     RuleData ruleData(rule, selectorIndex, m_ruleCount++, addRuleFlags);
-    static const unsigned athostRuleSpecificity = 0x100000;
 
-    if (addRuleFlags & RuleIsHostRule)
-        ruleData.increaseSpecificity(athostRuleSpecificity);
-
     collectFeaturesFromRuleData(m_features, ruleData);
 
     CSSSelector* selector = ruleData.selector();

Modified: trunk/Source/WebCore/css/RuleSet.h (137707 => 137708)


--- trunk/Source/WebCore/css/RuleSet.h	2012-12-14 04:38:20 UTC (rev 137707)
+++ trunk/Source/WebCore/css/RuleSet.h	2012-12-14 04:40:47 UTC (rev 137708)
@@ -36,7 +36,6 @@
     RuleHasDocumentSecurityOrigin = 1,
     RuleCanUseFastCheckSelector   = 1 << 1,
     RuleIsInRegionRule            = 1 << 2,
-    RuleIsHostRule                = 1 << 3,
 };
 
 class CSSSelector;
@@ -63,7 +62,6 @@
     unsigned linkMatchType() const { return m_linkMatchType; }
     bool hasDocumentSecurityOrigin() const { return m_hasDocumentSecurityOrigin; }
     bool isInRegionRule() const { return m_isInRegionRule; }
-    void increaseSpecificity(unsigned value) { m_specificity += value; }
 
     // Try to balance between memory usage (there can be lots of RuleData objects) and good filtering performance.
     static const unsigned maximumIdentifierCount = 4;

Modified: trunk/Source/WebCore/css/StyleResolver.cpp (137707 => 137708)


--- trunk/Source/WebCore/css/StyleResolver.cpp	2012-12-14 04:38:20 UTC (rev 137707)
+++ trunk/Source/WebCore/css/StyleResolver.cpp	2012-12-14 04:40:47 UTC (rev 137708)
@@ -726,34 +726,33 @@
     if (!m_scopeResolver)
         return;
 
-    matchHostRules(result, includeEmptyRules);
+    // Match scoped author rules by traversing the scoped element stack (rebuild it if it got inconsistent).
+    if (m_scopeResolver->hasScopedStyles() && m_scopeResolver->ensureStackConsistency(m_element)) {
+        bool applyAuthorStyles = m_element->treeScope()->applyAuthorStyles();
+        bool documentScope = true;
+        unsigned scopeSize = m_scopeResolver->stackSize();
+        for (unsigned i = 0; i < scopeSize; ++i) {
+            m_matchedRules.clear();
+            result.ranges.lastAuthorRule = result.matchedProperties.size() - 1;
 
-    if (!m_scopeResolver->hasScopedStyles())
-        return;
+            const StyleScopeResolver::StackFrame& frame = m_scopeResolver->stackFrameAt(i);
+            documentScope = documentScope && !frame.m_scope->isInShadowTree();
+            if (documentScope) {
+                if (!applyAuthorStyles)
+                    continue;
+            } else {
+                if (!m_scopeResolver->matchesStyleBounds(frame))
+                    continue;
+            }
 
-    // Match scoped author rules by traversing the scoped element stack (rebuild it if it got inconsistent).
-    if (!m_scopeResolver->ensureStackConsistency(m_element))
-        return;
-
-    bool applyAuthorStyles = m_element->treeScope()->applyAuthorStyles();
-    bool documentScope = true;
-    unsigned scopeSize = m_scopeResolver->stackSize();
-    for (unsigned i = 0; i < scopeSize; ++i) {
-        const StyleScopeResolver::StackFrame& frame = m_scopeResolver->stackFrameAt(i);
-        documentScope = documentScope && !frame.m_scope->isInShadowTree();
-        if (documentScope) {
-            if (!applyAuthorStyles)
-                continue;
-        } else {
-            if (!m_scopeResolver->matchesStyleBounds(frame))
-                continue;
+            MatchOptions options(includeEmptyRules, frame.m_scope);
+            collectMatchingRules(frame.m_ruleSet, result.ranges.firstAuthorRule, result.ranges.lastAuthorRule, options);
+            collectMatchingRulesForRegion(frame.m_ruleSet, result.ranges.firstAuthorRule, result.ranges.lastAuthorRule, options);
+            sortAndTransferMatchedRules(result);
         }
-           
-        MatchOptions options(includeEmptyRules, frame.m_scope);
-        collectMatchingRules(frame.m_ruleSet, result.ranges.firstAuthorRule, result.ranges.lastAuthorRule, options);
-        collectMatchingRulesForRegion(frame.m_ruleSet, result.ranges.firstAuthorRule, result.ranges.lastAuthorRule, options);
     }
 
+    matchHostRules(result, includeEmptyRules);
 #else
     UNUSED_PARAM(result);
     UNUSED_PARAM(includeEmptyRules);
@@ -774,15 +773,18 @@
 #if ENABLE(SHADOW_DOM)
     ASSERT(m_scopeResolver);
 
+    m_matchedRules.clear();
+    result.ranges.lastAuthorRule = result.matchedProperties.size() - 1;
+
     Vector<RuleSet*> matchedRules;
     m_scopeResolver->matchHostRules(m_element, matchedRules);
     if (matchedRules.isEmpty())
         return;
 
-    MatchOptions options(includeEmptyRules);
-    options.scope = m_element;
+    MatchOptions options(includeEmptyRules, m_element);
     for (unsigned i = matchedRules.size(); i > 0; --i)
         collectMatchingRules(matchedRules.at(i-1), result.ranges.firstAuthorRule, result.ranges.lastAuthorRule, options);
+    sortAndTransferMatchedRules(result);
 #else
     UNUSED_PARAM(result);
     UNUSED_PARAM(includeEmptyRules);
@@ -801,10 +803,9 @@
     MatchOptions options(includeEmptyRules);
     collectMatchingRules(m_authorStyle.get(), result.ranges.firstAuthorRule, result.ranges.lastAuthorRule, options);
     collectMatchingRulesForRegion(m_authorStyle.get(), result.ranges.firstAuthorRule, result.ranges.lastAuthorRule, options);
+    sortAndTransferMatchedRules(result);
 
     matchScopedAuthorRules(result, includeEmptyRules);
-
-    sortAndTransferMatchedRules(result);
 }
 
 void StyleResolver::matchUserRules(MatchResult& result, bool includeEmptyRules)

Modified: trunk/Source/WebCore/css/StyleScopeResolver.cpp (137707 => 137708)


--- trunk/Source/WebCore/css/StyleScopeResolver.cpp	2012-12-14 04:38:20 UTC (rev 137707)
+++ trunk/Source/WebCore/css/StyleScopeResolver.cpp	2012-12-14 04:40:47 UTC (rev 137708)
@@ -183,7 +183,7 @@
 
     const Vector<RefPtr<StyleRuleBase> >& childRules = hostRule->childRules();
     AddRuleFlags addRuleFlags = hasDocumentSecurityOrigin ? RuleHasDocumentSecurityOrigin : RuleHasNoSpecialState;
-    addRuleFlags = static_cast<AddRuleFlags>(addRuleFlags | RuleCanUseFastCheckSelector | RuleIsHostRule);
+    addRuleFlags = static_cast<AddRuleFlags>(addRuleFlags | RuleCanUseFastCheckSelector);
     for (unsigned i = 0; i < childRules.size(); ++i) {
         StyleRuleBase* hostStylingRule = childRules[i].get();
         if (hostStylingRule->isStyleRule())

Modified: trunk/Source/WebCore/html/HTMLStyleElement.cpp (137707 => 137708)


--- trunk/Source/WebCore/html/HTMLStyleElement.cpp	2012-12-14 04:38:20 UTC (rev 137707)
+++ trunk/Source/WebCore/html/HTMLStyleElement.cpp	2012-12-14 04:40:47 UTC (rev 137708)
@@ -140,9 +140,11 @@
         ASSERT_NOT_REACHED();
         return;
     }
-
     scope->registerScopedHTMLStyleChild();
-    scope->setNeedsStyleRecalc();
+    if (scope->isShadowRoot())
+        scope->shadowHost()->setNeedsStyleRecalc();
+    else
+        scope->setNeedsStyleRecalc();
     if (inDocument() && !document()->parsing() && document()->renderer())
         document()->styleResolverChanged(DeferRecalcStyle);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to