Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1145)

Side by Side Diff: chrome/browser/resources/file_manager/js/image_editor/image_view.js

Issue 10399047: [Photo Editor] Save edited images immediately. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 * The overlay displaying the image. 6 * The overlay displaying the image.
7 */ 7 */
8 function ImageView(container, viewport, metadataProvider) { 8 function ImageView(container, viewport, metadataProvider) {
9 this.container_ = container; 9 this.container_ = container;
10 this.viewport_ = viewport; 10 this.viewport_ = viewport;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 ImageView.prototype.getCanvas = function() { return this.contentCanvas_ }; 115 ImageView.prototype.getCanvas = function() { return this.contentCanvas_ };
116 116
117 ImageView.prototype.hasValidImage = function() { 117 ImageView.prototype.hasValidImage = function() {
118 return !this.preview_ && this.contentCanvas_ && this.contentCanvas_.width; 118 return !this.preview_ && this.contentCanvas_ && this.contentCanvas_.width;
119 }; 119 };
120 120
121 ImageView.prototype.getVideo = function() { return this.videoElement_ }; 121 ImageView.prototype.getVideo = function() { return this.videoElement_ };
122 122
123 ImageView.prototype.getThumbnail = function() { return this.thumbnailCanvas_ }; 123 ImageView.prototype.getThumbnail = function() { return this.thumbnailCanvas_ };
124 124
125 ImageView.prototype.getContentRevision = function() {
126 return this.contentRevision_;
127 };
128
125 /** 129 /**
126 * Copy an image fragment from a full resolution canvas to a device resolution 130 * Copy an image fragment from a full resolution canvas to a device resolution
127 * canvas. 131 * canvas.
128 * 132 *
129 * @param {Rect} deviceRect Rectangle in the device coordinates. 133 * @param {Rect} deviceRect Rectangle in the device coordinates.
130 * @param {HTMLCanvasElement} canvas Full resolution canvas. 134 * @param {HTMLCanvasElement} canvas Full resolution canvas.
131 * @param {Rect} imageRect Rectangle in the full resolution canvas. 135 * @param {Rect} imageRect Rectangle in the full resolution canvas.
132 */ 136 */
133 ImageView.prototype.paintDeviceRect = function (deviceRect, canvas, imageRect) { 137 ImageView.prototype.paintDeviceRect = function (deviceRect, canvas, imageRect) {
134 // Map screen canvas (0,0) to (deviceBounds.left, deviceBounds.top) 138 // Map screen canvas (0,0) to (deviceBounds.left, deviceBounds.top)
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 ImageView.prototype.load = function( 216 ImageView.prototype.load = function(
213 id, source, metadata, slide, opt_callback) { 217 id, source, metadata, slide, opt_callback) {
214 218
215 metadata = metadata|| {}; 219 metadata = metadata|| {};
216 220
217 ImageUtil.metrics.startInterval(ImageUtil.getMetricName('DisplayTime')); 221 ImageUtil.metrics.startInterval(ImageUtil.getMetricName('DisplayTime'));
218 222
219 var self = this; 223 var self = this;
220 224
221 this.contentID_ = id; 225 this.contentID_ = id;
226 this.contentRevision_ = -1;
222 227
223 var loadingVideo = FileType.getMediaType(source) == 'video'; 228 var loadingVideo = FileType.getMediaType(source) == 'video';
224 if (loadingVideo) { 229 if (loadingVideo) {
225 var video = this.document_.createElement('video'); 230 var video = this.document_.createElement('video');
226 if (metadata.thumbnailURL) { 231 if (metadata.thumbnailURL) {
227 video.setAttribute('poster', metadata.thumbnailURL); 232 video.setAttribute('poster', metadata.thumbnailURL);
228 this.replace(video, slide); // Show the poster immediately. 233 this.replace(video, slide); // Show the poster immediately.
229 } 234 }
230 video.addEventListener('loadedmetadata', onVideoLoad); 235 video.addEventListener('loadedmetadata', onVideoLoad);
231 video.addEventListener('error', onVideoLoad); 236 video.addEventListener('error', onVideoLoad);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 return source; 368 return source;
364 369
365 return this.contentCache_.getItem(id); 370 return this.contentCache_.getItem(id);
366 }; 371 };
367 372
368 /** 373 /**
369 * Prefetch an image. 374 * Prefetch an image.
370 * 375 *
371 * @param {number} id Unique image id for caching purposes 376 * @param {number} id Unique image id for caching purposes
372 * @param {string|HTMLCanvasElement} source 377 * @param {string|HTMLCanvasElement} source
373 * @param {Object} metadata
374 */ 378 */
375 ImageView.prototype.prefetch = function(id, source, metadata) { 379 ImageView.prototype.prefetch = function(id, source) {
376 var self = this; 380 var self = this;
377 function prefetchDone(canvas) { 381 function prefetchDone(canvas) {
378 if (canvas.width) 382 if (canvas.width)
379 self.contentCache_.putItem(id, canvas); 383 self.contentCache_.putItem(id, canvas);
380 } 384 }
381 385
382 var cached = this.getReadyContent(id, source); 386 var cached = this.getReadyContent(id, source);
383 if (cached) { 387 if (cached) {
384 prefetchDone(cached); 388 prefetchDone(cached);
385 } else if (FileType.getMediaType(source) == 'image') { 389 } else if (FileType.getMediaType(source) == 'image') {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 // If this is not a thumbnail, cache the content and the screen-scale image. 434 // If this is not a thumbnail, cache the content and the screen-scale image.
431 if (this.hasValidImage()) { 435 if (this.hasValidImage()) {
432 this.contentCache_.putItem(this.contentID_, this.contentCanvas_, true); 436 this.contentCache_.putItem(this.contentID_, this.contentCanvas_, true);
433 this.screenCache_.putItem(this.contentID_, this.screenImage_); 437 this.screenCache_.putItem(this.contentID_, this.screenImage_);
434 438
435 // TODO(kaznacheev): It is better to pass screenImage_ as it is usually 439 // TODO(kaznacheev): It is better to pass screenImage_ as it is usually
436 // much smaller than contentCanvas_ and still contains the entire image. 440 // much smaller than contentCanvas_ and still contains the entire image.
437 // Once we implement zoom/pan we should pass contentCanvas_ instead. 441 // Once we implement zoom/pan we should pass contentCanvas_ instead.
438 this.updateThumbnail_(this.screenImage_); 442 this.updateThumbnail_(this.screenImage_);
439 443
444 this.contentRevision_++;
440 for (var i = 0; i != this.contentCallbacks_.length; i++) { 445 for (var i = 0; i != this.contentCallbacks_.length; i++) {
441 try { 446 try {
442 this.contentCallbacks_[i](); 447 this.contentCallbacks_[i]();
443 } catch(e) { 448 } catch(e) {
444 console.error(e); 449 console.error(e);
445 } 450 }
446 } 451 }
447 } 452 }
448 }; 453 };
449 454
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 if (this.order_.length > this.capacity_) 663 if (this.order_.length > this.capacity_)
659 throw new Error('Exceeded cache capacity'); 664 throw new Error('Exceeded cache capacity');
660 }; 665 };
661 666
662 ImageView.Cache.prototype.evictLRU = function() { 667 ImageView.Cache.prototype.evictLRU = function() {
663 if (this.order_.length == this.capacity_) { 668 if (this.order_.length == this.capacity_) {
664 var id = this.order_.shift(); 669 var id = this.order_.shift();
665 delete this.map_[id]; 670 delete this.map_[id];
666 } 671 }
667 }; 672 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698