Auto merge of #12921 - paulrouget:imgOnError, r=nox

Trigger image.onerror

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #12885 (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->

---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12921)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-08-23 02:31:48 -05:00 committed by GitHub
commit fe09cb5504
4 changed files with 35 additions and 4 deletions

View file

@ -86,14 +86,14 @@ impl Runnable for ImageResponseHandlerRunnable {
// Update the image field
let element = self.element.root();
let element_ref = element.r();
let (image, metadata, trigger_image_load) = match self.image {
let (image, metadata, trigger_image_load, trigger_image_error) = match self.image {
ImageResponse::Loaded(image) | ImageResponse::PlaceholderLoaded(image) => {
(Some(image.clone()), Some(ImageMetadata { height: image.height, width: image.width } ), true)
(Some(image.clone()), Some(ImageMetadata { height: image.height, width: image.width } ), true, false)
}
ImageResponse::MetadataLoaded(meta) => {
(None, Some(meta), false)
(None, Some(meta), false, false)
}
ImageResponse::None => (None, None, true)
ImageResponse::None => (None, None, false, true)
};
element_ref.current_request.borrow_mut().image = image;
element_ref.current_request.borrow_mut().metadata = metadata;
@ -107,6 +107,11 @@ impl Runnable for ImageResponseHandlerRunnable {
element.upcast::<EventTarget>().fire_simple_event("load");
}
// Fire image.onerror
if trigger_image_error {
element.upcast::<EventTarget>().fire_simple_event("error");
}
// Trigger reflow
let window = window_from_node(document.r());
window.add_pending_reflow();