| 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 * Crop mode. | 8 * Crop mode. |
| 9 * | 9 * |
| 10 * @extends {ImageEditor.Mode} | 10 * @extends {ImageEditor.Mode} |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 */ | 121 */ |
| 122 ImageEditor.Mode.Crop.prototype.reset = function() { | 122 ImageEditor.Mode.Crop.prototype.reset = function() { |
| 123 ImageEditor.Mode.prototype.reset.call(this); | 123 ImageEditor.Mode.prototype.reset.call(this); |
| 124 this.createDefaultCrop(); | 124 this.createDefaultCrop(); |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 /** | 127 /** |
| 128 * Updates the position of DOM elements. | 128 * Updates the position of DOM elements. |
| 129 */ | 129 */ |
| 130 ImageEditor.Mode.Crop.prototype.positionDOM = function() { | 130 ImageEditor.Mode.Crop.prototype.positionDOM = function() { |
| 131 var screenClipped = this.viewport_.getScreenClipped(); | 131 var screenClipped = this.viewport_.getImageBoundsOnScreenClipped(); |
| 132 | 132 |
| 133 var screenCrop = this.viewport_.imageToScreenRect(this.cropRect_.getRect()); | 133 var screenCrop = this.viewport_.imageToScreenRect(this.cropRect_.getRect()); |
| 134 var delta = ImageEditor.Mode.Crop.MOUSE_GRAB_RADIUS; | 134 var delta = ImageEditor.Mode.Crop.MOUSE_GRAB_RADIUS; |
| 135 this.editor_.hideOverlappingTools( | 135 this.editor_.hideOverlappingTools( |
| 136 screenCrop.inflate(delta, delta), | 136 screenCrop.inflate(delta, delta), |
| 137 screenCrop.inflate(-delta, -delta)); | 137 screenCrop.inflate(-delta, -delta)); |
| 138 | 138 |
| 139 this.domOverlay_.style.left = screenClipped.left + 'px'; | 139 this.domOverlay_.style.left = screenClipped.left + 'px'; |
| 140 this.domOverlay_.style.top = screenClipped.top + 'px'; | 140 this.domOverlay_.style.top = screenClipped.top + 'px'; |
| 141 this.domOverlay_.style.width = screenClipped.width + 'px'; | 141 this.domOverlay_.style.width = screenClipped.width + 'px'; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 */ | 183 */ |
| 184 ImageEditor.Mode.Crop.prototype.getCommand = function() { | 184 ImageEditor.Mode.Crop.prototype.getCommand = function() { |
| 185 var cropImageRect = this.cropRect_.getRect(); | 185 var cropImageRect = this.cropRect_.getRect(); |
| 186 return new Command.Crop(cropImageRect); | 186 return new Command.Crop(cropImageRect); |
| 187 }; | 187 }; |
| 188 | 188 |
| 189 /** | 189 /** |
| 190 * Creates default (initial) crop. | 190 * Creates default (initial) crop. |
| 191 */ | 191 */ |
| 192 ImageEditor.Mode.Crop.prototype.createDefaultCrop = function() { | 192 ImageEditor.Mode.Crop.prototype.createDefaultCrop = function() { |
| 193 var rect = new Rect(this.getViewport().getImageClipped()); | 193 var rect = this.getViewport().screenToImageRect( |
| 194 new Rect(this.getViewport().getImageBoundsOnScreenClipped())); |
| 194 rect = rect.inflate( | 195 rect = rect.inflate( |
| 195 -Math.round(rect.width / 6), -Math.round(rect.height / 6)); | 196 -Math.round(rect.width / 6), -Math.round(rect.height / 6)); |
| 196 this.cropRect_ = new DraggableRect(rect, this.getViewport()); | 197 this.cropRect_ = new DraggableRect(rect, this.getViewport()); |
| 197 this.positionDOM(); | 198 this.positionDOM(); |
| 198 }; | 199 }; |
| 199 | 200 |
| 200 /** | 201 /** |
| 201 * Obtains the cursor style depending on the mouse state. | 202 * Obtains the cursor style depending on the mouse state. |
| 202 * | 203 * |
| 203 * @param {number} x X coordinate for cursor. | 204 * @param {number} x X coordinate for cursor. |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 * @return {function(number,number,boolean)} Drag handler that takes x | 459 * @return {function(number,number,boolean)} Drag handler that takes x |
| 459 * coordinate value, y coordinate value, and shift key flag. | 460 * coordinate value, y coordinate value, and shift key flag. |
| 460 */ | 461 */ |
| 461 DraggableRect.prototype.getDragHandler = function( | 462 DraggableRect.prototype.getDragHandler = function( |
| 462 initialScreenX, initialScreenY, touch) { | 463 initialScreenX, initialScreenY, touch) { |
| 463 // Check if the initial coordinate in the clip rect. | 464 // Check if the initial coordinate in the clip rect. |
| 464 var initialX = this.viewport_.screenToImageX(initialScreenX); | 465 var initialX = this.viewport_.screenToImageX(initialScreenX); |
| 465 var initialY = this.viewport_.screenToImageY(initialScreenY); | 466 var initialY = this.viewport_.screenToImageY(initialScreenY); |
| 466 var initialWidth = this.bounds_.right - this.bounds_.left; | 467 var initialWidth = this.bounds_.right - this.bounds_.left; |
| 467 var initialHeight = this.bounds_.bottom - this.bounds_.top; | 468 var initialHeight = this.bounds_.bottom - this.bounds_.top; |
| 468 var clipRect = this.viewport_.getImageClipped(); | 469 var clipRect = this.viewport_.screenToImageRect( |
| 470 this.viewport_.getImageBoundsOnScreenClipped()); |
| 469 if (!clipRect.inside(initialX, initialY)) | 471 if (!clipRect.inside(initialX, initialY)) |
| 470 return null; | 472 return null; |
| 471 | 473 |
| 472 // Obtain the drag mode. | 474 // Obtain the drag mode. |
| 473 this.dragMode_ = this.getDragMode(initialX, initialY, touch); | 475 this.dragMode_ = this.getDragMode(initialX, initialY, touch); |
| 474 | 476 |
| 475 if (this.dragMode_.whole) { | 477 if (this.dragMode_.whole) { |
| 476 // Calc constant values during the operation. | 478 // Calc constant values during the operation. |
| 477 var mouseBiasX = this.bounds_.left - initialX; | 479 var mouseBiasX = this.bounds_.left - initialX; |
| 478 var mouseBiasY = this.bounds_.top - initialY; | 480 var mouseBiasY = this.bounds_.top - initialY; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 | 552 |
| 551 /** | 553 /** |
| 552 * Obtains double tap action depending on the coordinate. | 554 * Obtains double tap action depending on the coordinate. |
| 553 * | 555 * |
| 554 * @param {number} x X coordinate for cursor. | 556 * @param {number} x X coordinate for cursor. |
| 555 * @param {number} y Y coordinate for cursor. | 557 * @param {number} y Y coordinate for cursor. |
| 556 * @param {boolean} touch Whether the operation is done by touch or not. | 558 * @param {boolean} touch Whether the operation is done by touch or not. |
| 557 * @return {ImageBuffer.DoubleTapAction} Double tap action. | 559 * @return {ImageBuffer.DoubleTapAction} Double tap action. |
| 558 */ | 560 */ |
| 559 DraggableRect.prototype.getDoubleTapAction = function(x, y, touch) { | 561 DraggableRect.prototype.getDoubleTapAction = function(x, y, touch) { |
| 560 x = this.viewport_.screenToImageX(x); | 562 var clipRect = this.viewport_.getImageBoundsOnScreenClipped(); |
| 561 y = this.viewport_.screenToImageY(y); | |
| 562 | |
| 563 var clipRect = this.viewport_.getImageClipped(); | |
| 564 if (clipRect.inside(x, y)) | 563 if (clipRect.inside(x, y)) |
| 565 return ImageBuffer.DoubleTapAction.COMMIT; | 564 return ImageBuffer.DoubleTapAction.COMMIT; |
| 566 else | 565 else |
| 567 return ImageBuffer.DoubleTapAction.NOTHING; | 566 return ImageBuffer.DoubleTapAction.NOTHING; |
| 568 }; | 567 }; |
| 569 | 568 |
| 570 /** | 569 /** |
| 571 * Forces the aspect ratio. | 570 * Forces the aspect ratio. |
| 572 * | 571 * |
| 573 * @param {number} aspectRatio Aspect ratio. | 572 * @param {number} aspectRatio Aspect ratio. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 break; | 643 break; |
| 645 case 'bottom': | 644 case 'bottom': |
| 646 this.bounds_.bottom = this.bounds_.top + newHeight; | 645 this.bounds_.bottom = this.bounds_.top + newHeight; |
| 647 break; | 646 break; |
| 648 case 'none': | 647 case 'none': |
| 649 this.bounds_.top = middle - newHeight / 2; | 648 this.bounds_.top = middle - newHeight / 2; |
| 650 this.bounds_.bottom = middle + newHeight / 2; | 649 this.bounds_.bottom = middle + newHeight / 2; |
| 651 break; | 650 break; |
| 652 } | 651 } |
| 653 }; | 652 }; |
| OLD | NEW |