Reviewed by Darin.
[WebKit-https.git] / WebCore / khtml / xml / dom_docimpl.cpp
index c517343a347a5d04e878a87b5860eda8d52055ea..afee8f0f29b55980f3cad31ccfa3154d3987a863 100644 (file)
@@ -1191,6 +1191,8 @@ void DocumentImpl::detach()
     m_imageLoadEventDispatchSoonList.clear();
     m_imageLoadEventDispatchingList.clear();
 
+    removeAllEventListenersFromAllNodes();
+
     NodeBaseImpl::detach();
 
     if ( render )
@@ -1206,6 +1208,34 @@ void DocumentImpl::detach()
     }
 }
 
+void DocumentImpl::removeAllEventListenersFromAllNodes()
+{
+    m_windowEventListeners.clear();
+    removeAllDisconnectedNodeEventListeners();
+    for (NodeImpl *n = this; n; n = n->traverseNextNode()) {
+        n->removeAllEventListeners();
+    }
+}
+
+void DocumentImpl::registerDisconnectedNodeWithEventListeners(NodeImpl *node)
+{
+    m_disconnectedNodesWithEventListeners.insert(node, node);
+}
+
+void DocumentImpl::unregisterDisconnectedNodeWithEventListeners(NodeImpl *node)
+{
+    m_disconnectedNodesWithEventListeners.remove(node);
+}
+
+void DocumentImpl::removeAllDisconnectedNodeEventListeners()
+{
+    for (QPtrDictIterator<NodeImpl> iter(m_disconnectedNodesWithEventListeners);
+         iter.current();
+         ++iter) {
+        iter.current()->removeAllEventListeners();
+    }
+}
+
 #if APPLE_CHANGES
 KWQAccObjectCache* DocumentImpl::getAccObjectCache()
 {