Implemented {Document,Element}.getElementsByTagName

This commit is contained in:
Bruno de Oliveira Abinader 2014-02-27 13:14:02 -04:00
parent c768097adc
commit d22dbb53ca
4 changed files with 11 additions and 6 deletions

View file

@ -32,6 +32,7 @@ DOMInterfaces = {
'createElement',
'createProcessingInstruction',
'createTextNode',
'getElementsByTagName',
'title',
],
},
@ -43,6 +44,7 @@ DOMInterfaces = {
'attributes',
'getBoundingClientRect',
'getClientRects',
'getElementsByTagName',
'id',
'innerHTML',
'outerHTML',

View file

@ -212,8 +212,8 @@ impl Document {
}
// http://dom.spec.whatwg.org/#dom-document-getelementsbytagname
pub fn GetElementsByTagName(&self, tag: DOMString) -> JS<HTMLCollection> {
self.createHTMLCollection(|elem| elem.get().tag_name == tag)
pub fn GetElementsByTagName(&self, abstract_self: &JS<Document>, tag_name: DOMString) -> JS<HTMLCollection> {
HTMLCollection::by_tag_name(&self.window, &NodeCast::from(abstract_self), tag_name)
}
// http://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid

View file

@ -503,11 +503,10 @@ impl Element {
self.GetAttributeNS(namespace, local_name).is_some()
}
// http://dom.spec.whatwg.org/#dom-element-getelementsbytagname
pub fn GetElementsByTagName(&self, _localname: DOMString) -> JS<HTMLCollection> {
// FIXME: stub - https://github.com/mozilla/servo/issues/1660
pub fn GetElementsByTagName(&self, abstract_self: &JS<Element>, localname: DOMString) -> JS<HTMLCollection> {
let doc = self.node.owner_doc();
HTMLCollection::new(&doc.get().window, ~[])
let doc = doc.get();
HTMLCollection::by_tag_name(&doc.window, &NodeCast::from(abstract_self), localname)
}
// http://dom.spec.whatwg.org/#dom-element-getelementsbytagnamens

View file

@ -46,6 +46,10 @@ impl HTMLCollection {
}
HTMLCollection::new(window, elements)
}
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)
}
}
impl HTMLCollection {