This source file includes following definitions.
- notifyDescendantInsertedIntoDocument
- notifyDescendantInsertedIntoTree
- notifyDescendantRemovedFromDocument
- notifyDescendantRemovedFromTree
- collectFrameOwners
- assertConnectedSubrameCountIsConsistent
#include "config.h"
#include "core/dom/ContainerNodeAlgorithms.h"
#include "core/dom/Element.h"
#include "core/dom/shadow/ElementShadow.h"
#include "core/dom/shadow/ShadowRoot.h"
namespace WebCore {
class ShadowRootVector : public Vector<RefPtr<ShadowRoot> > {
public:
explicit ShadowRootVector(ElementShadow* tree)
{
for (ShadowRoot* root = tree->youngestShadowRoot(); root; root = root->olderShadowRoot())
append(root);
}
};
void ChildNodeInsertionNotifier::notifyDescendantInsertedIntoDocument(ContainerNode& node)
{
ChildNodesLazySnapshot snapshot(node);
while (RefPtr<Node> child = snapshot.nextNode()) {
if (node.inDocument() && child->parentNode() == node)
notifyNodeInsertedIntoDocument(*child);
}
if (!node.isElementNode())
return;
if (ElementShadow* shadow = toElement(node).shadow()) {
ShadowRootVector roots(shadow);
for (size_t i = 0; i < roots.size(); ++i) {
if (node.inDocument() && roots[i]->host() == node)
notifyNodeInsertedIntoDocument(*roots[i]);
}
}
}
void ChildNodeInsertionNotifier::notifyDescendantInsertedIntoTree(ContainerNode& node)
{
for (Node* child = node.firstChild(); child; child = child->nextSibling()) {
if (child->isContainerNode())
notifyNodeInsertedIntoTree(toContainerNode(*child));
}
for (ShadowRoot* root = node.youngestShadowRoot(); root; root = root->olderShadowRoot())
notifyNodeInsertedIntoTree(*root);
}
void ChildNodeRemovalNotifier::notifyDescendantRemovedFromDocument(ContainerNode& node)
{
ChildNodesLazySnapshot snapshot(node);
while (RefPtr<Node> child = snapshot.nextNode()) {
if (!node.inDocument() && child->parentNode() == node)
notifyNodeRemovedFromDocument(*child);
}
if (!node.isElementNode())
return;
if (node.document().cssTarget() == node)
node.document().setCSSTarget(0);
if (ElementShadow* shadow = toElement(node).shadow()) {
ShadowRootVector roots(shadow);
for (size_t i = 0; i < roots.size(); ++i) {
if (!node.inDocument() && roots[i]->host() == node)
notifyNodeRemovedFromDocument(*roots[i]);
}
}
}
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()) {
ShadowRootVector roots(shadow);
for (size_t i = 0; i < roots.size(); ++i)
notifyNodeRemovedFromTree(*roots[i]);
}
}
void ChildFrameDisconnector::collectFrameOwners(ElementShadow& shadow)
{
for (ShadowRoot* root = shadow.youngestShadowRoot(); root; root = root->olderShadowRoot())
collectFrameOwners(*root);
}
#ifndef NDEBUG
unsigned assertConnectedSubrameCountIsConsistent(Node& node)
{
unsigned count = 0;
if (node.isElementNode()) {
if (node.isFrameOwnerElement() && toHTMLFrameOwnerElement(node).contentFrame())
count++;
if (ElementShadow* shadow = toElement(node).shadow()) {
for (ShadowRoot* root = shadow->youngestShadowRoot(); root; root = root->olderShadowRoot())
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
}