Source/WebCore/ChangeLog

 12012-11-19 Takashi Sakamoto <tasak@google.com>
 2
 3 Text nodes in shadow roots don't inherit style properly
 4 https://bugs.webkit.org/show_bug.cgi?id=101116
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Use NodeRenderingContext to solve styles of text nodes.
 9 If text nodes are direct chilren of shadow roots, the text nodes
 10 should be inherited styles from their shadow hosts.
 11 But if reset-style-inheritance flag is true, the text nodes should
 12 not be inherited. And if text nodes are distributed nodes,
 13 we have to check whether their insertion point's
 14 reset-style-inheritance.
 15 c.f. shadow dom spec is:
 16 http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html#styles
 17
 18 Test: fast/dom/shadow/text-node-in-shadow.html
 19
 20 * css/StyleResolver.cpp:
 21 (WebCore::StyleResolver::styleForText):
 22 Use NodeRenderingContext to find the parent node for style from the
 23 given text node. If no parent node is found or reset-style-inheritance
 24 is true (i.e. the given node is a distributed node or direct child of
 25 a shadow root), returns an empty RenderStyle. Otherwise, just returns
 26 the found node's style.
 27 * css/StyleResolver.h:
 28 (StyleResolver):
 29 * dom/NodeRenderingContext.cpp:
 30 (WebCore::NodeRendererFactory::createRendererIfNeeded):
 31 Use styleForText's results for text nodes instead of
 32 parentRenderer's styles.
 33 * dom/Text.cpp:
 34 (WebCore::Text::recalcTextStyle):
 35
1362012-11-19 Kentaro Hara <haraken@chromium.org>
237
338 In the IDL parser, we should rename $dataNode to $interface

Source/WebCore/css/StyleResolver.cpp

@@PassRefPtr<RenderStyle> StyleResolver::styleForPage(int pageIndex)
17871787 return m_style.release();
17881788}
17891789
 1790PassRefPtr<RenderStyle> StyleResolver::styleForText(Node* textNode)
 1791{
 1792 ASSERT(textNode);
 1793 ASSERT(textNode->isTextNode());
 1794
 1795 NodeRenderingContext context(textNode);
 1796 Node* parentNode = context.parentNodeForRenderingAndStyle();
 1797 if (!shouldResetStyleInheritance(context) && parentNode)
 1798 return parentNode->renderStyle();
 1799
 1800 m_style = RenderStyle::create();
 1801 if (Settings* settings = documentSettings()) {
 1802 initializeFontStyle(settings);
 1803 m_style->font().update(fontSelector());
 1804 } else
 1805 m_style->font().update(0);
 1806
 1807 return m_style.release();
 1808}
 1809
17901810static void addIntrinsicMargins(RenderStyle* style)
17911811{
17921812 // Intrinsic margin value.

Source/WebCore/css/StyleResolver.h

@@public:
151151 PassRefPtr<RenderStyle> pseudoStyleForElement(PseudoId, Element*, RenderStyle* parentStyle);
152152
153153 PassRefPtr<RenderStyle> styleForPage(int pageIndex);
 154 PassRefPtr<RenderStyle> styleForText(Node*);
154155
155156 static PassRefPtr<RenderStyle> styleForDocument(Document*, CSSFontSelector* = 0);
156157

Source/WebCore/dom/NodeRenderingContext.cpp

4141#include "RenderView.h"
4242#include "ShadowRoot.h"
4343#include "StyleInheritedData.h"
 44#include "StyleResolver.h"
4445
4546#if ENABLE(SVG)
4647#include "SVGNames.h"

@@void NodeRendererFactory::createRendererIfNeeded()
236237 Element* element = node->isElementNode() ? toElement(node) : 0;
237238 if (element)
238239 m_context.setStyle(element->styleForRenderer());
 240 else if (node->isTextNode())
 241 m_context.setStyle(document->styleResolver()->styleForText(node));
239242 else if (RenderObject* parentRenderer = m_context.parentRenderer())
240243 m_context.setStyle(parentRenderer->style());
241244

Source/WebCore/dom/Text.cpp

3333#endif
3434
3535#include "StyleInheritedData.h"
 36#include "StyleResolver.h"
3637#include <wtf/text/CString.h>
3738#include <wtf/text/StringBuilder.h>
3839

@@void Text::recalcTextStyle(StyleChange change)
260261
261262 // The only time we have a renderer and our parent doesn't is if our parent
262263 // is a shadow root.
263  if (change != NoChange && renderer && !parentNode()->isShadowRoot())
264  renderer->setStyle(parentNode()->renderer()->style());
 264 if (change != NoChange && renderer)
 265 renderer->setStyle(document()->styleResolver()->styleForText(this));
265266
266267 if (needsStyleRecalc()) {
267268 if (renderer) {

LayoutTests/ChangeLog

 12012-11-19 Takashi Sakamoto <tasak@google.com>
 2
 3 Text nodes in shadow roots don't inherit style properly
 4 https://bugs.webkit.org/show_bug.cgi?id=101116
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 * fast/dom/shadow/text-node-in-shadow-expected.html: Added.
 9 * fast/dom/shadow/text-node-in-shadow.html: Added.
 10 Four test cases, one is for testing a text node which is a direct
 11 child of a shadow root without reset-style-inheritance.
 12 One is with reset-style-inheritance.
 13 One is for testing a text node which is a distributed node and its
 14 insertion point doesn't have reset-style-inheritance set to be true.
 15 The other one is almost the same as the previous one except
 16 reset-style-inheritance.
 17
1182012-11-19 Adam Klein <adamk@chromium.org>
219
320 MutationObserver wrapper should not be collected while still observing

LayoutTests/fast/dom/shadow/text-node-in-shadow-expected.html

 1<!doctype html>
 2<html>
 3<body>
 4 <div style="font-size: 5em;"><span>foo</span>bar</div>
 5 <div><span>foo</span>bar</span><span style="font-size: 6em;">&nbsp;</span></div>
 6 <div><span style="font-size: 5em;">Foo<span>Bar</span></span></div>
 7 <div>Foo<span>Bar</span><span style="font-size: 6em;">&nbsp;</span></div>
 8</body>
 9</html>

LayoutTests/fast/dom/shadow/text-node-in-shadow.html

 1<!doctype html>
 2<html>
 3<head>
 4<style>
 5span {
 6 text-align: top;
 7}
 8</style>
 9
 10<script>
 11function testChildTextOfShadowRoot() {
 12 var host = document.getElementById("host");
 13 var shadowRoot = new WebKitShadowRoot(host);
 14 var span = document.createElement('span')
 15 span.textContent = "foo";
 16 shadowRoot.appendChild(span);
 17 shadowRoot.appendChild(document.createTextNode("bar"));
 18 document.body.offsetLeft;
 19 host.style.fontSize = '5em';
 20}
 21
 22function testChildTextOfShadowRootWithResetStyleInheritance() {
 23 var host = document.getElementById("hostResetStyleInheritance");
 24 var shadowRoot = new WebKitShadowRoot(host);
 25 var span = document.createElement('span')
 26 span.textContent = "foo";
 27 shadowRoot.appendChild(span);
 28 shadowRoot.appendChild(document.createTextNode("bar"));
 29 shadowRoot.resetStyleInheritance = true;
 30 document.body.offsetLeft;
 31 host.style.fontSize = '6em';
 32}
 33
 34function testDistributedText() {
 35 var host = document.getElementById("hostWithDistribution");
 36 var shadowRoot = new WebKitShadowRoot(host);
 37 shadowRoot.innerHTML = "<span id='span1'><content></content></span>"
 38 document.body.offsetLeft;
 39 shadowRoot.getElementById("span1").style.fontSize = '5em';
 40}
 41
 42function testDistributedTextWithResetStyleInheritance() {
 43 var host = document.getElementById("hostResetStyleInheritanceWithDistribution");
 44 var shadowRoot = new WebKitShadowRoot(host);
 45 shadowRoot.innerHTML = "<span id='span2'><content id='content'></content></span>"
 46 shadowRoot.getElementById("content").resetStyleInheritance = true;
 47 document.body.offsetLeft;
 48 shadowRoot.getElementById("span2").style.fontSize = '6em';
 49}
 50
 51function runTests() {
 52 testChildTextOfShadowRoot();
 53 testChildTextOfShadowRootWithResetStyleInheritance();
 54 testDistributedText();
 55 testDistributedTextWithResetStyleInheritance();
 56}
 57</script>
 58</head>
 59<body onload="runTests()">
 60 <!-- [bug 101116] Text nodes in shadow roots don't inherit style properly -->
 61 <!-- https://bugs.webkit.org/show_bug.cgi?id=101116 -->
 62 <div id="host"></div>
 63 <div id="hostResetStyleInheritance"></div>
 64 <div id="hostWithDistribution">Foo<span>Bar</span></div>
 65 <div id="hostResetStyleInheritanceWithDistribution">Foo<span>Bar</span></div>
 66</body>
 67</html>