mirror of
https://github.com/servo/servo.git
synced 2025-06-23 16:44:33 +01:00
Replaced Document::createHTMLDocument in favor of HTMLCollection helpers
This commit is contained in:
parent
d010861b75
commit
38ba71ceb1
2 changed files with 32 additions and 33 deletions
|
@ -26,15 +26,23 @@ DOMInterfaces = {
|
|||
'Console': {},
|
||||
'Document': {
|
||||
'needsAbstract': [
|
||||
'anchors',
|
||||
'applets',
|
||||
'body',
|
||||
'createComment',
|
||||
'createDocumentFragment',
|
||||
'createElement',
|
||||
'createProcessingInstruction',
|
||||
'createTextNode',
|
||||
'embeds',
|
||||
'forms',
|
||||
'getElementsByClassName',
|
||||
'getElementsByTagName',
|
||||
'getElementsByTagNameNS',
|
||||
'images',
|
||||
'links',
|
||||
'plugins',
|
||||
'scripts',
|
||||
'title',
|
||||
],
|
||||
},
|
||||
|
|
|
@ -431,43 +431,49 @@ impl Document {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn Images(&self) -> JS<HTMLCollection> {
|
||||
self.createHTMLCollection(|elem| "img" == elem.get().tag_name)
|
||||
pub fn Images(&self, abstract_self: &JS<Document>) -> JS<HTMLCollection> {
|
||||
// FIXME: https://github.com/mozilla/servo/issues/1847
|
||||
HTMLCollection::by_tag_name(&self.window, &NodeCast::from(abstract_self), ~"img")
|
||||
}
|
||||
|
||||
pub fn Embeds(&self) -> JS<HTMLCollection> {
|
||||
self.createHTMLCollection(|elem| "embed" == elem.get().tag_name)
|
||||
pub fn Embeds(&self, abstract_self: &JS<Document>) -> JS<HTMLCollection> {
|
||||
// FIXME: https://github.com/mozilla/servo/issues/1847
|
||||
HTMLCollection::by_tag_name(&self.window, &NodeCast::from(abstract_self), ~"embed")
|
||||
}
|
||||
|
||||
pub fn Plugins(&self) -> JS<HTMLCollection> {
|
||||
self.Embeds()
|
||||
pub fn Plugins(&self, abstract_self: &JS<Document>) -> JS<HTMLCollection> {
|
||||
// FIXME: https://github.com/mozilla/servo/issues/1847
|
||||
self.Embeds(abstract_self)
|
||||
}
|
||||
|
||||
pub fn Links(&self) -> JS<HTMLCollection> {
|
||||
self.createHTMLCollection(|elem| {
|
||||
pub fn Links(&self, abstract_self: &JS<Document>) -> JS<HTMLCollection> {
|
||||
// FIXME: https://github.com/mozilla/servo/issues/1847
|
||||
HTMLCollection::create(&self.window, &NodeCast::from(abstract_self), |elem| {
|
||||
("a" == elem.get().tag_name || "area" == elem.get().tag_name) &&
|
||||
elem.get().get_attribute(Null, "href").is_some()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn Forms(&self) -> JS<HTMLCollection> {
|
||||
self.createHTMLCollection(|elem| "form" == elem.get().tag_name)
|
||||
pub fn Forms(&self, abstract_self: &JS<Document>) -> JS<HTMLCollection> {
|
||||
// FIXME: https://github.com/mozilla/servo/issues/1847
|
||||
HTMLCollection::by_tag_name(&self.window, &NodeCast::from(abstract_self), ~"form")
|
||||
}
|
||||
|
||||
pub fn Scripts(&self) -> JS<HTMLCollection> {
|
||||
self.createHTMLCollection(|elem| "script" == elem.get().tag_name)
|
||||
pub fn Scripts(&self, abstract_self: &JS<Document>) -> JS<HTMLCollection> {
|
||||
// FIXME: https://github.com/mozilla/servo/issues/1847
|
||||
HTMLCollection::by_tag_name(&self.window, &NodeCast::from(abstract_self), ~"script")
|
||||
}
|
||||
|
||||
pub fn Anchors(&self) -> JS<HTMLCollection> {
|
||||
self.createHTMLCollection(|elem| {
|
||||
"a" == elem.get().tag_name &&
|
||||
elem.get().get_attribute(Null, "name").is_some()
|
||||
pub fn Anchors(&self, abstract_self: &JS<Document>) -> JS<HTMLCollection> {
|
||||
// FIXME: https://github.com/mozilla/servo/issues/1847
|
||||
HTMLCollection::create(&self.window, &NodeCast::from(abstract_self), |elem| {
|
||||
"a" == elem.get().tag_name && elem.get().get_attribute(Null, "name").is_some()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn Applets(&self) -> JS<HTMLCollection> {
|
||||
pub fn Applets(&self, abstract_self: &JS<Document>) -> JS<HTMLCollection> {
|
||||
// FIXME: This should be return OBJECT elements containing applets.
|
||||
self.createHTMLCollection(|elem| "applet" == elem.get().tag_name)
|
||||
HTMLCollection::by_tag_name(&self.window, &NodeCast::from(abstract_self), ~"applet")
|
||||
}
|
||||
|
||||
pub fn create_collection<T>(&self, callback: |elem: &JS<Node>| -> Option<JS<T>>) -> ~[JS<T>] {
|
||||
|
@ -487,21 +493,6 @@ impl Document {
|
|||
nodes
|
||||
}
|
||||
|
||||
pub fn createHTMLCollection(&self, callback: |elem: &JS<Element>| -> bool) -> JS<HTMLCollection> {
|
||||
HTMLCollection::new(&self.window, self.create_collection(|node| {
|
||||
if !node.is_element() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let element: JS<Element> = ElementCast::to(node);
|
||||
if !callback(&element) {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(element)
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn createNodeList(&self, callback: |node: &JS<Node>| -> bool) -> JS<NodeList> {
|
||||
NodeList::new_simple_list(&self.window, self.create_collection(|node| {
|
||||
if !callback(node) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue