Changeset 189987 in webkit


Ignore:
Timestamp:
Sep 18, 2015 3:25:08 PM (9 years ago)
Author:
Antti Koivisto
Message:

Support style isolation in shadow trees
https://bugs.webkit.org/show_bug.cgi?id=149353

Reviewed by Ryosuke Niwa.

Allow ShadowRoots to have their own StyleResolvers.

This patch just adds the mechanism, all shadow roots still use the document resolver.

  • css/StyleResolver.h:

(WebCore::StyleResolverParentPusher::push):
(WebCore::StyleResolverParentPusher::~StyleResolverParentPusher):

  • dom/Element.cpp:

(WebCore::Element::absoluteLinkURL):
(WebCore::Element::styleResolver):

Helper function for getting the right StyleResolver for the element.

(WebCore::Element::resolveStyle):

Helper function for resolving element style.

  • dom/Element.h:
  • dom/ShadowRoot.cpp:

(WebCore::ShadowRoot::~ShadowRoot):
(WebCore::ShadowRoot::styleResolver):
(WebCore::ShadowRoot::cloneNode):

  • dom/ShadowRoot.h:

(WebCore::ShadowRoot::resetStyleInheritance):

  • editing/EditingStyle.cpp:

(WebCore::styleFromMatchedRulesForElement):

  • html/HTMLTitleElement.cpp:

(WebCore::HTMLTitleElement::computedTextWithDirection):

  • html/canvas/CanvasRenderingContext2D.cpp:

(WebCore::CanvasRenderingContext2D::setFont):

  • inspector/InspectorCSSAgent.cpp:

(WebCore::InspectorCSSAgent::getMatchedStylesForNode):

  • page/animation/KeyframeAnimation.cpp:

(WebCore::KeyframeAnimation::KeyframeAnimation):

  • rendering/RenderElement.cpp:

(WebCore::RenderElement::getUncachedPseudoStyle):
(WebCore::RenderElement::containingBlockForFixedPosition):

  • rendering/RenderNamedFlowFragment.cpp:

(WebCore::RenderNamedFlowFragment::checkRegionStyle):
(WebCore::RenderNamedFlowFragment::computeStyleInRegion):

  • style/StyleResolveTree.cpp:

(WebCore::Style::styleForElement):

  • svg/SVGElement.cpp:

(WebCore::SVGElement::customStyleForRenderer):
(WebCore::SVGElement::animatedSMILStyleProperties):

  • svg/SVGElementRareData.h:

(WebCore::SVGElementRareData::overrideComputedStyle):

Location:
trunk/Source/WebCore
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r189985 r189987  
     12015-09-18  Antti Koivisto  <antti@apple.com>
     2
     3        Support style isolation in shadow trees
     4        https://bugs.webkit.org/show_bug.cgi?id=149353
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Allow ShadowRoots to have their own StyleResolvers.
     9
     10        This patch just adds the mechanism, all shadow roots still use the document resolver.
     11
     12        * css/StyleResolver.h:
     13        (WebCore::StyleResolverParentPusher::push):
     14        (WebCore::StyleResolverParentPusher::~StyleResolverParentPusher):
     15        * dom/Element.cpp:
     16        (WebCore::Element::absoluteLinkURL):
     17        (WebCore::Element::styleResolver):
     18
     19            Helper function for getting the right StyleResolver for the element.
     20
     21        (WebCore::Element::resolveStyle):
     22
     23            Helper function for resolving element style.
     24
     25        * dom/Element.h:
     26        * dom/ShadowRoot.cpp:
     27        (WebCore::ShadowRoot::~ShadowRoot):
     28        (WebCore::ShadowRoot::styleResolver):
     29        (WebCore::ShadowRoot::cloneNode):
     30        * dom/ShadowRoot.h:
     31        (WebCore::ShadowRoot::resetStyleInheritance):
     32        * editing/EditingStyle.cpp:
     33        (WebCore::styleFromMatchedRulesForElement):
     34        * html/HTMLTitleElement.cpp:
     35        (WebCore::HTMLTitleElement::computedTextWithDirection):
     36        * html/canvas/CanvasRenderingContext2D.cpp:
     37        (WebCore::CanvasRenderingContext2D::setFont):
     38        * inspector/InspectorCSSAgent.cpp:
     39        (WebCore::InspectorCSSAgent::getMatchedStylesForNode):
     40        * page/animation/KeyframeAnimation.cpp:
     41        (WebCore::KeyframeAnimation::KeyframeAnimation):
     42        * rendering/RenderElement.cpp:
     43        (WebCore::RenderElement::getUncachedPseudoStyle):
     44        (WebCore::RenderElement::containingBlockForFixedPosition):
     45        * rendering/RenderNamedFlowFragment.cpp:
     46        (WebCore::RenderNamedFlowFragment::checkRegionStyle):
     47        (WebCore::RenderNamedFlowFragment::computeStyleInRegion):
     48        * style/StyleResolveTree.cpp:
     49        (WebCore::Style::styleForElement):
     50        * svg/SVGElement.cpp:
     51        (WebCore::SVGElement::customStyleForRenderer):
     52        (WebCore::SVGElement::animatedSMILStyleProperties):
     53        * svg/SVGElementRareData.h:
     54        (WebCore::SVGElementRareData::overrideComputedStyle):
     55
    1562015-09-18  Alex Christensen  <achristensen@webkit.org>
    257
  • trunk/Source/WebCore/css/StyleResolver.h

    r189830 r189987  
    579579        if (m_pushedStyleResolver)
    580580            return;
    581         m_pushedStyleResolver = &m_parent->document().ensureStyleResolver();
     581        m_pushedStyleResolver = &m_parent->styleResolver();
    582582        m_pushedStyleResolver->pushParentElement(m_parent);
    583583    }
     
    588588        // This tells us that our pushed style selector is in a bad state,
    589589        // so we should just bail out in that scenario.
    590         ASSERT(m_pushedStyleResolver == &m_parent->document().ensureStyleResolver());
    591         if (m_pushedStyleResolver != &m_parent->document().ensureStyleResolver())
    592             return;
     590        ASSERT(m_pushedStyleResolver == &m_parent->styleResolver());
    593591        m_pushedStyleResolver->popParentElement(m_parent);
    594592    }
  • trunk/Source/WebCore/dom/Element.cpp

    r189950 r189987  
    13821382}
    13831383
     1384StyleResolver& Element::styleResolver()
     1385{
     1386    if (auto* shadowRoot = containingShadowRoot())
     1387        return shadowRoot->styleResolver();
     1388
     1389    return document().ensureStyleResolver();
     1390}
     1391
     1392Ref<RenderStyle> Element::resolveStyle(RenderStyle* parentStyle)
     1393{
     1394    return styleResolver().styleForElement(this, parentStyle);
     1395}
     1396
    13841397// Returns true is the given attribute is an event handler.
    13851398// We consider an event handler any attribute that begins with "on".
  • trunk/Source/WebCore/dom/Element.h

    r189841 r189987  
    488488    WEBCORE_EXPORT URL absoluteLinkURL() const;
    489489
     490    StyleResolver& styleResolver();
     491    Ref<RenderStyle> resolveStyle(RenderStyle* parentStyle);
     492
    490493protected:
    491494    Element(const QualifiedName&, Document&, ConstructionType);
  • trunk/Source/WebCore/dom/ShadowRoot.cpp

    r189950 r189987  
    4040struct SameSizeAsShadowRoot : public DocumentFragment, public TreeScope {
    4141    unsigned countersAndFlags[1];
     42    void* styleResolver;
    4243    void* host;
    4344#if ENABLE(SHADOW_DOM)
     
    6970    // destructed tree scope in each descendant.
    7071    removeDetachedChildren();
     72}
     73
     74StyleResolver& ShadowRoot::styleResolver()
     75{
     76    if (m_styleResolver)
     77        return *m_styleResolver;
     78
     79    return document().ensureStyleResolver();
    7180}
    7281
  • trunk/Source/WebCore/dom/ShadowRoot.h

    r189950 r189987  
    5656    virtual ~ShadowRoot();
    5757
     58    StyleResolver& styleResolver();
     59
    5860    bool resetStyleInheritance() const { return m_resetStyleInheritance; }
    5961    void setResetStyleInheritance(bool);
     
    100102    Type m_type;
    101103
     104    std::unique_ptr<StyleResolver> m_styleResolver;
     105
    102106    Element* m_host;
    103107
  • trunk/Source/WebCore/editing/EditingStyle.cpp

    r189182 r189987  
    12781278{
    12791279    RefPtr<MutableStyleProperties> style = MutableStyleProperties::create();
    1280     auto matchedRules = element->document().ensureStyleResolver().styleRulesForElement(element, rulesToInclude);
     1280    auto matchedRules = element->styleResolver().styleRulesForElement(element, rulesToInclude);
    12811281    for (unsigned i = 0; i < matchedRules.size(); ++i) {
    12821282        if (matchedRules[i]->isStyleRule())
  • trunk/Source/WebCore/html/HTMLTitleElement.cpp

    r189680 r189987  
    8383        direction = computedStyle->direction();
    8484    else {
    85         Ref<RenderStyle> style(document().ensureStyleResolver().styleForElement(this, parentElement() ? parentElement()->renderStyle() : nullptr));
     85        auto style = resolveStyle(parentElement() ? parentElement()->renderStyle() : nullptr);
    8686        direction = style.get().direction();
    8787    }
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp

    r189830 r189987  
    21642164
    21652165    // Now map the font property longhands into the style.
    2166     StyleResolver& styleResolver = canvas()->document().ensureStyleResolver();
     2166    StyleResolver& styleResolver = canvas()->styleResolver();
    21672167    styleResolver.applyPropertyToStyle(CSSPropertyFontFamily, parsedStyle->getPropertyCSSValue(CSSPropertyFontFamily).get(), &newStyle.get());
    21682168    styleResolver.applyPropertyToCurrentStyle(CSSPropertyFontStyle, parsedStyle->getPropertyCSSValue(CSSPropertyFontStyle).get());
  • trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp

    r189576 r189987  
    572572
    573573    // Matched rules.
    574     StyleResolver& styleResolver = element->document().ensureStyleResolver();
     574    StyleResolver& styleResolver = element->styleResolver();
    575575    auto matchedRules = styleResolver.pseudoStyleRulesForElement(element, elementPseudoId, StyleResolver::AllCSSRules);
    576576    matchedCSSRules = buildArrayForMatchedRuleList(matchedRules, styleResolver, element, elementPseudoId);
     
    599599            Element* parentElement = element->parentElement();
    600600            while (parentElement) {
    601                 StyleResolver& parentStyleResolver = parentElement->document().ensureStyleResolver();
     601                StyleResolver& parentStyleResolver = parentElement->styleResolver();
    602602                auto parentMatchedRules = parentStyleResolver.styleRulesForElement(parentElement, StyleResolver::AllCSSRules);
    603603                auto entry = Inspector::Protocol::CSS::InheritedStyleEntry::create()
  • trunk/Source/WebCore/page/animation/KeyframeAnimation.cpp

    r188647 r189987  
    5050    // Get the keyframe RenderStyles
    5151    if (m_object && m_object->element())
    52         m_object->document().ensureStyleResolver().keyframeStylesForAnimation(m_object->element(), unanimatedStyle, m_keyframes);
     52        m_object->element()->styleResolver().keyframeStylesForAnimation(m_object->element(), unanimatedStyle, m_keyframes);
    5353
    5454    // Update the m_transformFunctionListValid flag based on whether the function lists in the keyframes match.
  • trunk/Source/WebCore/rendering/RenderElement.cpp

    r189841 r189987  
    15381538        return nullptr;
    15391539
     1540    auto& styleResolver = element()->styleResolver();
     1541
    15401542    if (pseudoStyleRequest.pseudoId == FIRST_LINE_INHERITED) {
    1541         RefPtr<RenderStyle> result = document().ensureStyleResolver().styleForElement(element(), parentStyle, DisallowStyleSharing);
     1543        RefPtr<RenderStyle> result = styleResolver.styleForElement(element(), parentStyle, DisallowStyleSharing);
    15421544        result->setStyleType(FIRST_LINE_INHERITED);
    15431545        return result.release();
    15441546    }
    15451547
    1546     return document().ensureStyleResolver().pseudoStyleForElement(element(), pseudoStyleRequest, parentStyle);
     1548    return styleResolver.pseudoStyleForElement(element(), pseudoStyleRequest, parentStyle);
    15471549}
    15481550
  • trunk/Source/WebCore/rendering/RenderNamedFlowFragment.cpp

    r189567 r189987  
    343343    // FIXME: Region styling doesn't work for pseudo elements.
    344344    if (!isPseudoElement())
    345         customRegionStyle = view().document().ensureStyleResolver().checkRegionStyle(generatingElement());
     345        customRegionStyle = generatingElement()->styleResolver().checkRegionStyle(generatingElement());
    346346    setHasCustomRegionStyle(customRegionStyle);
    347347    downcast<RenderNamedFlowThread>(*m_flowThread).checkRegionsWithStyling();
     
    353353
    354354    // FIXME: Region styling fails for pseudo-elements because the renderers don't have a node.
    355     RefPtr<RenderStyle> renderObjectRegionStyle = renderer.view().document().ensureStyleResolver().styleForElement(renderer.element(), &parentStyle, DisallowStyleSharing, MatchAllRules, this);
     355    RefPtr<RenderStyle> renderObjectRegionStyle = renderer.element()->styleResolver().styleForElement(renderer.element(), &parentStyle, DisallowStyleSharing, MatchAllRules, this);
    356356
    357357    return renderObjectRegionStyle.release();
  • trunk/Source/WebCore/style/StyleResolveTree.cpp

    r189910 r189987  
    142142            return style.releaseNonNull();
    143143    }
    144     return element.document().ensureStyleResolver().styleForElement(&element, &inheritedStyle);
     144    return element.resolveStyle(&inheritedStyle);
    145145}
    146146
  • trunk/Source/WebCore/svg/SVGElement.cpp

    r189841 r189987  
    793793{
    794794    if (!correspondingElement())
    795         return document().ensureStyleResolver().styleForElement(this, &parentStyle);
    796 
    797     return document().ensureStyleResolver().styleForElement(correspondingElement(), &parentStyle, DisallowStyleSharing);
     795        return resolveStyle(&parentStyle);
     796
     797    return styleResolver().styleForElement(correspondingElement(), &parentStyle, DisallowStyleSharing);
    798798}
    799799
  • trunk/Source/WebCore/svg/SVGElementRareData.h

    r179260 r189987  
    7373        if (!m_overrideComputedStyle || m_needsOverrideComputedStyleUpdate) {
    7474            // The style computed here contains no CSS Animations/Transitions or SMIL induced rules - this is needed to compute the "base value" for the SMIL animation sandwhich model.
    75             m_overrideComputedStyle = element->document().ensureStyleResolver().styleForElement(element, parentStyle, DisallowStyleSharing, MatchAllRulesExcludingSMIL);
     75            m_overrideComputedStyle = element->styleResolver().styleForElement(element, parentStyle, DisallowStyleSharing, MatchAllRulesExcludingSMIL);
    7676            m_needsOverrideComputedStyleUpdate = false;
    7777        }
Note: See TracChangeset for help on using the changeset viewer.