diff options
Diffstat (limited to 'src/components/script/dom/htmldocument.rs')
-rw-r--r-- | src/components/script/dom/htmldocument.rs | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/src/components/script/dom/htmldocument.rs b/src/components/script/dom/htmldocument.rs index 8297fd3e90c..7b967d68bea 100644 --- a/src/components/script/dom/htmldocument.rs +++ b/src/components/script/dom/htmldocument.rs @@ -3,67 +3,80 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::HTMLDocumentBinding; -use dom::bindings::utils::{Reflectable, Reflector, Traceable}; -use dom::document::{AbstractDocument, Document, HTML}; +use dom::bindings::codegen::InheritTypes::HTMLDocumentDerived; +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; -use js::jsapi::JSTracer; +#[deriving(Encodable)] pub struct HTMLDocument { parent: Document } +impl HTMLDocumentDerived for EventTarget { + fn is_htmldocument(&self) -> bool { + match self.type_id { + NodeTargetTypeId(DocumentNodeTypeId(HTMLDocumentTypeId)) => true, + _ => false + } + } +} + impl HTMLDocument { - pub fn new_inherited(window: @mut Window, url: Option<Url>) -> HTMLDocument { + pub fn new_inherited(window: JS<Window>, url: Option<Url>) -> HTMLDocument { HTMLDocument { parent: Document::new_inherited(window, url, HTML, None) } } - pub fn new(window: @mut Window, url: Option<Url>) -> AbstractDocument { - let document = HTMLDocument::new_inherited(window, url); - Document::reflect_document(@mut document, window, HTMLDocumentBinding::Wrap) + pub fn new(window: &JS<Window>, url: Option<Url>) -> JS<HTMLDocument> { + let document = HTMLDocument::new_inherited(window.clone(), url); + Document::reflect_document(~document, window, HTMLDocumentBinding::Wrap) } } impl HTMLDocument { - pub fn Images(&self) -> @mut HTMLCollection { + pub fn Images(&self) -> JS<HTMLCollection> { self.parent.createHTMLCollection(|elem| "img" == elem.tag_name) } - pub fn Embeds(&self) -> @mut HTMLCollection { + pub fn Embeds(&self) -> JS<HTMLCollection> { self.parent.createHTMLCollection(|elem| "embed" == elem.tag_name) } - pub fn Plugins(&self) -> @mut HTMLCollection { + pub fn Plugins(&self) -> JS<HTMLCollection> { self.Embeds() } - pub fn Links(&self) -> @mut HTMLCollection { + pub fn Links(&self) -> JS<HTMLCollection> { self.parent.createHTMLCollection(|elem| { ("a" == elem.tag_name || "area" == elem.tag_name) && elem.get_attribute(Null, "href").is_some() }) } - pub fn Forms(&self) -> @mut HTMLCollection { + pub fn Forms(&self) -> JS<HTMLCollection> { self.parent.createHTMLCollection(|elem| "form" == elem.tag_name) } - pub fn Scripts(&self) -> @mut HTMLCollection { + pub fn Scripts(&self) -> JS<HTMLCollection> { self.parent.createHTMLCollection(|elem| "script" == elem.tag_name) } - pub fn Anchors(&self) -> @mut HTMLCollection { + pub fn Anchors(&self) -> JS<HTMLCollection> { self.parent.createHTMLCollection(|elem| { "a" == elem.tag_name && elem.get_attribute(Null, "name").is_some() }) } - pub fn Applets(&self) -> @mut HTMLCollection { + pub fn Applets(&self) -> JS<HTMLCollection> { // FIXME: This should be return OBJECT elements containing applets. self.parent.createHTMLCollection(|elem| "applet" == elem.tag_name) } @@ -78,9 +91,3 @@ impl Reflectable for HTMLDocument { self.parent.mut_reflector() } } - -impl Traceable for HTMLDocument { - fn trace(&self, tracer: *mut JSTracer) { - self.parent.trace(tracer); - } -} |