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 /** | 5 /** |
6 * Crop mode. | 6 * Crop mode. |
7 * | 7 * |
8 * @extends {ImageEditor.Mode} | 8 * @extends {ImageEditor.Mode} |
9 * @constructor | 9 * @constructor |
10 * @struct | 10 * @struct |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 */ | 206 */ |
207 ImageEditor.Mode.Crop.prototype.reset = function() { | 207 ImageEditor.Mode.Crop.prototype.reset = function() { |
208 ImageEditor.Mode.prototype.reset.call(this); | 208 ImageEditor.Mode.prototype.reset.call(this); |
209 this.createDefaultCrop(); | 209 this.createDefaultCrop(); |
210 }; | 210 }; |
211 | 211 |
212 /** | 212 /** |
213 * Updates the position of DOM elements. | 213 * Updates the position of DOM elements. |
214 */ | 214 */ |
215 ImageEditor.Mode.Crop.prototype.positionDOM = function() { | 215 ImageEditor.Mode.Crop.prototype.positionDOM = function() { |
216 var screenClipped = this.viewport_.getImageBoundsOnScreenClipped(); | 216 var screenCrop = this.viewport_.imageToScreenRect(this.cropRect_.getRect()); |
217 | 217 |
218 var screenCrop = this.viewport_.imageToScreenRect(this.cropRect_.getRect()); | 218 this.shadowLeft_.style.width = screenCrop.left + 'px'; |
219 var delta = ImageEditor.Mode.Crop.MOUSE_GRAB_RADIUS; | 219 this.shadowTop_.style.height = screenCrop.top + 'px'; |
220 this.editor_.hideOverlappingTools( | 220 this.shadowRight_.style.width = window.innerWidth - screenCrop.right + 'px'; |
221 screenCrop.inflate(delta, delta), | 221 this.shadowBottom_.style.height = |
222 screenCrop.inflate(-delta, -delta)); | 222 window.innerHeight - screenCrop.bottom + 'px'; |
223 | |
224 this.domOverlay_.style.left = screenClipped.left + 'px'; | |
225 this.domOverlay_.style.top = screenClipped.top + 'px'; | |
226 this.domOverlay_.style.width = screenClipped.width + 'px'; | |
227 this.domOverlay_.style.height = screenClipped.height + 'px'; | |
228 | |
229 this.shadowLeft_.style.width = screenCrop.left - screenClipped.left + 'px'; | |
230 | |
231 this.shadowTop_.style.height = screenCrop.top - screenClipped.top + 'px'; | |
232 | |
233 this.shadowRight_.style.width = screenClipped.left + screenClipped.width - | |
234 (screenCrop.left + screenCrop.width) + 'px'; | |
235 | |
236 this.shadowBottom_.style.height = screenClipped.top + screenClipped.height - | |
237 (screenCrop.top + screenCrop.height) + 'px'; | |
238 }; | 223 }; |
239 | 224 |
240 /** | 225 /** |
241 * Removes the overlay elements from the document. | 226 * Removes the overlay elements from the document. |
242 */ | 227 */ |
243 ImageEditor.Mode.Crop.prototype.cleanUpUI = function() { | 228 ImageEditor.Mode.Crop.prototype.cleanUpUI = function() { |
244 ImageEditor.Mode.prototype.cleanUpUI.apply(this, arguments); | 229 ImageEditor.Mode.prototype.cleanUpUI.apply(this, arguments); |
245 this.domOverlay_.parentNode.removeChild(this.domOverlay_); | 230 this.domOverlay_.parentNode.removeChild(this.domOverlay_); |
246 this.domOverlay_ = null; | 231 this.domOverlay_ = null; |
247 this.editor_.hideOverlappingTools(); | |
248 this.getViewport().removeEventListener( | 232 this.getViewport().removeEventListener( |
249 'resize', this.onViewportResizedBound_); | 233 'resize', this.onViewportResizedBound_); |
250 this.onViewportResizedBound_ = null; | 234 this.onViewportResizedBound_ = null; |
251 | 235 |
252 // Restore the screen to the full size of window. | 236 // Restore the screen to the full size of window. |
253 this.getViewport().setScreenTop(0); | 237 this.getViewport().setScreenTop(0); |
254 this.getViewport().setScreenBottom(0); | 238 this.getViewport().setScreenBottom(0); |
255 this.getImageView().applyViewportChange(); | 239 this.getImageView().applyViewportChange(); |
256 }; | 240 }; |
257 | 241 |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 * Obtains the drag handler depending on the coordinate. | 540 * Obtains the drag handler depending on the coordinate. |
557 * | 541 * |
558 * @param {number} initialScreenX X coordinate for cursor in the screen. | 542 * @param {number} initialScreenX X coordinate for cursor in the screen. |
559 * @param {number} initialScreenY Y coordinate for cursor in the screen. | 543 * @param {number} initialScreenY Y coordinate for cursor in the screen. |
560 * @param {boolean} touch Whether the operation is done by touch or not. | 544 * @param {boolean} touch Whether the operation is done by touch or not. |
561 * @return {?function(number,number,boolean)} Drag handler that takes x | 545 * @return {?function(number,number,boolean)} Drag handler that takes x |
562 * coordinate value, y coordinate value, and shift key flag. | 546 * coordinate value, y coordinate value, and shift key flag. |
563 */ | 547 */ |
564 DraggableRect.prototype.getDragHandler = function( | 548 DraggableRect.prototype.getDragHandler = function( |
565 initialScreenX, initialScreenY, touch) { | 549 initialScreenX, initialScreenY, touch) { |
566 // Check if the initial coordinate in the clip rect. | 550 // Check if the initial coordinate is in the image rect. |
| 551 var boundsOnScreen = this.viewport_.getImageBoundsOnScreenClipped(); |
| 552 var handlerRadius = touch ? ImageEditor.Mode.Crop.TOUCH_GRAB_RADIUS : |
| 553 ImageEditor.Mode.Crop.MOUSE_GRAB_RADIUS; |
| 554 var draggableAreas = [ |
| 555 boundsOnScreen, |
| 556 new Circle(boundsOnScreen.left, boundsOnScreen.top, handlerRadius), |
| 557 new Circle(boundsOnScreen.right, boundsOnScreen.top, handlerRadius), |
| 558 new Circle(boundsOnScreen.left, boundsOnScreen.bottom, handlerRadius), |
| 559 new Circle(boundsOnScreen.right, boundsOnScreen.bottom, handlerRadius) |
| 560 ]; |
| 561 |
| 562 if (!draggableAreas.some( |
| 563 (area) => area.inside(initialScreenX, initialScreenY))) { |
| 564 return null; |
| 565 } |
| 566 |
| 567 // Convert coordinates. |
567 var initialX = this.viewport_.screenToImageX(initialScreenX); | 568 var initialX = this.viewport_.screenToImageX(initialScreenX); |
568 var initialY = this.viewport_.screenToImageY(initialScreenY); | 569 var initialY = this.viewport_.screenToImageY(initialScreenY); |
569 var initialWidth = this.bounds_.right - this.bounds_.left; | 570 var initialWidth = this.bounds_.right - this.bounds_.left; |
570 var initialHeight = this.bounds_.bottom - this.bounds_.top; | 571 var initialHeight = this.bounds_.bottom - this.bounds_.top; |
571 var clipRect = this.viewport_.screenToImageRect( | 572 var clipRect = this.viewport_.screenToImageRect(boundsOnScreen); |
572 this.viewport_.getImageBoundsOnScreenClipped()); | |
573 if (!clipRect.inside(initialX, initialY)) | |
574 return null; | |
575 | 573 |
576 // Obtain the drag mode. | 574 // Obtain the drag mode. |
577 this.dragMode_ = this.getDragMode(initialX, initialY, touch); | 575 this.dragMode_ = this.getDragMode(initialX, initialY, touch); |
578 | 576 |
579 if (this.dragMode_.whole) { | 577 if (this.dragMode_.whole) { |
580 // Calc constant values during the operation. | 578 // Calc constant values during the operation. |
581 var mouseBiasX = this.bounds_.left - initialX; | 579 var mouseBiasX = this.bounds_.left - initialX; |
582 var mouseBiasY = this.bounds_.top - initialY; | 580 var mouseBiasY = this.bounds_.top - initialY; |
583 var maxX = clipRect.left + clipRect.width - initialWidth; | 581 var maxX = clipRect.left + clipRect.width - initialWidth; |
584 var maxY = clipRect.top + clipRect.height - initialHeight; | 582 var maxY = clipRect.top + clipRect.height - initialHeight; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 break; | 746 break; |
749 case 'bottom': | 747 case 'bottom': |
750 this.bounds_.bottom = this.bounds_.top + newHeight; | 748 this.bounds_.bottom = this.bounds_.top + newHeight; |
751 break; | 749 break; |
752 case 'none': | 750 case 'none': |
753 this.bounds_.top = middle - newHeight / 2; | 751 this.bounds_.top = middle - newHeight / 2; |
754 this.bounds_.bottom = middle + newHeight / 2; | 752 this.bounds_.bottom = middle + newHeight / 2; |
755 break; | 753 break; |
756 } | 754 } |
757 }; | 755 }; |
OLD | NEW |