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 * 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 * | 8 * |
9 * @param {!Viewport} viewport The viewport. | 9 * @param {!Viewport} viewport The viewport. |
10 * @param {!ImageView} imageView The ImageView containing the images to edit. | 10 * @param {!ImageView} imageView The ImageView containing the images to edit. |
(...skipping 26 matching lines...) Expand all Loading... |
37 /** | 37 /** |
38 * @private {HTMLElement} | 38 * @private {HTMLElement} |
39 */ | 39 */ |
40 this.currentTool_ = null; | 40 this.currentTool_ = null; |
41 | 41 |
42 /** | 42 /** |
43 * @private {boolean} | 43 * @private {boolean} |
44 */ | 44 */ |
45 this.settingUpNextMode_ = false; | 45 this.settingUpNextMode_ = false; |
46 | 46 |
| 47 /** |
| 48 * @private {boolean} |
| 49 */ |
| 50 this.showingAlertDialog_ = false; |
| 51 |
47 ImageUtil.removeChildren(this.container_); | 52 ImageUtil.removeChildren(this.container_); |
48 | 53 |
49 this.viewport_ = viewport; | 54 this.viewport_ = viewport; |
50 | 55 |
51 this.imageView_ = imageView; | 56 this.imageView_ = imageView; |
52 | 57 |
53 this.buffer_ = new ImageBuffer(); | 58 this.buffer_ = new ImageBuffer(); |
54 this.buffer_.addOverlay(this.imageView_); | 59 this.buffer_.addOverlay(this.imageView_); |
55 | 60 |
56 this.panControl_ = new ImageEditor.MouseControl( | 61 this.panControl_ = new ImageEditor.MouseControl( |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 /** | 677 /** |
673 * The user clicked on 'OK' or 'Cancel' or on a different mode button. | 678 * The user clicked on 'OK' or 'Cancel' or on a different mode button. |
674 * @param {boolean} commit True if commit is required. | 679 * @param {boolean} commit True if commit is required. |
675 * @param {boolean} leaveToSwitchMode True if it leaves to change mode. | 680 * @param {boolean} leaveToSwitchMode True if it leaves to change mode. |
676 * @private | 681 * @private |
677 */ | 682 */ |
678 ImageEditor.prototype.leaveModeInternal_ = function(commit, leaveToSwitchMode) { | 683 ImageEditor.prototype.leaveModeInternal_ = function(commit, leaveToSwitchMode) { |
679 if (!this.currentMode_) | 684 if (!this.currentMode_) |
680 return; | 685 return; |
681 | 686 |
| 687 // If the current mode is image-resize, and commit is required, |
| 688 // leaving mode should be stopped when an input value is not valid. |
| 689 if(commit && this.currentMode_.name === 'image-resize') { |
| 690 var imageResizeMode = /** @type {!ImageEditor.Mode.ImageResize} */ |
| 691 (this.currentMode_); |
| 692 if(!imageResizeMode.isInputValid()) { |
| 693 this.showingAlertDialog_ = true; |
| 694 |
| 695 imageResizeMode.showAlertDialog(function() { |
| 696 this.showingAlertDialog_ = false; |
| 697 }.bind(this)); |
| 698 return; |
| 699 } |
| 700 } |
| 701 |
682 this.modeToolbar_.show(false); | 702 this.modeToolbar_.show(false); |
683 | 703 |
684 // If it leaves to switch mode, do not restore screen size since the next mode | 704 // If it leaves to switch mode, do not restore screen size since the next mode |
685 // might change screen size. We should avoid to show intermediate animation | 705 // might change screen size. We should avoid to show intermediate animation |
686 // which tries to restore screen size. | 706 // which tries to restore screen size. |
687 if (!leaveToSwitchMode) { | 707 if (!leaveToSwitchMode) { |
688 this.getViewport().setScreenTop(ImageEditor.Toolbar.HEIGHT); | 708 this.getViewport().setScreenTop(ImageEditor.Toolbar.HEIGHT); |
689 this.getViewport().setScreenBottom(ImageEditor.Toolbar.HEIGHT); | 709 this.getViewport().setScreenBottom(ImageEditor.Toolbar.HEIGHT); |
690 this.getImageView().applyViewportChange(); | 710 this.getImageView().applyViewportChange(); |
691 } | 711 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 | 764 |
745 /** | 765 /** |
746 * Key down handler. | 766 * Key down handler. |
747 * @param {!Event} event The keydown event. | 767 * @param {!Event} event The keydown event. |
748 * @return {boolean} True if handled. | 768 * @return {boolean} True if handled. |
749 */ | 769 */ |
750 ImageEditor.prototype.onKeyDown = function(event) { | 770 ImageEditor.prototype.onKeyDown = function(event) { |
751 switch (util.getKeyModifiers(event) + event.key) { | 771 switch (util.getKeyModifiers(event) + event.key) { |
752 case 'Escape': | 772 case 'Escape': |
753 case 'Enter': | 773 case 'Enter': |
| 774 if (this.showingAlertDialog_) |
| 775 return false; |
754 if (this.getMode()) { | 776 if (this.getMode()) { |
755 this.leaveModeInternal_(event.key === 'Enter', | 777 this.leaveModeInternal_(event.key === 'Enter', |
756 false /* not to switch mode */); | 778 false /* not to switch mode */); |
757 return true; | 779 return true; |
758 } | 780 } |
759 break; | 781 break; |
760 | 782 |
761 case 'Ctrl-z': // Ctrl+Z | 783 case 'Ctrl-z': // Ctrl+Z |
762 if (this.commandQueue_.canUndo()) { | 784 if (this.commandQueue_.canUndo()) { |
763 this.undo(); | 785 this.undo(); |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1291 */ | 1313 */ |
1292 ImageEditor.Toolbar.prototype.addButton = function( | 1314 ImageEditor.Toolbar.prototype.addButton = function( |
1293 title, type, handler, opt_class) { | 1315 title, type, handler, opt_class) { |
1294 var button = ImageEditor.Toolbar.createButton_( | 1316 var button = ImageEditor.Toolbar.createButton_( |
1295 title, type, handler, opt_class); | 1317 title, type, handler, opt_class); |
1296 this.add(button); | 1318 this.add(button); |
1297 return button; | 1319 return button; |
1298 }; | 1320 }; |
1299 | 1321 |
1300 /** | 1322 /** |
| 1323 * Add a checkbox |
| 1324 * |
| 1325 * @param {string} name Checkbox name |
| 1326 * @param {string} title Checkbox title |
| 1327 * @param {function(Event)} handler onChange handler |
| 1328 * @param {boolean} value Default value |
| 1329 * @return {!HTMLElement} Checkbox Element |
| 1330 */ |
| 1331 ImageEditor.Toolbar.prototype.addCheckbox = function( |
| 1332 name, title, handler, value) { |
| 1333 |
| 1334 var checkbox = /** @type {!HTMLElement} */ |
| 1335 (document.createElement('paper-checkbox')); |
| 1336 checkbox.textContent = strf(title); |
| 1337 checkbox.addEventListener('change', handler, false); |
| 1338 checkbox.checked = value; |
| 1339 checkbox.classList.add('checkbox', name); |
| 1340 |
| 1341 this.add(checkbox); |
| 1342 |
| 1343 return checkbox; |
| 1344 }; |
| 1345 |
| 1346 /** |
| 1347 * Add a input field. |
| 1348 * |
| 1349 * @param {string} name Input name |
| 1350 * @param {string} title Input title |
| 1351 * @param {function(Event)} handler onInput handler |
| 1352 * @param {string|number} value Default value |
| 1353 * @param {string=} opt_unit Unit for an input field |
| 1354 * @return {!HTMLElement} Input Element |
| 1355 */ |
| 1356 ImageEditor.Toolbar.prototype.addInput = function( |
| 1357 name, title, handler, value, opt_unit) { |
| 1358 |
| 1359 var input = /** @type {!HTMLElement} */ (document.createElement('div')); |
| 1360 input.classList.add('input', name); |
| 1361 |
| 1362 var text = document.createElement('paper-input'); |
| 1363 text.setAttribute('label', strf(title)); |
| 1364 text.classList.add('text', name); |
| 1365 text.value = value; |
| 1366 text.addEventListener('input', handler, false); |
| 1367 input.appendChild(text); |
| 1368 |
| 1369 if(opt_unit) { |
| 1370 var unit_label = document.createElement('span'); |
| 1371 unit_label.textContent = opt_unit; |
| 1372 unit_label.classList.add('unit_label'); |
| 1373 input.appendChild(unit_label); |
| 1374 } |
| 1375 |
| 1376 input.name = name; |
| 1377 input.getValue = function(text) { |
| 1378 return text.value; |
| 1379 }.bind(this, text); |
| 1380 input.setValue = function(text, value) { |
| 1381 text.value = value; |
| 1382 }.bind(this, text); |
| 1383 |
| 1384 this.add(input); |
| 1385 |
| 1386 return input; |
| 1387 }; |
| 1388 |
| 1389 /** |
1301 * Add a range control (scalar value picker). | 1390 * Add a range control (scalar value picker). |
1302 * | 1391 * |
1303 * @param {string} name An option name. | 1392 * @param {string} name An option name. |
1304 * @param {string} title An option title. | 1393 * @param {string} title An option title. |
1305 * @param {number} min Min value of the option. | 1394 * @param {number} min Min value of the option. |
1306 * @param {number} value Default value of the option. | 1395 * @param {number} value Default value of the option. |
1307 * @param {number} max Max value of the options. | 1396 * @param {number} max Max value of the options. |
1308 * @param {number=} opt_scale A number to multiply by when setting | 1397 * @param {number=} opt_scale A number to multiply by when setting |
1309 * min/value/max in DOM. | 1398 * min/value/max in DOM. |
1310 * @param {boolean=} opt_showNumeric True if numeric value should be displayed. | 1399 * @param {boolean=} opt_showNumeric True if numeric value should be displayed. |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1528 | 1617 |
1529 /** | 1618 /** |
1530 * Hide the prompt. | 1619 * Hide the prompt. |
1531 */ | 1620 */ |
1532 ImageEditor.Prompt.prototype.hide = function() { | 1621 ImageEditor.Prompt.prototype.hide = function() { |
1533 if (!this.prompt_) return; | 1622 if (!this.prompt_) return; |
1534 this.prompt_.setAttribute('state', 'fadeout'); | 1623 this.prompt_.setAttribute('state', 'fadeout'); |
1535 // Allow some time for the animation to play out. | 1624 // Allow some time for the animation to play out. |
1536 this.setTimer(this.reset.bind(this), 500); | 1625 this.setTimer(this.reset.bind(this), 500); |
1537 }; | 1626 }; |
OLD | NEW |