Changeset 154746 in webkit


Ignore:
Timestamp:
Aug 28, 2013, 7:41:12 AM (12 years ago)
Author:
Antti Koivisto
Message:

Share attach loops between Elements and ShadowRoots
https://bugs.webkit.org/show_bug.cgi?id=120414

Reviewed Andreas Kling.

  • style/StyleResolveTree.cpp:

(WebCore::Style::attachChildren):
(WebCore::Style::attachShadowRoot):
(WebCore::Style::detachChildren):
(WebCore::Style::detachShadowRoot):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r154745 r154746  
     12013-08-28  Antti Koivisto  <antti@apple.com>
     2
     3        Share attach loops between Elements and ShadowRoots
     4        https://bugs.webkit.org/show_bug.cgi?id=120414
     5
     6        Reviewed Andreas Kling.
     7
     8        * style/StyleResolveTree.cpp:
     9        (WebCore::Style::attachChildren):
     10        (WebCore::Style::attachShadowRoot):
     11        (WebCore::Style::detachChildren):
     12        (WebCore::Style::detachShadowRoot):
     13
    1142013-08-28  Anders Carlsson  <andersca@apple.com>
    215
  • trunk/Source/WebCore/style/StyleResolveTree.cpp

    r154738 r154746  
    288288}
    289289
    290 
    291 static void attachShadowRoot(ShadowRoot* shadowRoot, const AttachContext& context)
    292 {
    293     if (shadowRoot->attached())
    294         return;
    295     StyleResolver& styleResolver = shadowRoot->document()->ensureStyleResolver();
    296     styleResolver.pushParentShadowRoot(shadowRoot);
    297 
    298     Style::AttachContext childrenContext(context);
    299     childrenContext.resolvedStyle = 0;
    300     for (Node* child = shadowRoot->firstChild(); child; child = child->nextSibling()) {
    301         if (child->isTextNode()) {
    302             attachTextRenderer(*toText(child));
    303             continue;
    304         }
    305         if (child->isElementNode())
    306             attachRenderTree(toElement(child), childrenContext);
    307     }
    308     styleResolver.popParentShadowRoot(shadowRoot);
    309 
    310     shadowRoot->clearNeedsStyleRecalc();
    311     shadowRoot->setAttached(true);
    312 }
    313 
    314290#ifndef NDEBUG
    315 static bool childAttachedAllowedWhenAttachingChildren(ContainerNode* node)
    316 {
    317     if (node->isShadowRoot())
     291static bool childAttachedAllowedWhenAttachingChildren(ContainerNode& node)
     292{
     293    if (node.isShadowRoot())
    318294        return true;
    319     if (node->isInsertionPoint())
     295    if (node.isInsertionPoint())
    320296        return true;
    321     if (node->isElementNode() && toElement(node)->shadowRoot())
     297    if (node.isElementNode() && toElement(&node)->shadowRoot())
    322298        return true;
    323299    return false;
     
    325301#endif
    326302
    327 static void attachChildren(Element* current, const AttachContext& context)
     303static void attachChildren(ContainerNode& current, const AttachContext& context)
    328304{
    329305    AttachContext childrenContext(context);
    330306    childrenContext.resolvedStyle = 0;
    331307
    332     for (Node* child = current->firstChild(); child; child = child->nextSibling()) {
     308    for (Node* child = current.firstChild(); child; child = child->nextSibling()) {
    333309        ASSERT(!child->attached() || childAttachedAllowedWhenAttachingChildren(current));
    334310        if (child->attached())
     
    343319}
    344320
     321static void attachShadowRoot(ShadowRoot& shadowRoot, const AttachContext& context)
     322{
     323    if (shadowRoot.attached())
     324        return;
     325    StyleResolver& styleResolver = shadowRoot.document()->ensureStyleResolver();
     326    styleResolver.pushParentShadowRoot(&shadowRoot);
     327
     328    attachChildren(shadowRoot, context);
     329
     330    styleResolver.popParentShadowRoot(&shadowRoot);
     331
     332    shadowRoot.clearNeedsStyleRecalc();
     333    shadowRoot.setAttached(true);
     334}
     335
    345336void attachRenderTree(Element* current, const AttachContext& context)
    346337{
     
    363354    if (ShadowRoot* shadowRoot = current->shadowRoot()) {
    364355        parentPusher.push();
    365         attachShadowRoot(shadowRoot, context);
     356        attachShadowRoot(*shadowRoot, context);
    366357    } else if (current->firstChild())
    367358        parentPusher.push();
    368359
    369     attachChildren(current, context);
     360    attachChildren(*current, context);
    370361
    371362    Node* sibling = current->nextSibling();
     
    389380}
    390381
    391 static void detachShadowRoot(ShadowRoot* shadowRoot, const AttachContext& context)
    392 {
    393     if (!shadowRoot->attached())
    394         return;
    395     Style::AttachContext childrenContext(context);
     382static void detachChildren(ContainerNode& current, const AttachContext& context)
     383{
     384    AttachContext childrenContext(context);
    396385    childrenContext.resolvedStyle = 0;
    397     for (Node* child = shadowRoot->firstChild(); child; child = child->nextSibling()) {
     386
     387    for (Node* child = current.firstChild(); child; child = child->nextSibling()) {
    398388        if (child->isTextNode()) {
    399389            Style::detachTextRenderer(*toText(child));
     
    401391        }
    402392        if (child->isElementNode())
    403             detachRenderTree(toElement(child), context);
    404     }
    405     shadowRoot->clearChildNeedsStyleRecalc();
    406     shadowRoot->setAttached(false);
    407 }
    408 
    409 static void detachChildren(Element* current, const AttachContext& context)
    410 {
    411     AttachContext childrenContext(context);
    412     childrenContext.resolvedStyle = 0;
    413 
    414     for (Node* child = current->firstChild(); child; child = child->nextSibling()) {
    415         if (child->isTextNode()) {
    416             Style::detachTextRenderer(*toText(child));
    417             continue;
    418         }
    419         if (child->isElementNode())
    420393            detachRenderTree(toElement(child), childrenContext);
    421394    }
    422     current->clearChildNeedsStyleRecalc();
     395    current.clearChildNeedsStyleRecalc();
     396}
     397
     398static void detachShadowRoot(ShadowRoot& shadowRoot, const AttachContext& context)
     399{
     400    if (!shadowRoot.attached())
     401        return;
     402    detachChildren(shadowRoot, context);
     403
     404    shadowRoot.setAttached(false);
    423405}
    424406
     
    438420
    439421    if (ShadowRoot* shadowRoot = current->shadowRoot())
    440         detachShadowRoot(shadowRoot, context);
    441 
    442     detachChildren(current, context);
     422        detachShadowRoot(*shadowRoot, context);
     423
     424    detachChildren(*current, context);
    443425
    444426    if (current->renderer())
Note: See TracChangeset for help on using the changeset viewer.