OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * Command queue is the only way to modify images. | 8 * Command queue is the only way to modify images. |
9 * Supports undo/redo. | 9 * Supports undo/redo. |
10 * Command execution is asynchronous (callback-based). | 10 * Command execution is asynchronous (callback-based). |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 this.filter_ = filter; | 408 this.filter_ = filter; |
409 this.message_ = message; | 409 this.message_ = message; |
410 }; | 410 }; |
411 | 411 |
412 Command.Filter.prototype = { __proto__: Command.prototype }; | 412 Command.Filter.prototype = { __proto__: Command.prototype }; |
413 | 413 |
414 /** @override */ | 414 /** @override */ |
415 Command.Filter.prototype.execute = function( | 415 Command.Filter.prototype.execute = function( |
416 document, srcCanvas, callback, uiContext) { | 416 document, srcCanvas, callback, uiContext) { |
417 var result = this.createCanvas_(document, srcCanvas); | 417 var result = this.createCanvas_(document, srcCanvas); |
418 | |
419 var self = this; | 418 var self = this; |
420 | |
421 var previousRow = 0; | 419 var previousRow = 0; |
422 | 420 |
423 function onProgressVisible(updatedRow, rowCount) { | 421 function onProgressVisible(updatedRow, rowCount) { |
424 if (updatedRow == rowCount) { | 422 if (updatedRow == rowCount) { |
425 uiContext.imageView.replace(result); | 423 uiContext.imageView.replace(result); |
426 if (self.message_) | 424 if (self.message_) |
427 uiContext.prompt.show(self.message_, 2000); | 425 uiContext.prompt.show(self.message_, 2000); |
428 callback(result); | 426 callback(result); |
429 } else { | 427 } else { |
430 var viewport = uiContext.imageView.viewport_; | 428 var viewport = uiContext.imageView.viewport_; |
431 | 429 |
432 var imageStrip = new Rect(viewport.getImageBounds()); | 430 var imageStrip = new Rect(viewport.getImageBounds()); |
433 imageStrip.top = previousRow; | 431 imageStrip.top = previousRow; |
434 imageStrip.height = updatedRow - previousRow; | 432 imageStrip.height = updatedRow - previousRow; |
435 | 433 |
436 var screenStrip = new Rect(viewport.getImageBoundsOnScreen()); | 434 var screenStrip = new Rect(viewport.getImageBoundsOnScreen()); |
437 screenStrip.top = Math.round(viewport.imageToScreenY(previousRow)); | 435 screenStrip.top = Math.round(viewport.imageToScreenY(previousRow)); |
438 screenStrip.height = | 436 screenStrip.height = |
439 Math.round(viewport.imageToScreenY(updatedRow)) - screenStrip.top; | 437 Math.round(viewport.imageToScreenY(updatedRow)) - screenStrip.top; |
440 | 438 |
441 uiContext.imageView.paintDeviceRect( | 439 uiContext.imageView.paintDeviceRect(result, imageStrip); |
442 viewport.screenToDeviceRect(screenStrip), result, imageStrip); | |
443 previousRow = updatedRow; | 440 previousRow = updatedRow; |
444 } | 441 } |
445 } | 442 } |
446 | 443 |
447 function onProgressInvisible(updatedRow, rowCount) { | 444 function onProgressInvisible(updatedRow, rowCount) { |
448 if (updatedRow == rowCount) { | 445 if (updatedRow == rowCount) { |
449 callback(result); | 446 callback(result); |
450 } | 447 } |
451 } | 448 } |
452 | 449 |
453 filter.applyByStrips(result, srcCanvas, this.filter_, | 450 filter.applyByStrips(result, srcCanvas, this.filter_, |
454 uiContext.imageView ? onProgressVisible : onProgressInvisible); | 451 uiContext.imageView ? onProgressVisible : onProgressInvisible); |
455 }; | 452 }; |
OLD | NEW |