Changeset 109203 in webkit


Ignore:
Timestamp:
Feb 29, 2012 12:07:16 AM (12 years ago)
Author:
morrita@google.com
Message:

[Refactoring] Shadow related attach paths should be in ShadowTree.
https://bugs.webkit.org/show_bug.cgi?id=79854

Reviewed by Ryosuke Niwa.

No new tests. No behavior change.

This change introduces ShadowTree::attachHost() and ShadowTree::detachHost()
and moves shadow-enabled attachment code from Element to ShadowRoot.
This also factored out small ContainerNode method to use it from ShadowTree.

Even after this change, the traveral order in ShadowTree
attachment has some unclear part. Coming changes will clarify
these. This change is aimed to be purely textural.

  • dom/ContainerNode.cpp:

(WebCore::ContainerNode::attach):
(WebCore::ContainerNode::detach):

  • dom/ContainerNode.h:

(ContainerNode):
(WebCore::ContainerNode::attachAsNode): Added.
(WebCore::ContainerNode::attachChildren): Added.
(WebCore::ContainerNode::attachChildrenIfNeeded): Added.
(WebCore::ContainerNode::attachChildrenLazily): Added.
(WebCore::ContainerNode::detachAsNode): Added.
(WebCore::ContainerNode::detachChildrenIfNeeded): Added.
(WebCore::ContainerNode::detachChildren): Added.

  • dom/Element.cpp:

(WebCore::Element::attach):
(WebCore::Element::detach):

  • dom/ShadowTree.cpp:

(WebCore::ShadowTree::addShadowRoot):
(WebCore::ShadowTree::removeAllShadowRoots):
(WebCore::ShadowTree::detachHost):
(WebCore):
(WebCore::ShadowTree::attachHost):
(WebCore::ShadowTree::reattachHostChildrenAndShadow):

  • dom/ShadowTree.h:

(ShadowTree):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r109200 r109203  
     12012-02-28  MORITA Hajime  <morrita@google.com>
     2
     3        [Refactoring] Shadow related attach paths should be in ShadowTree.
     4        https://bugs.webkit.org/show_bug.cgi?id=79854
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        No new tests. No behavior change.
     9
     10        This change introduces ShadowTree::attachHost() and ShadowTree::detachHost()
     11        and moves shadow-enabled attachment code from Element to ShadowRoot.
     12        This also factored out small ContainerNode method to use it from ShadowTree.
     13
     14        Even after this change, the traveral order in ShadowTree
     15        attachment has some unclear part. Coming changes will clarify
     16        these. This change is aimed to be purely textural.
     17
     18        * dom/ContainerNode.cpp:
     19        (WebCore::ContainerNode::attach):
     20        (WebCore::ContainerNode::detach):
     21        * dom/ContainerNode.h:
     22        (ContainerNode):
     23        (WebCore::ContainerNode::attachAsNode): Added.
     24        (WebCore::ContainerNode::attachChildren): Added.
     25        (WebCore::ContainerNode::attachChildrenIfNeeded): Added.
     26        (WebCore::ContainerNode::attachChildrenLazily): Added.
     27        (WebCore::ContainerNode::detachAsNode): Added.
     28        (WebCore::ContainerNode::detachChildrenIfNeeded): Added.
     29        (WebCore::ContainerNode::detachChildren): Added.
     30        * dom/Element.cpp:
     31        (WebCore::Element::attach):
     32        (WebCore::Element::detach):
     33        * dom/ShadowTree.cpp:
     34        (WebCore::ShadowTree::addShadowRoot):
     35        (WebCore::ShadowTree::removeAllShadowRoots):
     36        (WebCore::ShadowTree::detachHost):
     37        (WebCore):
     38        (WebCore::ShadowTree::attachHost):
     39        (WebCore::ShadowTree::reattachHostChildrenAndShadow):
     40        * dom/ShadowTree.h:
     41        (ShadowTree):
     42
    1432012-02-28  Arko Saha  <arko@motorola.com>
    244
  • trunk/Source/WebCore/dom/ContainerNode.cpp

    r109054 r109203  
    767767void ContainerNode::attach()
    768768{
    769     for (Node* child = m_firstChild; child; child = child->nextSibling())
    770         child->attach();
     769    attachChildren();
    771770    Node::attach();
    772771}
     
    774773void ContainerNode::detach()
    775774{
    776     for (Node* child = m_firstChild; child; child = child->nextSibling())
    777         child->detach();
     775    detachChildren();
    778776    clearChildNeedsStyleRecalc();
    779777    Node::detach();
  • trunk/Source/WebCore/dom/ContainerNode.h

    r109026 r109203  
    9595    virtual void childrenChanged(bool createdByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
    9696
     97    void attachAsNode();
     98    void attachChildren();
     99    void attachChildrenIfNeeded();
     100    void attachChildrenLazily();
     101    void detachAsNode();
     102    void detachChildren();
     103    void detachChildrenIfNeeded();
     104
    97105protected:
    98106    ContainerNode(Document*, ConstructionType = CreateContainer);
     
    147155}
    148156
     157inline void ContainerNode::attachAsNode()
     158{
     159    Node::attach();
     160}
     161
     162inline void ContainerNode::attachChildren()
     163{
     164    for (Node* child = firstChild(); child; child = child->nextSibling())
     165        child->attach();
     166}
     167
     168inline void ContainerNode::attachChildrenIfNeeded()
     169{
     170    for (Node* child = firstChild(); child; child = child->nextSibling()) {
     171        if (!child->attached())
     172            child->attach();
     173    }
     174}
     175
     176inline void ContainerNode::attachChildrenLazily()
     177{
     178    for (Node* child = firstChild(); child; child = child->nextSibling())
     179        if (!child->attached())
     180            child->lazyAttach();
     181}
     182
     183inline void ContainerNode::detachAsNode()
     184{
     185    Node::detach();
     186}
     187
     188inline void ContainerNode::detachChildrenIfNeeded()
     189{
     190    for (Node* child = firstChild(); child; child = child->nextSibling()) {
     191        if (child->attached())
     192            child->detach();
     193    }
     194}
     195
     196inline void ContainerNode::detachChildren()
     197{
     198    for (Node* child = firstChild(); child; child = child->nextSibling())
     199        child->detach();
     200}
     201
    149202inline unsigned Node::childNodeCount() const
    150203{
  • trunk/Source/WebCore/dom/Element.cpp

    r109134 r109203  
    929929
    930930    // When a shadow root exists, it does the work of attaching the children.
    931     if (hasShadowRoot()) {
     931    if (ShadowTree* tree = shadowTree()) {
    932932        parentPusher.push();
    933         shadowTree()->attach();
    934 
    935         // In a shadow tree, some of light children may be attached by <content> or <shadow>.
    936         // However, when there is no content element or content element does not select
    937         // all light children, we have to attach the rest of light children here.
    938         for (Node* child = firstChild(); child; child = child->nextSibling()) {
    939             if (!child->attached())
    940                 child->attach();
    941         }
    942         Node::attach();
     933        tree->attachHost(this);
    943934    } else {
    944935        if (firstChild())
     
    968959        rareData()->resetComputedStyle();
    969960
    970     if (hasShadowRoot()) {
    971         for (Node* child = firstChild(); child; child = child->nextSibling()) {
    972             if (child->attached())
    973                 child->detach();
    974         }
    975 
    976         shadowTree()->detach();
    977         Node::detach();
    978     } else
     961    if (ShadowTree* tree = shadowTree())
     962        tree->detachHost(this);
     963    else
    979964        ContainerNode::detach();
    980 
    981965
    982966    RenderWidget::resumeWidgetHierarchyUpdates();
  • trunk/Source/WebCore/dom/ShadowTree.cpp

    r109096 r109203  
    8787        shadowRoot->lazyAttach();
    8888        detach();
    89         for (Node* child = shadowHost->firstChild(); child; child = child->nextSibling())
    90             child->detach();
     89        shadowHost->detachChildren();
    9190    }
    9291
     
    119118    }
    120119
    121     if (shadowHost->attached()) {
    122         for (Node* child = shadowHost->firstChild(); child; child = child->nextSibling()) {
    123             if (!child->attached())
    124                 child->lazyAttach();
    125         }
    126     }
     120    if (shadowHost->attached())
     121        shadowHost->attachChildrenLazily();
    127122}
    128123
     
    172167}
    173168
     169void ShadowTree::attachHost(Element* host)
     170{
     171    attach();
     172    host->attachChildrenIfNeeded();
     173    host->attachAsNode();
     174}
     175
     176
    174177void ShadowTree::detach()
    175178{
     
    178181            root->detach();
    179182    }
     183}
     184
     185void ShadowTree::detachHost(Element* host)
     186{
     187    host->detachChildrenIfNeeded();
     188    detach();
     189    host->detachAsNode();
    180190}
    181191
     
    270280    ASSERT(youngestShadowRoot());
    271281
    272     Node* hostNode = youngestShadowRoot()->host();
    273     if (!hostNode)
    274         return;
    275 
    276     for (Node* child = hostNode->firstChild(); child; child = child->nextSibling()) {
    277         if (child->attached())
    278             child->detach();
    279     }
    280 
     282    Element* hostNode = youngestShadowRoot()->host();
     283    hostNode->detachChildrenIfNeeded();
    281284    reattach();
    282 
    283     for (Node* child = hostNode->firstChild(); child; child = child->nextSibling()) {
    284         if (!child->attached())
    285             child->attach();
    286     }
     285    hostNode->attachChildrenIfNeeded();
    287286}
    288287
  • trunk/Source/WebCore/dom/ShadowTree.h

    r109084 r109203  
    6363    void detach();
    6464    void reattach();
     65    void attachHost(Element*);
     66    void detachHost(Element*);
    6567
    6668    bool childNeedsStyleRecalc();
Note: See TracChangeset for help on using the changeset viewer.