aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbors-servo <release+servo@mozilla.com>2014-02-09 10:04:50 -0500
committerbors-servo <release+servo@mozilla.com>2014-02-09 10:04:50 -0500
commitdda62cc97fa2304aeac0cca5404241aeae7048d9 (patch)
treec87fcbd374a0507ce1f09293cd460df7a2906731 /src
parent9305a95b68907c91a98a4cdd817f980c9f7f7e1f (diff)
parent99b3b144d4cd3935ff3f90e0f32caf99a3f93cff (diff)
downloadservo-dda62cc97fa2304aeac0cca5404241aeae7048d9.tar.gz
servo-dda62cc97fa2304aeac0cca5404241aeae7048d9.zip
auto merge of #1648 : brunoabinader/servo/node-contains, r=Ms2ger
Spec: http://dom.spec.whatwg.org/#dom-node-contains Closes #1647.
Diffstat (limited to 'src')
-rw-r--r--src/components/script/dom/bindings/codegen/Bindings.conf3
-rw-r--r--src/components/script/dom/node.rs7
-rw-r--r--src/components/script/dom/webidls/Node.webidl2
-rw-r--r--src/test/html/content/test_node_contains.html25
4 files changed, 33 insertions, 4 deletions
diff --git a/src/components/script/dom/bindings/codegen/Bindings.conf b/src/components/script/dom/bindings/codegen/Bindings.conf
index b9fd8d9c1d8..f99bbf890b0 100644
--- a/src/components/script/dom/bindings/codegen/Bindings.conf
+++ b/src/components/script/dom/bindings/codegen/Bindings.conf
@@ -323,7 +323,8 @@ DOMInterfaces = {
'nodeValue',
'removeChild',
'textContent',
- 'childNodes'
+ 'childNodes',
+ 'contains',
]
},
diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs
index 6af9bff6331..8857e503b64 100644
--- a/src/components/script/dom/node.rs
+++ b/src/components/script/dom/node.rs
@@ -1538,8 +1538,11 @@ impl Node {
0
}
- pub fn Contains(&self, _other: Option<AbstractNode>) -> bool {
- false
+ pub fn Contains(&self, abstract_self: AbstractNode, maybe_other: Option<AbstractNode>) -> bool {
+ match maybe_other {
+ None => false,
+ Some(other) => abstract_self.is_inclusive_ancestor_of(other)
+ }
}
pub fn LookupPrefix(&self, _prefix: Option<DOMString>) -> Option<DOMString> {
diff --git a/src/components/script/dom/webidls/Node.webidl b/src/components/script/dom/webidls/Node.webidl
index 1a9d9d53bb3..ba48fd94e11 100644
--- a/src/components/script/dom/webidls/Node.webidl
+++ b/src/components/script/dom/webidls/Node.webidl
@@ -78,7 +78,7 @@ interface Node : EventTarget {
const unsigned short DOCUMENT_POSITION_CONTAINED_BY = 0x10;
const unsigned short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20; // historical
unsigned short compareDocumentPosition(Node other);
- //boolean contains(Node? other); //XXXjdm we don't deal well with Node? parameters
+ boolean contains(Node? other);
DOMString? lookupPrefix(DOMString? namespace);
DOMString? lookupNamespaceURI(DOMString? prefix);
diff --git a/src/test/html/content/test_node_contains.html b/src/test/html/content/test_node_contains.html
new file mode 100644
index 00000000000..400b407b82d
--- /dev/null
+++ b/src/test/html/content/test_node_contains.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <script src="harness.js"></script>
+ <script>
+ // test1: Node.contains
+ {
+ var parent = document.createElement("div");
+ var child = document.createElement("div");
+ var child_of_child = document.createElement("div");
+ var other = document.createElement("div");
+
+ child.appendChild(child_of_child);
+ parent.appendChild(child);
+
+ is(parent.contains(parent), true, "test1-0, Node.contains");
+ is(parent.contains(child), true, "test1-1, Node.contains");
+ is(parent.contains(child_of_child), true, "test1-2, Node.contains");
+ is(parent.contains(other), false, "test1-3, Node.contains");
+ }
+
+ finish();
+ </script>
+ </head>
+</html>