Skip to content
Permalink
Browse files
[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):

Canonical link: https://commits.webkit.org/96960@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@109203 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
omo committed Feb 29, 2012
1 parent c51b560 commit fe3db136cdbbb591b70c94b9cca95104f07c1b36
@@ -1,3 +1,45 @@
2012-02-28 MORITA Hajime <morrita@google.com>

[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):

2012-02-28 Arko Saha <arko@motorola.com>

Microdata: Implement HTMLPropertiesCollection collection.namedItem().
@@ -766,15 +766,13 @@ void ContainerNode::scheduleSetNeedsStyleRecalc(StyleChangeType changeType)

void ContainerNode::attach()
{
for (Node* child = m_firstChild; child; child = child->nextSibling())
child->attach();
attachChildren();
Node::attach();
}

void ContainerNode::detach()
{
for (Node* child = m_firstChild; child; child = child->nextSibling())
child->detach();
detachChildren();
clearChildNeedsStyleRecalc();
Node::detach();
}
@@ -94,6 +94,14 @@ class ContainerNode : public Node {
// node that is of the type CDATA_SECTION_NODE, TEXT_NODE or COMMENT_NODE has changed its value.
virtual void childrenChanged(bool createdByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);

void attachAsNode();
void attachChildren();
void attachChildrenIfNeeded();
void attachChildrenLazily();
void detachAsNode();
void detachChildren();
void detachChildrenIfNeeded();

protected:
ContainerNode(Document*, ConstructionType = CreateContainer);

@@ -146,6 +154,51 @@ inline ContainerNode::ContainerNode(Document* document, ConstructionType type)
{
}

inline void ContainerNode::attachAsNode()
{
Node::attach();
}

inline void ContainerNode::attachChildren()
{
for (Node* child = firstChild(); child; child = child->nextSibling())
child->attach();
}

inline void ContainerNode::attachChildrenIfNeeded()
{
for (Node* child = firstChild(); child; child = child->nextSibling()) {
if (!child->attached())
child->attach();
}
}

inline void ContainerNode::attachChildrenLazily()
{
for (Node* child = firstChild(); child; child = child->nextSibling())
if (!child->attached())
child->lazyAttach();
}

inline void ContainerNode::detachAsNode()
{
Node::detach();
}

inline void ContainerNode::detachChildrenIfNeeded()
{
for (Node* child = firstChild(); child; child = child->nextSibling()) {
if (child->attached())
child->detach();
}
}

inline void ContainerNode::detachChildren()
{
for (Node* child = firstChild(); child; child = child->nextSibling())
child->detach();
}

inline unsigned Node::childNodeCount() const
{
if (!isContainerNode())
@@ -928,18 +928,9 @@ void Element::attach()
StyleSelectorParentPusher parentPusher(this);

// When a shadow root exists, it does the work of attaching the children.
if (hasShadowRoot()) {
if (ShadowTree* tree = shadowTree()) {
parentPusher.push();
shadowTree()->attach();

// In a shadow tree, some of light children may be attached by <content> or <shadow>.
// However, when there is no content element or content element does not select
// all light children, we have to attach the rest of light children here.
for (Node* child = firstChild(); child; child = child->nextSibling()) {
if (!child->attached())
child->attach();
}
Node::attach();
tree->attachHost(this);
} else {
if (firstChild())
parentPusher.push();
@@ -967,18 +958,11 @@ void Element::detach()
if (hasRareData())
rareData()->resetComputedStyle();

if (hasShadowRoot()) {
for (Node* child = firstChild(); child; child = child->nextSibling()) {
if (child->attached())
child->detach();
}

shadowTree()->detach();
Node::detach();
} else
if (ShadowTree* tree = shadowTree())
tree->detachHost(this);
else
ContainerNode::detach();


RenderWidget::resumeWidgetHierarchyUpdates();
}

@@ -86,8 +86,7 @@ void ShadowTree::addShadowRoot(Element* shadowHost, PassRefPtr<ShadowRoot> shado
if (shadowHost->attached()) {
shadowRoot->lazyAttach();
detach();
for (Node* child = shadowHost->firstChild(); child; child = child->nextSibling())
child->detach();
shadowHost->detachChildren();
}

m_shadowRoots.push(shadowRoot.get());
@@ -118,12 +117,8 @@ void ShadowTree::removeAllShadowRoots()
oldRoot->removedFromTree(true);
}

if (shadowHost->attached()) {
for (Node* child = shadowHost->firstChild(); child; child = child->nextSibling()) {
if (!child->attached())
child->lazyAttach();
}
}
if (shadowHost->attached())
shadowHost->attachChildrenLazily();
}

void ShadowTree::insertedIntoDocument()
@@ -171,6 +166,14 @@ void ShadowTree::attach()
contentSelector->didSelect();
}

void ShadowTree::attachHost(Element* host)
{
attach();
host->attachChildrenIfNeeded();
host->attachAsNode();
}


void ShadowTree::detach()
{
for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadowRoot()) {
@@ -179,6 +182,13 @@ void ShadowTree::detach()
}
}

void ShadowTree::detachHost(Element* host)
{
host->detachChildrenIfNeeded();
detach();
host->detachAsNode();
}

InsertionPoint* ShadowTree::insertionPointFor(Node* node) const
{
if (!m_selector)
@@ -269,21 +279,10 @@ void ShadowTree::reattachHostChildrenAndShadow()
{
ASSERT(youngestShadowRoot());

Node* hostNode = youngestShadowRoot()->host();
if (!hostNode)
return;

for (Node* child = hostNode->firstChild(); child; child = child->nextSibling()) {
if (child->attached())
child->detach();
}

Element* hostNode = youngestShadowRoot()->host();
hostNode->detachChildrenIfNeeded();
reattach();

for (Node* child = hostNode->firstChild(); child; child = child->nextSibling()) {
if (!child->attached())
child->attach();
}
hostNode->attachChildrenIfNeeded();
}

HTMLContentSelector* ShadowTree::ensureSelector()
@@ -62,6 +62,8 @@ class ShadowTree {
void attach();
void detach();
void reattach();
void attachHost(Element*);
void detachHost(Element*);

bool childNeedsStyleRecalc();
bool needsStyleRecalc();

0 comments on commit fe3db13

Please sign in to comment.