Changeset 139128 in webkit


Ignore:
Timestamp:
Jan 8, 2013 4:16:19 PM (11 years ago)
Author:
morrita@google.com
Message:

[Shadow DOM] Distribution related code on ShadowRoot should be minimized.
https://bugs.webkit.org/show_bug.cgi?id=106282

Reviewed by Dimitri Glazkov.

.:

  • Source/autotools/symbols.filter:

Source/WebCore:

ShadowRoot had a certain amount of logic which is dedicated for
node distribution computation. These code is going to be compiled
out (Bug 103339) and better be part of the node distribution
algorithm, which is ScopeContentDistribution class.

This change

  • Renames ShadowRootContentDistributionData to ScopeContentDistribution. New name is concise and a bit more meaningful: It owns per TreeScope distribution state.
  • Moves distribution related code from ShadowRoot to ScopeContentDistribution

No new tests. Refactoring.

  • WebCore.exp.in:
  • css/StyleScopeResolver.cpp:

(WebCore::StyleScopeResolver::styleSharingCandidateMatchesHostRules):
(WebCore::StyleScopeResolver::matchHostRules):

  • dom/ComposedShadowTreeWalker.cpp:

(WebCore::nodeCanBeDistributed):
(WebCore::ComposedShadowTreeWalker::traverseBackToYoungerShadowRoot):
(WebCore::ComposedShadowTreeWalker::traverseParentBackToYoungerShadowRootOrHost):
(WebCore::AncestorChainWalker::parent):

  • dom/ElementShadow.cpp:

(WebCore::ElementShadow::collectSelectFeatureSetFrom):

  • dom/ShadowRoot.cpp:

(WebCore::ShadowRoot::insertedInto):
(WebCore::ShadowRoot::removedFrom):
(WebCore::ShadowRoot::ensureScopeDistribution):
(WebCore::ShadowRoot::reportMemoryUsage):

  • dom/ShadowRoot.h:

(WebCore):
(ShadowRoot):
(WebCore::ShadowRoot::scopeDistribution):

  • html/shadow/ContentDistributor.cpp:

(WebCore::ScopeContentDistribution::ScopeContentDistribution):
(WebCore::ScopeContentDistribution::invalidateInsertionPointList):
(WebCore::ScopeContentDistribution::ensureInsertionPointList):
(WebCore::ScopeContentDistribution::registerInsertionPoint):
(WebCore::ScopeContentDistribution::unregisterInsertionPoint):
(WebCore::ScopeContentDistribution::hasShadowElement):
(WebCore):
(WebCore::ScopeContentDistribution::hasContentElement):
(WebCore::ScopeContentDistribution::countElementShadow):
(WebCore::ScopeContentDistribution::hasInsertionPoint):
(WebCore::ScopeContentDistribution::assignedTo):
(WebCore::ContentDistributor::distribute):
(WebCore::ContentDistributor::invalidate):

  • html/shadow/ContentDistributor.h:

(ScopeContentDistribution):
(WebCore::ScopeContentDistribution::registerElementShadow):
(WebCore::ScopeContentDistribution::unregisterElementShadow):
(WebCore::ScopeContentDistribution::hasElementShadow):

  • html/shadow/HTMLShadowElement.cpp:

(WebCore::HTMLShadowElement::olderShadowRoot):

  • html/shadow/InsertionPoint.cpp:

(WebCore::InsertionPoint::insertedInto):
(WebCore::InsertionPoint::removedFrom):
(WebCore::InsertionPoint::contains):
(WebCore):
(WebCore::resolveReprojection):

  • html/shadow/InsertionPoint.h:

(InsertionPoint):
(WebCore):

  • testing/Internals.cpp:

(WebCore::Internals::hasShadowInsertionPoint):
(WebCore::Internals::hasContentElement):
(WebCore::Internals::countElementShadow):

Source/WebKit/win:

  • WebKit.vcproj/WebKit.def.in:
Location:
trunk
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r139046 r139128  
     12013-01-08  Hajime Morrita  <morrita@google.com>
     2
     3        [Shadow DOM] Distribution related code on ShadowRoot should be minimized.
     4        https://bugs.webkit.org/show_bug.cgi?id=106282
     5
     6        Reviewed by Dimitri Glazkov.
     7
     8        * Source/autotools/symbols.filter:
     9
    1102013-01-03  Sergio Villar Senin  <svillar@igalia.com>
    211
  • trunk/Source/WebCore/ChangeLog

    r139111 r139128  
     12013-01-08  Hajime Morrita  <morrita@google.com>
     2
     3        [Shadow DOM] Distribution related code on ShadowRoot should be minimized.
     4        https://bugs.webkit.org/show_bug.cgi?id=106282
     5
     6        Reviewed by Dimitri Glazkov.
     7
     8        ShadowRoot had a certain amount of logic which is dedicated for
     9        node distribution computation.  These code is going to be compiled
     10        out (Bug 103339) and better be part of the node distribution
     11        algorithm, which is ScopeContentDistribution class.
     12
     13        This change
     14
     15        - Renames ShadowRootContentDistributionData to
     16          ScopeContentDistribution.  New name is concise and a bit more
     17          meaningful: It owns per TreeScope distribution state.
     18        - Moves distribution related code from ShadowRoot to ScopeContentDistribution
     19
     20        No new tests. Refactoring.
     21
     22        * WebCore.exp.in:
     23        * css/StyleScopeResolver.cpp:
     24        (WebCore::StyleScopeResolver::styleSharingCandidateMatchesHostRules):
     25        (WebCore::StyleScopeResolver::matchHostRules):
     26        * dom/ComposedShadowTreeWalker.cpp:
     27        (WebCore::nodeCanBeDistributed):
     28        (WebCore::ComposedShadowTreeWalker::traverseBackToYoungerShadowRoot):
     29        (WebCore::ComposedShadowTreeWalker::traverseParentBackToYoungerShadowRootOrHost):
     30        (WebCore::AncestorChainWalker::parent):
     31        * dom/ElementShadow.cpp:
     32        (WebCore::ElementShadow::collectSelectFeatureSetFrom):
     33        * dom/ShadowRoot.cpp:
     34        (WebCore::ShadowRoot::insertedInto):
     35        (WebCore::ShadowRoot::removedFrom):
     36        (WebCore::ShadowRoot::ensureScopeDistribution):
     37        (WebCore::ShadowRoot::reportMemoryUsage):
     38        * dom/ShadowRoot.h:
     39        (WebCore):
     40        (ShadowRoot):
     41        (WebCore::ShadowRoot::scopeDistribution):
     42        * html/shadow/ContentDistributor.cpp:
     43        (WebCore::ScopeContentDistribution::ScopeContentDistribution):
     44        (WebCore::ScopeContentDistribution::invalidateInsertionPointList):
     45        (WebCore::ScopeContentDistribution::ensureInsertionPointList):
     46        (WebCore::ScopeContentDistribution::registerInsertionPoint):
     47        (WebCore::ScopeContentDistribution::unregisterInsertionPoint):
     48        (WebCore::ScopeContentDistribution::hasShadowElement):
     49        (WebCore):
     50        (WebCore::ScopeContentDistribution::hasContentElement):
     51        (WebCore::ScopeContentDistribution::countElementShadow):
     52        (WebCore::ScopeContentDistribution::hasInsertionPoint):
     53        (WebCore::ScopeContentDistribution::assignedTo):
     54        (WebCore::ContentDistributor::distribute):
     55        (WebCore::ContentDistributor::invalidate):
     56        * html/shadow/ContentDistributor.h:
     57        (ScopeContentDistribution):
     58        (WebCore::ScopeContentDistribution::registerElementShadow):
     59        (WebCore::ScopeContentDistribution::unregisterElementShadow):
     60        (WebCore::ScopeContentDistribution::hasElementShadow):
     61        * html/shadow/HTMLShadowElement.cpp:
     62        (WebCore::HTMLShadowElement::olderShadowRoot):
     63        * html/shadow/InsertionPoint.cpp:
     64        (WebCore::InsertionPoint::insertedInto):
     65        (WebCore::InsertionPoint::removedFrom):
     66        (WebCore::InsertionPoint::contains):
     67        (WebCore):
     68        (WebCore::resolveReprojection):
     69        * html/shadow/InsertionPoint.h:
     70        (InsertionPoint):
     71        (WebCore):
     72        * testing/Internals.cpp:
     73        (WebCore::Internals::hasShadowInsertionPoint):
     74        (WebCore::Internals::hasContentElement):
     75        (WebCore::Internals::countElementShadow):
     76
    1772013-01-08  Tom Sepez  <tsepez@chromium.org>
    278
  • trunk/Source/WebCore/WebCore.exp.in

    r139027 r139128  
    8383__ZN7WebCore10ScrollView24windowResizerRectChangedEv
    8484__ZN7WebCore10ScrollView8addChildEN3WTF10PassRefPtrINS_6WidgetEEE
    85 __ZNK7WebCore10ShadowRoot17hasContentElementEv
    86 __ZNK7WebCore10ShadowRoot18countElementShadowEv
    87 __ZNK7WebCore10ShadowRoot23hasShadowInsertionPointEv
    8885__ZNK7WebCore14ScrollableArea17reportMemoryUsageEPN3WTF16MemoryObjectInfoE
    8986__ZN7WebCore10ShadowRoot6createEPNS_7ElementERi
     
    673670__ZN7WebCore24FrameDestructionObserverC2EPNS_5FrameE
    674671__ZN7WebCore24FrameDestructionObserverD2Ev
     672__ZN7WebCore24ScopeContentDistribution16hasShadowElementEPKNS_10ShadowRootE
     673__ZN7WebCore24ScopeContentDistribution18countElementShadowEPKNS_10ShadowRootE
     674__ZN7WebCore24ScopeContentDistribution17hasContentElementEPKNS_10ShadowRootE
    675675__ZN7WebCore24createFragmentFromMarkupEPNS_8DocumentERKN3WTF6StringES5_NS_27FragmentScriptingPermissionE
    676676__ZN7WebCore24decodeURLEscapeSequencesERKN3WTF6StringE
  • trunk/Source/WebCore/css/StyleScopeResolver.cpp

    r138929 r139128  
    3232#include "CSSStyleRule.h"
    3333#include "CSSStyleSheet.h"
     34#include "ContentDistributor.h"
    3435#include "ContextFeatures.h"
    3536#include "ElementShadow.h"
     
    211212            return true;
    212213
    213         if (!shadowRoot->hasShadowInsertionPoint())
     214        if (!ScopeContentDistribution::hasShadowElement(shadowRoot))
    214215            break;
    215216    }
     
    233234        if (RuleSet* ruleSet = atHostRuleSetFor(shadowRoot))
    234235            matchedRules.append(ruleSet);
    235         if (!shadowRoot->hasShadowInsertionPoint())
     236        if (!ScopeContentDistribution::hasShadowElement(shadowRoot))
    236237            break;
    237238    }
  • trunk/Source/WebCore/dom/ComposedShadowTreeWalker.cpp

    r137715 r139128  
    6464
    6565    if (ShadowRoot* shadowRoot = parent->isShadowRoot() ? toShadowRoot(parent) : 0)
    66         return shadowRoot->assignedTo();
     66        return ScopeContentDistribution::assignedTo(shadowRoot);
    6767
    6868    if (parent->isElementNode() && toElement(parent)->shadow())
     
    199199        ShadowRoot* parentShadowRoot = toShadowRoot(node->parentNode());
    200200        if (!parentShadowRoot->isYoungest()) {
    201             InsertionPoint* assignedInsertionPoint = parentShadowRoot->assignedTo();
     201            InsertionPoint* assignedInsertionPoint = ScopeContentDistribution::assignedTo(parentShadowRoot);
    202202            ASSERT(assignedInsertionPoint);
    203203            return traverseSiblingInCurrentTree(assignedInsertionPoint, direction);
     
    268268{
    269269    ASSERT(shadowRoot);
    270     ASSERT(!shadowRoot->assignedTo());
     270    ASSERT(!ScopeContentDistribution::assignedTo(shadowRoot));
    271271
    272272    if (shadowRoot->isYoungest()) {
     
    344344    if (!m_node->isShadowRoot()) {
    345345        m_node = m_node->parentNode();
    346         if (!(m_node && m_node->isShadowRoot() && toShadowRoot(m_node)->assignedTo()))
     346        if (!(m_node && m_node->isShadowRoot() && ScopeContentDistribution::assignedTo(toShadowRoot(m_node))))
    347347            m_distributedNode = m_node;
    348348        m_isCrossingInsertionPoint = false;
     
    351351
    352352    const ShadowRoot* shadowRoot = toShadowRoot(m_node);
    353     if (InsertionPoint* insertionPoint = shadowRoot->assignedTo()) {
     353    if (InsertionPoint* insertionPoint = ScopeContentDistribution::assignedTo(shadowRoot)) {
    354354        m_node = insertionPoint;
    355355        m_isCrossingInsertionPoint = true;
  • trunk/Source/WebCore/dom/ElementShadow.cpp

    r139064 r139128  
    234234void ElementShadow::collectSelectFeatureSetFrom(ShadowRoot* root)
    235235{
    236     if (root->hasElementShadow()) {
     236    if (ScopeContentDistribution::hasElementShadow(root)) {
    237237        for (Element* element = ElementTraversal::firstWithin(root); element; element = ElementTraversal::next(element)) {
    238238            if (ElementShadow* elementShadow = element->shadow()) {
     
    243243    }
    244244
    245     if (root->hasContentElement()) {
     245    if (ScopeContentDistribution::hasContentElement(root)) {
    246246        for (Element* element = ElementTraversal::firstWithin(root); element; element = ElementTraversal::next(element)) {
    247247            if (isHTMLContentElement(element)) {
  • trunk/Source/WebCore/dom/ShadowRoot.cpp

    r138735 r139128  
    227227}
    228228
    229 bool ShadowRoot::hasInsertionPoint() const
    230 {
    231     return hasShadowInsertionPoint() || hasContentElement();
    232 }
    233 
    234229bool ShadowRoot::applyAuthorStyles() const
    235230{
     
    285280
    286281    if (ShadowRoot* root = host()->containingShadowRoot()) {
    287         root->registerElementShadow();
     282        root->ensureScopeDistribution()->registerElementShadow();
    288283        m_registeredWithParentShadowRoot = true;
    289284    }
     
    299294            root = insertionPoint->containingShadowRoot();
    300295
    301         if (root)
    302             root->unregisterElementShadow();
     296        if (root && root->scopeDistribution())
     297            root->scopeDistribution()->unregisterElementShadow();
    303298        m_registeredWithParentShadowRoot = false;
    304299    }
    305300
    306301    DocumentFragment::removedFrom(insertionPoint);
    307 }
    308 
    309 InsertionPoint* ShadowRoot::assignedTo() const
    310 {
    311     if (!distributionData())
    312         return 0;
    313 
    314     return distributionData()->insertionPointAssignedTo();
    315 }
    316 
    317 void ShadowRoot::setAssignedTo(InsertionPoint* insertionPoint)
    318 {
    319     ASSERT(!assignedTo() || !insertionPoint);
    320     ensureDistributionData()->setInsertionPointAssignedTo(insertionPoint);
    321302}
    322303
     
    327308    ContainerNode::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
    328309    owner()->invalidateDistribution();
    329 }
    330 
    331 const Vector<RefPtr<InsertionPoint> >& ShadowRoot::insertionPointList()
    332 {
    333     typedef Vector<RefPtr<InsertionPoint> > InsertionPointVector;
    334     DEFINE_STATIC_LOCAL(InsertionPointVector, emptyVector, ());
    335 
    336     return distributionData() ? distributionData()->ensureInsertionPointList(this) : emptyVector;
    337310}
    338311
     
    350323}
    351324
    352 inline ShadowRootContentDistributionData* ShadowRoot::ensureDistributionData()
    353 {
    354     if (m_distributionData)
    355         return m_distributionData.get();
    356 
    357     m_distributionData = adoptPtr(new ShadowRootContentDistributionData);
    358     return m_distributionData.get();
     325ScopeContentDistribution* ShadowRoot::ensureScopeDistribution()
     326{
     327    if (m_scopeDistribution)
     328        return m_scopeDistribution.get();
     329
     330    m_scopeDistribution = adoptPtr(new ScopeContentDistribution);
     331    return m_scopeDistribution.get();
    359332}   
    360 
    361 void ShadowRoot::registerInsertionPoint(InsertionPoint* point)
    362 {
    363     ensureDistributionData()->regiterInsertionPoint(this, point);
    364 }
    365 
    366 void ShadowRoot::unregisterInsertionPoint(InsertionPoint* point)
    367 {
    368     ensureDistributionData()->unregisterInsertionPoint(this, point);
    369 }
    370 
    371 bool ShadowRoot::hasShadowInsertionPoint() const
    372 {
    373     if (!distributionData())
    374         return false;
    375 
    376     return distributionData()->hasShadowElementChildren();
    377 }
    378 
    379 bool ShadowRoot::hasContentElement() const
    380 {
    381     if (!distributionData())
    382         return false;
    383 
    384     return distributionData()->hasContentElementChildren();
    385 }
    386 
    387 void ShadowRoot::registerElementShadow()
    388 {
    389     ensureDistributionData()->incrementNumberOfElementShadowChildren();
    390 }
    391 
    392 void ShadowRoot::unregisterElementShadow()
    393 {
    394     ASSERT(hasElementShadow());
    395     distributionData()->decrementNumberOfElementShadowChildren();
    396 }
    397 
    398 bool ShadowRoot::hasElementShadow() const
    399 {
    400     if (!distributionData())
    401         return false;
    402 
    403     return distributionData()->hasElementShadowChildren();
    404 }
    405 
    406 unsigned ShadowRoot::countElementShadow() const
    407 {
    408     if (!distributionData())
    409         return 0;
    410 
    411     return distributionData()->numberOfElementShadowChildren();
    412 }
    413333
    414334void ShadowRoot::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
     
    419339    info.addMember(m_prev);
    420340    info.addMember(m_next);
    421     info.addMember(m_distributionData);
    422 }
    423 
    424 }
     341    info.addMember(m_scopeDistribution);
     342}
     343
     344}
  • trunk/Source/WebCore/dom/ShadowRoot.h

    r138404 r139128  
    4242class ElementShadow;
    4343class InsertionPoint;
    44 class ShadowRootContentDistributionData;
     44class ScopeContentDistribution;
    4545
    4646class ShadowRoot : public DocumentFragment, public TreeScope, public DoublyLinkedListNode<ShadowRoot> {
     
    8181    bool isOldest() const { return !olderShadowRoot(); }
    8282
    83     bool hasInsertionPoint() const;
    84 
    8583    virtual void attach();
    8684
     
    8886    virtual void removedFrom(ContainerNode*) OVERRIDE;
    8987
    90     bool isUsedForRendering() const;
    91     InsertionPoint* assignedTo() const;
    92     void setAssignedTo(InsertionPoint*);
    93 
    94     bool hasShadowInsertionPoint() const;
    95     bool hasContentElement() const;
    96 
    97     void registerInsertionPoint(InsertionPoint*);
    98     void unregisterInsertionPoint(InsertionPoint*);
    99    
    100     void registerElementShadow();
    101     void unregisterElementShadow();
    102     bool hasElementShadow() const;
    103     unsigned countElementShadow() const;
    104 
    105     const Vector<RefPtr<InsertionPoint> >& insertionPointList();
    106 
    10788    virtual void registerScopedHTMLStyleChild() OVERRIDE;
    10889    virtual void unregisterScopedHTMLStyleChild() OVERRIDE;
     90
     91    ScopeContentDistribution* scopeDistribution() { return m_scopeDistribution.get(); }
     92    const ScopeContentDistribution* scopeDistribution() const { return m_scopeDistribution.get(); }
     93    ScopeContentDistribution* ensureScopeDistribution();
    10994
    11095    ShadowRootType type() const { return m_isAuthorShadowRoot ? AuthorShadowRoot : UserAgentShadowRoot; }
     
    125110    void setType(ShadowRootType type) { m_isAuthorShadowRoot = type == AuthorShadowRoot; }
    126111
    127     ShadowRootContentDistributionData* distributionData() { return m_distributionData.get(); }
    128     const ShadowRootContentDistributionData* distributionData() const { return m_distributionData.get(); }
    129     ShadowRootContentDistributionData* ensureDistributionData();
    130 
    131112    ShadowRoot* m_prev;
    132113    ShadowRoot* m_next;
    133     OwnPtr<ShadowRootContentDistributionData> m_distributionData;
     114    OwnPtr<ScopeContentDistribution> m_scopeDistribution;
    134115    unsigned m_numberOfStyles : 28;
    135116    unsigned m_applyAuthorStyles : 1;
     
    147128{
    148129    setParentOrHostNode(host);
    149 }
    150 
    151 inline bool ShadowRoot::isUsedForRendering() const
    152 {
    153     return isYoungest() || assignedTo();
    154130}
    155131
  • trunk/Source/WebCore/html/shadow/ContentDistributor.cpp

    r137717 r139128  
    7777
    7878
    79 ShadowRootContentDistributionData::ShadowRootContentDistributionData()
     79ScopeContentDistribution::ScopeContentDistribution()
    8080    : m_insertionPointAssignedTo(0)
    8181    , m_numberOfShadowElementChildren(0)
     
    8686}
    8787
    88 void ShadowRootContentDistributionData::invalidateInsertionPointList()
     88void ScopeContentDistribution::invalidateInsertionPointList()
    8989{
    9090    m_insertionPointListIsValid = false;
     
    9292}
    9393
    94 const Vector<RefPtr<InsertionPoint> >& ShadowRootContentDistributionData::ensureInsertionPointList(ShadowRoot* shadowRoot)
     94const Vector<RefPtr<InsertionPoint> >& ScopeContentDistribution::ensureInsertionPointList(ShadowRoot* shadowRoot)
    9595{
    9696    if (m_insertionPointListIsValid)
     
    100100    ASSERT(m_insertionPointList.isEmpty());
    101101
    102     if (!shadowRoot->hasInsertionPoint())
     102    if (!hasInsertionPoint(shadowRoot))
    103103        return m_insertionPointList;
    104104
     
    111111}
    112112
    113 void ShadowRootContentDistributionData::regiterInsertionPoint(ShadowRoot* scope, InsertionPoint* point)
     113void ScopeContentDistribution::registerInsertionPoint(ShadowRoot* scope, InsertionPoint* point)
    114114{
    115115    switch (point->insertionPointType()) {
     
    126126}
    127127
    128 void ShadowRootContentDistributionData::unregisterInsertionPoint(ShadowRoot* scope, InsertionPoint* point)
     128void ScopeContentDistribution::unregisterInsertionPoint(ShadowRoot* scope, InsertionPoint* point)
    129129{
    130130    switch (point->insertionPointType()) {
     
    144144}
    145145
     146bool ScopeContentDistribution::hasShadowElement(const ShadowRoot* holder)
     147{
     148    if (!holder->scopeDistribution())
     149        return false;
     150
     151    return holder->scopeDistribution()->hasShadowElementChildren();
     152}
     153
     154bool ScopeContentDistribution::hasContentElement(const ShadowRoot* holder)
     155{
     156    if (!holder->scopeDistribution())
     157        return false;
     158
     159    return holder->scopeDistribution()->hasContentElementChildren();
     160}
     161
     162unsigned ScopeContentDistribution::countElementShadow(const ShadowRoot* holder)
     163{
     164    if (!holder->scopeDistribution())
     165        return 0;
     166
     167    return holder->scopeDistribution()->numberOfElementShadowChildren();
     168}
     169
     170bool ScopeContentDistribution::hasInsertionPoint(const ShadowRoot* holder)
     171{
     172    return hasShadowElement(holder) || hasContentElement(holder);
     173}
     174
     175InsertionPoint* ScopeContentDistribution::assignedTo(const ShadowRoot* holder)
     176{
     177    if (!holder->scopeDistribution())
     178        return 0;
     179
     180    return holder->scopeDistribution()->insertionPointAssignedTo();
     181}
    146182
    147183ContentDistributor::ContentDistributor()
     
    194230        HTMLShadowElement* firstActiveShadowInsertionPoint = 0;
    195231
    196         const Vector<RefPtr<InsertionPoint> >& insertionPoints = root->insertionPointList();
    197         for (size_t i = 0; i < insertionPoints.size(); ++i) {
    198             InsertionPoint* point = insertionPoints[i].get();
    199             if (!point->isActive())
    200                 continue;
    201 
    202             if (isHTMLShadowElement(point)) {
    203                 if (!firstActiveShadowInsertionPoint)
    204                     firstActiveShadowInsertionPoint = toHTMLShadowElement(point);
    205             } else {
    206                 distributeSelectionsTo(point, pool, distributed);
    207                 if (ElementShadow* shadow = point->parentNode()->isElementNode() ? toElement(point->parentNode())->shadow() : 0)
    208                     shadow->invalidateDistribution();
     232        if (ScopeContentDistribution* scope = root->scopeDistribution()) {
     233            const Vector<RefPtr<InsertionPoint> >& insertionPoints = scope->ensureInsertionPointList(root);
     234            for (size_t i = 0; i < insertionPoints.size(); ++i) {
     235                InsertionPoint* point = insertionPoints[i].get();
     236                if (!point->isActive())
     237                    continue;
     238
     239                if (isHTMLShadowElement(point)) {
     240                    if (!firstActiveShadowInsertionPoint)
     241                        firstActiveShadowInsertionPoint = toHTMLShadowElement(point);
     242                } else {
     243                    distributeSelectionsTo(point, pool, distributed);
     244                    if (ElementShadow* shadow = point->parentNode()->isElementNode() ? toElement(point->parentNode())->shadow() : 0)
     245                        shadow->invalidateDistribution();
     246                }
    209247            }
    210248        }
     
    220258        if (root->olderShadowRoot()) {
    221259            distributeNodeChildrenTo(shadowElement, root->olderShadowRoot());
    222             root->olderShadowRoot()->setAssignedTo(shadowElement);
     260            root->olderShadowRoot()->ensureScopeDistribution()->setInsertionPointAssignedTo(shadowElement);
    223261        } else {
    224262            distributeSelectionsTo(shadowElement, pool, distributed);
     
    235273
    236274    for (ShadowRoot* root = host->youngestShadowRoot(); root; root = root->olderShadowRoot()) {
    237         root->setAssignedTo(0);
    238         const Vector<RefPtr<InsertionPoint> >& insertionPoints = root->insertionPointList();
    239         for (size_t i = 0; i < insertionPoints.size(); ++i) {
    240             needsReattach = needsReattach || true;
    241             insertionPoints[i]->clearDistribution();
     275        if (ScopeContentDistribution* scope = root->scopeDistribution()) {
     276            scope->setInsertionPointAssignedTo(0);
     277            const Vector<RefPtr<InsertionPoint> >& insertionPoints = scope->ensureInsertionPointList(root);
     278            for (size_t i = 0; i < insertionPoints.size(); ++i) {
     279                needsReattach = needsReattach || true;
     280                insertionPoints[i]->clearDistribution();
     281            }
    242282        }
    243283    }
  • trunk/Source/WebCore/html/shadow/ContentDistributor.h

    r137717 r139128  
    7171};
    7272
    73 class ShadowRootContentDistributionData {
     73class ScopeContentDistribution {
    7474public:
    75     ShadowRootContentDistributionData();
     75    ScopeContentDistribution();
    7676
    7777    InsertionPoint* insertionPointAssignedTo() const { return m_insertionPointAssignedTo; }
    7878    void setInsertionPointAssignedTo(InsertionPoint* insertionPoint) { m_insertionPointAssignedTo = insertionPoint; }
    7979
    80     void regiterInsertionPoint(ShadowRoot*, InsertionPoint*);
     80    void registerInsertionPoint(ShadowRoot*, InsertionPoint*);
    8181    void unregisterInsertionPoint(ShadowRoot*, InsertionPoint*);
    8282    bool hasShadowElementChildren() const { return m_numberOfShadowElementChildren > 0; }
    8383    bool hasContentElementChildren() const { return m_numberOfContentElementChildren > 0; }
    8484
    85     void incrementNumberOfElementShadowChildren() { ++m_numberOfElementShadowChildren; }
    86     void decrementNumberOfElementShadowChildren() { ASSERT(m_numberOfElementShadowChildren > 0); --m_numberOfElementShadowChildren; }
     85    void registerElementShadow() { ++m_numberOfElementShadowChildren; }
     86    void unregisterElementShadow() { ASSERT(m_numberOfElementShadowChildren > 0); --m_numberOfElementShadowChildren; }
    8787    unsigned numberOfElementShadowChildren() const { return m_numberOfElementShadowChildren; }
    8888    bool hasElementShadowChildren() const { return m_numberOfElementShadowChildren > 0; }
     
    9090    void invalidateInsertionPointList();
    9191    const Vector<RefPtr<InsertionPoint> >& ensureInsertionPointList(ShadowRoot*);
     92
     93    bool isUsedForRendering() const;
     94
     95    static bool hasShadowElement(const ShadowRoot*);
     96    static bool hasContentElement(const ShadowRoot*);
     97    static bool hasInsertionPoint(const ShadowRoot*);
     98    static bool hasElementShadow(const ShadowRoot* holder) { return countElementShadow(holder); }
     99    static unsigned countElementShadow(const ShadowRoot*);
     100    static InsertionPoint* assignedTo(const ShadowRoot*);
    92101
    93102private:
  • trunk/Source/WebCore/html/shadow/HTMLShadowElement.cpp

    r137429 r139128  
    7474
    7575    ShadowRoot* older = toShadowRoot(treeScope()->rootNode())->olderShadowRoot();
    76     if (!older || older->type() != ShadowRoot::AuthorShadowRoot || older->assignedTo() != this)
     76    if (!older || older->type() != ShadowRoot::AuthorShadowRoot || ScopeContentDistribution::assignedTo(older) != this)
    7777        return 0;
    7878
  • trunk/Source/WebCore/html/shadow/InsertionPoint.cpp

    r138923 r139128  
    136136            if (isActive() && !m_registeredWithShadowRoot && insertionPoint->treeScope()->rootNode() == root) {
    137137                m_registeredWithShadowRoot = true;
    138                 root->registerInsertionPoint(this);
     138                root->ensureScopeDistribution()->registerInsertionPoint(root, this);
    139139            }
    140140        }
     
    161161        ASSERT(root);
    162162        m_registeredWithShadowRoot = false;
    163         root->unregisterInsertionPoint(this);
     163        root->ensureScopeDistribution()->unregisterInsertionPoint(root, this);
    164164    }
    165165
     
    187187}
    188188
     189bool InsertionPoint::contains(const Node* node) const
     190{
     191    return m_distribution.contains(const_cast<Node*>(node)) || (node->isShadowRoot() && ScopeContentDistribution::assignedTo(toShadowRoot(node)) == this);
     192}
     193
     194InsertionPoint* resolveReprojection(const Node* projectedNode)
     195{
     196    InsertionPoint* insertionPoint = 0;
     197    const Node* current = projectedNode;
     198
     199    while (current) {
     200        if (ElementShadow* shadow = shadowOfParentForDistribution(current)) {
     201            shadow->ensureDistribution();
     202            if (InsertionPoint* insertedTo = shadow->distributor().findInsertionPointFor(projectedNode)) {
     203                current = insertedTo;
     204                insertionPoint = insertedTo;
     205                continue;
     206            }
     207        }
     208
     209        if (Node* parent = parentNodeForDistribution(current)) {
     210            if (InsertionPoint* insertedTo = parent->isShadowRoot() ? ScopeContentDistribution::assignedTo(toShadowRoot(parent)) : 0) {
     211                current = insertedTo;
     212                insertionPoint = insertedTo;
     213                continue;
     214            }
     215        }
     216
     217        break;
     218    }
     219
     220    return insertionPoint;
     221}
     222
    189223} // namespace WebCore
  • trunk/Source/WebCore/html/shadow/InsertionPoint.h

    r137715 r139128  
    7373
    7474    size_t indexOf(Node* node) const { return m_distribution.find(node); }
    75     bool contains(const Node* node) const { return m_distribution.contains(const_cast<Node*>(node)) || (node->isShadowRoot() && toShadowRoot(node)->assignedTo() == this); }
     75    bool contains(const Node*) const;
    7676    size_t size() const { return m_distribution.size(); }
    7777    Node* at(size_t index)  const { return m_distribution.at(index).get(); }
     
    151151}
    152152
    153 inline InsertionPoint* resolveReprojection(const Node* projectedNode)
    154 {
    155     InsertionPoint* insertionPoint = 0;
    156     const Node* current = projectedNode;
    157 
    158     while (current) {
    159         if (ElementShadow* shadow = shadowOfParentForDistribution(current)) {
    160             shadow->ensureDistribution();
    161             if (InsertionPoint* insertedTo = shadow->distributor().findInsertionPointFor(projectedNode)) {
    162                 current = insertedTo;
    163                 insertionPoint = insertedTo;
    164                 continue;
    165             }
    166         }
    167 
    168         if (Node* parent = parentNodeForDistribution(current)) {
    169             if (InsertionPoint* insertedTo = parent->isShadowRoot() ? toShadowRoot(parent)->assignedTo() : 0) {
    170                 current = insertedTo;
    171                 insertionPoint = insertedTo;
    172                 continue;
    173             }
    174         }
    175 
    176         break;
    177     }
    178 
    179     return insertionPoint;
    180 }
     153InsertionPoint* resolveReprojection(const Node*);
    181154
    182155} // namespace WebCore
  • trunk/Source/WebCore/testing/Internals.cpp

    r139050 r139128  
    3434#include "ClientRectList.h"
    3535#include "ComposedShadowTreeWalker.h"
     36#include "ContentDistributor.h"
    3637#include "Cursor.h"
    3738#include "DOMStringList.h"
     
    439440{
    440441    if (root && root->isShadowRoot())
    441         return toShadowRoot(root)->hasShadowInsertionPoint();
     442        return ScopeContentDistribution::hasShadowElement(toShadowRoot(root));
    442443
    443444    ec = INVALID_ACCESS_ERR;
     
    448449{
    449450    if (root && root->isShadowRoot())
    450         return toShadowRoot(root)->hasContentElement();
     451        return ScopeContentDistribution::hasContentElement(toShadowRoot(root));
    451452
    452453    ec = INVALID_ACCESS_ERR;
     
    461462    }
    462463
    463     return toShadowRoot(root)->countElementShadow();
     464    return ScopeContentDistribution::countElementShadow(toShadowRoot(root));
    464465}
    465466
  • trunk/Source/WebKit/win/ChangeLog

    r139078 r139128  
     12013-01-08  Hajime Morrita  <morrita@google.com>
     2
     3        [Shadow DOM] Distribution related code on ShadowRoot should be minimized.
     4        https://bugs.webkit.org/show_bug.cgi?id=106282
     5
     6        Reviewed by Dimitri Glazkov.
     7
     8        * WebKit.vcproj/WebKit.def.in:
     9
    1102013-01-08  Mark Lam  <mark.lam@apple.com>
    211
  • trunk/Source/WebKit/win/WebKit.vcproj/WebKit.def.in

    r138991 r139128  
    197197        ?getLocationAndLengthFromRange@TextIterator@WebCore@@SA_NPAVElement@2@PBVRange@2@AAI2@Z
    198198        ?getReferencedFilePaths@FormController@WebCore@@SA?AV?$Vector@VString@WTF@@$0A@@WTF@@ABV34@@Z
    199         ?countElementShadow@ShadowRoot@WebCore@@QBEIXZ
    200         ?hasShadowInsertionPoint@ShadowRoot@WebCore@@QBE_NXZ
    201         ?hasContentElement@ShadowRoot@WebCore@@QBE_NXZ
    202199        ?inputTag@HTMLNames@WebCore@@3VQualifiedName@2@B
    203200#if ENABLE(INSPECTOR)
     
    589586        ?getLocationAndLengthFromRange@TextIterator@WebCore@@SA_NPAVElement@2@PBVRange@2@AAI2@Z
    590587        ?getReferencedFilePaths@FormController@WebCore@@SA?AV?$Vector@VString@WTF@@$0A@@WTF@@ABV34@@Z
    591         ?countElementShadow@ShadowRoot@WebCore@@QBEIXZ
    592         ?hasShadowInsertionPoint@ShadowRoot@WebCore@@QBE_NXZ
    593         ?hasContentElement@ShadowRoot@WebCore@@QBE_NXZ
    594588        ?inputTag@HTMLNames@WebCore@@3VQualifiedName@2@B
    595589#if ENABLE(INSPECTOR)
     
    981975        ?getLocationAndLengthFromRange@TextIterator@WebCore@@SA_NPAVElement@2@PBVRange@2@AAI2@Z
    982976        ?getReferencedFilePaths@FormController@WebCore@@SA?AV?$Vector@VString@WTF@@$0A@@WTF@@ABV34@@Z
    983         ?countElementShadow@ShadowRoot@WebCore@@QBEIXZ
    984         ?hasShadowInsertionPoint@ShadowRoot@WebCore@@QBE_NXZ
    985         ?hasContentElement@ShadowRoot@WebCore@@QBE_NXZ
    986977        ?inputTag@HTMLNames@WebCore@@3VQualifiedName@2@B
    987978#if ENABLE(INSPECTOR)
     
    13631354        ?equalIgnoringCase@WTF@@YA_NPAVStringImpl@1@PBE@Z
    13641355        ?externalRepresentation@WebCore@@YA?AVString@WTF@@PAVElement@1@I@Z
     1356        ?hasShadowElement@ScopeContentDistribution@WebCore@@SA_NPBVShadowRoot@2@@Z
     1357        ?hasContentElement@ScopeContentDistribution@WebCore@@SA_NPBVShadowRoot@2@@Z
     1358        ?countElementShadow@ScopeContentDistribution@WebCore@@SAIPBVShadowRoot@2@@Z
    13651359        ?find@StringImpl@WTF@@QAEIPAV12@I@Z
    13661360        ?find@StringImpl@WTF@@QAEIPAV12@@Z
     
    13731367        ?getLocationAndLengthFromRange@TextIterator@WebCore@@SA_NPAVElement@2@PBVRange@2@AAI2@Z
    13741368        ?getReferencedFilePaths@FormController@WebCore@@SA?AV?$Vector@VString@WTF@@$0A@@WTF@@ABV34@@Z
    1375         ?countElementShadow@ShadowRoot@WebCore@@QBEIXZ
    1376         ?hasShadowInsertionPoint@ShadowRoot@WebCore@@QBE_NXZ
    1377         ?hasContentElement@ShadowRoot@WebCore@@QBE_NXZ
    13781369        ?inputTag@HTMLNames@WebCore@@3VQualifiedName@2@B
    13791370#if ENABLE(INSPECTOR)
  • trunk/Source/autotools/symbols.filter

    r138991 r139128  
    5050_ZN7WebCore10ClientRectC1Ev;
    5151_ZN7WebCore10ClientRectC1ERKNS_7IntRectE;
    52 _ZNK7WebCore10ShadowRoot17hasContentElementEv;
    53 _ZNK7WebCore10ShadowRoot18countElementShadowEv;
    54 _ZNK7WebCore10ShadowRoot23hasShadowInsertionPointEv;
    5552_ZN7WebCore10ShadowRoot6createEPNS_7ElementERi;
    5653_ZN7WebCore11EventTarget17toGeneratedStreamEv;
     
    231228_ZN7WebCore21SerializedScriptValueC1ERN3WTF6VectorIhLm0EEE;
    232229_ZN7WebCore21SerializedScriptValueD1Ev;
     230_ZN7WebCore24ScopeContentDistribution16hasShadowElementEPKNS_10ShadowRootE;
     231_ZN7WebCore24ScopeContentDistribution18countElementShadowEPKNS_10ShadowRootE;
     232_ZN7WebCore24ScopeContentDistribution17hasContentElementEPKNS_10ShadowRootE;
    233233_ZN7WebCore16CSSParserContextC1EPNS_8DocumentERKNS_4KURLERKN3WTF6StringE;
    234234_ZN7WebCore18StyleSheetContents11parseStringERKN3WTF6StringE;
Note: See TracChangeset for help on using the changeset viewer.