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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 ImageEditor.Mode.Crop.prototype.getCommand = function() { | 198 ImageEditor.Mode.Crop.prototype.getCommand = function() { |
199 var cropImageRect = this.cropRect_.getRect(); | 199 var cropImageRect = this.cropRect_.getRect(); |
200 return new Command.Crop(cropImageRect); | 200 return new Command.Crop(cropImageRect); |
201 }; | 201 }; |
202 | 202 |
203 /** | 203 /** |
204 * Creates default (initial) crop. | 204 * Creates default (initial) crop. |
205 */ | 205 */ |
206 ImageEditor.Mode.Crop.prototype.createDefaultCrop = function() { | 206 ImageEditor.Mode.Crop.prototype.createDefaultCrop = function() { |
207 var rect = this.getViewport().screenToImageRect( | 207 var rect = this.getViewport().screenToImageRect( |
208 new Rect(this.getViewport().getImageBoundsOnScreenClipped())); | 208 new ImageRect(this.getViewport().getImageBoundsOnScreenClipped())); |
209 rect = rect.inflate( | 209 rect = rect.inflate( |
210 -Math.round(rect.width / 6), -Math.round(rect.height / 6)); | 210 -Math.round(rect.width / 6), -Math.round(rect.height / 6)); |
211 this.cropRect_ = new DraggableRect(rect, this.getViewport()); | 211 this.cropRect_ = new DraggableRect(rect, this.getViewport()); |
212 this.positionDOM(); | 212 this.positionDOM(); |
213 }; | 213 }; |
214 | 214 |
215 /** | 215 /** |
216 * Obtains the cursor style depending on the mouse state. | 216 * Obtains the cursor style depending on the mouse state. |
217 * | 217 * |
218 * @param {number} x X coordinate for cursor. | 218 * @param {number} x X coordinate for cursor. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 * @param {number} y Y coordinate of the event. | 255 * @param {number} y Y coordinate of the event. |
256 * @return {ImageBuffer.DoubleTapAction} Action to perform as result. | 256 * @return {ImageBuffer.DoubleTapAction} Action to perform as result. |
257 */ | 257 */ |
258 ImageEditor.Mode.Crop.prototype.getDoubleTapAction = function(x, y) { | 258 ImageEditor.Mode.Crop.prototype.getDoubleTapAction = function(x, y) { |
259 return this.cropRect_.getDoubleTapAction(x, y); | 259 return this.cropRect_.getDoubleTapAction(x, y); |
260 }; | 260 }; |
261 | 261 |
262 /** | 262 /** |
263 * A draggable rectangle over the image. | 263 * A draggable rectangle over the image. |
264 * | 264 * |
265 * @param {Rect} rect Initial size of the image. | 265 * @param {ImageRect} rect Initial size of the image. |
266 * @param {Viewport} viewport Viewport. | 266 * @param {Viewport} viewport Viewport. |
267 * @constructor | 267 * @constructor |
268 */ | 268 */ |
269 function DraggableRect(rect, viewport) { | 269 function DraggableRect(rect, viewport) { |
270 /** | 270 /** |
271 * The bounds are not held in a regular rectangle (with width/height). | 271 * The bounds are not held in a regular rectangle (with width/height). |
272 * left/top/right/bottom held instead for convenience. | 272 * left/top/right/bottom held instead for convenience. |
273 * | 273 * |
274 * @type {{left: number, right: number, top: number, bottom: number}} | 274 * @type {{left: number, right: number, top: number, bottom: number}} |
275 * @private | 275 * @private |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 /** | 364 /** |
365 * Obtains the bottom position. | 365 * Obtains the bottom position. |
366 * @return {number} Position. | 366 * @return {number} Position. |
367 */ | 367 */ |
368 DraggableRect.prototype.getBottom = function() { | 368 DraggableRect.prototype.getBottom = function() { |
369 return this.bounds_[DraggableRect.BOTTOM]; | 369 return this.bounds_[DraggableRect.BOTTOM]; |
370 }; | 370 }; |
371 | 371 |
372 /** | 372 /** |
373 * Obtains the geometry of the rectangle. | 373 * Obtains the geometry of the rectangle. |
374 * @return {Rect} Geometry of the rectangle. | 374 * @return {ImageRect} Geometry of the rectangle. |
375 */ | 375 */ |
376 DraggableRect.prototype.getRect = function() { | 376 DraggableRect.prototype.getRect = function() { |
377 return new Rect(this.bounds_); | 377 return new ImageRect(this.bounds_); |
378 }; | 378 }; |
379 | 379 |
380 /** | 380 /** |
381 * Obtains the drag mode depending on the coordinate. | 381 * Obtains the drag mode depending on the coordinate. |
382 * | 382 * |
383 * @param {number} x X coordinate for cursor. | 383 * @param {number} x X coordinate for cursor. |
384 * @param {number} y Y coordinate for cursor. | 384 * @param {number} y Y coordinate for cursor. |
385 * @param {boolean} touch Whether the operation is done by touch or not. | 385 * @param {boolean} touch Whether the operation is done by touch or not. |
386 * @return {Object} Drag mode. | 386 * @return {Object} Drag mode. |
387 */ | 387 */ |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 break; | 663 break; |
664 case 'bottom': | 664 case 'bottom': |
665 this.bounds_.bottom = this.bounds_.top + newHeight; | 665 this.bounds_.bottom = this.bounds_.top + newHeight; |
666 break; | 666 break; |
667 case 'none': | 667 case 'none': |
668 this.bounds_.top = middle - newHeight / 2; | 668 this.bounds_.top = middle - newHeight / 2; |
669 this.bounds_.bottom = middle + newHeight / 2; | 669 this.bounds_.bottom = middle + newHeight / 2; |
670 break; | 670 break; |
671 } | 671 } |
672 }; | 672 }; |
OLD | NEW |