Implemented {Document,Element}.getElementsByTagNameNS

This commit is contained in:
Bruno de Oliveira Abinader 2014-02-27 13:18:03 -04:00
parent d22dbb53ca
commit e1499b610e
6 changed files with 26 additions and 6 deletions

View file

@ -33,6 +33,7 @@ DOMInterfaces = {
'createProcessingInstruction',
'createTextNode',
'getElementsByTagName',
'getElementsByTagNameNS',
'title',
],
},
@ -45,6 +46,7 @@ DOMInterfaces = {
'getBoundingClientRect',
'getClientRects',
'getElementsByTagName',
'getElementsByTagNameNS',
'id',
'innerHTML',
'outerHTML',

View file

@ -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<Document>, maybe_ns: Option<DOMString>, tag_name: DOMString) -> JS<HTMLCollection> {
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<JS<Element>> {
// TODO: "in tree order, within the context object's tree"

View file

@ -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<DOMString>, _localname: DOMString) -> Fallible<JS<HTMLCollection>> {
// FIXME: stub - https://github.com/mozilla/servo/issues/1660
pub fn GetElementsByTagNameNS(&self, abstract_self: &JS<Element>, maybe_ns: Option<DOMString>,
localname: DOMString) -> JS<HTMLCollection> {
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

View file

@ -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<Window>, root: &JS<Node>, tag_name: DOMString) -> JS<HTMLCollection> {
HTMLCollection::create(window, root, |elem| elem.get().tag_name == tag_name)
}
pub fn by_tag_name_ns(window: &JS<Window>, root: &JS<Node>, tag_name: DOMString, namespace: Namespace) -> JS<HTMLCollection> {
HTMLCollection::create(window, root, |elem| elem.get().namespace == namespace && elem.get().tag_name == tag_name)
}
}
impl HTMLCollection {

View file

@ -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]

View file

@ -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);
};