Distributed nodes should not share styles.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Aug 2012 17:08:21 +0000 (17:08 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Aug 2012 17:08:21 +0000 (17:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=90661

Patch by Takashi Sakamoto <tasak@google.com> on 2012-08-23
Reviewed by Hajime Morita.

Source/WebCore:

styleForElement tries to use previous sibling's style for distributed
nodes. However distributed nodes are children of a shadow host, but
the nodes are not siblings as the result of distribution.
The spec is:
http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html#shadow-dom-subtrees
So sharing previous sibling's style should be disabled for distrbuted
nodes.

Test: fast/dom/shadow/style-of-distributed-node.html

* css/StyleResolver.cpp:
(WebCore::StyleResolver::StyleResolver):
Initialized m_distributedToInsertionPoint. Its initial value is false.
(WebCore::StyleResolver::initForStyleResolve):
After invoking NodeRenderingContext, if the context returns any
insertion point, set m_distributedToInsertionPoint to be true.
Otherwise, false. The value is used in styleForElement.
(WebCore::StyleResolver::styleForElement):
If m_distributedToInsertionPoint is true, disable local sibling style
cache.
* css/StyleResolver.h:
(StyleResolver):
Added a new member variable, m_distributedToInsertionPoint.
The variable keeps whether the m_element is distributed to an
insertion point.

LayoutTests:

* fast/dom/shadow/style-of-distributed-node-expected.txt: Added.
* fast/dom/shadow/style-of-distributed-node.html: Added.
* fast/dom/shadow/user-modify-inheritance-expected.txt:
As this patch also change the user-modify-inheritance's test result,
updated the expected result.
* fast/dom/shadow/user-modify-inheritance.html:
Added FIXME comment.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@126442 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/dom/shadow/style-of-distributed-node-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/shadow/style-of-distributed-node.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/user-modify-inheritance-expected.txt
LayoutTests/fast/dom/shadow/user-modify-inheritance.html
Source/WebCore/ChangeLog
Source/WebCore/css/StyleResolver.cpp
Source/WebCore/css/StyleResolver.h

index 6dc50b8..0efc92f 100644 (file)
@@ -1,3 +1,18 @@
+2012-08-23  Takashi Sakamoto  <tasak@google.com>
+
+        Distributed nodes should not share styles.
+        https://bugs.webkit.org/show_bug.cgi?id=90661
+
+        Reviewed by Hajime Morita.
+
+        * fast/dom/shadow/style-of-distributed-node-expected.txt: Added.
+        * fast/dom/shadow/style-of-distributed-node.html: Added.
+        * fast/dom/shadow/user-modify-inheritance-expected.txt:
+        As this patch also change the user-modify-inheritance's test result,
+        updated the expected result.
+        * fast/dom/shadow/user-modify-inheritance.html:
+        Added FIXME comment.
+
 2012-08-23  John Mellor  <johnme@chromium.org>
 
         Text Autosizing: Multiply large fonts less, as they are already more legible.
diff --git a/LayoutTests/fast/dom/shadow/style-of-distributed-node-expected.txt b/LayoutTests/fast/dom/shadow/style-of-distributed-node-expected.txt
new file mode 100644 (file)
index 0000000..5e83e1c
--- /dev/null
@@ -0,0 +1,17 @@
+Tests to ensure that styles of distributed nodes are different if their parent styles are different.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+
+PASS getColorProperty("child-a") is "rgb(255, 0, 0)"
+PASS getColorProperty("child-b") is "rgb(0, 0, 255)"
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
+
+
+
diff --git a/LayoutTests/fast/dom/shadow/style-of-distributed-node.html b/LayoutTests/fast/dom/shadow/style-of-distributed-node.html
new file mode 100644 (file)
index 0000000..0a939bb
--- /dev/null
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="resources/polyfill.js"></script>
+<script src="../../js/resources/js-test-pre.js"></script>
+<script>
+function getColorProperty(id) {
+    return window.getComputedStyle(document.getElementById(id)).color;
+}
+
+function log(message) {
+    var console = document.getElementById('console');
+    console.innerHTML += message + '\n';
+}
+</script>
+</head>
+<body>
+<pre id="console"></div>
+<div id="test">
+    <div id="host" style="color: red">
+        <div id="child-a"></div>
+        <div id="child-b"></div>
+    </div>
+</div>
+<script>
+description("Tests to ensure that styles of distributed nodes are different if their parent styles are different.");
+
+if (window.testRunner)
+  testRunner.dumpAsText();
+
+var sr = new WebKitShadowRoot(document.getElementById("host"));
+sr.innerHTML = '<content select="#child-a"></content><div style="color: blue"><content select="#child-b"></content></div>';
+
+shouldBe('getColorProperty("child-a")', '"rgb(255, 0, 0)"');
+shouldBe('getColorProperty("child-b")', '"rgb(0, 0, 255)"');
+
+document.getElementById("test").innerHTML = '';
+</script>
+<script src="../../js/resources/js-test-post.js"></script>
+</body>
+</html>
index c76e10d..7af24c9 100644 (file)
@@ -10,7 +10,7 @@ PASS computedStyle(prepareNodeInShadowRoot(document.getElementById("non-contente
 PASS computedStyle(prepareNodeInShadowRoot(document.getElementById("non-contenteditable-host2"), "false"), userModifyPropertyName) is "read-only"
 PASS computedStyle(prepareNodeInShadowRoot(document.getElementById("non-contenteditable-host3"), "true"), userModifyPropertyName) is "read-write"
 PASS getUserModifyProperty("child-a") is "read-write"
-PASS getUserModifyProperty("child-b") is "read-write"
+FAIL getUserModifyProperty("child-b") should be read-write. Was read-only.
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 4ea0c6a..b449335 100644 (file)
@@ -62,6 +62,7 @@ document.getElementById('sandbox').appendChild(
 document.body.offsetLeft;
 
 shouldBeEqualToString('getUserModifyProperty("child-a")', 'read-write');
+/* FIXME(90017): css property: -user-modify should be inherited from parent.*/
 shouldBeEqualToString('getUserModifyProperty("child-b")', 'read-write');
 
 </script>
index 9ae311c..8955e0c 100644 (file)
@@ -1,3 +1,36 @@
+2012-08-23  Takashi Sakamoto  <tasak@google.com>
+
+        Distributed nodes should not share styles.
+        https://bugs.webkit.org/show_bug.cgi?id=90661
+
+        Reviewed by Hajime Morita.
+
+        styleForElement tries to use previous sibling's style for distributed
+        nodes. However distributed nodes are children of a shadow host, but
+        the nodes are not siblings as the result of distribution.
+        The spec is:
+        http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html#shadow-dom-subtrees
+        So sharing previous sibling's style should be disabled for distrbuted
+        nodes.
+
+        Test: fast/dom/shadow/style-of-distributed-node.html
+
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::StyleResolver):
+        Initialized m_distributedToInsertionPoint. Its initial value is false.
+        (WebCore::StyleResolver::initForStyleResolve):
+        After invoking NodeRenderingContext, if the context returns any
+        insertion point, set m_distributedToInsertionPoint to be true.
+        Otherwise, false. The value is used in styleForElement.
+        (WebCore::StyleResolver::styleForElement):
+        If m_distributedToInsertionPoint is true, disable local sibling style
+        cache.
+        * css/StyleResolver.h:
+        (StyleResolver):
+        Added a new member variable, m_distributedToInsertionPoint.
+        The variable keeps whether the m_element is distributed to an
+        insertion point.
+
 2012-08-23  John Griggs  <jgriggs@rim.com>
 
                 Replace access ot HTMLMediaElement from MediaPlayerPrivateBlackBerry with methods in MediaPlayerClient - updated with notes from initial reviews.  https://bugs.webkit.org/show_bug.cgi?id=84291
index a7397ae..623b08b 100644 (file)
@@ -377,6 +377,7 @@ StyleResolver::StyleResolver(Document* document, bool matchAuthorAndUserStyles)
     , m_fontDirty(false)
     , m_matchAuthorAndUserStyles(matchAuthorAndUserStyles)
     , m_sameOriginOnly(false)
+    , m_distributedToInsertionPoint(false)
     , m_fontSelector(CSSFontSelector::create(document))
     , m_applyPropertyToRegularStyle(true)
     , m_applyPropertyToVisitedLinkStyle(false)
@@ -1220,9 +1221,11 @@ inline void StyleResolver::initForStyleResolve(Element* e, RenderStyle* parentSt
         m_parentStyle = context.resetStyleInheritance()? 0 :
             parentStyle ? parentStyle :
             m_parentNode ? m_parentNode->renderStyle() : 0;
+        m_distributedToInsertionPoint = context.insertionPoint();
     } else {
         m_parentNode = 0;
         m_parentStyle = parentStyle;
+        m_distributedToInsertionPoint = false;
     }
 
     Node* docElement = e ? e->document()->documentElement() : 0;
@@ -1752,7 +1755,7 @@ PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS
     initElement(element);
     initForStyleResolve(element, defaultParent);
     m_regionForStyling = regionForStyling;
-    if (sharingBehavior == AllowStyleSharing) {
+    if (sharingBehavior == AllowStyleSharing && !m_distributedToInsertionPoint) {
         RenderStyle* sharedStyle = locateSharedStyle();
         if (sharedStyle)
             return sharedStyle;
index 712085b..2bbc682 100644 (file)
@@ -496,6 +496,7 @@ private:
     bool m_fontDirty;
     bool m_matchAuthorAndUserStyles;
     bool m_sameOriginOnly;
+    bool m_distributedToInsertionPoint;
 
     RefPtr<CSSFontSelector> m_fontSelector;
     Vector<OwnPtr<MediaQueryResult> > m_viewportDependentMediaQueryResults;