diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index d6165b7b85e..5dbd8b1194b 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -431,6 +431,44 @@ impl Document { }) } + pub fn Images(&self) -> JS { + self.createHTMLCollection(|elem| "img" == elem.tag_name) + } + + pub fn Embeds(&self) -> JS { + self.createHTMLCollection(|elem| "embed" == elem.tag_name) + } + + pub fn Plugins(&self) -> JS { + self.Embeds() + } + + pub fn Links(&self) -> JS { + self.createHTMLCollection(|elem| { + ("a" == elem.tag_name || "area" == elem.tag_name) && + elem.get_attribute(Null, "href").is_some() + }) + } + + pub fn Forms(&self) -> JS { + self.createHTMLCollection(|elem| "form" == elem.tag_name) + } + + pub fn Scripts(&self) -> JS { + self.createHTMLCollection(|elem| "script" == elem.tag_name) + } + + pub fn Anchors(&self) -> JS { + self.createHTMLCollection(|elem| { + "a" == elem.tag_name && elem.get_attribute(Null, "name").is_some() + }) + } + + pub fn Applets(&self) -> JS { + // FIXME: This should be return OBJECT elements containing applets. + self.createHTMLCollection(|elem| "applet" == elem.tag_name) + } + pub fn createHTMLCollection(&self, callback: |elem: &Element| -> bool) -> JS { let mut elements = ~[]; match self.GetDocumentElement() { diff --git a/src/components/script/dom/htmldocument.rs b/src/components/script/dom/htmldocument.rs index 7b967d68bea..64bed6c211c 100644 --- a/src/components/script/dom/htmldocument.rs +++ b/src/components/script/dom/htmldocument.rs @@ -8,10 +8,8 @@ use dom::bindings::js::JS; use dom::bindings::utils::{Reflectable, Reflector}; use dom::document::{Document, HTML, HTMLDocumentTypeId}; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; -use dom::htmlcollection::HTMLCollection; use dom::node::DocumentNodeTypeId; use dom::window::Window; -use servo_util::namespace::Null; use extra::url::Url; @@ -42,46 +40,6 @@ impl HTMLDocument { } } -impl HTMLDocument { - pub fn Images(&self) -> JS { - self.parent.createHTMLCollection(|elem| "img" == elem.tag_name) - } - - pub fn Embeds(&self) -> JS { - self.parent.createHTMLCollection(|elem| "embed" == elem.tag_name) - } - - pub fn Plugins(&self) -> JS { - self.Embeds() - } - - pub fn Links(&self) -> JS { - self.parent.createHTMLCollection(|elem| { - ("a" == elem.tag_name || "area" == elem.tag_name) && - elem.get_attribute(Null, "href").is_some() - }) - } - - pub fn Forms(&self) -> JS { - self.parent.createHTMLCollection(|elem| "form" == elem.tag_name) - } - - pub fn Scripts(&self) -> JS { - self.parent.createHTMLCollection(|elem| "script" == elem.tag_name) - } - - pub fn Anchors(&self) -> JS { - self.parent.createHTMLCollection(|elem| { - "a" == elem.tag_name && elem.get_attribute(Null, "name").is_some() - }) - } - - pub fn Applets(&self) -> JS { - // FIXME: This should be return OBJECT elements containing applets. - self.parent.createHTMLCollection(|elem| "applet" == elem.tag_name) - } -} - impl Reflectable for HTMLDocument { fn reflector<'a>(&'a self) -> &'a Reflector { self.parent.reflector() diff --git a/src/components/script/dom/webidls/Document.webidl b/src/components/script/dom/webidls/Document.webidl index feb312c559d..daa91f540fb 100644 --- a/src/components/script/dom/webidls/Document.webidl +++ b/src/components/script/dom/webidls/Document.webidl @@ -45,4 +45,13 @@ partial interface Document { attribute HTMLElement? body; readonly attribute HTMLHeadElement? head; /*NodeList*/ HTMLCollection getElementsByName(DOMString elementName); + + readonly attribute HTMLCollection images; + readonly attribute HTMLCollection embeds; + readonly attribute HTMLCollection plugins; + readonly attribute HTMLCollection links; + readonly attribute HTMLCollection forms; + readonly attribute HTMLCollection scripts; + readonly attribute HTMLCollection anchors; + readonly attribute HTMLCollection applets; }; diff --git a/src/components/script/dom/webidls/HTMLDocument.webidl b/src/components/script/dom/webidls/HTMLDocument.webidl index b899a46678f..464d771df62 100644 --- a/src/components/script/dom/webidls/HTMLDocument.webidl +++ b/src/components/script/dom/webidls/HTMLDocument.webidl @@ -5,13 +5,4 @@ */ /* http://www.whatwg.org/specs/web-apps/current-work/#the-document-object */ -interface HTMLDocument : Document { - readonly attribute HTMLCollection images; - readonly attribute HTMLCollection embeds; - readonly attribute HTMLCollection plugins; - readonly attribute HTMLCollection links; - readonly attribute HTMLCollection forms; - readonly attribute HTMLCollection scripts; - readonly attribute HTMLCollection anchors; - readonly attribute HTMLCollection applets; -}; +interface HTMLDocument : Document {};