Commit 0b3cd1da authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

Files app: Remove thumbnail animation when updating its image

This CL removes the animation when updating the thumbnail image. This
animation is very quick and hardly noticed and some code paths weren't
even using the animation.

This fixes 2 issues:
1. Old images weren't removed when there animation wasn't used.
2. The event listener for 'animationend' wasn't removed.

No change in functionality for the user, so no new tests added.

Test: Manually checked that file list and grid display and update their thumbnails.
Bug: 1056443
Change-Id: I8a6bd050c2bbb358387934ff9371c075a6703508
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2076749
Commit-Queue: Noel Gordon <noel@chromium.org>
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744972}
parent cd9c40f9
...@@ -1758,10 +1758,6 @@ body.check-select .thumbnail-grid .thumbnail-item[selected] .checkmark.active { ...@@ -1758,10 +1758,6 @@ body.check-select .thumbnail-grid .thumbnail-item[selected] .checkmark.active {
width: 100%; width: 100%;
} }
.thumbnail-grid .img-container > .thumbnail.animate {
animation: fadeIn 250ms linear;
}
.thumbnail-grid .shield { .thumbnail-grid .shield {
background-color: rgba(160, 160, 160, 50%); background-color: rgba(160, 160, 160, 50%);
bottom: 0; bottom: 0;
...@@ -2002,15 +1998,6 @@ li[renaming=''] .badge { ...@@ -2002,15 +1998,6 @@ li[renaming=''] .badge {
justify-content: flex-end; justify-content: flex-end;
} }
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes fadeOut { @keyframes fadeOut {
from { from {
opacity: 1; opacity: 1;
...@@ -2169,10 +2156,6 @@ body.check-select #list-container li[selected] .detail-checkmark { ...@@ -2169,10 +2156,6 @@ body.check-select #list-container li[selected] .detail-checkmark {
width: 100%; width: 100%;
} }
#list-container list li .detail-thumbnail > .thumbnail.animate {
animation: fadeIn 220ms ease;
}
body.check-select #list-container list li[selected] .detail-thumbnail body.check-select #list-container list li[selected] .detail-thumbnail
> .thumbnail { > .thumbnail {
/* Fade out after checkmark fades in. */ /* Fade out after checkmark fades in. */
......
...@@ -228,7 +228,7 @@ class FileGrid extends cr.ui.Grid { ...@@ -228,7 +228,7 @@ class FileGrid extends cr.ui.Grid {
FileGrid.setThumbnailImage_( FileGrid.setThumbnailImage_(
assertInstanceof(box, HTMLDivElement), entry, assertInstanceof(box, HTMLDivElement), entry,
assert(event.dataUrl), assert(event.width), assert(event.height), assert(event.dataUrl), assert(event.width), assert(event.height),
/* should animate */ true, mimeType); mimeType);
} }
} }
listItem.classList.toggle('thumbnail-loaded', !!event.dataUrl); listItem.classList.toggle('thumbnail-loaded', !!event.dataUrl);
...@@ -691,8 +691,7 @@ class FileGrid extends cr.ui.Grid { ...@@ -691,8 +691,7 @@ class FileGrid extends cr.ui.Grid {
.contentMimeType; .contentMimeType;
FileGrid.setThumbnailImage_( FileGrid.setThumbnailImage_(
box, entry, thumbnailData.dataUrl, (thumbnailData.width || 0), box, entry, thumbnailData.dataUrl, (thumbnailData.width || 0),
(thumbnailData.height || 0), (thumbnailData.height || 0), mimeType);
/* should not animate */ false, mimeType);
li.classList.toggle('thumbnail-loaded', true); li.classList.toggle('thumbnail-loaded', true);
} else { } else {
FileGrid.setGenericThumbnail_(box, entry); FileGrid.setGenericThumbnail_(box, entry);
...@@ -761,15 +760,10 @@ class FileGrid extends cr.ui.Grid { ...@@ -761,15 +760,10 @@ class FileGrid extends cr.ui.Grid {
* @param {string} dataUrl Data url of thumbnail. * @param {string} dataUrl Data url of thumbnail.
* @param {number} width Width of thumbnail. * @param {number} width Width of thumbnail.
* @param {number} height Height of thumbnail. * @param {number} height Height of thumbnail.
* @param {boolean} shouldAnimate Whether the thumbnail is shown with
* animation or not.
* @param {string=} opt_mimeType Optional mime type for the image. * @param {string=} opt_mimeType Optional mime type for the image.
* @private * @private
*/ */
static setThumbnailImage_( static setThumbnailImage_(box, entry, dataUrl, width, height, opt_mimeType) {
box, entry, dataUrl, width, height, shouldAnimate, opt_mimeType) {
const oldThumbnails = box.querySelectorAll('.thumbnail');
const thumbnail = box.ownerDocument.createElement('div'); const thumbnail = box.ownerDocument.createElement('div');
thumbnail.classList.add('thumbnail'); thumbnail.classList.add('thumbnail');
...@@ -782,20 +776,12 @@ class FileGrid extends cr.ui.Grid { ...@@ -782,20 +776,12 @@ class FileGrid extends cr.ui.Grid {
} }
thumbnail.style.backgroundImage = 'url(' + dataUrl + ')'; thumbnail.style.backgroundImage = 'url(' + dataUrl + ')';
thumbnail.addEventListener('animationend', () => {
// Remove animation css once animation is completed in order not to const oldThumbnails = box.querySelectorAll('.thumbnail');
// animate again when an item is attached to the dom again. for (let i = 0; i < oldThumbnails.length; i++) {
thumbnail.classList.remove('animate'); box.removeChild(oldThumbnails[i]);
for (let i = 0; i < oldThumbnails.length; i++) {
if (box.contains(oldThumbnails[i])) {
box.removeChild(oldThumbnails[i]);
}
}
});
if (shouldAnimate) {
thumbnail.classList.add('animate');
} }
box.appendChild(thumbnail); box.appendChild(thumbnail);
} }
......
...@@ -647,8 +647,7 @@ class FileTable extends cr.ui.Table { ...@@ -647,8 +647,7 @@ class FileTable extends cr.ui.Table {
if (box) { if (box) {
if (event.dataUrl) { if (event.dataUrl) {
this.setThumbnailImage_( this.setThumbnailImage_(
assertInstanceof(box, HTMLDivElement), event.dataUrl, assertInstanceof(box, HTMLDivElement), event.dataUrl);
true /* with animation */);
} else { } else {
this.clearThumbnailImage_(assertInstanceof(box, HTMLDivElement)); this.clearThumbnailImage_(assertInstanceof(box, HTMLDivElement));
} }
...@@ -1129,8 +1128,7 @@ class FileTable extends cr.ui.Table { ...@@ -1129,8 +1128,7 @@ class FileTable extends cr.ui.Table {
this.listThumbnailLoader_.getThumbnailFromCache(entry) : this.listThumbnailLoader_.getThumbnailFromCache(entry) :
null; null;
if (thumbnailData && thumbnailData.dataUrl) { if (thumbnailData && thumbnailData.dataUrl) {
this.setThumbnailImage_( this.setThumbnailImage_(box, thumbnailData.dataUrl);
box, thumbnailData.dataUrl, false /* without animation */);
} }
return box; return box;
...@@ -1140,30 +1138,18 @@ class FileTable extends cr.ui.Table { ...@@ -1140,30 +1138,18 @@ class FileTable extends cr.ui.Table {
* Sets thumbnail image to the box. * Sets thumbnail image to the box.
* @param {!HTMLDivElement} box Detail thumbnail div element. * @param {!HTMLDivElement} box Detail thumbnail div element.
* @param {string} dataUrl Data url of thumbnail. * @param {string} dataUrl Data url of thumbnail.
* @param {boolean} shouldAnimate Whether the thumbnail is shown with
* animation or not.
* @private * @private
*/ */
setThumbnailImage_(box, dataUrl, shouldAnimate) { setThumbnailImage_(box, dataUrl) {
const oldThumbnails = box.querySelectorAll('.thumbnail');
const thumbnail = box.ownerDocument.createElement('div'); const thumbnail = box.ownerDocument.createElement('div');
thumbnail.classList.add('thumbnail'); thumbnail.classList.add('thumbnail');
thumbnail.style.backgroundImage = 'url(' + dataUrl + ')'; thumbnail.style.backgroundImage = 'url(' + dataUrl + ')';
thumbnail.addEventListener('animationend', () => { const oldThumbnails = box.querySelectorAll('.thumbnail');
// Remove animation css once animation is completed in order not to
// animate again when an item is attached to the dom again.
thumbnail.classList.remove('animate');
for (let i = 0; i < oldThumbnails.length; i++) {
if (box.contains(oldThumbnails[i])) {
box.removeChild(oldThumbnails[i]);
}
}
});
if (shouldAnimate) { for (let i = 0; i < oldThumbnails.length; i++) {
thumbnail.classList.add('animate'); if (box.contains(oldThumbnails[i])) {
box.removeChild(oldThumbnails[i]);
}
} }
box.appendChild(thumbnail); box.appendChild(thumbnail);
......
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