diff options
author | Bruno de Oliveira Abinader <bruno.d@partner.samsung.com> | 2014-03-20 18:36:43 -0400 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno.d@partner.samsung.com> | 2014-03-26 09:11:13 -0400 |
commit | e95aa0febdad07bf8812f4d66cf49883f855c4df (patch) | |
tree | 7c8cccc0e464170361234d780f09e63225fbb9cb /src/components/script/dom | |
parent | 0bc59eb4de31800a84699afc203c46a6eff5fa76 (diff) | |
download | servo-e95aa0febdad07bf8812f4d66cf49883f855c4df.tar.gz servo-e95aa0febdad07bf8812f4d66cf49883f855c4df.zip |
Support live HTMLCollection for Document collections
The following interface methods now return live collections:
Document.{images,embeds,plugins,links,forms,scripts,anchors,applets}
Diffstat (limited to 'src/components/script/dom')
-rw-r--r-- | src/components/script/dom/document.rs | 71 |
1 files changed, 58 insertions, 13 deletions
diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index 622263458d8..0829b08e722 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -20,7 +20,7 @@ use dom::element::{HTMLHtmlElementTypeId, HTMLHeadElementTypeId, HTMLTitleElemen use dom::element::{HTMLBodyElementTypeId, HTMLFrameSetElementTypeId}; use dom::event::Event; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; -use dom::htmlcollection::HTMLCollection; +use dom::htmlcollection::{HTMLCollection, CollectionFilter}; use dom::nodelist::NodeList; use dom::htmlelement::HTMLElement; use dom::htmlheadelement::HTMLHeadElement; @@ -443,12 +443,26 @@ impl Document { 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") + struct ImagesFilter; + impl CollectionFilter for ImagesFilter { + fn filter(&self, elem: &JS<Element>, _root: &JS<Node>) -> bool { + elem.get().tag_name == ~"img" + } + } + let filter = ~ImagesFilter; + HTMLCollection::create_live(&self.window, &NodeCast::from(abstract_self), filter) } 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") + struct EmbedsFilter; + impl CollectionFilter for EmbedsFilter { + fn filter(&self, elem: &JS<Element>, _root: &JS<Node>) -> bool { + elem.get().tag_name == ~"embed" + } + } + let filter = ~EmbedsFilter; + HTMLCollection::create_live(&self.window, &NodeCast::from(abstract_self), filter) } pub fn Plugins(&self, abstract_self: &JS<Document>) -> JS<HTMLCollection> { @@ -458,32 +472,63 @@ impl Document { 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_attribute(Null, "href").is_some() - }) + struct LinksFilter; + impl CollectionFilter for LinksFilter { + fn filter(&self, elem: &JS<Element>, _root: &JS<Node>) -> bool { + (elem.get().tag_name == ~"a" || elem.get().tag_name == ~"area") && + elem.get_attribute(Null, "href").is_some() + } + } + let filter = ~LinksFilter; + HTMLCollection::create_live(&self.window, &NodeCast::from(abstract_self), filter) } 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") + struct FormsFilter; + impl CollectionFilter for FormsFilter { + fn filter(&self, elem: &JS<Element>, _root: &JS<Node>) -> bool { + elem.get().tag_name == ~"form" + } + } + let filter = ~FormsFilter; + HTMLCollection::create_live(&self.window, &NodeCast::from(abstract_self), filter) } 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") + struct ScriptsFilter; + impl CollectionFilter for ScriptsFilter { + fn filter(&self, elem: &JS<Element>, _root: &JS<Node>) -> bool { + elem.get().tag_name == ~"script" + } + } + let filter = ~ScriptsFilter; + HTMLCollection::create_live(&self.window, &NodeCast::from(abstract_self), filter) } 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_attribute(Null, "name").is_some() - }) + struct AnchorsFilter; + impl CollectionFilter for AnchorsFilter { + fn filter(&self, elem: &JS<Element>, _root: &JS<Node>) -> bool { + elem.get().tag_name == ~"a" && elem.get_attribute(Null, "name").is_some() + } + } + let filter = ~AnchorsFilter; + HTMLCollection::create_live(&self.window, &NodeCast::from(abstract_self), filter) } pub fn Applets(&self, abstract_self: &JS<Document>) -> JS<HTMLCollection> { // FIXME: This should be return OBJECT elements containing applets. - HTMLCollection::by_tag_name(&self.window, &NodeCast::from(abstract_self), ~"applet") + struct AppletsFilter; + impl CollectionFilter for AppletsFilter { + fn filter(&self, elem: &JS<Element>, _root: &JS<Node>) -> bool { + elem.get().tag_name == ~"applet" + } + } + let filter = ~AppletsFilter; + HTMLCollection::create_live(&self.window, &NodeCast::from(abstract_self), filter) } pub fn create_collection<T>(&self, callback: |elem: &JS<Node>| -> Option<JS<T>>) -> ~[JS<T>] { |