Title: [137418] trunk
Revision
137418
Author
[email protected]
Date
2012-12-11 22:24:30 -0800 (Tue, 11 Dec 2012)

Log Message

Text nodes in shadow roots don't inherit style properly
https://bugs.webkit.org/show_bug.cgi?id=101116

Reviewed by Hajime Morita.

Source/WebCore:

Use NodeRenderingContext to resolve styles of text nodes.
If text nodes are direct children of shadow roots, the text nodes
should be inherited styles from their shadow hosts.
But if reset-style-inheritance flag is true, the text nodes should
not be inherited. And if text nodes are distributed nodes,
we have to check whether their insertion point's
reset-style-inheritance.
c.f. shadow dom spec is:
http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html#styles

Test: fast/dom/shadow/text-node-in-shadow.html

* css/StyleResolver.cpp:
(WebCore::StyleResolver::styleForElement):
Modified to use defaultStyleForElement if the given element has
no parent style.
(WebCore::StyleResolver::initForStyleResolve):
Removed shouldResetStyleInheritance, because now NodeRenderingContext
resetStyleInheritance() takes care of reset-style-inheritance of
both shadow roots and insertion points.
(WebCore::StyleResolver::defaultStyleForElement):
Added to create a default style for elements.
(WebCore):
(WebCore::StyleResolver::styleForText):
Use NodeRenderingContext to find the parent node for style from the
given text node. If no parent node is found or reset-style-inheritance
is true, returns a default style (i.e. empty render style).
Otherwise, just returns the found node's style.
* css/StyleResolver.h:
(StyleResolver):
* dom/ComposedShadowTreeWalker.cpp:
(WebCore::ComposedShadowTreeWalker::ParentTraversalDetails::didTraverseInsertionPoint):
Modify to consider insertion point's resetStyleInheritance.
* dom/NodeRenderingContext.cpp:
(WebCore::NodeRenderingContext::createRendererForTextIfNeeded):
Since NodeRenderingContext has already found a parent node for
rendering and style and a parentRenderer is just the found node's
renderer, we have to only check reset-style-inheritance.
If reset, use default style. Otherwise, the parentRenderer's style.
* dom/Text.cpp:
(WebCore::Text::recalcTextStyle):
Use styleForText instead of parentRenderer's styles if the given text
node is a direct child of a shadow root or a direct child of a shadow
host.

LayoutTests:

* fast/dom/shadow/text-node-in-shadow-expected.html: Added.
* fast/dom/shadow/text-node-in-shadow.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (137417 => 137418)


--- trunk/LayoutTests/ChangeLog	2012-12-12 06:20:38 UTC (rev 137417)
+++ trunk/LayoutTests/ChangeLog	2012-12-12 06:24:30 UTC (rev 137418)
@@ -1,3 +1,13 @@
+2012-12-11  Takashi Sakamoto  <[email protected]>
+
+        Text nodes in shadow roots don't inherit style properly
+        https://bugs.webkit.org/show_bug.cgi?id=101116
+
+        Reviewed by Hajime Morita.
+
+        * fast/dom/shadow/text-node-in-shadow-expected.html: Added.
+        * fast/dom/shadow/text-node-in-shadow.html: Added.
+
 2012-12-11  Dominic Mazzoni  <[email protected]>
 
         AX: Make isActionSupported cross-platform.

Added: trunk/LayoutTests/fast/dom/shadow/text-node-in-shadow-expected.html (0 => 137418)


--- trunk/LayoutTests/fast/dom/shadow/text-node-in-shadow-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/text-node-in-shadow-expected.html	2012-12-12 06:24:30 UTC (rev 137418)
@@ -0,0 +1,9 @@
+<!doctype html>
+<html>
+<body>
+  <div style="font-size: 5em;"><span>foo</span>bar</div>
+  <div><span>foo</span>bar</span><span style="font-size: 6em;">&nbsp;</span></div>
+  <div><span style="font-size: 5em;">Foo<span>Bar</span></span></div>
+  <div>Foo<span>Bar</span><span style="font-size: 6em;">&nbsp;</span></div>
+</body>
+</html>

Added: trunk/LayoutTests/fast/dom/shadow/text-node-in-shadow.html (0 => 137418)


--- trunk/LayoutTests/fast/dom/shadow/text-node-in-shadow.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/text-node-in-shadow.html	2012-12-12 06:24:30 UTC (rev 137418)
@@ -0,0 +1,67 @@
+<!doctype html>
+<html>
+<head>
+<style>
+span {
+   text-align: top;
+}
+</style>
+<script src=""
+<script>
+function testChildTextOfShadowRoot() {
+    var host = document.getElementById("host");
+    var shadowRoot = host.webkitCreateShadowRoot();
+    var span = document.createElement('span')
+    span.textContent = "foo";
+    shadowRoot.appendChild(span);
+    shadowRoot.appendChild(document.createTextNode("bar"));
+    document.body.offsetLeft;
+    host.style.fontSize = '5em';
+}
+
+function testChildTextOfShadowRootWithResetStyleInheritance() {
+    var host = document.getElementById("hostResetStyleInheritance");
+    var shadowRoot = host.webkitCreateShadowRoot();
+    var span = document.createElement('span')
+    span.textContent = "foo";
+    shadowRoot.appendChild(span);
+    shadowRoot.appendChild(document.createTextNode("bar"));
+    shadowRoot.resetStyleInheritance = true;
+    document.body.offsetLeft;
+    host.style.fontSize = '6em';
+}
+
+function testDistributedText() {
+    var host = document.getElementById("hostWithDistribution");
+    var shadowRoot = host.webkitCreateShadowRoot();
+    shadowRoot.innerHTML = "<span id='span1'><content></content></span>"
+    document.body.offsetLeft;
+    shadowRoot.getElementById("span1").style.fontSize = '5em';
+}
+
+function testDistributedTextWithResetStyleInheritance() {
+    var host = document.getElementById("hostResetStyleInheritanceWithDistribution");
+    var shadowRoot = host.webkitCreateShadowRoot();
+    shadowRoot.innerHTML = "<span id='span2'><content id='content'></content></span>"
+    shadowRoot.getElementById("content").resetStyleInheritance = true;
+    document.body.offsetLeft;
+    shadowRoot.getElementById("span2").style.fontSize = '6em';
+}
+
+function runTests() {
+    testChildTextOfShadowRoot();
+    testChildTextOfShadowRootWithResetStyleInheritance();
+    testDistributedText();
+    testDistributedTextWithResetStyleInheritance();
+}
+</script>
+</head>
+<body _onload_="runTests()">
+  <!-- [bug 101116] Text nodes in shadow roots don't inherit style properly -->
+  <!-- https://bugs.webkit.org/show_bug.cgi?id=101116 -->
+  <div id="host"></div>
+  <div id="hostResetStyleInheritance"></div>
+  <div id="hostWithDistribution">Foo<span>Bar</span></div>
+  <div id="hostResetStyleInheritanceWithDistribution">Foo<span>Bar</span></div>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (137417 => 137418)


--- trunk/Source/WebCore/ChangeLog	2012-12-12 06:20:38 UTC (rev 137417)
+++ trunk/Source/WebCore/ChangeLog	2012-12-12 06:24:30 UTC (rev 137418)
@@ -1,5 +1,57 @@
 2012-12-11  Takashi Sakamoto  <[email protected]>
 
+        Text nodes in shadow roots don't inherit style properly
+        https://bugs.webkit.org/show_bug.cgi?id=101116
+
+        Reviewed by Hajime Morita.
+
+        Use NodeRenderingContext to resolve styles of text nodes.
+        If text nodes are direct children of shadow roots, the text nodes
+        should be inherited styles from their shadow hosts.
+        But if reset-style-inheritance flag is true, the text nodes should
+        not be inherited. And if text nodes are distributed nodes,
+        we have to check whether their insertion point's
+        reset-style-inheritance.
+        c.f. shadow dom spec is:
+        http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html#styles
+
+        Test: fast/dom/shadow/text-node-in-shadow.html
+
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::styleForElement):
+        Modified to use defaultStyleForElement if the given element has
+        no parent style.
+        (WebCore::StyleResolver::initForStyleResolve):
+        Removed shouldResetStyleInheritance, because now NodeRenderingContext
+        resetStyleInheritance() takes care of reset-style-inheritance of
+        both shadow roots and insertion points.
+        (WebCore::StyleResolver::defaultStyleForElement):
+        Added to create a default style for elements.
+        (WebCore):
+        (WebCore::StyleResolver::styleForText):
+        Use NodeRenderingContext to find the parent node for style from the
+        given text node. If no parent node is found or reset-style-inheritance
+        is true, returns a default style (i.e. empty render style).
+        Otherwise, just returns the found node's style.
+        * css/StyleResolver.h:
+        (StyleResolver):
+        * dom/ComposedShadowTreeWalker.cpp:
+        (WebCore::ComposedShadowTreeWalker::ParentTraversalDetails::didTraverseInsertionPoint):
+        Modify to consider insertion point's resetStyleInheritance.
+        * dom/NodeRenderingContext.cpp:
+        (WebCore::NodeRenderingContext::createRendererForTextIfNeeded):
+        Since NodeRenderingContext has already found a parent node for
+        rendering and style and a parentRenderer is just the found node's
+        renderer, we have to only check reset-style-inheritance.
+        If reset, use default style. Otherwise, the parentRenderer's style.
+        * dom/Text.cpp:
+        (WebCore::Text::recalcTextStyle):
+        Use styleForText instead of parentRenderer's styles if the given text
+        node is a direct child of a shadow root or a direct child of a shadow
+        host.
+
+2012-12-11  Takashi Sakamoto  <[email protected]>
+
         Hide HOST_RULE behind SHADOW_DOM flag.
         https://bugs.webkit.org/show_bug.cgi?id=102321
 

Modified: trunk/Source/WebCore/css/StyleResolver.cpp (137417 => 137418)


--- trunk/Source/WebCore/css/StyleResolver.cpp	2012-12-12 06:20:38 UTC (rev 137417)
+++ trunk/Source/WebCore/css/StyleResolver.cpp	2012-12-12 06:24:30 UTC (rev 137418)
@@ -966,17 +966,6 @@
     }
 }
 
-inline bool shouldResetStyleInheritance(NodeRenderingContext& context)
-{
-    if (context.resetStyleInheritance())
-        return true;
-
-    if (InsertionPoint* insertionPoint = context.insertionPoint())
-        return insertionPoint->resetStyleInheritance();
-
-    return false;
-}
-
 inline void StyleResolver::initForStyleResolve(Element* e, RenderStyle* parentStyle, PseudoId pseudoID)
 {
     m_pseudoStyle = pseudoID;
@@ -984,7 +973,7 @@
     if (e) {
         NodeRenderingContext context(e);
         m_parentNode = context.parentNodeForRenderingAndStyle();
-        m_parentStyle = shouldResetStyleInheritance(context) ? 0 :
+        m_parentStyle = context.resetStyleInheritance() ? 0 :
             parentStyle ? parentStyle :
             m_parentNode ? m_parentNode->renderStyle() : 0;
         m_distributedToInsertionPoint = context.insertionPoint();
@@ -1553,19 +1542,13 @@
             return sharedStyle;
     }
 
-    m_style = RenderStyle::create();
-
     RefPtr<RenderStyle> cloneForParent;
 
-    if (m_parentStyle)
+    if (m_parentStyle) {
+        m_style = RenderStyle::create();
         m_style->inheritFrom(m_parentStyle, isAtShadowBoundary(element) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary);
-    else {
-        // Make sure our fonts are initialized if we don't inherit them from our parent style.
-        if (Settings* settings = documentSettings()) {
-            initializeFontStyle(settings);
-            m_style->font().update(fontSelector());
-        } else
-            m_style->font().update(0);
+    } else {
+        m_style = defaultStyleForElement();
         cloneForParent = RenderStyle::clone(style());
         m_parentStyle = cloneForParent.get();
     }
@@ -1808,6 +1791,29 @@
     return m_style.release();
 }
 
+PassRefPtr<RenderStyle> StyleResolver::defaultStyleForElement()
+{
+    m_style = RenderStyle::create();
+    // Make sure our fonts are initialized if we don't inherit them from our parent style.
+    if (Settings* settings = documentSettings()) {
+        initializeFontStyle(settings);
+        m_style->font().update(fontSelector());
+    } else
+        m_style->font().update(0);
+
+    return m_style.release();
+}
+
+PassRefPtr<RenderStyle> StyleResolver::styleForText(Text* textNode)
+{
+    ASSERT(textNode);
+
+    NodeRenderingContext context(textNode);
+    Node* parentNode = context.parentNodeForRenderingAndStyle();
+    return context.resetStyleInheritance() || !parentNode ?
+        defaultStyleForElement() : parentNode->renderStyle();
+}
+
 static void addIntrinsicMargins(RenderStyle* style)
 {
     // Intrinsic margin value.

Modified: trunk/Source/WebCore/css/StyleResolver.h (137417 => 137418)


--- trunk/Source/WebCore/css/StyleResolver.h	2012-12-12 06:20:38 UTC (rev 137417)
+++ trunk/Source/WebCore/css/StyleResolver.h	2012-12-12 06:24:30 UTC (rev 137418)
@@ -154,6 +154,8 @@
     PassRefPtr<RenderStyle> pseudoStyleForElement(PseudoId, Element*, RenderStyle* parentStyle);
 
     PassRefPtr<RenderStyle> styleForPage(int pageIndex);
+    PassRefPtr<RenderStyle> defaultStyleForElement();
+    PassRefPtr<RenderStyle> styleForText(Text*);
 
     static PassRefPtr<RenderStyle> styleForDocument(Document*, CSSFontSelector* = 0);
 

Modified: trunk/Source/WebCore/dom/ComposedShadowTreeWalker.cpp (137417 => 137418)


--- trunk/Source/WebCore/dom/ComposedShadowTreeWalker.cpp	2012-12-12 06:20:38 UTC (rev 137417)
+++ trunk/Source/WebCore/dom/ComposedShadowTreeWalker.cpp	2012-12-12 06:24:30 UTC (rev 137418)
@@ -72,8 +72,10 @@
 
 inline void ComposedShadowTreeWalker::ParentTraversalDetails::didTraverseInsertionPoint(InsertionPoint* insertionPoint)
 {
-    if (!m_insertionPoint)
+    if (!m_insertionPoint) {
         m_insertionPoint = insertionPoint;
+        m_resetStyleInheritance  = m_resetStyleInheritance || insertionPoint->resetStyleInheritance();
+    }
 }
 
 inline void ComposedShadowTreeWalker::ParentTraversalDetails::didTraverseShadowRoot(const ShadowRoot* root)

Modified: trunk/Source/WebCore/dom/NodeRenderingContext.cpp (137417 => 137418)


--- trunk/Source/WebCore/dom/NodeRenderingContext.cpp	2012-12-12 06:20:38 UTC (rev 137417)
+++ trunk/Source/WebCore/dom/NodeRenderingContext.cpp	2012-12-12 06:24:30 UTC (rev 137418)
@@ -44,6 +44,7 @@
 #include "RenderView.h"
 #include "ShadowRoot.h"
 #include "StyleInheritedData.h"
+#include "StyleResolver.h"
 #include "Text.h"
 
 #if ENABLE(SVG)
@@ -265,13 +266,18 @@
 
     if (!shouldCreateRenderer())
         return;
+
     RenderObject* parentRenderer = this->parentRenderer();
     ASSERT(parentRenderer);
-    m_style = parentRenderer->style();
+    Document* document = textNode->document();
 
+    if (resetStyleInheritance())
+        m_style = document->styleResolver()->defaultStyleForElement();
+    else
+        m_style = parentRenderer->style();
+
     if (!textNode->textRendererIsNeeded(*this))
         return;
-    Document* document = textNode->document();
     RenderText* newRenderer = textNode->createTextRenderer(document->renderArena(), m_style.get());
     if (!newRenderer)
         return;

Modified: trunk/Source/WebCore/dom/Text.cpp (137417 => 137418)


--- trunk/Source/WebCore/dom/Text.cpp	2012-12-12 06:20:38 UTC (rev 137417)
+++ trunk/Source/WebCore/dom/Text.cpp	2012-12-12 06:24:30 UTC (rev 137418)
@@ -33,6 +33,7 @@
 #endif
 
 #include "StyleInheritedData.h"
+#include "StyleResolver.h"
 #include <wtf/text/CString.h>
 #include <wtf/text/StringBuilder.h>
 
@@ -282,17 +283,10 @@
 void Text::recalcTextStyle(StyleChange change)
 {
     RenderText* renderer = toRenderText(this->renderer());
-    // The only time we have a renderer and our parent doesn't is if our parent
-    // is a shadow root.
-    if (change != NoChange && renderer) {
-        if (!parentNode()->isShadowRoot())
-            renderer->setStyle(parentNode()->renderer()->style());
-#if ENABLE(SVG)
-        else if (isSVGShadowText(this))
-            renderer->setStyle(toShadowRoot(parentNode())->host()->renderer()->style());
-#endif
-    }
 
+    if (change != NoChange && renderer)
+        renderer->setStyle(document()->styleResolver()->styleForText(this));
+
     if (needsStyleRecalc()) {
         if (renderer)
             renderer->setText(dataImpl());
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to