Index: Source/WebCore/dom/ContainerNode.cpp |
diff --git a/Source/WebCore/dom/ContainerNode.cpp b/Source/WebCore/dom/ContainerNode.cpp |
index 8b26223a678a706a835394a863ec0eaf8b4461bf..cde058b940d5405bbdc844a1cb7399518f1ee1ab 100644 |
--- a/Source/WebCore/dom/ContainerNode.cpp |
+++ b/Source/WebCore/dom/ContainerNode.cpp |
@@ -567,37 +567,36 @@ void ContainerNode::removeChildren() |
ChildListMutationScope mutation(this); |
NodeVector removedChildren; |
- { |
- WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates; |
+ while (RefPtr<Node> child = m_firstChild) { |
+ // Dispatch synchronous events like mutation and unload events. |
+ dispatchChildRemovalEvents(child.get()); |
+ ChildFrameDisconnector(child.get()).disconnect(); |
- while (RefPtr<Node> child = m_firstChild) { |
- // Dispatch synchronous events like mutation and unload events. |
- dispatchChildRemovalEvents(child.get()); |
- ChildFrameDisconnector(child.get()).disconnect(); |
+ // FIXME: In theory this can fire focus events when the selection |
+ // changes, but there's no obvious way to test it. |
+ document()->nodeWillBeRemoved(child.get()); |
- // FIXME: In theory this can fire focus events when the selection |
- // changes, but there's no obvious way to test it. |
- document()->nodeWillBeRemoved(child.get()); |
+ // If an event moved the child start over. |
+ if (child != m_firstChild) |
+ continue; |
- // If an event moved the child start over. |
- if (child != m_firstChild) |
- continue; |
- |
- mutation.willRemoveChild(child.get()); |
- child->notifyMutationObserversNodeWillDetach(); |
- removeBetween(0, child->nextSibling(), child.get()); |
- removedChildren.append(child.release()); |
- } |
- |
- // FIXME: We could avoid walking all the children twice by calling |
- // notify inside the loop and childrenChanged after but that would mean |
- // calling childrenChanged in a different order than all other methods. |
- // Figure out if this is safe. |
- childrenChanged(false, 0, 0, -static_cast<int>(removedChildren.size())); |
- for (size_t i = 0; i < removedChildren.size(); ++i) |
- ChildNodeRemovalNotifier(this).notify(removedChildren[i].get()); |
+ // The widget tree must be updated between each removal so script |
+ // cannot run before the tree is in a consistent state. |
+ WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates; |
+ mutation.willRemoveChild(child.get()); |
+ child->notifyMutationObserversNodeWillDetach(); |
+ removeBetween(0, child->nextSibling(), child.get()); |
+ removedChildren.append(child.release()); |
} |
+ // FIXME: We could avoid walking all the children twice by calling |
+ // notify inside the loop and childrenChanged after but that would mean |
+ // calling childrenChanged in a different order than all other methods. |
+ // Figure out if this is safe. |
+ childrenChanged(false, 0, 0, -static_cast<int>(removedChildren.size())); |
+ for (size_t i = 0; i < removedChildren.size(); ++i) |
+ ChildNodeRemovalNotifier(this).notify(removedChildren[i].get()); |
+ |
dispatchSubtreeModifiedEvent(); |
} |