Changeset 137418 in webkit


Ignore:
Timestamp:
Dec 11, 2012 10:24:30 PM (11 years ago)
Author:
tasak@google.com
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.
Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r137414 r137418  
     12012-12-11  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 Hajime Morita.
     7
     8        * fast/dom/shadow/text-node-in-shadow-expected.html: Added.
     9        * fast/dom/shadow/text-node-in-shadow.html: Added.
     10
    1112012-12-11  Dominic Mazzoni  <dmazzoni@google.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r137417 r137418  
     12012-12-11  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 Hajime Morita.
     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::styleForElement):
     22        Modified to use defaultStyleForElement if the given element has
     23        no parent style.
     24        (WebCore::StyleResolver::initForStyleResolve):
     25        Removed shouldResetStyleInheritance, because now NodeRenderingContext
     26        resetStyleInheritance() takes care of reset-style-inheritance of
     27        both shadow roots and insertion points.
     28        (WebCore::StyleResolver::defaultStyleForElement):
     29        Added to create a default style for elements.
     30        (WebCore):
     31        (WebCore::StyleResolver::styleForText):
     32        Use NodeRenderingContext to find the parent node for style from the
     33        given text node. If no parent node is found or reset-style-inheritance
     34        is true, returns a default style (i.e. empty render style).
     35        Otherwise, just returns the found node's style.
     36        * css/StyleResolver.h:
     37        (StyleResolver):
     38        * dom/ComposedShadowTreeWalker.cpp:
     39        (WebCore::ComposedShadowTreeWalker::ParentTraversalDetails::didTraverseInsertionPoint):
     40        Modify to consider insertion point's resetStyleInheritance.
     41        * dom/NodeRenderingContext.cpp:
     42        (WebCore::NodeRenderingContext::createRendererForTextIfNeeded):
     43        Since NodeRenderingContext has already found a parent node for
     44        rendering and style and a parentRenderer is just the found node's
     45        renderer, we have to only check reset-style-inheritance.
     46        If reset, use default style. Otherwise, the parentRenderer's style.
     47        * dom/Text.cpp:
     48        (WebCore::Text::recalcTextStyle):
     49        Use styleForText instead of parentRenderer's styles if the given text
     50        node is a direct child of a shadow root or a direct child of a shadow
     51        host.
     52
    1532012-12-11  Takashi Sakamoto  <tasak@google.com>
    254
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r137359 r137418  
    967967}
    968968
    969 inline bool shouldResetStyleInheritance(NodeRenderingContext& context)
    970 {
    971     if (context.resetStyleInheritance())
    972         return true;
    973 
    974     if (InsertionPoint* insertionPoint = context.insertionPoint())
    975         return insertionPoint->resetStyleInheritance();
    976 
    977     return false;
    978 }
    979 
    980969inline void StyleResolver::initForStyleResolve(Element* e, RenderStyle* parentStyle, PseudoId pseudoID)
    981970{
     
    985974        NodeRenderingContext context(e);
    986975        m_parentNode = context.parentNodeForRenderingAndStyle();
    987         m_parentStyle = shouldResetStyleInheritance(context) ? 0 :
     976        m_parentStyle = context.resetStyleInheritance() ? 0 :
    988977            parentStyle ? parentStyle :
    989978            m_parentNode ? m_parentNode->renderStyle() : 0;
     
    15541543    }
    15551544
    1556     m_style = RenderStyle::create();
    1557 
    15581545    RefPtr<RenderStyle> cloneForParent;
    15591546
    1560     if (m_parentStyle)
     1547    if (m_parentStyle) {
     1548        m_style = RenderStyle::create();
    15611549        m_style->inheritFrom(m_parentStyle, isAtShadowBoundary(element) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary);
    1562     else {
    1563         // Make sure our fonts are initialized if we don't inherit them from our parent style.
    1564         if (Settings* settings = documentSettings()) {
    1565             initializeFontStyle(settings);
    1566             m_style->font().update(fontSelector());
    1567         } else
    1568             m_style->font().update(0);
     1550    } else {
     1551        m_style = defaultStyleForElement();
    15691552        cloneForParent = RenderStyle::clone(style());
    15701553        m_parentStyle = cloneForParent.get();
     
    18071790    // Now return the style.
    18081791    return m_style.release();
     1792}
     1793
     1794PassRefPtr<RenderStyle> StyleResolver::defaultStyleForElement()
     1795{
     1796    m_style = RenderStyle::create();
     1797    // Make sure our fonts are initialized if we don't inherit them from our parent style.
     1798    if (Settings* settings = documentSettings()) {
     1799        initializeFontStyle(settings);
     1800        m_style->font().update(fontSelector());
     1801    } else
     1802        m_style->font().update(0);
     1803
     1804    return m_style.release();
     1805}
     1806
     1807PassRefPtr<RenderStyle> StyleResolver::styleForText(Text* textNode)
     1808{
     1809    ASSERT(textNode);
     1810
     1811    NodeRenderingContext context(textNode);
     1812    Node* parentNode = context.parentNodeForRenderingAndStyle();
     1813    return context.resetStyleInheritance() || !parentNode ?
     1814        defaultStyleForElement() : parentNode->renderStyle();
    18091815}
    18101816
  • trunk/Source/WebCore/css/StyleResolver.h

    r137417 r137418  
    155155
    156156    PassRefPtr<RenderStyle> styleForPage(int pageIndex);
     157    PassRefPtr<RenderStyle> defaultStyleForElement();
     158    PassRefPtr<RenderStyle> styleForText(Text*);
    157159
    158160    static PassRefPtr<RenderStyle> styleForDocument(Document*, CSSFontSelector* = 0);
  • trunk/Source/WebCore/dom/ComposedShadowTreeWalker.cpp

    r137336 r137418  
    7373inline void ComposedShadowTreeWalker::ParentTraversalDetails::didTraverseInsertionPoint(InsertionPoint* insertionPoint)
    7474{
    75     if (!m_insertionPoint)
     75    if (!m_insertionPoint) {
    7676        m_insertionPoint = insertionPoint;
     77        m_resetStyleInheritance  = m_resetStyleInheritance || insertionPoint->resetStyleInheritance();
     78    }
    7779}
    7880
  • trunk/Source/WebCore/dom/NodeRenderingContext.cpp

    r137336 r137418  
    4545#include "ShadowRoot.h"
    4646#include "StyleInheritedData.h"
     47#include "StyleResolver.h"
    4748#include "Text.h"
    4849
     
    266267    if (!shouldCreateRenderer())
    267268        return;
     269
    268270    RenderObject* parentRenderer = this->parentRenderer();
    269271    ASSERT(parentRenderer);
    270     m_style = parentRenderer->style();
     272    Document* document = textNode->document();
     273
     274    if (resetStyleInheritance())
     275        m_style = document->styleResolver()->defaultStyleForElement();
     276    else
     277        m_style = parentRenderer->style();
    271278
    272279    if (!textNode->textRendererIsNeeded(*this))
    273280        return;
    274     Document* document = textNode->document();
    275281    RenderText* newRenderer = textNode->createTextRenderer(document->renderArena(), m_style.get());
    276282    if (!newRenderer)
  • trunk/Source/WebCore/dom/Text.cpp

    r135668 r137418  
    3434
    3535#include "StyleInheritedData.h"
     36#include "StyleResolver.h"
    3637#include <wtf/text/CString.h>
    3738#include <wtf/text/StringBuilder.h>
     
    283284{
    284285    RenderText* renderer = toRenderText(this->renderer());
    285     // The only time we have a renderer and our parent doesn't is if our parent
    286     // is a shadow root.
    287     if (change != NoChange && renderer) {
    288         if (!parentNode()->isShadowRoot())
    289             renderer->setStyle(parentNode()->renderer()->style());
    290 #if ENABLE(SVG)
    291         else if (isSVGShadowText(this))
    292             renderer->setStyle(toShadowRoot(parentNode())->host()->renderer()->style());
    293 #endif
    294     }
     286
     287    if (change != NoChange && renderer)
     288        renderer->setStyle(document()->styleResolver()->styleForText(this));
    295289
    296290    if (needsStyleRecalc()) {
Note: See TracChangeset for help on using the changeset viewer.