/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::HTMLImageElementBinding; use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast, HTMLElementCast, HTMLImageElementDerived}; use dom::bindings::error::ErrorResult; use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::trace::Untraceable; use dom::document::Document; use dom::element::{Element, HTMLImageElementTypeId}; use dom::element::AttributeHandlers; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::htmlelement::HTMLElement; use dom::node::{Node, ElementNodeTypeId, NodeHelpers, window_from_node}; use dom::virtualmethods::VirtualMethods; use servo_util::geometry::to_px; use servo_net::image_cache_task; use servo_util::url::parse_url; use servo_util::str::DOMString; use url::Url; #[deriving(Encodable)] pub struct HTMLImageElement { pub htmlelement: HTMLElement, image: Untraceable>, } impl HTMLImageElementDerived for EventTarget { fn is_htmlimageelement(&self) -> bool { self.type_id == NodeTargetTypeId(ElementNodeTypeId(HTMLImageElementTypeId)) } } trait PrivateHTMLImageElementHelpers { fn update_image(&mut self, value: Option, url: Option); } impl<'a> PrivateHTMLImageElementHelpers for JSRef<'a, HTMLImageElement> { /// Makes the local `image` member match the status of the `src` attribute and starts /// prefetching the image. This method must be called after `src` is changed. fn update_image(&mut self, value: Option, url: Option) { let self_alias = self.clone(); let node_alias: &JSRef = NodeCast::from_ref(&self_alias); let document = node_alias.owner_doc().root(); let window = document.deref().window.root(); let image_cache = &window.image_cache_task; match value { None => { *self.image = None; } Some(src) => { let img_url = parse_url(src, url); *self.image = Some(img_url.clone()); // inform the image cache to load this, but don't store a // handle. // // TODO (Issue #84): don't prefetch if we are within a //