| 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Loads a thumbnail using provided url. In CANVAS mode, loaded images | 8 * Loads a thumbnail using provided url. In CANVAS mode, loaded images |
| 9 * are attached as <canvas> element, while in IMAGE mode as <img>. | 9 * are attached as <canvas> element, while in IMAGE mode as <img>. |
| 10 * <canvas> renders faster than <img>, however has bigger memory overhead. | 10 * <canvas> renders faster than <img>, however has bigger memory overhead. |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 135 |
| 136 /** | 136 /** |
| 137 * Loads and attaches an image. | 137 * Loads and attaches an image. |
| 138 * | 138 * |
| 139 * @param {HTMLElement} box Container element. | 139 * @param {HTMLElement} box Container element. |
| 140 * @param {ThumbnailLoader.FillMode} fillMode Fill mode. | 140 * @param {ThumbnailLoader.FillMode} fillMode Fill mode. |
| 141 * @param {ThumbnailLoader.OptimizationMode=} opt_optimizationMode Optimization | 141 * @param {ThumbnailLoader.OptimizationMode=} opt_optimizationMode Optimization |
| 142 * for downloading thumbnails. By default optimizations are disabled. | 142 * for downloading thumbnails. By default optimizations are disabled. |
| 143 * @param {function(Image, Object)=} opt_onSuccess Success callback, | 143 * @param {function(Image, Object)=} opt_onSuccess Success callback, |
| 144 * accepts the image and the transform. | 144 * accepts the image and the transform. |
| 145 * @param {function=} opt_onError Error callback. | 145 * @param {function()=} opt_onError Error callback. |
| 146 * @param {function=} opt_onGeneric Callback for generic image used. | 146 * @param {function()=} opt_onGeneric Callback for generic image used. |
| 147 */ | 147 */ |
| 148 ThumbnailLoader.prototype.load = function(box, fillMode, opt_optimizationMode, | 148 ThumbnailLoader.prototype.load = function(box, fillMode, opt_optimizationMode, |
| 149 opt_onSuccess, opt_onError, opt_onGeneric) { | 149 opt_onSuccess, opt_onError, opt_onGeneric) { |
| 150 opt_optimizationMode = opt_optimizationMode || | 150 opt_optimizationMode = opt_optimizationMode || |
| 151 ThumbnailLoader.OptimizationMode.NEVER_DISCARD; | 151 ThumbnailLoader.OptimizationMode.NEVER_DISCARD; |
| 152 | 152 |
| 153 if (!this.thumbnailUrl_) { | 153 if (!this.thumbnailUrl_) { |
| 154 // Relevant CSS rules are in file_types.css. | 154 // Relevant CSS rules are in file_types.css. |
| 155 box.setAttribute('generic-thumbnail', this.mediaType_); | 155 box.setAttribute('generic-thumbnail', this.mediaType_); |
| 156 if (opt_onGeneric) opt_onGeneric(); | 156 if (opt_onGeneric) opt_onGeneric(); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 | 415 |
| 416 function percent(fraction) { | 416 function percent(fraction) { |
| 417 return (fraction * 100).toFixed(2) + '%'; | 417 return (fraction * 100).toFixed(2) + '%'; |
| 418 } | 418 } |
| 419 | 419 |
| 420 img.style.width = percent(fractionX); | 420 img.style.width = percent(fractionX); |
| 421 img.style.height = percent(fractionY); | 421 img.style.height = percent(fractionY); |
| 422 img.style.left = percent((1 - fractionX) / 2); | 422 img.style.left = percent((1 - fractionX) / 2); |
| 423 img.style.top = percent((1 - fractionY) / 2); | 423 img.style.top = percent((1 - fractionY) / 2); |
| 424 }; | 424 }; |
| OLD | NEW |