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 |
10 * @param {Document} document Document to create canvases in. | 11 * @param {Document} document Document to create canvases in. |
11 * @param {HTMLCanvasElement} canvas The canvas with the original image. | 12 * @param {HTMLCanvasElement} canvas The canvas with the original image. |
12 * @param {function(callback)} saveFunction Function to save the image. | 13 * @param {function(callback)} saveFunction Function to save the image. |
13 */ | 14 */ |
14 function CommandQueue(document, canvas, saveFunction) { | 15 function CommandQueue(document, canvas, saveFunction) { |
15 this.document_ = document; | 16 this.document_ = document; |
16 this.undo_ = []; | 17 this.undo_ = []; |
17 this.redo_ = []; | 18 this.redo_ = []; |
18 this.subscribers_ = []; | 19 this.subscribers_ = []; |
19 | 20 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 if (!this.canRedo()) | 211 if (!this.canRedo()) |
211 throw new Error('Cannot redo'); | 212 throw new Error('Cannot redo'); |
212 | 213 |
213 this.execute(this.redo_.pop(), true); | 214 this.execute(this.redo_.pop(), true); |
214 }; | 215 }; |
215 | 216 |
216 /** | 217 /** |
217 * 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 |
218 * its result. | 219 * its result. |
219 * | 220 * |
| 221 * @constructor |
220 * @param {string} name Command name. | 222 * @param {string} name Command name. |
221 */ | 223 */ |
222 function Command(name) { | 224 function Command(name) { |
223 this.name_ = name; | 225 this.name_ = name; |
224 } | 226 } |
225 | 227 |
226 /** | 228 /** |
227 * @return {string} String representation of the command. | 229 * @return {string} String representation of the command. |
228 */ | 230 */ |
229 Command.prototype.toString = function() { | 231 Command.prototype.toString = function() { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 | 400 |
399 function onProgressInvisible(updatedRow, rowCount) { | 401 function onProgressInvisible(updatedRow, rowCount) { |
400 if (updatedRow == rowCount) { | 402 if (updatedRow == rowCount) { |
401 callback(result); | 403 callback(result); |
402 } | 404 } |
403 } | 405 } |
404 | 406 |
405 filter.applyByStrips(result, srcCanvas, this.filter_, | 407 filter.applyByStrips(result, srcCanvas, this.filter_, |
406 uiContext.imageView ? onProgressVisible : onProgressInvisible); | 408 uiContext.imageView ? onProgressVisible : onProgressInvisible); |
407 }; | 409 }; |
OLD | NEW |