ContainerNodeAlgorithms.cpp [plain text]
#include "config.h"
#include "ContainerNodeAlgorithms.h"
#include "Element.h"
#include "ElementShadow.h"
#include "HTMLFrameOwnerElement.h"
namespace WebCore {
void ChildNodeInsertionNotifier::notifyDescendantInsertedIntoDocument(ContainerNode* node)
{
ChildNodesLazySnapshot snapshot(node);
while (RefPtr<Node> child = snapshot.nextNode()) {
if (node->inDocument() && child->parentNode() == node)
notifyNodeInsertedIntoDocument(child.get());
}
if (!node->isElementNode())
return;
if (ElementShadow* shadow = toElement(node)->shadow()) {
if (RefPtr<ShadowRoot> root = shadow->shadowRoot()) {
if (node->inDocument() && root->host() == node)
notifyNodeInsertedIntoDocument(root.get());
}
}
}
void ChildNodeInsertionNotifier::notifyDescendantInsertedIntoTree(ContainerNode* node)
{
for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
if (child->isContainerNode())
notifyNodeInsertedIntoTree(toContainerNode(child));
}
if (ShadowRoot* root = node->shadowRoot())
notifyNodeInsertedIntoTree(root);
}
void ChildNodeRemovalNotifier::notifyDescendantRemovedFromDocument(ContainerNode* node)
{
ChildNodesLazySnapshot snapshot(node);
while (RefPtr<Node> child = snapshot.nextNode()) {
if (!node->inDocument() && child->parentNode() == node)
notifyNodeRemovedFromDocument(child.get());
}
if (!node->isElementNode())
return;
if (node->document()->cssTarget() == node)
node->document()->setCSSTarget(0);
if (ElementShadow* shadow = toElement(node)->shadow()) {
if (RefPtr<ShadowRoot> root = shadow->shadowRoot()) {
if (!node->inDocument() && root->host() == node)
notifyNodeRemovedFromDocument(root.get());
}
}
}
void ChildNodeRemovalNotifier::notifyDescendantRemovedFromTree(ContainerNode* node)
{
for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
if (child->isContainerNode())
notifyNodeRemovedFromTree(toContainerNode(child));
}
if (!node->isElementNode())
return;
if (ElementShadow* shadow = toElement(node)->shadow()) {
if (RefPtr<ShadowRoot> root = shadow->shadowRoot())
notifyNodeRemovedFromTree(root.get());
}
}
void ChildFrameDisconnector::collectFrameOwners(ElementShadow* shadow)
{
if (ShadowRoot* root = shadow->shadowRoot())
collectFrameOwners(root);
}
#ifndef NDEBUG
unsigned assertConnectedSubrameCountIsConsistent(Node* node)
{
unsigned count = 0;
if (node->isElementNode()) {
if (node->isFrameOwnerElement() && toFrameOwnerElement(node)->contentFrame())
count++;
if (ElementShadow* shadow = toElement(node)->shadow()) {
if (ShadowRoot* root = shadow->shadowRoot())
count += assertConnectedSubrameCountIsConsistent(root);
}
}
for (Node* child = node->firstChild(); child; child = child->nextSibling())
count += assertConnectedSubrameCountIsConsistent(child);
ASSERT(node->connectedSubframeCount() >= count);
ASSERT(node->connectedSubframeCount() == count);
return count;
}
#endif
}