mirror of
https://github.com/servo/servo.git
synced 2025-06-24 09:04:33 +01:00
Implemented {Document,Element}.getElementsByTagNameNS
This commit is contained in:
parent
d22dbb53ca
commit
e1499b610e
6 changed files with 26 additions and 6 deletions
|
@ -33,6 +33,7 @@ DOMInterfaces = {
|
||||||
'createProcessingInstruction',
|
'createProcessingInstruction',
|
||||||
'createTextNode',
|
'createTextNode',
|
||||||
'getElementsByTagName',
|
'getElementsByTagName',
|
||||||
|
'getElementsByTagNameNS',
|
||||||
'title',
|
'title',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -45,6 +46,7 @@ DOMInterfaces = {
|
||||||
'getBoundingClientRect',
|
'getBoundingClientRect',
|
||||||
'getClientRects',
|
'getClientRects',
|
||||||
'getElementsByTagName',
|
'getElementsByTagName',
|
||||||
|
'getElementsByTagNameNS',
|
||||||
'id',
|
'id',
|
||||||
'innerHTML',
|
'innerHTML',
|
||||||
'outerHTML',
|
'outerHTML',
|
||||||
|
|
|
@ -35,7 +35,7 @@ use dom::window::Window;
|
||||||
use html::hubbub_html_parser::build_element_from_tag;
|
use html::hubbub_html_parser::build_element_from_tag;
|
||||||
use hubbub::hubbub::{QuirksMode, NoQuirks, LimitedQuirks, FullQuirks};
|
use hubbub::hubbub::{QuirksMode, NoQuirks, LimitedQuirks, FullQuirks};
|
||||||
use layout_interface::{DocumentDamageLevel, ContentChangedDocumentDamage};
|
use layout_interface::{DocumentDamageLevel, ContentChangedDocumentDamage};
|
||||||
use servo_util::namespace::Null;
|
use servo_util::namespace::{Namespace, Null};
|
||||||
use servo_util::str::DOMString;
|
use servo_util::str::DOMString;
|
||||||
|
|
||||||
use extra::url::{Url, from_str};
|
use extra::url::{Url, from_str};
|
||||||
|
@ -216,6 +216,15 @@ impl Document {
|
||||||
HTMLCollection::by_tag_name(&self.window, &NodeCast::from(abstract_self), tag_name)
|
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
|
// http://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid
|
||||||
pub fn GetElementById(&self, id: DOMString) -> Option<JS<Element>> {
|
pub fn GetElementById(&self, id: DOMString) -> Option<JS<Element>> {
|
||||||
// TODO: "in tree order, within the context object's tree"
|
// TODO: "in tree order, within the context object's tree"
|
||||||
|
|
|
@ -509,11 +509,15 @@ impl Element {
|
||||||
HTMLCollection::by_tag_name(&doc.window, &NodeCast::from(abstract_self), localname)
|
HTMLCollection::by_tag_name(&doc.window, &NodeCast::from(abstract_self), localname)
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://dom.spec.whatwg.org/#dom-element-getelementsbytagnamens
|
pub fn GetElementsByTagNameNS(&self, abstract_self: &JS<Element>, maybe_ns: Option<DOMString>,
|
||||||
pub fn GetElementsByTagNameNS(&self, _namespace: Option<DOMString>, _localname: DOMString) -> Fallible<JS<HTMLCollection>> {
|
localname: DOMString) -> JS<HTMLCollection> {
|
||||||
// FIXME: stub - https://github.com/mozilla/servo/issues/1660
|
|
||||||
let doc = self.node.owner_doc();
|
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
|
// http://dom.spec.whatwg.org/#dom-element-getelementsbyclassname
|
||||||
|
|
|
@ -9,6 +9,7 @@ use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||||
use dom::element::Element;
|
use dom::element::Element;
|
||||||
use dom::node::{Node, NodeHelpers};
|
use dom::node::{Node, NodeHelpers};
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
|
use servo_util::namespace::Namespace;
|
||||||
use servo_util::str::DOMString;
|
use servo_util::str::DOMString;
|
||||||
|
|
||||||
#[deriving(Encodable)]
|
#[deriving(Encodable)]
|
||||||
|
@ -50,6 +51,10 @@ impl HTMLCollection {
|
||||||
pub fn by_tag_name(window: &JS<Window>, root: &JS<Node>, tag_name: DOMString) -> JS<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)
|
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 {
|
impl HTMLCollection {
|
||||||
|
|
|
@ -21,6 +21,7 @@ interface Document : Node {
|
||||||
readonly attribute DocumentType? doctype;
|
readonly attribute DocumentType? doctype;
|
||||||
readonly attribute Element? documentElement;
|
readonly attribute Element? documentElement;
|
||||||
HTMLCollection getElementsByTagName(DOMString localName);
|
HTMLCollection getElementsByTagName(DOMString localName);
|
||||||
|
HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);
|
||||||
Element? getElementById(DOMString elementId);
|
Element? getElementById(DOMString elementId);
|
||||||
|
|
||||||
[Creator, Throws]
|
[Creator, Throws]
|
||||||
|
|
|
@ -51,7 +51,6 @@ interface Element : Node {
|
||||||
boolean hasAttributeNS(DOMString? namespace, DOMString localName);
|
boolean hasAttributeNS(DOMString? namespace, DOMString localName);
|
||||||
|
|
||||||
HTMLCollection getElementsByTagName(DOMString localName);
|
HTMLCollection getElementsByTagName(DOMString localName);
|
||||||
[Throws]
|
|
||||||
HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);
|
HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);
|
||||||
HTMLCollection getElementsByClassName(DOMString classNames);
|
HTMLCollection getElementsByClassName(DOMString classNames);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue