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

Unified Diff: chrome/browser/resources/file_manager/js/image_editor/commands.js

Issue 12761002: Fixed multiple undo in the Files.app's image editor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/file_manager/js/image_editor/commands.js
diff --git a/chrome/browser/resources/file_manager/js/image_editor/commands.js b/chrome/browser/resources/file_manager/js/image_editor/commands.js
index a08f0d5a775468754e738b3b639842987445090a..32dd9ced046c10647d49c6e9c2d8c93baf77dfbd 100644
--- a/chrome/browser/resources/file_manager/js/image_editor/commands.js
+++ b/chrome/browser/resources/file_manager/js/image_editor/commands.js
@@ -18,9 +18,16 @@ function CommandQueue(document, canvas, saveFunction) {
this.redo_ = [];
this.subscribers_ = [];
- this.baselineImage_ = canvas;
this.currentImage_ = canvas;
+
+ this.baselineImage_ = document.createElement('canvas');
+ this.baselineImage_.width = this.currentImage_.width;
+ this.baselineImage_.height = this.currentImage_.height;
+ var context = this.baselineImage_.getContext('2d');
+ context.drawImage(this.currentImage_, 0, 0);
+
this.previousImage_ = document.createElement('canvas');
+ this.previousImageAvailable_ = false;
this.saveFunction_ = saveFunction;
@@ -122,6 +129,7 @@ CommandQueue.prototype.doExecute_ = function(command, uiContext, callback) {
// Remember one previous image so that the first undo is as fast as possible.
this.previousImage_.width = this.currentImage_.width;
this.previousImage_.height = this.currentImage_.height;
+ this.previousImageAvailable_ = true;
var context = this.previousImage_.getContext('2d');
context.drawImage(this.currentImage_, 0, 0);
@@ -179,7 +187,8 @@ CommandQueue.prototype.undo = function() {
self.commit_(delay);
}
- if (this.previousImage_) {
+ if (this.previousImageAvailable_) {
+ console.log('TRYING, WITH: ' + this.previousImage_.width);
yoshiki 2013/03/11 05:21:59 nit: Can you remove this?
mtomasz 2013/03/11 05:44:56 Done.
// First undo after an execute call.
this.currentImage_.width = this.previousImage_.width;
this.currentImage_.height = this.previousImage_.height;
@@ -189,12 +198,16 @@ CommandQueue.prototype.undo = function() {
// Free memory.
this.previousImage_.width = 0;
this.previousImage_.height = 0;
+ this.previousImageAvailable_ = false;
complete();
// TODO(kaznacheev) Consider recalculating previousImage_ right here
// by replaying the commands in the background.
} else {
- this.currentImage_ = this.baselineImage_;
+ this.currentImage_.width = this.baselineImage_.width;
+ this.currentImage_.height = this.baselineImage_.height;
+ var context = this.currentImage_.getContext('2d');
+ context.drawImage(this.baselineImage_, 0, 0);
var replay = function(index) {
if (index < self.undo_.length)
@@ -233,6 +246,10 @@ CommandQueue.prototype.close = function() {
// Free memory used by the undo buffer.
this.previousImage_.width = 0;
this.previousImage_.height = 0;
+ this.previousImageAvailable_ = false;
+
+ this.baselineImage_.width = 0;
+ this.baselineImage_.height = 0;
};
/**
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698