/* 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::HTMLImageElementBinding; use dom::bindings::utils::ErrorResult; use dom::document::AbstractDocument; use dom::element::HTMLImageElementTypeId; use dom::htmlelement::HTMLElement; use dom::node::{AbstractNode, Node}; use extra::url::Url; use servo_util::geometry::to_px; use layout_interface::{ContentBoxQuery, ContentBoxResponse}; use servo_net::image_cache_task; use servo_net::image_cache_task::ImageCacheTask; use servo_util::url::parse_url; use servo_util::namespace::Null; use servo_util::str::DOMString; pub struct HTMLImageElement { htmlelement: HTMLElement, image: Option, } impl HTMLImageElement { pub fn new_inherited(localName: DOMString, document: AbstractDocument) -> HTMLImageElement { HTMLImageElement { htmlelement: HTMLElement::new_inherited(HTMLImageElementTypeId, localName, document), image: None, } } pub fn new(localName: DOMString, document: AbstractDocument) -> AbstractNode { let element = HTMLImageElement::new_inherited(localName, document); Node::reflect_node(@mut element, document, HTMLImageElementBinding::Wrap) } } impl 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. pub fn update_image(&mut self, image_cache: ImageCacheTask, url: Option) { let elem = &mut self.htmlelement.element; let src_opt = elem.get_attribute(Null, "src").map(|x| x.Value()); match src_opt { 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 //