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

Unified Diff: chrome/browser/resources/file_manager/js/image_editor/commands.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 side-by-side diff with in-line comments
Download patch
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 a4f507935453ab249bd049583465f9f338a31e5f..54cdc1889e56239470ef5d5d789876f9fafd635b 100644
--- a/chrome/browser/resources/file_manager/js/image_editor/commands.js
+++ b/chrome/browser/resources/file_manager/js/image_editor/commands.js
@@ -6,8 +6,12 @@
* Command queue is the only way to modify images.
* Supports undo/redo.
* Command execution is asynchronous (callback-based).
+ *
+ * @param {Document} document Document to create canvases in.
+ * @param {HTMLCanvasElement} canvas The canvas with the original image.
+ * @param {function(callback)} saveFunction Function to save the image.
*/
-function CommandQueue(document, canvas) {
+function CommandQueue(document, canvas, saveFunction) {
this.document_ = document;
this.undo_ = [];
this.redo_ = [];
@@ -17,6 +21,8 @@ function CommandQueue(document, canvas) {
this.currentImage_ = canvas;
this.previousImage_ = null;
+ this.saveFunction_ = saveFunction;
+
this.busy_ = false;
this.UIContext_ = {};
@@ -39,30 +45,14 @@ CommandQueue.prototype.attachUI = function(imageView, prompt, lock) {
};
/**
- * Detach the UI. Further image modifications will not be displayed.
- */
-CommandQueue.prototype.detachUI = function() {
- // The current this.UIContext_ object might be used by the command currently
- // being executed. Null out its fields so that the command continues silently.
- this.UIContext_.imageView = null;
- this.UIContext_.prompt = null;
- this.UIContext_.lock = null;
-
- // Now replace the object to guarantee that we do not interfere with the
- // current command.
- this.UIContext_ = {};
-};
-
-/**
- * Asynchronous getter. Does not return the image while the queue is busy.
+ * Execute the action when the queue is not busy.
+ * @param {function} callback Callback.
*/
-CommandQueue.prototype.requestCurrentImage = function(callback) {
- if (this.isBusy()) {
+CommandQueue.prototype.executeWhenReady = function(callback) {
+ if (this.isBusy())
this.subscribers_.push(callback);
- } else {
- var self = this;
- setTimeout(function() { callback(self.currentImage_) }, 0);
- }
+ else
+ setTimeout(callback, 0);
};
CommandQueue.prototype.isBusy = function() { return this.busy_ };
@@ -74,20 +64,25 @@ CommandQueue.prototype.setBusy_ = function(on) {
this.busy_ = on;
if (!on) {
- // Notify the subscribers that requested the image while the queue was busy.
- while (this.subscribers_.length) {
- this.subscribers_.pop()(this.currentImage_);
- }
+ // Execute the actions requested while the queue was busy.
+ while (this.subscribers_.length)
+ this.subscribers_.shift()();
}
if (this.UIContext_.lock)
this.UIContext_.lock(on);
- if (on) {
+ if (on)
ImageUtil.trace.resetTimer('command-busy');
- } else {
+ else
ImageUtil.trace.reportTimer('command-busy');
- }
+};
+
+CommandQueue.prototype.save_ = function() {
dgozman 2012/05/16 16:05:40 It's hard to understand the difference between |th
Vladislav Kaznacheev 2012/05/17 09:04:40 renamed to commit_ and added a JSDoc On 2012/05/1
+ setTimeout(
+ this.saveFunction_,
+ ImageView.ANIMATION_WAIT_INTERVAL,
+ this.setBusy_.bind(this, false));
dgozman 2012/05/16 16:05:40 Is this setBusy a parameter to saveFunction? Add a
Vladislav Kaznacheev 2012/05/17 09:04:40 Rewrote for clarity. And yes, this assumes isBusy=
};
CommandQueue.prototype.doExecute_ = function(command, uiContext, callback) {
@@ -121,7 +116,7 @@ CommandQueue.prototype.execute = function(command, opt_keep_redo) {
this.undo_.push(command);
- this.doExecute_(command, this.UIContext_, this.setBusy_.bind(this, false));
+ this.doExecute_(command, this.UIContext_, this.save_.bind(this));
};
CommandQueue.prototype.canUndo = function() {
@@ -143,7 +138,7 @@ CommandQueue.prototype.undo = function() {
if (self.UIContext_.imageView) {
command.revertView(self.currentImage_, self.UIContext_.imageView);
}
- self.setBusy_(false);
+ self.save_();
}
if (this.previousImage_) {

Powered by Google App Engine
This is Rietveld 408576698