diff --git a/src/components/script/dom/bindings/codegen/Bindings.conf b/src/components/script/dom/bindings/codegen/Bindings.conf index 36dbf48a6e8..ffa19b30198 100644 --- a/src/components/script/dom/bindings/codegen/Bindings.conf +++ b/src/components/script/dom/bindings/codegen/Bindings.conf @@ -33,6 +33,7 @@ DOMInterfaces = { 'createProcessingInstruction', 'createTextNode', 'getElementsByTagName', + 'getElementsByTagNameNS', 'title', ], }, @@ -45,6 +46,7 @@ DOMInterfaces = { 'getBoundingClientRect', 'getClientRects', 'getElementsByTagName', + 'getElementsByTagNameNS', 'id', 'innerHTML', 'outerHTML', diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index 9190e36b0dd..fba0d4b506f 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -35,7 +35,7 @@ use dom::window::Window; use html::hubbub_html_parser::build_element_from_tag; use hubbub::hubbub::{QuirksMode, NoQuirks, LimitedQuirks, FullQuirks}; use layout_interface::{DocumentDamageLevel, ContentChangedDocumentDamage}; -use servo_util::namespace::Null; +use servo_util::namespace::{Namespace, Null}; use servo_util::str::DOMString; use extra::url::{Url, from_str}; @@ -216,6 +216,15 @@ impl Document { HTMLCollection::by_tag_name(&self.window, &NodeCast::from(abstract_self), tag_name) } + // http://dom.spec.whatwg.org/#dom-document-getelementsbytagnamens + pub fn GetElementsByTagNameNS(&self, abstract_self: &JS, maybe_ns: Option, tag_name: DOMString) -> JS { + let namespace = match maybe_ns { + Some(namespace) => Namespace::from_str(namespace), + None => Null + }; + HTMLCollection::by_tag_name_ns(&self.window, &NodeCast::from(abstract_self), tag_name, namespace) + } + // http://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid pub fn GetElementById(&self, id: DOMString) -> Option> { // TODO: "in tree order, within the context object's tree" diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index 108d9aed19e..a004126cc6d 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -509,11 +509,15 @@ impl Element { HTMLCollection::by_tag_name(&doc.window, &NodeCast::from(abstract_self), localname) } - // http://dom.spec.whatwg.org/#dom-element-getelementsbytagnamens - pub fn GetElementsByTagNameNS(&self, _namespace: Option, _localname: DOMString) -> Fallible> { - // FIXME: stub - https://github.com/mozilla/servo/issues/1660 + pub fn GetElementsByTagNameNS(&self, abstract_self: &JS, maybe_ns: Option, + localname: DOMString) -> JS { let doc = self.node.owner_doc(); - Ok(HTMLCollection::new(&doc.get().window, ~[])) + let doc = doc.get(); + let namespace = match maybe_ns { + Some(namespace) => Namespace::from_str(namespace), + None => Null + }; + HTMLCollection::by_tag_name_ns(&doc.window, &NodeCast::from(abstract_self), localname, namespace) } // http://dom.spec.whatwg.org/#dom-element-getelementsbyclassname diff --git a/src/components/script/dom/htmlcollection.rs b/src/components/script/dom/htmlcollection.rs index b2a8ca0aa02..4d18e9734f4 100644 --- a/src/components/script/dom/htmlcollection.rs +++ b/src/components/script/dom/htmlcollection.rs @@ -9,6 +9,7 @@ use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::element::Element; use dom::node::{Node, NodeHelpers}; use dom::window::Window; +use servo_util::namespace::Namespace; use servo_util::str::DOMString; #[deriving(Encodable)] @@ -50,6 +51,10 @@ impl HTMLCollection { pub fn by_tag_name(window: &JS, root: &JS, tag_name: DOMString) -> JS { HTMLCollection::create(window, root, |elem| elem.get().tag_name == tag_name) } + + pub fn by_tag_name_ns(window: &JS, root: &JS, tag_name: DOMString, namespace: Namespace) -> JS { + HTMLCollection::create(window, root, |elem| elem.get().namespace == namespace && elem.get().tag_name == tag_name) + } } impl HTMLCollection { diff --git a/src/components/script/dom/webidls/Document.webidl b/src/components/script/dom/webidls/Document.webidl index 11e92a0930e..9dc92b1520f 100644 --- a/src/components/script/dom/webidls/Document.webidl +++ b/src/components/script/dom/webidls/Document.webidl @@ -21,6 +21,7 @@ interface Document : Node { readonly attribute DocumentType? doctype; readonly attribute Element? documentElement; HTMLCollection getElementsByTagName(DOMString localName); + HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName); Element? getElementById(DOMString elementId); [Creator, Throws] diff --git a/src/components/script/dom/webidls/Element.webidl b/src/components/script/dom/webidls/Element.webidl index 6c393f00067..e26c9415d4a 100644 --- a/src/components/script/dom/webidls/Element.webidl +++ b/src/components/script/dom/webidls/Element.webidl @@ -51,7 +51,6 @@ interface Element : Node { boolean hasAttributeNS(DOMString? namespace, DOMString localName); HTMLCollection getElementsByTagName(DOMString localName); - [Throws] HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName); HTMLCollection getElementsByClassName(DOMString classNames); };