#include "config.h"
#include "ContainerNode.h"
#include "BeforeLoadEvent.h"
#include "MemoryCache.h"
#include "ContainerNodeAlgorithms.h"
#include "DeleteButtonController.h"
#include "EventNames.h"
#include "ExceptionCode.h"
#include "FloatRect.h"
#include "Frame.h"
#include "FrameView.h"
#include "InlineTextBox.h"
#include "InspectorInstrumentation.h"
#include "MutationEvent.h"
#include "ResourceLoadScheduler.h"
#include "Page.h"
#include "RenderBox.h"
#include "RenderTheme.h"
#include "RootInlineBox.h"
#include <wtf/CurrentTime.h>
#include <wtf/Vector.h>
namespace WebCore {
static void notifyChildInserted(Node*);
static void dispatchChildInsertionEvents(Node*);
static void dispatchChildRemovalEvents(Node*);
typedef Vector<std::pair<NodeCallback, RefPtr<Node> > > NodeCallbackQueue;
typedef Vector<RefPtr<Node>, 1> NodeVector;
static NodeCallbackQueue* s_postAttachCallbackQueue;
static size_t s_attachDepth;
static bool s_shouldReEnableMemoryCacheCallsAfterAttach;
static inline void collectNodes(Node* node, NodeVector& nodes)
{
for (Node* child = node->firstChild(); child; child = child->nextSibling())
nodes.append(child);
}
static void collectTargetNodes(Node* node, NodeVector& nodes)
{
if (node->nodeType() != Node::DOCUMENT_FRAGMENT_NODE) {
nodes.append(node);
return;
}
collectNodes(node, nodes);
}
void ContainerNode::removeAllChildren()
{
removeAllChildrenInContainer<Node, ContainerNode>(this);
}
void ContainerNode::takeAllChildrenFrom(ContainerNode* oldParent)
{
NodeVector children;
collectNodes(oldParent, children);
oldParent->removeAllChildren();
for (unsigned i = 0; i < children.size(); ++i) {
ExceptionCode ec = 0;
if (children[i]->attached())
children[i]->detach();
RefPtr<Node> child = document()->adoptNode(children[i].release(), ec);
ASSERT(!ec);
parserAddChild(child.get());
child->setTreeScopeRecursively(treeScope());
if (attached() && !child->attached())
child->attach();
}
}
ContainerNode::~ContainerNode()
{
removeAllChildren();
}
bool ContainerNode::insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode& ec, bool shouldLazyAttach)
{
ASSERT(refCount() || parentOrHostNode());
ec = 0;
if (!refChild)
return appendChild(newChild, ec, shouldLazyAttach);
checkAddChild(newChild.get(), ec);
if (ec)
return false;
if (refChild->parentNode() != this) {
ec = NOT_FOUND_ERR;
return false;
}
NodeVector targets;
collectTargetNodes(newChild.get(), targets);
if (targets.isEmpty())
return true;
if (refChild->previousSibling() == newChild || refChild == newChild) return true;
RefPtr<Node> next = refChild;
RefPtr<Node> refChildPreviousSibling = refChild->previousSibling();
for (NodeVector::const_iterator it = targets.begin(); it != targets.end(); ++it) {
Node* child = it->get();
if (ContainerNode* oldParent = child->parentNode())
oldParent->removeChild(child, ec);
if (ec)
return false;
if (next->parentNode() != this)
break;
if (child->parentNode())
break;
#if ENABLE(INSPECTOR)
InspectorInstrumentation::willInsertDOMNode(document(), child, this);
#endif
child->setTreeScopeRecursively(treeScope());
insertBeforeCommon(next.get(), child);
childrenChanged(false, refChildPreviousSibling.get(), next.get(), 1);
notifyChildInserted(child);
if (attached() && !child->attached() && child->parentNode() == this) {
if (shouldLazyAttach)
child->lazyAttach();
else
child->attach();
}
dispatchChildInsertionEvents(child);
}
dispatchSubtreeModifiedEvent();
return true;
}
void ContainerNode::insertBeforeCommon(Node* nextChild, Node* newChild)
{
ASSERT(newChild);
ASSERT(!newChild->parentNode()); ASSERT(!newChild->nextSibling());
ASSERT(!newChild->previousSibling());
forbidEventDispatch();
Node* prev = nextChild->previousSibling();
ASSERT(m_lastChild != prev);
nextChild->setPreviousSibling(newChild);
if (prev) {
ASSERT(m_firstChild != nextChild);
ASSERT(prev->nextSibling() == nextChild);
prev->setNextSibling(newChild);
} else {
ASSERT(m_firstChild == nextChild);
m_firstChild = newChild;
}
newChild->setParent(this);
newChild->setPreviousSibling(prev);
newChild->setNextSibling(nextChild);
allowEventDispatch();
}
void ContainerNode::parserInsertBefore(PassRefPtr<Node> newChild, Node* nextChild)
{
ASSERT(newChild);
ASSERT(nextChild);
ASSERT(nextChild->parentNode() == this);
NodeVector targets;
collectTargetNodes(newChild.get(), targets);
if (targets.isEmpty())
return;
if (nextChild->previousSibling() == newChild || nextChild == newChild) return;
RefPtr<Node> next = nextChild;
RefPtr<Node> nextChildPreviousSibling = nextChild->previousSibling();
for (NodeVector::const_iterator it = targets.begin(); it != targets.end(); ++it) {
Node* child = it->get();
#if ENABLE(INSPECTOR)
InspectorInstrumentation::willInsertDOMNode(document(), child, this);
#endif
insertBeforeCommon(next.get(), child);
childrenChanged(true, nextChildPreviousSibling.get(), nextChild, 1);
notifyChildInserted(child);
}
}
bool ContainerNode::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode& ec, bool shouldLazyAttach)
{
ASSERT(refCount() || parentOrHostNode());
ec = 0;
if (oldChild == newChild) return true;
checkReplaceChild(newChild.get(), oldChild, ec);
if (ec)
return false;
if (!oldChild || oldChild->parentNode() != this) {
ec = NOT_FOUND_ERR;
return false;
}
RefPtr<Node> prev = oldChild->previousSibling();
RefPtr<Node> next = oldChild->nextSibling();
RefPtr<Node> removedChild = oldChild;
removeChild(oldChild, ec);
if (ec)
return false;
bool isFragment = newChild->nodeType() == DOCUMENT_FRAGMENT_NODE;
RefPtr<Node> child = isFragment ? newChild->firstChild() : newChild;
while (child) {
if (prev && (prev == child || prev == child->previousSibling()))
break;
RefPtr<Node> nextChild = isFragment ? child->nextSibling() : 0;
if (ContainerNode* oldParent = child->parentNode())
oldParent->removeChild(child.get(), ec);
if (ec)
return false;
if (prev && prev->parentNode() != this)
break;
if (child->parentNode())
break;
ASSERT(!child->nextSibling());
ASSERT(!child->previousSibling());
#if ENABLE(INSPECTOR)
InspectorInstrumentation::willInsertDOMNode(document(), child.get(), this);
#endif
child->setTreeScopeRecursively(treeScope());
forbidEventDispatch();
Node* next;
if (prev) {
next = prev->nextSibling();
ASSERT(m_firstChild != next);
prev->setNextSibling(child.get());
} else {
next = m_firstChild;
m_firstChild = child.get();
}
if (next) {
ASSERT(m_lastChild != prev);
ASSERT(next->previousSibling() == prev);
next->setPreviousSibling(child.get());
} else {
ASSERT(m_lastChild == prev);
m_lastChild = child.get();
}
child->setParent(this);
child->setPreviousSibling(prev.get());
child->setNextSibling(next);
allowEventDispatch();
childrenChanged(false, prev.get(), next, 1);
notifyChildInserted(child.get());
if (attached() && !child->attached() && child->parentNode() == this) {
if (shouldLazyAttach)
child->lazyAttach();
else
child->attach();
}
dispatchChildInsertionEvents(child.get());
prev = child;
child = nextChild.release();
}
dispatchSubtreeModifiedEvent();
return true;
}
void ContainerNode::willRemove()
{
RefPtr<Node> protect(this);
for (RefPtr<Node> child = firstChild(); child; child = child->nextSibling()) {
if (child->parentNode() != this) break;
child->willRemove();
}
Node::willRemove();
}
static void willRemoveChild(Node* child)
{
child->document()->nodeWillBeRemoved(child);
child->document()->incDOMTreeVersion();
dispatchChildRemovalEvents(child);
child->willRemove();
}
static void willRemoveChildren(ContainerNode* container)
{
container->document()->nodeChildrenWillBeRemoved(container);
container->document()->incDOMTreeVersion();
NodeVector children;
collectNodes(container, children);
for (NodeVector::const_iterator it = children.begin(); it != children.end(); it++) {
Node* child = it->get();
dispatchChildRemovalEvents(child);
child->willRemove();
}
}
bool ContainerNode::removeChild(Node* oldChild, ExceptionCode& ec)
{
ASSERT(refCount() || parentOrHostNode());
ec = 0;
if (isReadOnlyNode()) {
ec = NO_MODIFICATION_ALLOWED_ERR;
return false;
}
if (!oldChild || oldChild->parentNode() != this) {
ec = NOT_FOUND_ERR;
return false;
}
RefPtr<Node> child = oldChild;
willRemoveChild(child.get());
if (child->parentNode() != this) {
ec = NOT_FOUND_ERR;
return false;
}
document()->removeFocusedNodeOfSubtree(child.get());
#if ENABLE(FULLSCREEN_API)
document()->removeFullScreenElementOfSubtree(child.get());
#endif
if (child->parentNode() != this) {
ec = NOT_FOUND_ERR;
return false;
}
Node* prev = child->previousSibling();
Node* next = child->nextSibling();
removeBetween(prev, next, child.get());
childrenChanged(false, prev, next, -1);
dispatchSubtreeModifiedEvent();
if (child->inDocument())
child->removedFromDocument();
else
child->removedFromTree(true);
return child;
}
void ContainerNode::removeBetween(Node* previousChild, Node* nextChild, Node* oldChild)
{
ASSERT(oldChild);
ASSERT(oldChild->parentNode() == this);
forbidEventDispatch();
if (oldChild->attached())
oldChild->detach();
if (nextChild)
nextChild->setPreviousSibling(previousChild);
if (previousChild)
previousChild->setNextSibling(nextChild);
if (m_firstChild == oldChild)
m_firstChild = nextChild;
if (m_lastChild == oldChild)
m_lastChild = previousChild;
oldChild->setPreviousSibling(0);
oldChild->setNextSibling(0);
oldChild->setParent(0);
oldChild->setTreeScopeRecursively(document());
allowEventDispatch();
}
void ContainerNode::parserRemoveChild(Node* oldChild)
{
ASSERT(oldChild);
ASSERT(oldChild->parentNode() == this);
Node* prev = oldChild->previousSibling();
Node* next = oldChild->nextSibling();
removeBetween(prev, next, oldChild);
childrenChanged(true, prev, next, -1);
if (oldChild->inDocument())
oldChild->removedFromDocument();
else
oldChild->removedFromTree(true);
}
void ContainerNode::removeChildren()
{
if (!m_firstChild)
return;
RefPtr<ContainerNode> protect(this);
willRemoveChildren(protect.get());
document()->removeFocusedNodeOfSubtree(this, true);
#if ENABLE(FULLSCREEN_API)
document()->removeFullScreenElementOfSubtree(this, true);
#endif
forbidEventDispatch();
Vector<RefPtr<Node>, 10> removedChildren;
removedChildren.reserveInitialCapacity(childNodeCount());
while (RefPtr<Node> n = m_firstChild) {
Node* next = n->nextSibling();
n->setPreviousSibling(0);
n->setNextSibling(0);
n->setParent(0);
n->setTreeScopeRecursively(document());
m_firstChild = next;
if (n == m_lastChild)
m_lastChild = 0;
removedChildren.append(n.release());
}
size_t removedChildrenCount = removedChildren.size();
size_t i;
for (i = 0; i < removedChildrenCount; ++i) {
Node* removedChild = removedChildren[i].get();
if (removedChild->attached())
removedChild->detach();
}
allowEventDispatch();
childrenChanged(false, 0, 0, -static_cast<int>(removedChildrenCount));
dispatchSubtreeModifiedEvent();
for (i = 0; i < removedChildrenCount; ++i) {
Node* removedChild = removedChildren[i].get();
if (removedChild->inDocument())
removedChild->removedFromDocument();
}
}
bool ContainerNode::appendChild(PassRefPtr<Node> newChild, ExceptionCode& ec, bool shouldLazyAttach)
{
ASSERT(refCount() || parentOrHostNode());
ec = 0;
checkAddChild(newChild.get(), ec);
if (ec)
return false;
if (newChild == m_lastChild) return newChild;
NodeVector targets;
collectTargetNodes(newChild.get(), targets);
if (targets.isEmpty())
return true;
RefPtr<Node> prev = lastChild();
for (NodeVector::const_iterator it = targets.begin(); it != targets.end(); ++it) {
Node* child = it->get();
if (ContainerNode* oldParent = child->parentNode()) {
oldParent->removeChild(child, ec);
if (ec)
return false;
if (child->parentNode())
break;
}
#if ENABLE(INSPECTOR)
InspectorInstrumentation::willInsertDOMNode(document(), child, this);
#endif
child->setTreeScopeRecursively(treeScope());
forbidEventDispatch();
child->setParent(this);
if (m_lastChild) {
child->setPreviousSibling(m_lastChild);
m_lastChild->setNextSibling(child);
} else
m_firstChild = child;
m_lastChild = child;
allowEventDispatch();
childrenChanged(false, prev.get(), 0, 1);
notifyChildInserted(child);
if (attached() && !child->attached() && child->parentNode() == this) {
if (shouldLazyAttach)
child->lazyAttach();
else
child->attach();
}
dispatchChildInsertionEvents(child);
prev = child;
}
dispatchSubtreeModifiedEvent();
return true;
}
void ContainerNode::parserAddChild(PassRefPtr<Node> newChild)
{
ASSERT(newChild);
ASSERT(!newChild->parentNode());
#if ENABLE(INSPECTOR)
InspectorInstrumentation::willInsertDOMNode(document(), newChild.get(), this);
#endif
forbidEventDispatch();
Node* last = m_lastChild;
appendChildToContainer<Node, ContainerNode>(newChild.get(), this);
newChild->setTreeScopeRecursively(treeScope());
allowEventDispatch();
document()->incDOMTreeVersion();
if (inDocument())
newChild->insertedIntoDocument();
childrenChanged(true, last, 0, 1);
}
void ContainerNode::deprecatedParserAddChild(PassRefPtr<Node> node)
{
parserAddChild(node);
}
void ContainerNode::suspendPostAttachCallbacks()
{
if (!s_attachDepth) {
ASSERT(!s_shouldReEnableMemoryCacheCallsAfterAttach);
if (Page* page = document()->page()) {
if (page->areMemoryCacheClientCallsEnabled()) {
page->setMemoryCacheClientCallsEnabled(false);
s_shouldReEnableMemoryCacheCallsAfterAttach = true;
}
}
resourceLoadScheduler()->suspendPendingRequests();
}
++s_attachDepth;
}
void ContainerNode::resumePostAttachCallbacks()
{
if (s_attachDepth == 1) {
if (s_postAttachCallbackQueue)
dispatchPostAttachCallbacks();
if (s_shouldReEnableMemoryCacheCallsAfterAttach) {
s_shouldReEnableMemoryCacheCallsAfterAttach = false;
if (Page* page = document()->page())
page->setMemoryCacheClientCallsEnabled(true);
}
resourceLoadScheduler()->resumePendingRequests();
}
--s_attachDepth;
}
void ContainerNode::queuePostAttachCallback(NodeCallback callback, Node* node)
{
if (!s_postAttachCallbackQueue)
s_postAttachCallbackQueue = new NodeCallbackQueue;
s_postAttachCallbackQueue->append(std::pair<NodeCallback, RefPtr<Node> >(callback, node));
}
bool ContainerNode::postAttachCallbacksAreSuspended()
{
return s_attachDepth;
}
void ContainerNode::dispatchPostAttachCallbacks()
{
for (size_t i = 0; i < s_postAttachCallbackQueue->size(); ++i) {
std::pair<NodeCallback, RefPtr<Node> >& pair = (*s_postAttachCallbackQueue)[i];
NodeCallback callback = pair.first;
Node* node = pair.second.get();
callback(node);
}
s_postAttachCallbackQueue->clear();
}
void ContainerNode::attach()
{
for (Node* child = m_firstChild; child; child = child->nextSibling())
child->attach();
Node::attach();
}
void ContainerNode::detach()
{
for (Node* child = m_firstChild; child; child = child->nextSibling())
child->detach();
clearChildNeedsStyleRecalc();
Node::detach();
}
void ContainerNode::insertedIntoDocument()
{
RefPtr<Node> protect(this);
Node::insertedIntoDocument();
insertedIntoTree(false);
for (RefPtr<Node> child = m_firstChild; child; child = child->nextSibling()) {
if (!inDocument()) break;
if (child->parentNode() != this) break;
child->insertedIntoDocument();
}
}
void ContainerNode::removedFromDocument()
{
Node::removedFromDocument();
if (document()->cssTarget() == this)
document()->setCSSTarget(0);
clearInDocument();
removedFromTree(false);
for (Node* child = m_firstChild; child; child = child->nextSibling())
child->removedFromDocument();
}
void ContainerNode::insertedIntoTree(bool deep)
{
if (!deep)
return;
for (Node* child = m_firstChild; child; child = child->nextSibling())
child->insertedIntoTree(true);
}
void ContainerNode::removedFromTree(bool deep)
{
if (!deep)
return;
for (Node* child = m_firstChild; child; child = child->nextSibling())
child->removedFromTree(true);
}
void ContainerNode::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
{
Node::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
if (!changedByParser && childCountDelta)
document()->nodeChildrenChanged(this);
if (document()->hasNodeListCaches())
notifyNodeListsChildrenChanged();
}
void ContainerNode::cloneChildNodes(ContainerNode *clone)
{
bool isEditorEnabled = false;
if (document()->frame() && document()->frame()->editor()->canEdit()) {
FrameSelection* selection = document()->frame()->selection();
Element* root = selection ? selection->rootEditableElement() : 0;
isEditorEnabled = root && isDescendantOf(root);
if (isEditorEnabled)
document()->frame()->editor()->deleteButtonController()->disable();
}
ExceptionCode ec = 0;
for (Node* n = firstChild(); n && !ec; n = n->nextSibling())
clone->appendChild(n->cloneNode(true), ec);
if (isEditorEnabled && document()->frame())
document()->frame()->editor()->deleteButtonController()->enable();
}
bool ContainerNode::getUpperLeftCorner(FloatPoint& point) const
{
if (!renderer())
return false;
RenderObject *o = renderer();
RenderObject *p = o;
if (!o->isInline() || o->isReplaced()) {
point = o->localToAbsolute(FloatPoint(), false, true);
return true;
}
while (o) {
p = o;
if (o->firstChild())
o = o->firstChild();
else if (o->nextSibling())
o = o->nextSibling();
else {
RenderObject *next = 0;
while (!next && o->parent()) {
o = o->parent();
next = o->nextSibling();
}
o = next;
if (!o)
break;
}
ASSERT(o);
if (!o->isInline() || o->isReplaced()) {
point = o->localToAbsolute(FloatPoint(), false, true);
return true;
}
if (p->node() && p->node() == this && o->isText() && !o->isBR() && !toRenderText(o)->firstTextBox()) {
} else if ((o->isText() && !o->isBR()) || o->isReplaced()) {
point = FloatPoint();
if (o->isText() && toRenderText(o)->firstTextBox()) {
point.move(toRenderText(o)->linesBoundingBox().x(),
toRenderText(o)->firstTextBox()->root()->lineTop());
} else if (o->isBox()) {
RenderBox* box = toRenderBox(o);
point.move(box->x(), box->y());
}
point = o->container()->localToAbsolute(point, false, true);
return true;
}
}
if (!o && document()->view()) {
point = FloatPoint(0, document()->view()->contentsHeight());
return true;
}
return false;
}
bool ContainerNode::getLowerRightCorner(FloatPoint& point) const
{
if (!renderer())
return false;
RenderObject* o = renderer();
if (!o->isInline() || o->isReplaced()) {
RenderBox* box = toRenderBox(o);
point = o->localToAbsolute(FloatPoint(), false, true);
point.move(box->width(), box->height());
return true;
}
while (o) {
if (o->lastChild())
o = o->lastChild();
else if (o->previousSibling())
o = o->previousSibling();
else {
RenderObject* prev = 0;
while (!prev) {
o = o->parent();
if (!o)
return false;
prev = o->previousSibling();
}
o = prev;
}
ASSERT(o);
if (o->isText() || o->isReplaced()) {
point = FloatPoint();
if (o->isText()) {
RenderText* text = toRenderText(o);
IntRect linesBox = text->linesBoundingBox();
if (!linesBox.x() && !linesBox.width() && !linesBox.y() && !linesBox.height())
continue;
point.move(linesBox.x() + linesBox.width(), linesBox.y() + linesBox.height());
} else {
RenderBox* box = toRenderBox(o);
point.move(box->x() + box->width(), box->y() + box->height());
}
point = o->container()->localToAbsolute(point, false, true);
return true;
}
}
return true;
}
IntRect ContainerNode::getRect() const
{
FloatPoint upperLeft, lowerRight;
bool foundUpperLeft = getUpperLeftCorner(upperLeft);
bool foundLowerRight = getLowerRightCorner(lowerRight);
if (foundUpperLeft != foundLowerRight) {
if (foundUpperLeft)
lowerRight = upperLeft;
else
upperLeft = lowerRight;
}
lowerRight.setX(max(upperLeft.x(), lowerRight.x()));
lowerRight.setY(max(upperLeft.y(), lowerRight.y()));
return enclosingIntRect(FloatRect(upperLeft, lowerRight - upperLeft));
}
void ContainerNode::setFocus(bool received)
{
if (focused() == received)
return;
Node::setFocus(received);
setNeedsStyleRecalc();
}
void ContainerNode::setActive(bool down, bool pause)
{
if (down == active()) return;
Node::setActive(down);
if (renderer()) {
bool reactsToPress = renderer()->style()->affectedByActiveRules();
if (reactsToPress)
setNeedsStyleRecalc();
if (renderer() && renderer()->style()->hasAppearance()) {
if (renderer()->theme()->stateChanged(renderer(), PressedState))
reactsToPress = true;
}
if (reactsToPress && pause) {
#ifdef HAVE_FUNC_USLEEP
double startTime = currentTime();
#endif
Document::updateStyleForAllDocuments();
if (renderer())
renderer()->repaint(true);
#ifdef HAVE_FUNC_USLEEP
double remainingTime = 0.1 - (currentTime() - startTime);
if (remainingTime > 0)
usleep(static_cast<useconds_t>(remainingTime * 1000000.0));
#endif
}
}
}
void ContainerNode::setHovered(bool over)
{
if (over == hovered()) return;
Node::setHovered(over);
if (renderer()) {
if (renderer()->style()->affectedByHoverRules())
setNeedsStyleRecalc();
if (renderer() && renderer()->style()->hasAppearance())
renderer()->theme()->stateChanged(renderer(), HoverState);
}
}
unsigned ContainerNode::childNodeCount() const
{
unsigned count = 0;
Node *n;
for (n = firstChild(); n; n = n->nextSibling())
count++;
return count;
}
Node *ContainerNode::childNode(unsigned index) const
{
unsigned i;
Node *n = firstChild();
for (i = 0; n != 0 && i < index; i++)
n = n->nextSibling();
return n;
}
static void notifyChildInserted(Node* child)
{
ASSERT(!eventDispatchForbidden());
#if ENABLE(INSPECTOR)
InspectorInstrumentation::didInsertDOMNode(child->document(), child);
#endif
RefPtr<Node> c = child;
RefPtr<Document> document = child->document();
Node* parentOrHostNode = c->parentOrHostNode();
if (parentOrHostNode && parentOrHostNode->inDocument())
c->insertedIntoDocument();
else
c->insertedIntoTree(true);
document->incDOMTreeVersion();
}
static void dispatchChildInsertionEvents(Node* child)
{
ASSERT(!eventDispatchForbidden());
RefPtr<Node> c = child;
RefPtr<Document> document = child->document();
if (c->parentNode() && document->hasListenerType(Document::DOMNODEINSERTED_LISTENER))
c->dispatchScopedEvent(MutationEvent::create(eventNames().DOMNodeInsertedEvent, true, c->parentNode()));
if (c->inDocument() && document->hasListenerType(Document::DOMNODEINSERTEDINTODOCUMENT_LISTENER)) {
for (; c; c = c->traverseNextNode(child))
c->dispatchScopedEvent(MutationEvent::create(eventNames().DOMNodeInsertedIntoDocumentEvent, false));
}
}
static void dispatchChildRemovalEvents(Node* child)
{
ASSERT(!eventDispatchForbidden());
#if ENABLE(INSPECTOR)
InspectorInstrumentation::willRemoveDOMNode(child->document(), child);
#endif
RefPtr<Node> c = child;
RefPtr<Document> document = child->document();
if (c->parentNode() && document->hasListenerType(Document::DOMNODEREMOVED_LISTENER))
c->dispatchScopedEvent(MutationEvent::create(eventNames().DOMNodeRemovedEvent, true, c->parentNode()));
if (c->inDocument() && document->hasListenerType(Document::DOMNODEREMOVEDFROMDOCUMENT_LISTENER)) {
for (; c; c = c->traverseNextNode(child))
c->dispatchScopedEvent(MutationEvent::create(eventNames().DOMNodeRemovedFromDocumentEvent, false));
}
}
bool ContainerNode::dispatchBeforeLoadEvent(const String& sourceURL)
{
if (!document()->hasListenerType(Document::BEFORELOAD_LISTENER))
return true;
RefPtr<ContainerNode> protector(this);
RefPtr<BeforeLoadEvent> beforeLoadEvent = BeforeLoadEvent::create(sourceURL);
dispatchEvent(beforeLoadEvent.get());
return !beforeLoadEvent->defaultPrevented();
}
}