mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Use task! for step 9 of updating the image data
This commit is contained in:
parent
fba54c7735
commit
407af95db5
1 changed files with 58 additions and 66 deletions
|
@ -403,37 +403,6 @@ impl HTMLImageElement {
|
||||||
self.update_source_set().first().cloned()
|
self.update_source_set().first().cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Step 9.2 of https://html.spec.whatwg.org/multipage/#update-the-image-data
|
|
||||||
fn set_current_request_url_to_none_fire_error(&self) {
|
|
||||||
struct SetUrlToNoneTask {
|
|
||||||
img: Trusted<HTMLImageElement>,
|
|
||||||
}
|
|
||||||
impl Task for SetUrlToNoneTask {
|
|
||||||
fn run(self: Box<Self>) {
|
|
||||||
let img = self.img.root();
|
|
||||||
{
|
|
||||||
let mut current_request = img.current_request.borrow_mut();
|
|
||||||
current_request.source_url = None;
|
|
||||||
current_request.parsed_url = None;
|
|
||||||
}
|
|
||||||
let elem = img.upcast::<Element>();
|
|
||||||
if elem.has_attribute(&local_name!("src")) {
|
|
||||||
img.upcast::<EventTarget>().fire_event(atom!("error"));
|
|
||||||
}
|
|
||||||
img.abort_request(State::Broken, ImageRequestPhase::Current);
|
|
||||||
img.abort_request(State::Broken, ImageRequestPhase::Pending);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let task = box SetUrlToNoneTask {
|
|
||||||
img: Trusted::new(self),
|
|
||||||
};
|
|
||||||
let document = document_from_node(self);
|
|
||||||
let window = document.window();
|
|
||||||
let task_source = window.dom_manipulation_task_source();
|
|
||||||
let _ = task_source.queue(task, window.upcast());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Step 5.3.7 of https://html.spec.whatwg.org/multipage/#update-the-image-data
|
/// Step 5.3.7 of https://html.spec.whatwg.org/multipage/#update-the-image-data
|
||||||
fn set_current_request_url_to_string_and_fire_load(&self, src: DOMString, url: ServoUrl) {
|
fn set_current_request_url_to_string_and_fire_load(&self, src: DOMString, url: ServoUrl) {
|
||||||
struct SetUrlToStringTask {
|
struct SetUrlToStringTask {
|
||||||
|
@ -524,49 +493,72 @@ impl HTMLImageElement {
|
||||||
/// Step 8-12 of html.spec.whatwg.org/multipage/#update-the-image-data
|
/// Step 8-12 of html.spec.whatwg.org/multipage/#update-the-image-data
|
||||||
fn update_the_image_data_sync_steps(&self) {
|
fn update_the_image_data_sync_steps(&self) {
|
||||||
let document = document_from_node(self);
|
let document = document_from_node(self);
|
||||||
// Step 8
|
let window = document.window();
|
||||||
// TODO: take pixel density into account
|
let task_source = window.dom_manipulation_task_source();
|
||||||
match self.select_image_source() {
|
let this = Trusted::new(self);
|
||||||
|
let src = match self.select_image_source() {
|
||||||
Some(src) => {
|
Some(src) => {
|
||||||
// Step 10.
|
// Step 8.
|
||||||
let window = document.window();
|
// TODO: Handle pixel density.
|
||||||
let this = Trusted::new(self);
|
src
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
// Step 9.
|
||||||
// FIXME(nox): Why are errors silenced here?
|
// FIXME(nox): Why are errors silenced here?
|
||||||
let _ = window.dom_manipulation_task_source().queue(
|
let _ = task_source.queue(
|
||||||
box task!(fire_progress_event: move || {
|
box task!(image_null_source_error: move || {
|
||||||
let this = this.root();
|
let this = this.root();
|
||||||
|
{
|
||||||
let event = ProgressEvent::new(
|
let mut current_request =
|
||||||
&this.global(),
|
this.current_request.borrow_mut();
|
||||||
atom!("loadstart"),
|
current_request.source_url = None;
|
||||||
EventBubbles::DoesNotBubble,
|
current_request.parsed_url = None;
|
||||||
EventCancelable::NotCancelable,
|
}
|
||||||
false,
|
if this.upcast::<Element>().has_attribute(&local_name!("src")) {
|
||||||
0,
|
this.upcast::<EventTarget>().fire_event(atom!("error"));
|
||||||
0,
|
}
|
||||||
);
|
// FIXME(nox): According to the spec, setting the current
|
||||||
event.upcast::<Event>().fire(this.upcast());
|
// request to the broken state is done prior to queuing a
|
||||||
|
// task, why is this here?
|
||||||
|
this.abort_request(State::Broken, ImageRequestPhase::Current);
|
||||||
|
this.abort_request(State::Broken, ImageRequestPhase::Pending);
|
||||||
}),
|
}),
|
||||||
window.upcast(),
|
window.upcast(),
|
||||||
);
|
);
|
||||||
// Step 11
|
return;
|
||||||
let base_url = document.base_url();
|
|
||||||
let parsed_url = base_url.join(&src);
|
|
||||||
match parsed_url {
|
|
||||||
Ok(url) => {
|
|
||||||
// Step 12
|
|
||||||
self.prepare_image_request(&url, &src);
|
|
||||||
},
|
|
||||||
Err(_) => {
|
|
||||||
// Step 11.1-11.5
|
|
||||||
self.set_current_request_url_to_selected_fire_error_and_loadend(src);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
None => {
|
};
|
||||||
// Step 9
|
// Step 10.
|
||||||
self.set_current_request_url_to_none_fire_error();
|
// FIXME(nox): Why are errors silenced here?
|
||||||
|
let _ = task_source.queue(
|
||||||
|
box task!(fire_progress_event: move || {
|
||||||
|
let this = this.root();
|
||||||
|
|
||||||
|
let event = ProgressEvent::new(
|
||||||
|
&this.global(),
|
||||||
|
atom!("loadstart"),
|
||||||
|
EventBubbles::DoesNotBubble,
|
||||||
|
EventCancelable::NotCancelable,
|
||||||
|
false,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
event.upcast::<Event>().fire(this.upcast());
|
||||||
|
}),
|
||||||
|
window.upcast(),
|
||||||
|
);
|
||||||
|
// Step 11
|
||||||
|
let base_url = document.base_url();
|
||||||
|
let parsed_url = base_url.join(&src);
|
||||||
|
match parsed_url {
|
||||||
|
Ok(url) => {
|
||||||
|
// Step 12
|
||||||
|
self.prepare_image_request(&url, &src);
|
||||||
},
|
},
|
||||||
|
Err(_) => {
|
||||||
|
// Step 11.1-11.5
|
||||||
|
self.set_current_request_url_to_selected_fire_error_and_loadend(src);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue