| Differences between
and this patch
- a/Source/WebCore/ChangeLog +35 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2012-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 resolve styles of text nodes.
9
        If text nodes are direct children 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
1
2012-11-19  Kentaro Hara  <haraken@chromium.org>
36
2012-11-19  Kentaro Hara  <haraken@chromium.org>
2
37
3
        In the IDL parser, we should rename $dataNode to $interface
38
        In the IDL parser, we should rename $dataNode to $interface
- a/Source/WebCore/css/StyleResolver.cpp +27 lines
Lines 1787-1792 PassRefPtr<RenderStyle> StyleResolver::styleForPage(int pageIndex) a/Source/WebCore/css/StyleResolver.cpp_sec1
1787
    return m_style.release();
1787
    return m_style.release();
1788
}
1788
}
1789
1789
1790
PassRefPtr<RenderStyle> StyleResolver::styleForText(Node* textNode, NodeRenderingContext& context)
1791
{
1792
    ASSERT(textNode);
1793
    ASSERT(textNode->isTextNode());
1794
1795
    Node* parentNode = context.parentNodeForRenderingAndStyle();
1796
    if (!shouldResetStyleInheritance(context) && parentNode)
1797
        return parentNode->renderStyle();
1798
1799
    m_style = RenderStyle::create();
1800
    if (Settings* settings = documentSettings()) {
1801
        initializeFontStyle(settings);
1802
        m_style->font().update(fontSelector());
1803
    } else
1804
        m_style->font().update(0);
1805
1806
    return m_style.release();
1807
}
1808
1809
PassRefPtr<RenderStyle> StyleResolver::styleForText(Node* textNode)
1810
{
1811
    ASSERT(textNode);
1812
    ASSERT(textNode->isTextNode());
1813
    NodeRenderingContext context(textNode);
1814
    return styleForText(textNode, context);
1815
}
1816
1790
static void addIntrinsicMargins(RenderStyle* style)
1817
static void addIntrinsicMargins(RenderStyle* style)
1791
{
1818
{
1792
    // Intrinsic margin value.
1819
    // Intrinsic margin value.
- a/Source/WebCore/css/StyleResolver.h +2 lines
Lines 151-156 public: a/Source/WebCore/css/StyleResolver.h_sec1
151
    PassRefPtr<RenderStyle> pseudoStyleForElement(PseudoId, Element*, RenderStyle* parentStyle);
151
    PassRefPtr<RenderStyle> pseudoStyleForElement(PseudoId, Element*, RenderStyle* parentStyle);
152
152
153
    PassRefPtr<RenderStyle> styleForPage(int pageIndex);
153
    PassRefPtr<RenderStyle> styleForPage(int pageIndex);
154
    PassRefPtr<RenderStyle> styleForText(Node*, NodeRenderingContext&);
155
    PassRefPtr<RenderStyle> styleForText(Node*);
154
156
155
    static PassRefPtr<RenderStyle> styleForDocument(Document*, CSSFontSelector* = 0);
157
    static PassRefPtr<RenderStyle> styleForDocument(Document*, CSSFontSelector* = 0);
156
158
- a/Source/WebCore/dom/NodeRenderingContext.cpp +3 lines
Lines 41-46 a/Source/WebCore/dom/NodeRenderingContext.cpp_sec1
41
#include "RenderView.h"
41
#include "RenderView.h"
42
#include "ShadowRoot.h"
42
#include "ShadowRoot.h"
43
#include "StyleInheritedData.h"
43
#include "StyleInheritedData.h"
44
#include "StyleResolver.h"
44
45
45
#if ENABLE(SVG)
46
#if ENABLE(SVG)
46
#include "SVGNames.h"
47
#include "SVGNames.h"
Lines 236-241 void NodeRendererFactory::createRendererIfNeeded() a/Source/WebCore/dom/NodeRenderingContext.cpp_sec2
236
    Element* element = node->isElementNode() ? toElement(node) : 0;
237
    Element* element = node->isElementNode() ? toElement(node) : 0;
237
    if (element)
238
    if (element)
238
        m_context.setStyle(element->styleForRenderer());
239
        m_context.setStyle(element->styleForRenderer());
240
    else if (node->isTextNode() && (node->parentOrHostNode()->isShadowRoot() || m_context.insertionPoint()))
241
        m_context.setStyle(document->styleResolver()->styleForText(node, m_context));
239
    else if (RenderObject* parentRenderer = m_context.parentRenderer())
242
    else if (RenderObject* parentRenderer = m_context.parentRenderer())
240
        m_context.setStyle(parentRenderer->style());
243
        m_context.setStyle(parentRenderer->style());
241
244
- a/Source/WebCore/dom/Text.cpp -4 / +3 lines
Lines 33-38 a/Source/WebCore/dom/Text.cpp_sec1
33
#endif
33
#endif
34
34
35
#include "StyleInheritedData.h"
35
#include "StyleInheritedData.h"
36
#include "StyleResolver.h"
36
#include <wtf/text/CString.h>
37
#include <wtf/text/CString.h>
37
#include <wtf/text/StringBuilder.h>
38
#include <wtf/text/StringBuilder.h>
38
39
Lines 258-267 void Text::recalcTextStyle(StyleChange change) a/Source/WebCore/dom/Text.cpp_sec2
258
259
259
    RenderObject* renderer = this->renderer();
260
    RenderObject* renderer = this->renderer();
260
261
261
    // The only time we have a renderer and our parent doesn't is if our parent
262
    if (change != NoChange && renderer)
262
    // is a shadow root.
263
        renderer->setStyle(document()->styleResolver()->styleForText(this));
263
    if (change != NoChange && renderer && !parentNode()->isShadowRoot())
264
        renderer->setStyle(parentNode()->renderer()->style());
265
264
266
    if (needsStyleRecalc()) {
265
    if (needsStyleRecalc()) {
267
        if (renderer) {
266
        if (renderer) {
- a/LayoutTests/ChangeLog +17 lines
Lines 1-3 a/LayoutTests/ChangeLog_sec1
1
2012-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
1
2012-11-19  Adam Klein  <adamk@chromium.org>
18
2012-11-19  Adam Klein  <adamk@chromium.org>
2
19
3
        MutationObserver wrapper should not be collected while still observing
20
        MutationObserver wrapper should not be collected while still observing
- a/LayoutTests/fast/dom/shadow/text-node-in-shadow-expected.html +9 lines
Line 0 a/LayoutTests/fast/dom/shadow/text-node-in-shadow-expected.html_sec1
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>
- a/LayoutTests/fast/dom/shadow/text-node-in-shadow.html +67 lines
Line 0 a/LayoutTests/fast/dom/shadow/text-node-in-shadow.html_sec1
1
<!doctype html>
2
<html>
3
<head>
4
<style>
5
span {
6
   text-align: top;
7
}
8
</style>
9
10
<script>
11
function 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
22
function 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
34
function 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
42
function 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
51
function 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>

Return to Bug 101116