Move Element.contains to Node
authorarv@chromium.org <arv@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 10 Sep 2011 03:21:41 +0000 (03:21 +0000)
committerarv@chromium.org <arv@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 10 Sep 2011 03:21:41 +0000 (03:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=67651

Reviewed by Darin Adler.

This moves the contains method from Element to Node as in the DOM4 working draft:
http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-node-contains

This also special cases Document contains to make it O(1) instead of O(depth).

Source/WebCore:

Tests: fast/dom/Node/contains-method.html
       perf/document-contains.html

* bindings/objc/PublicDOMInterfaces.h: Move contains from DOMElement to DOMNode.
* dom/Element.idl:
* dom/Node.cpp:
(WebCore::Node::contains): Added document special case.
* dom/Node.idl:
* editing/DeleteSelectionCommand.cpp:
(WebCore::DeleteSelectionCommand::mergeParagraphs): Added a null check.

LayoutTests:

* fast/dom/Element/contains-method-expected.txt: Removed.
* fast/dom/Element/script-tests/contains-method.js: Removed.
* fast/dom/Node/contains-method-expected.txt: Added.
* fast/dom/Node/contains-method.html: Renamed from LayoutTests/fast/dom/Element/contains-method.html.
* fast/dom/Node/script-tests/contains-method.js: Added. Expanded tests.
* fast/dom/Window/window-properties-expected.txt:
* perf/document-contains-expected.txt: Added.
* perf/document-contains.html: Added.
                               Perf test to ensure that document.contains is O(1).
* platform/gtk/fast/dom/Window/window-properties-expected.txt:
* platform/mac/fast/dom/Window/window-properties-expected.txt:
* platform/qt-wk2/fast/dom/Window/window-properties-expected.txt:
* platform/qt/fast/dom/Window/window-properties-expected.txt:

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

19 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/Element/contains-method-expected.txt [deleted file]
LayoutTests/fast/dom/Element/script-tests/contains-method.js [deleted file]
LayoutTests/fast/dom/Node/contains-method-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/Node/contains-method.html [moved from LayoutTests/fast/dom/Element/contains-method.html with 100% similarity]
LayoutTests/fast/dom/Node/script-tests/contains-method.js [new file with mode: 0644]
LayoutTests/fast/dom/Window/window-properties-expected.txt
LayoutTests/perf/document-contains-expected.txt [new file with mode: 0644]
LayoutTests/perf/document-contains.html [new file with mode: 0644]
LayoutTests/platform/gtk/fast/dom/Window/window-properties-expected.txt
LayoutTests/platform/mac/fast/dom/Window/window-properties-expected.txt
LayoutTests/platform/qt-wk2/fast/dom/Window/window-properties-expected.txt
LayoutTests/platform/qt/fast/dom/Window/window-properties-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/bindings/objc/PublicDOMInterfaces.h
Source/WebCore/dom/Element.idl
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/Node.idl
Source/WebCore/editing/DeleteSelectionCommand.cpp

index 96728b5..6c66217 100644 (file)
@@ -1,3 +1,29 @@
+2011-09-09  Erik Arvidsson  <arv@chromium.org>
+
+        Move Element.contains to Node
+        https://bugs.webkit.org/show_bug.cgi?id=67651
+
+        Reviewed by Darin Adler.
+
+        This moves the contains method from Element to Node as in the DOM4 working draft: 
+        http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-node-contains
+
+        This also special cases Document contains to make it O(1) instead of O(depth).
+
+        * fast/dom/Element/contains-method-expected.txt: Removed.
+        * fast/dom/Element/script-tests/contains-method.js: Removed.
+        * fast/dom/Node/contains-method-expected.txt: Added.
+        * fast/dom/Node/contains-method.html: Renamed from LayoutTests/fast/dom/Element/contains-method.html.
+        * fast/dom/Node/script-tests/contains-method.js: Added. Expanded tests.
+        * fast/dom/Window/window-properties-expected.txt:
+        * perf/document-contains-expected.txt: Added.
+        * perf/document-contains.html: Added.
+                                       Perf test to ensure that document.contains is O(1).
+        * platform/gtk/fast/dom/Window/window-properties-expected.txt:
+        * platform/mac/fast/dom/Window/window-properties-expected.txt:
+        * platform/qt-wk2/fast/dom/Window/window-properties-expected.txt:
+        * platform/qt/fast/dom/Window/window-properties-expected.txt:
+
 2011-09-09  Tim Horton  <timothy_horton@apple.com>
 
         Text rendered with a simple (i.e. 0px blur) shadow inside a transparency layer has a double shadow
diff --git a/LayoutTests/fast/dom/Element/contains-method-expected.txt b/LayoutTests/fast/dom/Element/contains-method-expected.txt
deleted file mode 100644 (file)
index 3a3e97c..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-This test checks behavior of Element.contains.
-
-[test1 [test 2]]
-On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-
-
-PASS document.contains is undefined.
-PASS test1.contains(test2) is true
-PASS test1.contains(test1TextChild) is false
-PASS test1.contains(123) is false
-PASS test1.contains(null) is false
-PASS successfullyParsed is true
-
-TEST COMPLETE
-
diff --git a/LayoutTests/fast/dom/Element/script-tests/contains-method.js b/LayoutTests/fast/dom/Element/script-tests/contains-method.js
deleted file mode 100644 (file)
index e4989f5..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-description(
-'This test checks behavior of Element.contains. <div id="test1">[test1 <span id="test2">[test 2]</span>]</div>'
-);
-
-var test1 = document.getElementById('test1');
-var test1TextChild = document.getElementById('test1').firstChild;
-var test2 = document.getElementById('test2');
-
-shouldBeUndefined("document.contains");
-shouldBeTrue("test1.contains(test2)");
-shouldBeFalse("test1.contains(test1TextChild)");
-shouldBeFalse("test1.contains(123)");
-shouldBeFalse("test1.contains(null)");
-
-var successfullyParsed = true;
diff --git a/LayoutTests/fast/dom/Node/contains-method-expected.txt b/LayoutTests/fast/dom/Node/contains-method-expected.txt
new file mode 100644 (file)
index 0000000..5bf7f58
--- /dev/null
@@ -0,0 +1,27 @@
+This test checks behavior of Node.contains.
+
+[test1 [test 2]]
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS typeof document.contains is "function"
+PASS test1.contains(test2) is true
+PASS test1.contains(test1TextChild) is true
+PASS document.contains(test1) is true
+PASS document.contains(test1TextChild) is true
+PASS document.contains(document) is true
+PASS test1.contains(test1) is true
+PASS test1TextChild.contains(test1TextChild) is true
+PASS test1.contains(123) is false
+PASS test1.contains(null) is false
+PASS document.contains(iframe) is false
+PASS iframe.contains(iframe) is true
+iframe is now in document
+PASS document.contains(iframe) is true
+PASS document.contains(iframeDoc) is false
+PASS iframeDoc.contains(iframeBody) is true
+PASS document.contains(iframeBody) is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/dom/Node/script-tests/contains-method.js b/LayoutTests/fast/dom/Node/script-tests/contains-method.js
new file mode 100644 (file)
index 0000000..6473303
--- /dev/null
@@ -0,0 +1,37 @@
+description(
+'This test checks behavior of Node.contains. <div id="test1">[test1 <span id="test2">[test 2]</span>]</div>'
+);
+
+var test1 = document.getElementById('test1');
+var test1TextChild = document.getElementById('test1').firstChild;
+var test2 = document.getElementById('test2');
+
+shouldBeEqualToString("typeof document.contains", "function");
+shouldBeTrue("test1.contains(test2)");
+shouldBeTrue("test1.contains(test1TextChild)");
+shouldBeTrue("document.contains(test1)");
+shouldBeTrue("document.contains(test1TextChild)");
+shouldBeTrue("document.contains(document)");
+shouldBeTrue("test1.contains(test1)");
+shouldBeTrue("test1TextChild.contains(test1TextChild)");
+shouldBeFalse("test1.contains(123)");
+shouldBeFalse("test1.contains(null)");
+
+// Cross document tests
+var iframe = document.createElement("iframe");
+
+shouldBeFalse("document.contains(iframe)");  // Not in document
+shouldBeTrue("iframe.contains(iframe)");
+
+document.body.appendChild(iframe);
+debug('iframe is now in document');
+shouldBeTrue("document.contains(iframe)");
+
+var iframeDoc = iframe.contentDocument;
+var iframeBody = iframeDoc.body;
+
+shouldBeFalse("document.contains(iframeDoc)");
+shouldBeTrue("iframeDoc.contains(iframeBody)");
+shouldBeFalse("document.contains(iframeBody)");
+
+var successfullyParsed = true;
index eeb41a8..2f293d9 100644 (file)
@@ -26,6 +26,7 @@ window.Attr.prototype.addEventListener [function]
 window.Attr.prototype.appendChild [function]
 window.Attr.prototype.cloneNode [function]
 window.Attr.prototype.compareDocumentPosition [function]
+window.Attr.prototype.contains [function]
 window.Attr.prototype.dispatchEvent [function]
 window.Attr.prototype.hasAttributes [function]
 window.Attr.prototype.hasChildNodes [function]
@@ -179,6 +180,7 @@ window.CDATASection.prototype.appendChild [function]
 window.CDATASection.prototype.appendData [function]
 window.CDATASection.prototype.cloneNode [function]
 window.CDATASection.prototype.compareDocumentPosition [function]
+window.CDATASection.prototype.contains [function]
 window.CDATASection.prototype.deleteData [function]
 window.CDATASection.prototype.dispatchEvent [function]
 window.CDATASection.prototype.hasAttributes [function]
@@ -450,6 +452,7 @@ window.CharacterData.prototype.appendChild [function]
 window.CharacterData.prototype.appendData [function]
 window.CharacterData.prototype.cloneNode [function]
 window.CharacterData.prototype.compareDocumentPosition [function]
+window.CharacterData.prototype.contains [function]
 window.CharacterData.prototype.deleteData [function]
 window.CharacterData.prototype.dispatchEvent [function]
 window.CharacterData.prototype.hasAttributes [function]
@@ -621,6 +624,7 @@ window.Document.prototype.appendChild [function]
 window.Document.prototype.caretRangeFromPoint [function]
 window.Document.prototype.cloneNode [function]
 window.Document.prototype.compareDocumentPosition [function]
+window.Document.prototype.contains [function]
 window.Document.prototype.createAttribute [function]
 window.Document.prototype.createAttributeNS [function]
 window.Document.prototype.createCDATASection [function]
@@ -695,6 +699,7 @@ window.DocumentFragment.prototype.addEventListener [function]
 window.DocumentFragment.prototype.appendChild [function]
 window.DocumentFragment.prototype.cloneNode [function]
 window.DocumentFragment.prototype.compareDocumentPosition [function]
+window.DocumentFragment.prototype.contains [function]
 window.DocumentFragment.prototype.dispatchEvent [function]
 window.DocumentFragment.prototype.hasAttributes [function]
 window.DocumentFragment.prototype.hasChildNodes [function]
@@ -735,6 +740,7 @@ window.DocumentType.prototype.addEventListener [function]
 window.DocumentType.prototype.appendChild [function]
 window.DocumentType.prototype.cloneNode [function]
 window.DocumentType.prototype.compareDocumentPosition [function]
+window.DocumentType.prototype.contains [function]
 window.DocumentType.prototype.dispatchEvent [function]
 window.DocumentType.prototype.hasAttributes [function]
 window.DocumentType.prototype.hasChildNodes [function]
@@ -842,6 +848,7 @@ window.Entity.prototype.addEventListener [function]
 window.Entity.prototype.appendChild [function]
 window.Entity.prototype.cloneNode [function]
 window.Entity.prototype.compareDocumentPosition [function]
+window.Entity.prototype.contains [function]
 window.Entity.prototype.dispatchEvent [function]
 window.Entity.prototype.hasAttributes [function]
 window.Entity.prototype.hasChildNodes [function]
@@ -880,6 +887,7 @@ window.EntityReference.prototype.addEventListener [function]
 window.EntityReference.prototype.appendChild [function]
 window.EntityReference.prototype.cloneNode [function]
 window.EntityReference.prototype.compareDocumentPosition [function]
+window.EntityReference.prototype.contains [function]
 window.EntityReference.prototype.dispatchEvent [function]
 window.EntityReference.prototype.hasAttributes [function]
 window.EntityReference.prototype.hasChildNodes [function]
@@ -1252,6 +1260,7 @@ window.Node.prototype.addEventListener [function]
 window.Node.prototype.appendChild [function]
 window.Node.prototype.cloneNode [function]
 window.Node.prototype.compareDocumentPosition [function]
+window.Node.prototype.contains [function]
 window.Node.prototype.dispatchEvent [function]
 window.Node.prototype.hasAttributes [function]
 window.Node.prototype.hasChildNodes [function]
diff --git a/LayoutTests/perf/document-contains-expected.txt b/LayoutTests/perf/document-contains-expected.txt
new file mode 100644 (file)
index 0000000..dbb4365
--- /dev/null
@@ -0,0 +1,5 @@
+Tests that document.contains is O(1).
+PASS
+PASS
+PASS
+
diff --git a/LayoutTests/perf/document-contains.html b/LayoutTests/perf/document-contains.html
new file mode 100644 (file)
index 0000000..a59e014
--- /dev/null
@@ -0,0 +1,60 @@
+<!DOCTYPE html>
+<script src="../resources/magnitude-perf.js"></script>
+<body>
+<script>
+
+var doc, node, expected;
+
+function appendDeepTree(magnitude)
+{
+    for (var i = 0; i < magnitude; i++) {
+        node = node.appendChild(doc.createElement('div'));
+    }
+}
+
+
+// Tests that contains is O(1) for document where the test |node| is in the document.
+
+function setup1(magnitude)
+{
+    node = document.body;
+    doc = document;
+    expected = true;
+    appendDeepTree(magnitude);
+}
+
+// Tests that contains is O(1) for document when the test |node| is not in the document.
+
+function setup2(magnitude)
+{
+    node = document.createElement('div');  // Not added to the document
+    doc = document;
+    expected = false;
+    appendDeepTree(magnitude);
+}
+
+// Tests that contains is O(1) for document when the test |node| is in a different document.
+
+function setup3(magnitude)
+{
+    var iframe = document.body.appendChild(document.createElement('iframe'));
+    doc = iframe.contentDocument;
+    node = doc.body;  // Different document.
+    expected = false;
+    appendDeepTree(magnitude);
+}
+
+function test(magnitude)
+{
+    var actual = document.contains(node);
+    if (actual !== expected)
+        throw 'Unexpected return value: ' + actual + ', expected: ' + expected;
+}
+
+Magnitude.description('Tests that document.contains is O(1).');
+Magnitude.run(setup1, test, Magnitude.CONSTANT);
+Magnitude.run(setup2, test, Magnitude.CONSTANT);
+Magnitude.run(setup3, test, Magnitude.CONSTANT);
+
+</script>
+</body>
index 7890ad6..1e83047 100644 (file)
@@ -26,6 +26,7 @@ window.Attr.prototype.addEventListener [function]
 window.Attr.prototype.appendChild [function]
 window.Attr.prototype.cloneNode [function]
 window.Attr.prototype.compareDocumentPosition [function]
+window.Attr.prototype.contains [function]
 window.Attr.prototype.dispatchEvent [function]
 window.Attr.prototype.hasAttributes [function]
 window.Attr.prototype.hasChildNodes [function]
@@ -179,6 +180,7 @@ window.CDATASection.prototype.appendChild [function]
 window.CDATASection.prototype.appendData [function]
 window.CDATASection.prototype.cloneNode [function]
 window.CDATASection.prototype.compareDocumentPosition [function]
+window.CDATASection.prototype.contains [function]
 window.CDATASection.prototype.deleteData [function]
 window.CDATASection.prototype.dispatchEvent [function]
 window.CDATASection.prototype.hasAttributes [function]
@@ -450,6 +452,7 @@ window.CharacterData.prototype.appendChild [function]
 window.CharacterData.prototype.appendData [function]
 window.CharacterData.prototype.cloneNode [function]
 window.CharacterData.prototype.compareDocumentPosition [function]
+window.CharacterData.prototype.contains [function]
 window.CharacterData.prototype.deleteData [function]
 window.CharacterData.prototype.dispatchEvent [function]
 window.CharacterData.prototype.hasAttributes [function]
@@ -674,6 +677,7 @@ window.Document.prototype.appendChild [function]
 window.Document.prototype.caretRangeFromPoint [function]
 window.Document.prototype.cloneNode [function]
 window.Document.prototype.compareDocumentPosition [function]
+window.Document.prototype.contains [function]
 window.Document.prototype.createAttribute [function]
 window.Document.prototype.createAttributeNS [function]
 window.Document.prototype.createCDATASection [function]
@@ -748,6 +752,7 @@ window.DocumentFragment.prototype.addEventListener [function]
 window.DocumentFragment.prototype.appendChild [function]
 window.DocumentFragment.prototype.cloneNode [function]
 window.DocumentFragment.prototype.compareDocumentPosition [function]
+window.DocumentFragment.prototype.contains [function]
 window.DocumentFragment.prototype.dispatchEvent [function]
 window.DocumentFragment.prototype.hasAttributes [function]
 window.DocumentFragment.prototype.hasChildNodes [function]
@@ -788,6 +793,7 @@ window.DocumentType.prototype.addEventListener [function]
 window.DocumentType.prototype.appendChild [function]
 window.DocumentType.prototype.cloneNode [function]
 window.DocumentType.prototype.compareDocumentPosition [function]
+window.DocumentType.prototype.contains [function]
 window.DocumentType.prototype.dispatchEvent [function]
 window.DocumentType.prototype.hasAttributes [function]
 window.DocumentType.prototype.hasChildNodes [function]
@@ -895,6 +901,7 @@ window.Entity.prototype.addEventListener [function]
 window.Entity.prototype.appendChild [function]
 window.Entity.prototype.cloneNode [function]
 window.Entity.prototype.compareDocumentPosition [function]
+window.Entity.prototype.contains [function]
 window.Entity.prototype.dispatchEvent [function]
 window.Entity.prototype.hasAttributes [function]
 window.Entity.prototype.hasChildNodes [function]
@@ -933,6 +940,7 @@ window.EntityReference.prototype.addEventListener [function]
 window.EntityReference.prototype.appendChild [function]
 window.EntityReference.prototype.cloneNode [function]
 window.EntityReference.prototype.compareDocumentPosition [function]
+window.EntityReference.prototype.contains [function]
 window.EntityReference.prototype.dispatchEvent [function]
 window.EntityReference.prototype.hasAttributes [function]
 window.EntityReference.prototype.hasChildNodes [function]
@@ -1333,6 +1341,7 @@ window.Node.prototype.addEventListener [function]
 window.Node.prototype.appendChild [function]
 window.Node.prototype.cloneNode [function]
 window.Node.prototype.compareDocumentPosition [function]
+window.Node.prototype.contains [function]
 window.Node.prototype.dispatchEvent [function]
 window.Node.prototype.hasAttributes [function]
 window.Node.prototype.hasChildNodes [function]
index 541d1a9..78aab18 100644 (file)
@@ -26,6 +26,7 @@ window.Attr.prototype.addEventListener [function]
 window.Attr.prototype.appendChild [function]
 window.Attr.prototype.cloneNode [function]
 window.Attr.prototype.compareDocumentPosition [function]
+window.Attr.prototype.contains [function]
 window.Attr.prototype.dispatchEvent [function]
 window.Attr.prototype.hasAttributes [function]
 window.Attr.prototype.hasChildNodes [function]
@@ -179,6 +180,7 @@ window.CDATASection.prototype.appendChild [function]
 window.CDATASection.prototype.appendData [function]
 window.CDATASection.prototype.cloneNode [function]
 window.CDATASection.prototype.compareDocumentPosition [function]
+window.CDATASection.prototype.contains [function]
 window.CDATASection.prototype.deleteData [function]
 window.CDATASection.prototype.dispatchEvent [function]
 window.CDATASection.prototype.hasAttributes [function]
@@ -450,6 +452,7 @@ window.CharacterData.prototype.appendChild [function]
 window.CharacterData.prototype.appendData [function]
 window.CharacterData.prototype.cloneNode [function]
 window.CharacterData.prototype.compareDocumentPosition [function]
+window.CharacterData.prototype.contains [function]
 window.CharacterData.prototype.deleteData [function]
 window.CharacterData.prototype.dispatchEvent [function]
 window.CharacterData.prototype.hasAttributes [function]
@@ -674,6 +677,7 @@ window.Document.prototype.appendChild [function]
 window.Document.prototype.caretRangeFromPoint [function]
 window.Document.prototype.cloneNode [function]
 window.Document.prototype.compareDocumentPosition [function]
+window.Document.prototype.contains [function]
 window.Document.prototype.createAttribute [function]
 window.Document.prototype.createAttributeNS [function]
 window.Document.prototype.createCDATASection [function]
@@ -748,6 +752,7 @@ window.DocumentFragment.prototype.addEventListener [function]
 window.DocumentFragment.prototype.appendChild [function]
 window.DocumentFragment.prototype.cloneNode [function]
 window.DocumentFragment.prototype.compareDocumentPosition [function]
+window.DocumentFragment.prototype.contains [function]
 window.DocumentFragment.prototype.dispatchEvent [function]
 window.DocumentFragment.prototype.hasAttributes [function]
 window.DocumentFragment.prototype.hasChildNodes [function]
@@ -788,6 +793,7 @@ window.DocumentType.prototype.addEventListener [function]
 window.DocumentType.prototype.appendChild [function]
 window.DocumentType.prototype.cloneNode [function]
 window.DocumentType.prototype.compareDocumentPosition [function]
+window.DocumentType.prototype.contains [function]
 window.DocumentType.prototype.dispatchEvent [function]
 window.DocumentType.prototype.hasAttributes [function]
 window.DocumentType.prototype.hasChildNodes [function]
@@ -895,6 +901,7 @@ window.Entity.prototype.addEventListener [function]
 window.Entity.prototype.appendChild [function]
 window.Entity.prototype.cloneNode [function]
 window.Entity.prototype.compareDocumentPosition [function]
+window.Entity.prototype.contains [function]
 window.Entity.prototype.dispatchEvent [function]
 window.Entity.prototype.hasAttributes [function]
 window.Entity.prototype.hasChildNodes [function]
@@ -933,6 +940,7 @@ window.EntityReference.prototype.addEventListener [function]
 window.EntityReference.prototype.appendChild [function]
 window.EntityReference.prototype.cloneNode [function]
 window.EntityReference.prototype.compareDocumentPosition [function]
+window.EntityReference.prototype.contains [function]
 window.EntityReference.prototype.dispatchEvent [function]
 window.EntityReference.prototype.hasAttributes [function]
 window.EntityReference.prototype.hasChildNodes [function]
@@ -1331,6 +1339,7 @@ window.Node.prototype.addEventListener [function]
 window.Node.prototype.appendChild [function]
 window.Node.prototype.cloneNode [function]
 window.Node.prototype.compareDocumentPosition [function]
+window.Node.prototype.contains [function]
 window.Node.prototype.dispatchEvent [function]
 window.Node.prototype.hasAttributes [function]
 window.Node.prototype.hasChildNodes [function]
index 72670d2..1cb55eb 100644 (file)
@@ -26,6 +26,7 @@ window.Attr.prototype.addEventListener [function]
 window.Attr.prototype.appendChild [function]
 window.Attr.prototype.cloneNode [function]
 window.Attr.prototype.compareDocumentPosition [function]
+window.Attr.prototype.contains [function]
 window.Attr.prototype.dispatchEvent [function]
 window.Attr.prototype.hasAttributes [function]
 window.Attr.prototype.hasChildNodes [function]
@@ -177,6 +178,7 @@ window.CDATASection.prototype.appendChild [function]
 window.CDATASection.prototype.appendData [function]
 window.CDATASection.prototype.cloneNode [function]
 window.CDATASection.prototype.compareDocumentPosition [function]
+window.CDATASection.prototype.contains [function]
 window.CDATASection.prototype.deleteData [function]
 window.CDATASection.prototype.dispatchEvent [function]
 window.CDATASection.prototype.hasAttributes [function]
@@ -448,6 +450,7 @@ window.CharacterData.prototype.appendChild [function]
 window.CharacterData.prototype.appendData [function]
 window.CharacterData.prototype.cloneNode [function]
 window.CharacterData.prototype.compareDocumentPosition [function]
+window.CharacterData.prototype.contains [function]
 window.CharacterData.prototype.deleteData [function]
 window.CharacterData.prototype.dispatchEvent [function]
 window.CharacterData.prototype.hasAttributes [function]
@@ -619,6 +622,7 @@ window.Document.prototype.appendChild [function]
 window.Document.prototype.caretRangeFromPoint [function]
 window.Document.prototype.cloneNode [function]
 window.Document.prototype.compareDocumentPosition [function]
+window.Document.prototype.contains [function]
 window.Document.prototype.createAttribute [function]
 window.Document.prototype.createAttributeNS [function]
 window.Document.prototype.createCDATASection [function]
@@ -694,6 +698,7 @@ window.DocumentFragment.prototype.addEventListener [function]
 window.DocumentFragment.prototype.appendChild [function]
 window.DocumentFragment.prototype.cloneNode [function]
 window.DocumentFragment.prototype.compareDocumentPosition [function]
+window.DocumentFragment.prototype.contains [function]
 window.DocumentFragment.prototype.dispatchEvent [function]
 window.DocumentFragment.prototype.hasAttributes [function]
 window.DocumentFragment.prototype.hasChildNodes [function]
@@ -734,6 +739,7 @@ window.DocumentType.prototype.addEventListener [function]
 window.DocumentType.prototype.appendChild [function]
 window.DocumentType.prototype.cloneNode [function]
 window.DocumentType.prototype.compareDocumentPosition [function]
+window.DocumentType.prototype.contains [function]
 window.DocumentType.prototype.dispatchEvent [function]
 window.DocumentType.prototype.hasAttributes [function]
 window.DocumentType.prototype.hasChildNodes [function]
@@ -838,6 +844,7 @@ window.Entity.prototype.addEventListener [function]
 window.Entity.prototype.appendChild [function]
 window.Entity.prototype.cloneNode [function]
 window.Entity.prototype.compareDocumentPosition [function]
+window.Entity.prototype.contains [function]
 window.Entity.prototype.dispatchEvent [function]
 window.Entity.prototype.hasAttributes [function]
 window.Entity.prototype.hasChildNodes [function]
@@ -876,6 +883,7 @@ window.EntityReference.prototype.addEventListener [function]
 window.EntityReference.prototype.appendChild [function]
 window.EntityReference.prototype.cloneNode [function]
 window.EntityReference.prototype.compareDocumentPosition [function]
+window.EntityReference.prototype.contains [function]
 window.EntityReference.prototype.dispatchEvent [function]
 window.EntityReference.prototype.hasAttributes [function]
 window.EntityReference.prototype.hasChildNodes [function]
@@ -1248,6 +1256,7 @@ window.Node.prototype.addEventListener [function]
 window.Node.prototype.appendChild [function]
 window.Node.prototype.cloneNode [function]
 window.Node.prototype.compareDocumentPosition [function]
+window.Node.prototype.contains [function]
 window.Node.prototype.dispatchEvent [function]
 window.Node.prototype.hasAttributes [function]
 window.Node.prototype.hasChildNodes [function]
index b2e2576..e324d57 100644 (file)
@@ -26,6 +26,7 @@ window.Attr.prototype.addEventListener [function]
 window.Attr.prototype.appendChild [function]
 window.Attr.prototype.cloneNode [function]
 window.Attr.prototype.compareDocumentPosition [function]
+window.Attr.prototype.contains [function]
 window.Attr.prototype.dispatchEvent [function]
 window.Attr.prototype.hasAttributes [function]
 window.Attr.prototype.hasChildNodes [function]
@@ -177,6 +178,7 @@ window.CDATASection.prototype.appendChild [function]
 window.CDATASection.prototype.appendData [function]
 window.CDATASection.prototype.cloneNode [function]
 window.CDATASection.prototype.compareDocumentPosition [function]
+window.CDATASection.prototype.contains [function]
 window.CDATASection.prototype.deleteData [function]
 window.CDATASection.prototype.dispatchEvent [function]
 window.CDATASection.prototype.hasAttributes [function]
@@ -448,6 +450,7 @@ window.CharacterData.prototype.appendChild [function]
 window.CharacterData.prototype.appendData [function]
 window.CharacterData.prototype.cloneNode [function]
 window.CharacterData.prototype.compareDocumentPosition [function]
+window.CharacterData.prototype.contains [function]
 window.CharacterData.prototype.deleteData [function]
 window.CharacterData.prototype.dispatchEvent [function]
 window.CharacterData.prototype.hasAttributes [function]
@@ -672,6 +675,7 @@ window.Document.prototype.appendChild [function]
 window.Document.prototype.caretRangeFromPoint [function]
 window.Document.prototype.cloneNode [function]
 window.Document.prototype.compareDocumentPosition [function]
+window.Document.prototype.contains [function]
 window.Document.prototype.createAttribute [function]
 window.Document.prototype.createAttributeNS [function]
 window.Document.prototype.createCDATASection [function]
@@ -747,6 +751,7 @@ window.DocumentFragment.prototype.addEventListener [function]
 window.DocumentFragment.prototype.appendChild [function]
 window.DocumentFragment.prototype.cloneNode [function]
 window.DocumentFragment.prototype.compareDocumentPosition [function]
+window.DocumentFragment.prototype.contains [function]
 window.DocumentFragment.prototype.dispatchEvent [function]
 window.DocumentFragment.prototype.hasAttributes [function]
 window.DocumentFragment.prototype.hasChildNodes [function]
@@ -787,6 +792,7 @@ window.DocumentType.prototype.addEventListener [function]
 window.DocumentType.prototype.appendChild [function]
 window.DocumentType.prototype.cloneNode [function]
 window.DocumentType.prototype.compareDocumentPosition [function]
+window.DocumentType.prototype.contains [function]
 window.DocumentType.prototype.dispatchEvent [function]
 window.DocumentType.prototype.hasAttributes [function]
 window.DocumentType.prototype.hasChildNodes [function]
@@ -891,6 +897,7 @@ window.Entity.prototype.addEventListener [function]
 window.Entity.prototype.appendChild [function]
 window.Entity.prototype.cloneNode [function]
 window.Entity.prototype.compareDocumentPosition [function]
+window.Entity.prototype.contains [function]
 window.Entity.prototype.dispatchEvent [function]
 window.Entity.prototype.hasAttributes [function]
 window.Entity.prototype.hasChildNodes [function]
@@ -929,6 +936,7 @@ window.EntityReference.prototype.addEventListener [function]
 window.EntityReference.prototype.appendChild [function]
 window.EntityReference.prototype.cloneNode [function]
 window.EntityReference.prototype.compareDocumentPosition [function]
+window.EntityReference.prototype.contains [function]
 window.EntityReference.prototype.dispatchEvent [function]
 window.EntityReference.prototype.hasAttributes [function]
 window.EntityReference.prototype.hasChildNodes [function]
@@ -1327,6 +1335,7 @@ window.Node.prototype.addEventListener [function]
 window.Node.prototype.appendChild [function]
 window.Node.prototype.cloneNode [function]
 window.Node.prototype.compareDocumentPosition [function]
+window.Node.prototype.contains [function]
 window.Node.prototype.dispatchEvent [function]
 window.Node.prototype.hasAttributes [function]
 window.Node.prototype.hasChildNodes [function]
index 8fd3fb4..8b18a9d 100644 (file)
@@ -1,3 +1,26 @@
+2011-09-09  Erik Arvidsson  <arv@chromium.org>
+
+        Move Element.contains to Node
+        https://bugs.webkit.org/show_bug.cgi?id=67651
+
+        Reviewed by Darin Adler.
+
+        This moves the contains method from Element to Node as in the DOM4 working draft: 
+        http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-node-contains
+
+        This also special cases Document contains to make it O(1) instead of O(depth).
+
+        Tests: fast/dom/Node/contains-method.html
+               perf/document-contains.html
+
+        * bindings/objc/PublicDOMInterfaces.h: Move contains from DOMElement to DOMNode.
+        * dom/Element.idl:
+        * dom/Node.cpp:
+        (WebCore::Node::contains): Added document special case.
+        * dom/Node.idl:
+        * editing/DeleteSelectionCommand.cpp:
+        (WebCore::DeleteSelectionCommand::mergeParagraphs): Added a null check.
+
 2011-09-09  Tim Horton  <timothy_horton@apple.com>
 
         Text rendered with a simple (i.e. 0px blur) shadow inside a transparency layer has a double shadow
index 428ac4a..6721ea0 100644 (file)
 - (BOOL)hasAttributeNS:(NSString *)namespaceURI localName:(NSString *)localName AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER;
 - (void)scrollIntoView:(BOOL)alignWithTop AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER;
 - (void)scrollIntoViewIfNeeded:(BOOL)centerIfNeeded AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER;
-- (BOOL)contains:(DOMElement *)element AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER;
 - (void)scrollByLines:(int)lines AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER;
 - (void)scrollByPages:(int)pages AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER;
 - (void)focus AVAILABLE_IN_WEBKIT_VERSION_4_0;
 - (BOOL)isDefaultNamespace:(NSString *)namespaceURI AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER;
 - (NSString *)lookupNamespaceURI:(NSString *)prefix AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER;
 - (unsigned short)compareDocumentPosition:(DOMNode *)other AVAILABLE_IN_WEBKIT_VERSION_4_0;
+- (BOOL)contains:(DOMNode *)other AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER;
 @end
 
 @interface DOMNodeList : DOMObject WEBKIT_VERSION_1_3
index 9ebb02a..81032e6 100644 (file)
@@ -85,10 +85,6 @@ module core {
         void blur();
         void scrollIntoView(in [Optional] boolean alignWithTop);
 
-        // IE extensions
-
-        boolean contains(in [Optional=CallWithDefaultValue] Element element);
-
         // WebKit extensions
 
         void scrollIntoViewIfNeeded(in [Optional] boolean centerIfNeeded);
index f52cfc1..aca3d8f 100644 (file)
@@ -1338,6 +1338,8 @@ bool Node::contains(const Node* node) const
 {
     if (!node)
         return false;
+    if (document() == this)
+        return node->document() == this && node->inDocument();
     return this == node || node->isDescendantOf(this);
 }
 
index aacef15..8bb3349 100644 (file)
@@ -118,6 +118,9 @@ module core {
 
         unsigned short     compareDocumentPosition(in [Optional=CallWithDefaultValue] Node other);
 
+        // Introduced in DOM4
+        boolean contains(in [Optional=CallWithDefaultValue] Node other);
+
 #if 0
         DOMObject          getFeature(in DOMString feature, 
                                       in DOMString version);
index 038b4a4..99cb5d1 100644 (file)
@@ -605,7 +605,7 @@ void DeleteSelectionCommand::mergeParagraphs()
     // m_downstreamEnd's block has been emptied out by deletion.  There is no content inside of it to
     // move, so just remove it.
     Element* endBlock = static_cast<Element*>(enclosingBlock(m_downstreamEnd.deprecatedNode()));
-    if (!startOfParagraphToMove.deepEquivalent().deprecatedNode() || !endBlock->contains(startOfParagraphToMove.deepEquivalent().deprecatedNode())) {
+    if (!endBlock || !endBlock->contains(startOfParagraphToMove.deepEquivalent().deprecatedNode()) || !startOfParagraphToMove.deepEquivalent().deprecatedNode()) {
         removeNode(enclosingBlock(m_downstreamEnd.deprecatedNode()));
         return;
     }