Commit 5efa972b authored by Alex Danilo's avatar Alex Danilo Committed by Commit Bot

Remove use of decode() for quickview images.

CL:1345378 changed display of images in quickview to use the decode()
API to allow the image to be decoded while the containing content node
was detached from the DOM tree in order to avoid visible artifacts
during decoding time. The decode() API fails when large image decodes
are attempted resulting in nothing being displayed, even when those
large images can be viewed from a simple <img src=...> container.

Removes the use of decode() and instead, creates an Image object
responsible for loading the image and uses the onload handler to
reattach the content node to the DOM. Adds an onerror handler
that sends an event to the host container in the case of load and/or
decode failures.

Note, this is in effect creating 2 images - the
first is the host node in the content, the second is a temporary 'Image'
object that is used to trigger the load/decode and when it's loaded the
URL to the object is set on the host image node. That way, the image
is already loaded so minimizes flicker when the 'src' is set, and in
the error case it doesn't set the 'src' at all. (We call  this the
Double Image Device:)

Bug: 645021, 1043799
Change-Id: Id14e01068c29d7cd373563ba20d2e13d7a4bbfe6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2012368Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Commit-Queue: Noel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734394}
parent f57f1ee6
...@@ -36,15 +36,20 @@ window.onload = () => { ...@@ -36,15 +36,20 @@ window.onload = () => {
break; break;
case 'image': case 'image':
content.remove(); content.remove();
content.onload = (e) => contentChanged(e.target.src); content.src = '';
content.src = event.data.src;
content.decode() const image = new Image();
.then(() => { image.onload = (e) => {
document.body.appendChild(content); contentChanged(e.target.src);
}) document.body.appendChild(content);
.catch(() => { content.src = e.target.src;
contentDecodeFailed(); };
});
image.onerror = (e) => {
contentDecodeFailed();
};
image.src = event.data.src;
break; break;
default: default:
content.onload = (e) => contentChanged(e.target.src); content.onload = (e) => contentChanged(e.target.src);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment