ContainerNodeAlgorithms.cpp [plain text]
#include "config.h"
#include "ContainerNodeAlgorithms.h"
#include "Element.h"
#include "ShadowTree.h"
namespace WebCore {
void ChildNodeInsertionNotifier::notifyDescendantInsertedIntoDocument(ContainerNode* node)
{
NodeVector children;
getChildNodes(node, children);
for (size_t i = 0; i < children.size(); ++i) {
if (node->inDocument() && children[i]->parentNode() == node)
notifyNodeInsertedIntoDocument(children[i].get());
}
if (!node->isElementNode())
return;
if (ShadowTree* tree = toElement(node)->shadowTree()) {
ShadowRootVector roots(tree);
for (size_t i = 0; i < roots.size(); ++i)
notifyNodeInsertedIntoDocument(roots[i].get());
}
}
void ChildNodeInsertionNotifier::notifyDescendantInsertedIntoTree(ContainerNode* node)
{
for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
if (child->isContainerNode())
notifyNodeInsertedIntoTree(toContainerNode(child));
}
if (!node->isElementNode())
return;
if (ShadowTree* tree = toElement(node)->shadowTree()) {
for (ShadowRoot* root = tree->youngestShadowRoot(); root; root = root->olderShadowRoot())
notifyNodeInsertedIntoTree(root);
}
}
void ChildNodeRemovalNotifier::notifyDescendantRemovedFromDocument(ContainerNode* node)
{
NodeVector children;
getChildNodes(node, children);
for (size_t i = 0; i < children.size(); ++i) {
if (!node->inDocument() && children[i]->parentNode() == node)
notifyNodeRemovedFromDocument(children[i].get());
}
if (!node->isElementNode())
return;
if (node->document()->cssTarget() == node)
node->document()->setCSSTarget(0);
if (ShadowTree* tree = toElement(node)->shadowTree()) {
ShadowRootVector roots(tree);
for (size_t i = 0; i < roots.size(); ++i)
notifyNodeRemovedFromDocument(roots[i].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 (ShadowTree* tree = toElement(node)->shadowTree()) {
ShadowRootVector roots(tree);
for (size_t i = 0; i < roots.size(); ++i)
notifyNodeRemovedFromTree(roots[i].get());
}
}
}