| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Loads a thumbnail using provided url. In CANVAS mode, loaded images | 6 * Loads a thumbnail using provided url. In CANVAS mode, loaded images |
| 7 * are attached as <canvas> element, while in IMAGE mode as <img>. | 7 * are attached as <canvas> element, while in IMAGE mode as <img>. |
| 8 * <canvas> renders faster than <img>, however has bigger memory overhead. | 8 * <canvas> renders faster than <img>, however has bigger memory overhead. |
| 9 * | 9 * |
| 10 * @param {string} url File URL. | 10 * @param {string} url File URL. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 ThumbnailLoader.LoaderType = { | 84 ThumbnailLoader.LoaderType = { |
| 85 IMAGE: 0, | 85 IMAGE: 0, |
| 86 CANVAS: 1 | 86 CANVAS: 1 |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 /** | 89 /** |
| 90 * If an image file does not have an embedded thumbnail we might want to use | 90 * If an image file does not have an embedded thumbnail we might want to use |
| 91 * the image itself as a thumbnail. If the image is too large it hurts | 91 * the image itself as a thumbnail. If the image is too large it hurts |
| 92 * the performance a lot so we allow it only for moderately sized files. | 92 * the performance a lot so we allow it only for moderately sized files. |
| 93 * | 93 * |
| 94 * @param {Object} metadata Metadata object | 94 * @param {Object} metadata Metadata object. |
| 95 * @return {boolean} Whether it is OK to use the image url for a preview. | 95 * @return {boolean} Whether it is OK to use the image url for a preview. |
| 96 * @private | 96 * @private |
| 97 */ | 97 */ |
| 98 ThumbnailLoader.canUseImageUrl_ = function(metadata) { | 98 ThumbnailLoader.canUseImageUrl_ = function(metadata) { |
| 99 return (metadata.filesystem && metadata.filesystem.size && | 99 return (metadata.filesystem && metadata.filesystem.size && |
| 100 metadata.filesystem.size <= ThumbnailLoader.MAX_FILE_SIZE) || | 100 metadata.filesystem.size <= ThumbnailLoader.MAX_FILE_SIZE) || |
| 101 (metadata.media && metadata.media.width && metadata.media.height && | 101 (metadata.media && metadata.media.width && metadata.media.height && |
| 102 metadata.media.width * metadata.media.height <= | 102 metadata.media.width * metadata.media.height <= |
| 103 ThumbnailLoader.MAX_PIXEL_COUNT); | 103 ThumbnailLoader.MAX_PIXEL_COUNT); |
| 104 }; | 104 }; |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 | 310 |
| 311 function percent(fraction) { | 311 function percent(fraction) { |
| 312 return (fraction * 100).toFixed(2) + '%'; | 312 return (fraction * 100).toFixed(2) + '%'; |
| 313 } | 313 } |
| 314 | 314 |
| 315 img.style.width = percent(fractionX); | 315 img.style.width = percent(fractionX); |
| 316 img.style.height = percent(fractionY); | 316 img.style.height = percent(fractionY); |
| 317 img.style.left = percent((1 - fractionX) / 2); | 317 img.style.left = percent((1 - fractionX) / 2); |
| 318 img.style.top = percent((1 - fractionY) / 2); | 318 img.style.top = percent((1 - fractionY) / 2); |
| 319 }; | 319 }; |
| OLD | NEW |