Never dispatch mutation events in shadow DOM
authoradamk@chromium.org <adamk@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 5 Mar 2012 21:29:44 +0000 (21:29 +0000)
committeradamk@chromium.org <adamk@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 5 Mar 2012 21:29:44 +0000 (21:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=79278

Reviewed by Ryosuke Niwa.

Source/WebCore:

Test: fast/dom/shadow/suppress-mutation-events-in-shadow.html

* dom/ContainerNode.cpp:
(WebCore::ContainerNode::removeChildren): Move allowEventDispatch() call later,
now that childrenChanged won't trigger mutation events in shadow dom.
(WebCore::dispatchChildInsertionEvents): Bail out if in shadow tree.
(WebCore::dispatchChildRemovalEvents): ditto.
* dom/Node.cpp:
(WebCore::Node::dispatchSubtreeModifiedEvent): ditto.

LayoutTests:

* fast/dom/shadow/suppress-mutation-events-in-shadow-expected.txt: Added.
* fast/dom/shadow/suppress-mutation-events-in-shadow.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@109790 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/dom/shadow/suppress-mutation-events-in-shadow-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/shadow/suppress-mutation-events-in-shadow.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/ContainerNode.cpp
Source/WebCore/dom/Node.cpp

index 44fd76e..6d11d09 100644 (file)
@@ -1,3 +1,13 @@
+2012-03-05  Adam Klein  <adamk@chromium.org>
+
+        Never dispatch mutation events in shadow DOM
+        https://bugs.webkit.org/show_bug.cgi?id=79278
+
+        Reviewed by Ryosuke Niwa.
+
+        * fast/dom/shadow/suppress-mutation-events-in-shadow-expected.txt: Added.
+        * fast/dom/shadow/suppress-mutation-events-in-shadow.html: Added.
+
 2012-03-05  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r109656.
diff --git a/LayoutTests/fast/dom/shadow/suppress-mutation-events-in-shadow-expected.txt b/LayoutTests/fast/dom/shadow/suppress-mutation-events-in-shadow-expected.txt
new file mode 100644 (file)
index 0000000..78f8e39
--- /dev/null
@@ -0,0 +1,10 @@
+Test that mutation events are not triggered in shadow DOM
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS mutationEventTriggered is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/dom/shadow/suppress-mutation-events-in-shadow.html b/LayoutTests/fast/dom/shadow/suppress-mutation-events-in-shadow.html
new file mode 100644 (file)
index 0000000..7536cd3
--- /dev/null
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<body>
+<input>
+<script src="../../js/resources/js-test-pre.js"></script>
+<script>
+description('Test that mutation events are not triggered in shadow DOM');
+var mutationEventTriggered = false;
+function doTest() {
+    var input = document.querySelector('input');
+    var shadowRoot = internals.shadowRoot(input);
+    var firstChild = shadowRoot.firstChild;
+    firstChild.addEventListener('DOMNodeInserted', function(evt) {
+        mutationEventTriggered = true;
+    });
+    input.value = 'hello';
+    shouldBeFalse('mutationEventTriggered');
+}
+
+if (window.internals)
+    doTest();
+else
+    testFailed('This test only runs in DRT');
+</script>
+<script src="../../js/resources/js-test-post.js"></script>
+</body>
index b5d0248..97450c4 100644 (file)
@@ -1,3 +1,20 @@
+2012-03-05  Adam Klein  <adamk@chromium.org>
+
+        Never dispatch mutation events in shadow DOM
+        https://bugs.webkit.org/show_bug.cgi?id=79278
+
+        Reviewed by Ryosuke Niwa.
+
+        Test: fast/dom/shadow/suppress-mutation-events-in-shadow.html
+
+        * dom/ContainerNode.cpp:
+        (WebCore::ContainerNode::removeChildren): Move allowEventDispatch() call later,
+        now that childrenChanged won't trigger mutation events in shadow dom.
+        (WebCore::dispatchChildInsertionEvents): Bail out if in shadow tree.
+        (WebCore::dispatchChildRemovalEvents): ditto.
+        * dom/Node.cpp:
+        (WebCore::Node::dispatchSubtreeModifiedEvent): ditto.
+
 2012-03-05  Alexey Proskuryakov  <ap@apple.com>
 
         BlobResourceHandle should keep a reference to itself when calling client code.
index af1fe6a..b0c56d3 100644 (file)
@@ -573,9 +573,6 @@ void ContainerNode::removeChildren()
             removedChild->detach();
     }
 
-    // FIXME: This should be just above dispatchSubtreeModifiedEvent();
-    allowEventDispatch();
-
     childrenChanged(false, 0, 0, -static_cast<int>(removedChildrenCount));
 
     for (i = 0; i < removedChildrenCount; ++i) {
@@ -586,6 +583,7 @@ void ContainerNode::removeChildren()
             toContainerNode(removedChild)->removedFromTree(true);
     }
 
+    allowEventDispatch();
     dispatchSubtreeModifiedEvent();
 }
 
@@ -1093,6 +1091,9 @@ static void notifyChildInserted(Node* child)
 
 static void dispatchChildInsertionEvents(Node* child)
 {
+    if (child->isInShadowTree())
+        return;
+
     ASSERT(!eventDispatchForbidden());
 
     RefPtr<Node> c = child;
@@ -1117,6 +1118,9 @@ static void dispatchChildInsertionEvents(Node* child)
 
 static void dispatchChildRemovalEvents(Node* child)
 {
+    if (child->isInShadowTree())
+        return;
+
     ASSERT(!eventDispatchForbidden());
 
 #if ENABLE(INSPECTOR)
index b56cf16..64f8100 100644 (file)
@@ -2804,10 +2804,15 @@ bool Node::dispatchEvent(PassRefPtr<Event> event)
 
 void Node::dispatchSubtreeModifiedEvent()
 {
-    ASSERT(!eventDispatchForbidden());
-    
+    // FIXME: This call shouldn't be necessary, since it should have already been
+    // called whenever any child is inserted or removed, or an attribute changed.
     document()->incDOMTreeVersion();
 
+    if (isInShadowTree())
+        return;
+
+    ASSERT(!eventDispatchForbidden());
+
     if (!document()->hasListenerType(Document::DOMSUBTREEMODIFIED_LISTENER))
         return;