Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 * ImageEditor is the top level object that holds together and connects | 6 * ImageEditor is the top level object that holds together and connects |
| 7 * everything needed for image editing. | 7 * everything needed for image editing. |
| 8 * @param {HTMLElement} container | 8 * @param {HTMLElement} container |
| 9 * @param {function(Blob)} saveCallback | 9 * @param {function(Blob)} saveCallback |
| 10 * @param {function()} closeCallback | 10 * @param {function()} closeCallback |
| 11 * @param {HTMLElement} toolbarContainer | |
| 11 */ | 12 */ |
| 12 function ImageEditor(container, saveCallback, closeCallback) { | 13 function ImageEditor(container, saveCallback, closeCallback, toolbarContainer) { |
| 13 this.container_ = container; | 14 this.container_ = container; |
| 14 this.saveCallback_ = saveCallback; | 15 this.saveCallback_ = saveCallback; |
| 15 this.closeCallback_ = closeCallback; | 16 this.closeCallback_ = closeCallback; |
| 16 | 17 |
| 17 this.container_.innerHTML = ''; | 18 this.container_.innerHTML = ''; |
| 18 | 19 |
| 19 var document = this.container_.ownerDocument; | 20 var document = this.container_.ownerDocument; |
| 20 | 21 |
| 21 this.canvasWrapper_ = document.createElement('div'); | 22 this.canvasWrapper_ = document.createElement('div'); |
| 22 this.canvasWrapper_.className = 'canvas-wrapper'; | 23 this.canvasWrapper_.className = 'canvas-wrapper'; |
| 23 container.appendChild(this.canvasWrapper_); | 24 container.appendChild(this.canvasWrapper_); |
| 24 | 25 |
| 25 var canvas = document.createElement('canvas'); | 26 var canvas = document.createElement('canvas'); |
| 26 this.canvasWrapper_.appendChild(canvas); | 27 this.canvasWrapper_.appendChild(canvas); |
| 27 canvas.width = this.canvasWrapper_.clientWidth; | 28 canvas.width = this.canvasWrapper_.clientWidth; |
| 28 canvas.height = this.canvasWrapper_.clientHeight; | 29 canvas.height = this.canvasWrapper_.clientHeight; |
| 29 | 30 |
| 30 this.buffer_ = new ImageBuffer(canvas); | 31 this.buffer_ = new ImageBuffer(canvas); |
| 31 | 32 |
| 32 this.scaleControl_ = new ImageEditor.ScaleControl( | 33 // We don't need this for now. |
|
zel
2011/09/02 17:11:58
then remove it if it's not needed
dgozman
2011/09/06 14:18:47
Done.
| |
| 33 this.canvasWrapper_, this.getBuffer().getViewport()); | 34 // this.scaleControl_ = new ImageEditor.ScaleControl( |
| 35 // this.canvasWrapper_, this.getBuffer().getViewport()); | |
| 34 | 36 |
| 35 this.panControl_ = new ImageEditor.MouseControl(canvas, this.getBuffer()); | 37 this.panControl_ = new ImageEditor.MouseControl(canvas, this.getBuffer()); |
| 36 | 38 |
| 37 this.toolbar_ = | 39 this.toolbar_ = new ImageEditor.Toolbar(toolbarContainer, |
| 38 new ImageEditor.Toolbar(container, this.onOptionsChange.bind(this)); | 40 this.onOptionsChange.bind(this)); |
| 39 this.initToolbar(); | 41 this.initToolbar(); |
| 40 } | 42 } |
| 41 | 43 |
| 42 /** | 44 /** |
| 43 * Create an ImageEditor instance bound to a current web page, load the content. | 45 * Create an ImageEditor instance bound to a current web page, load the content. |
| 44 * | 46 * |
| 45 * Use this method when image_editor.html is loaded into an iframe. | 47 * Use this method when image_editor.html is loaded into an iframe. |
| 46 * | 48 * |
| 47 * @param {function(Blob)} saveCallback | 49 * @param {function(Blob)} saveCallback |
| 48 * @param {function()} closeCallback | 50 * @param {function()} closeCallback |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 if (this.currentMode_) | 107 if (this.currentMode_) |
| 106 this.currentMode_.update(options); | 108 this.currentMode_.update(options); |
| 107 ImageUtil.trace.reportTimer('update'); | 109 ImageUtil.trace.reportTimer('update'); |
| 108 }; | 110 }; |
| 109 | 111 |
| 110 ImageEditor.prototype.initToolbar = function() { | 112 ImageEditor.prototype.initToolbar = function() { |
| 111 this.toolbar_.clear(); | 113 this.toolbar_.clear(); |
| 112 | 114 |
| 113 this.createModeButtons(); | 115 this.createModeButtons(); |
| 114 this.toolbar_.addButton('Save', this.save.bind(this, true)); | 116 this.toolbar_.addButton('Save', this.save.bind(this, true)); |
| 115 this.toolbar_.addButton('Close', this.close.bind(this, false)); | 117 // this.toolbar_.addButton('Close', this.close.bind(this, false)); |
|
zel
2011/09/02 17:11:58
if this button is removed, please remove this line
dgozman
2011/09/06 14:18:47
Done.
| |
| 116 }; | 118 }; |
| 117 | 119 |
| 118 /** | 120 /** |
| 119 * ImageEditor.Mode represents a modal state dedicated to a specific operation. | 121 * ImageEditor.Mode represents a modal state dedicated to a specific operation. |
| 120 * Inherits from ImageBuffer.Overlay to simplify the drawing of | 122 * Inherits from ImageBuffer.Overlay to simplify the drawing of |
| 121 * mode-specific tools. | 123 * mode-specific tools. |
| 122 */ | 124 */ |
| 123 | 125 |
| 124 ImageEditor.Mode = function(displayName) { | 126 ImageEditor.Mode = function(displayName) { |
| 125 this.displayName = displayName; | 127 this.displayName = displayName; |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 544 values[child.name] = child.getValue(); | 546 values[child.name] = child.getValue(); |
| 545 } | 547 } |
| 546 return values; | 548 return values; |
| 547 }; | 549 }; |
| 548 | 550 |
| 549 ImageEditor.Toolbar.prototype.reset = function() { | 551 ImageEditor.Toolbar.prototype.reset = function() { |
| 550 for (var child = this.wrapper_.firstChild; child; child = child.nextSibling) { | 552 for (var child = this.wrapper_.firstChild; child; child = child.nextSibling) { |
| 551 if (child.reset) child.reset(); | 553 if (child.reset) child.reset(); |
| 552 } | 554 } |
| 553 }; | 555 }; |
| OLD | NEW |