mirror of
https://github.com/servo/servo.git
synced 2025-06-24 17:14:33 +01:00
auto merge of #940 : jdm/servo/imagefix, r=metajack
This commit is contained in:
commit
bcc6c52507
5 changed files with 60 additions and 36 deletions
|
@ -166,10 +166,18 @@ impl<'self> Element {
|
|||
|
||||
//XXXjdm We really need something like a vtable so we can call AfterSetAttr.
|
||||
// This hardcoding is awful.
|
||||
if abstract_self.is_iframe_element() {
|
||||
do abstract_self.with_mut_iframe_element |iframe| {
|
||||
iframe.AfterSetAttr(raw_name, raw_value);
|
||||
match abstract_self.type_id() {
|
||||
ElementNodeTypeId(HTMLImageElementTypeId) => {
|
||||
do abstract_self.with_mut_image_element |image| {
|
||||
image.AfterSetAttr(raw_name, raw_value);
|
||||
}
|
||||
}
|
||||
ElementNodeTypeId(HTMLIframeElementTypeId) => {
|
||||
do abstract_self.with_mut_iframe_element |iframe| {
|
||||
iframe.AfterSetAttr(raw_name, raw_value);
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
|
||||
match self.parent.owner_doc {
|
||||
|
|
|
@ -9,6 +9,7 @@ use extra::url::Url;
|
|||
use gfx::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::make_url;
|
||||
|
||||
pub struct HTMLImageElement {
|
||||
|
@ -19,36 +20,37 @@ pub struct HTMLImageElement {
|
|||
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) {
|
||||
pub fn update_image(&mut self, image_cache: ImageCacheTask, url: Option<Url>) {
|
||||
let elem = &mut self.parent.parent;
|
||||
let src_opt = elem.get_attr("src").map(|x| x.to_str());
|
||||
let node = &mut elem.parent;
|
||||
match node.owner_doc {
|
||||
Some(doc) => {
|
||||
match doc.with_base(|doc| doc.window) {
|
||||
Some(window) => {
|
||||
match src_opt {
|
||||
None => {}
|
||||
Some(src) => {
|
||||
let page = window.page;
|
||||
let img_url = make_url(src,
|
||||
(*page).url
|
||||
.map(|&(ref url, _)| url.clone()));
|
||||
self.image = Some(img_url.clone());
|
||||
match src_opt {
|
||||
None => {}
|
||||
Some(src) => {
|
||||
let img_url = make_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
|
||||
// <noscript> tag.
|
||||
window.image_cache_task.send(image_cache_task::Prefetch(img_url));
|
||||
}
|
||||
}
|
||||
// inform the image cache to load this, but don't store a
|
||||
// handle.
|
||||
//
|
||||
// TODO (Issue #84): don't prefetch if we are within a
|
||||
// <noscript> tag.
|
||||
image_cache.send(image_cache_task::Prefetch(img_url));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn AfterSetAttr(&mut self, name: &DOMString, _value: &DOMString) {
|
||||
let name = name.to_str();
|
||||
if "src" == name {
|
||||
let doc = self.parent.parent.parent.owner_doc;
|
||||
for doc in doc.iter() {
|
||||
do doc.with_base |doc| {
|
||||
for window in doc.window.iter() {
|
||||
let url = window.page.url.map(|&(ref url, _)| url.clone());
|
||||
self.update_image(window.image_cache_task.clone(), url);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,13 +69,10 @@ impl HTMLImageElement {
|
|||
abstract_self: AbstractNode<ScriptView>,
|
||||
src: &DOMString,
|
||||
_rv: &mut ErrorResult) {
|
||||
{
|
||||
let node = &mut self.parent.parent;
|
||||
node.set_attr(abstract_self,
|
||||
&str(~"src"),
|
||||
&str(src.to_str()));
|
||||
}
|
||||
self.update_image();
|
||||
let node = &mut self.parent.parent;
|
||||
node.set_attr(abstract_self,
|
||||
&str(~"src"),
|
||||
&str(src.to_str()));
|
||||
}
|
||||
|
||||
pub fn CrossOrigin(&self) -> DOMString {
|
||||
|
|
|
@ -24,6 +24,7 @@ use std::task;
|
|||
use std::from_str::FromStr;
|
||||
use hubbub::hubbub;
|
||||
use servo_msg::constellation_msg::{ConstellationChan, SubpageId};
|
||||
use servo_net::image_cache_task::ImageCacheTask;
|
||||
use servo_net::resource_task::{Done, Load, Payload, ResourceTask};
|
||||
use servo_util::tree::TreeNodeRef;
|
||||
use servo_util::url::make_url;
|
||||
|
@ -300,6 +301,7 @@ pub fn build_element_from_tag(cx: *JSContext, tag: &str) -> AbstractNode<ScriptV
|
|||
pub fn parse_html(cx: *JSContext,
|
||||
url: Url,
|
||||
resource_task: ResourceTask,
|
||||
image_cache_task: ImageCacheTask,
|
||||
next_subpage_id: SubpageId,
|
||||
constellation_chan: ConstellationChan) -> HtmlParserResult {
|
||||
debug!("Hubbub: parsing %?", url);
|
||||
|
@ -431,9 +433,11 @@ pub fn parse_html(cx: *JSContext,
|
|||
}
|
||||
}
|
||||
|
||||
//FIXME: This should be taken care of by set_attr, but we don't have
|
||||
// access to a window so HTMLImageElement::AfterSetAttr bails.
|
||||
ElementNodeTypeId(HTMLImageElementTypeId) => {
|
||||
do node.with_mut_image_element |image_element| {
|
||||
image_element.update_image();
|
||||
image_element.update_image(image_cache_task.clone(), Some(url2.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -649,6 +649,7 @@ impl ScriptTask {
|
|||
let html_parsing_result = hubbub_html_parser::parse_html(cx.ptr,
|
||||
url.clone(),
|
||||
self.resource_task.clone(),
|
||||
self.image_cache_task.clone(),
|
||||
page.next_subpage_id.clone(),
|
||||
self.constellation_chan.clone());
|
||||
|
||||
|
|
|
@ -12,6 +12,18 @@ function is(a, b) {
|
|||
f(a + " == " + b);
|
||||
}
|
||||
|
||||
var _test_complete = false;
|
||||
var _test_timeout = 10000; //10 seconds
|
||||
function finish() {
|
||||
_test_complete = true;
|
||||
window.close();
|
||||
}
|
||||
}
|
||||
|
||||
function _test_timed_out() {
|
||||
if (!_test_complete) {
|
||||
_fail('test timed out (' + _test_timeout/1000 + 's)');
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(_test_timed_out, _test_timeout);
|
Loading…
Add table
Add a link
Reference in a new issue