OLD | NEW |
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 * Command queue is the only way to modify images. | 6 * Command queue is the only way to modify images. |
7 * Supports undo/redo. | 7 * Supports undo/redo. |
8 * Command execution is asynchronous (callback-based). | 8 * Command execution is asynchronous (callback-based). |
9 * | 9 * |
10 * @constructor | |
11 * @param {Document} document Document to create canvases in. | 10 * @param {Document} document Document to create canvases in. |
12 * @param {HTMLCanvasElement} canvas The canvas with the original image. | 11 * @param {HTMLCanvasElement} canvas The canvas with the original image. |
13 * @param {function(callback)} saveFunction Function to save the image. | 12 * @param {function(callback)} saveFunction Function to save the image. |
| 13 * @constructor |
14 */ | 14 */ |
15 function CommandQueue(document, canvas, saveFunction) { | 15 function CommandQueue(document, canvas, saveFunction) { |
16 this.document_ = document; | 16 this.document_ = document; |
17 this.undo_ = []; | 17 this.undo_ = []; |
18 this.redo_ = []; | 18 this.redo_ = []; |
19 this.subscribers_ = []; | 19 this.subscribers_ = []; |
20 | 20 |
21 this.baselineImage_ = canvas; | 21 this.baselineImage_ = canvas; |
22 this.currentImage_ = canvas; | 22 this.currentImage_ = canvas; |
23 this.previousImage_ = null; | 23 this.previousImage_ = null; |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 if (!this.canRedo()) | 211 if (!this.canRedo()) |
212 throw new Error('Cannot redo'); | 212 throw new Error('Cannot redo'); |
213 | 213 |
214 this.execute(this.redo_.pop(), true); | 214 this.execute(this.redo_.pop(), true); |
215 }; | 215 }; |
216 | 216 |
217 /** | 217 /** |
218 * Command object encapsulates an operation on an image and a way to visualize | 218 * Command object encapsulates an operation on an image and a way to visualize |
219 * its result. | 219 * its result. |
220 * | 220 * |
| 221 * @param {string} name Command name. |
221 * @constructor | 222 * @constructor |
222 * @param {string} name Command name. | |
223 */ | 223 */ |
224 function Command(name) { | 224 function Command(name) { |
225 this.name_ = name; | 225 this.name_ = name; |
226 } | 226 } |
227 | 227 |
228 /** | 228 /** |
229 * @return {string} String representation of the command. | 229 * @return {string} String representation of the command. |
230 */ | 230 */ |
231 Command.prototype.toString = function() { | 231 Command.prototype.toString = function() { |
232 return 'Command ' + this.name_; | 232 return 'Command ' + this.name_; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 | 400 |
401 function onProgressInvisible(updatedRow, rowCount) { | 401 function onProgressInvisible(updatedRow, rowCount) { |
402 if (updatedRow == rowCount) { | 402 if (updatedRow == rowCount) { |
403 callback(result); | 403 callback(result); |
404 } | 404 } |
405 } | 405 } |
406 | 406 |
407 filter.applyByStrips(result, srcCanvas, this.filter_, | 407 filter.applyByStrips(result, srcCanvas, this.filter_, |
408 uiContext.imageView ? onProgressVisible : onProgressInvisible); | 408 uiContext.imageView ? onProgressVisible : onProgressInvisible); |
409 }; | 409 }; |
OLD | NEW |