| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 {Entry} entry File entry. | 10 * @param {Entry} entry File entry. |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 ThumbnailLoader.prototype.loadAsDataUrl = function(fillMode) { | 257 ThumbnailLoader.prototype.loadAsDataUrl = function(fillMode) { |
| 258 assert(fillMode === ThumbnailLoader.FillMode.FIT || | 258 assert(fillMode === ThumbnailLoader.FillMode.FIT || |
| 259 fillMode === ThumbnailLoader.FillMode.OVER_FILL); | 259 fillMode === ThumbnailLoader.FillMode.OVER_FILL); |
| 260 | 260 |
| 261 return new Promise(function(resolve, reject) { | 261 return new Promise(function(resolve, reject) { |
| 262 // Load by using ImageLoaderClient. | 262 // Load by using ImageLoaderClient. |
| 263 var modificationTime = this.metadata_ && | 263 var modificationTime = this.metadata_ && |
| 264 this.metadata_.filesystem && | 264 this.metadata_.filesystem && |
| 265 this.metadata_.filesystem.modificationTime && | 265 this.metadata_.filesystem.modificationTime && |
| 266 this.metadata_.filesystem.modificationTime.getTime(); | 266 this.metadata_.filesystem.modificationTime.getTime(); |
| 267 var thumbnailUrl = | 267 var thumbnailUrl = this.thumbnailUrl_; |
| 268 fillMode === ThumbnailLoader.FillMode.OVER_FILL && | 268 var options = { |
| 269 this.croppedThumbnailUrl_ ? | 269 maxWidth: ThumbnailLoader.THUMBNAIL_MAX_WIDTH, |
| 270 this.croppedThumbnailUrl_ : | 270 maxHeight: ThumbnailLoader.THUMBNAIL_MAX_HEIGHT, |
| 271 this.thumbnailUrl_; | 271 cache: true, |
| 272 priority: this.priority_, |
| 273 timestamp: modificationTime |
| 274 }; |
| 275 |
| 276 if (fillMode === ThumbnailLoader.FillMode.OVER_FILL) { |
| 277 // Use cropped thumbnail url if available. |
| 278 thumbnailUrl = this.croppedThumbnailUrl_ ? |
| 279 this.croppedThumbnailUrl_ : this.thumbnailUrl_; |
| 280 |
| 281 // Set crop option to image loader. Since image of croppedThumbnailUrl_ is |
| 282 // 360x360 with current implemenation, it's no problem to crop it. |
| 283 options['width'] = 360; |
| 284 options['height'] = 360; |
| 285 options['crop'] = true; |
| 286 } |
| 287 |
| 272 ImageLoaderClient.getInstance().load( | 288 ImageLoaderClient.getInstance().load( |
| 273 thumbnailUrl, | 289 thumbnailUrl, |
| 274 function(result) { | 290 function(result) { |
| 275 if (result.status === 'success') | 291 if (result.status === 'success') |
| 276 resolve(result); | 292 resolve(result); |
| 277 else | 293 else |
| 278 reject(result); | 294 reject(result); |
| 279 }, | 295 }, |
| 280 { | 296 options); |
| 281 maxWidth: ThumbnailLoader.THUMBNAIL_MAX_WIDTH, | |
| 282 maxHeight: ThumbnailLoader.THUMBNAIL_MAX_HEIGHT, | |
| 283 cache: true, | |
| 284 priority: this.priority_, | |
| 285 timestamp: modificationTime | |
| 286 }); | |
| 287 }.bind(this)).then(function(result) { | 297 }.bind(this)).then(function(result) { |
| 288 if (!this.transform_) | 298 if (!this.transform_) |
| 289 return result; | 299 return result; |
| 290 else | 300 else |
| 291 return this.applyTransformToDataUrl_( | 301 return this.applyTransformToDataUrl_( |
| 292 this.transform_, result.data, result.width, result.height); | 302 this.transform_, result.data, result.width, result.height); |
| 293 }.bind(this)); | 303 }.bind(this)); |
| 294 }; | 304 }; |
| 295 | 305 |
| 296 /** | 306 /** |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 | 575 |
| 566 function percent(fraction) { | 576 function percent(fraction) { |
| 567 return (fraction * 100).toFixed(2) + '%'; | 577 return (fraction * 100).toFixed(2) + '%'; |
| 568 } | 578 } |
| 569 | 579 |
| 570 img.style.width = percent(fractionX); | 580 img.style.width = percent(fractionX); |
| 571 img.style.height = percent(fractionY); | 581 img.style.height = percent(fractionY); |
| 572 img.style.left = percent((1 - fractionX) / 2); | 582 img.style.left = percent((1 - fractionX) / 2); |
| 573 img.style.top = percent((1 - fractionY) / 2); | 583 img.style.top = percent((1 - fractionY) / 2); |
| 574 }; | 584 }; |
| OLD | NEW |