Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Unified Diff: Source/WebCore/dom/ContainerNode.cpp

Issue 14218002: Move WidgetHierarchyUpdatesSuspensionScope into removeChildren loop (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698