Chromium Code Reviews| 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.keyEventHandled_ = true; | |
| 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 'Resize', and commit is required, | |
| 688 // leaving mode should be stopped when an input value is not valid. | |
| 689 // 'onblur' event handler in ImageResize also checks if the value is valid, | |
| 690 // but 'keyDown' event is fired faster then it. | |
| 691 // So, We should check the value here, too. | |
| 692 if(commit && this.currentMode_.name === 'resize') { | |
| 693 var resizeMode = /** @type {!ImageEditor.Mode.Resize} */ | |
| 694 (this.currentMode_); | |
| 695 if(!resizeMode.isInputValid()) { | |
| 696 resizeMode.showAlertDialog(); | |
| 697 return; | |
| 698 } | |
| 699 } | |
| 700 | |
| 682 this.modeToolbar_.show(false); | 701 this.modeToolbar_.show(false); |
| 683 | 702 |
| 684 // If it leaves to switch mode, do not restore screen size since the next mode | 703 // 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 | 704 // might change screen size. We should avoid to show intermediate animation |
| 686 // which tries to restore screen size. | 705 // which tries to restore screen size. |
| 687 if (!leaveToSwitchMode) { | 706 if (!leaveToSwitchMode) { |
| 688 this.getViewport().setScreenTop(ImageEditor.Toolbar.HEIGHT); | 707 this.getViewport().setScreenTop(ImageEditor.Toolbar.HEIGHT); |
| 689 this.getViewport().setScreenBottom(ImageEditor.Toolbar.HEIGHT); | 708 this.getViewport().setScreenBottom(ImageEditor.Toolbar.HEIGHT); |
| 690 this.getImageView().applyViewportChange(); | 709 this.getImageView().applyViewportChange(); |
| 691 } | 710 } |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 718 * @param {boolean} leaveToSwitchMode True if it leaves to switch mode. | 737 * @param {boolean} leaveToSwitchMode True if it leaves to switch mode. |
| 719 */ | 738 */ |
| 720 ImageEditor.prototype.leaveMode = function(leaveToSwitchMode) { | 739 ImageEditor.prototype.leaveMode = function(leaveToSwitchMode) { |
| 721 this.leaveModeInternal_(!!this.currentMode_ && | 740 this.leaveModeInternal_(!!this.currentMode_ && |
| 722 this.currentMode_.updated_ && | 741 this.currentMode_.updated_ && |
| 723 this.currentMode_.implicitCommit, | 742 this.currentMode_.implicitCommit, |
| 724 leaveToSwitchMode); | 743 leaveToSwitchMode); |
| 725 }; | 744 }; |
| 726 | 745 |
| 727 /** | 746 /** |
| 747 * | |
|
fukino
2016/09/06 10:50:35
comment?
harukam
2016/09/09 10:37:42
Sorry for the carelessness.
| |
| 748 */ | |
| 749 ImageEditor.prototype.setKeyEventHandled = function(handled) { | |
|
fukino
2016/09/06 10:50:35
I'd like to avoid circular dependency which this m
harukam
2016/09/09 10:37:42
Sounds good, thanks.
| |
| 750 this.keyEventHandled_ = handled; | |
| 751 }; | |
| 752 | |
| 753 /** | |
| 728 * Enter the editor mode with the given name. | 754 * Enter the editor mode with the given name. |
| 729 * | 755 * |
| 730 * @param {string} name Mode name. | 756 * @param {string} name Mode name. |
| 731 * @private | 757 * @private |
| 732 */ | 758 */ |
| 733 ImageEditor.prototype.enterModeByName_ = function(name) { | 759 ImageEditor.prototype.enterModeByName_ = function(name) { |
| 734 for (var i = 0; i !== this.modes_.length; i++) { | 760 for (var i = 0; i !== this.modes_.length; i++) { |
| 735 var mode = this.modes_[i]; | 761 var mode = this.modes_[i]; |
| 736 if (mode.name === name) { | 762 if (mode.name === name) { |
| 737 if (!mode.button_.hasAttribute('disabled')) | 763 if (!mode.button_.hasAttribute('disabled')) |
| 738 this.enterMode(mode); | 764 this.enterMode(mode); |
| 739 return; | 765 return; |
| 740 } | 766 } |
| 741 } | 767 } |
| 742 console.error('Mode "' + name + '" not found.'); | 768 console.error('Mode "' + name + '" not found.'); |
| 743 }; | 769 }; |
| 744 | 770 |
| 745 /** | 771 /** |
| 746 * Key down handler. | 772 * Key down handler. |
| 747 * @param {!Event} event The keydown event. | 773 * @param {!Event} event The keydown event. |
| 748 * @return {boolean} True if handled. | 774 * @return {boolean} True if handled. |
| 749 */ | 775 */ |
| 750 ImageEditor.prototype.onKeyDown = function(event) { | 776 ImageEditor.prototype.onKeyDown = function(event) { |
| 777 if (!this.keyEventHandled_) | |
| 778 return false; | |
| 779 | |
| 751 switch (util.getKeyModifiers(event) + event.key) { | 780 switch (util.getKeyModifiers(event) + event.key) { |
| 752 case 'Escape': | 781 case 'Escape': |
| 753 case 'Enter': | 782 case 'Enter': |
| 754 if (this.getMode()) { | 783 if (this.getMode()) { |
| 755 this.leaveModeInternal_(event.key === 'Enter', | 784 this.leaveModeInternal_(event.key === 'Enter', |
| 756 false /* not to switch mode */); | 785 false /* not to switch mode */); |
| 757 return true; | 786 return true; |
| 758 } | 787 } |
| 759 break; | 788 break; |
| 760 | 789 |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1291 */ | 1320 */ |
| 1292 ImageEditor.Toolbar.prototype.addButton = function( | 1321 ImageEditor.Toolbar.prototype.addButton = function( |
| 1293 title, type, handler, opt_class) { | 1322 title, type, handler, opt_class) { |
| 1294 var button = ImageEditor.Toolbar.createButton_( | 1323 var button = ImageEditor.Toolbar.createButton_( |
| 1295 title, type, handler, opt_class); | 1324 title, type, handler, opt_class); |
| 1296 this.add(button); | 1325 this.add(button); |
| 1297 return button; | 1326 return button; |
| 1298 }; | 1327 }; |
| 1299 | 1328 |
| 1300 /** | 1329 /** |
| 1330 * Add a checkbox | |
| 1331 * | |
| 1332 * @param {string} name Checkbox name | |
| 1333 * @param {string} title Checkbox title | |
| 1334 * @param {function(Event)} handler onChange handler | |
| 1335 * @param {boolean} value Default value | |
| 1336 * @return {!HTMLElement} Checkbox Element | |
| 1337 */ | |
| 1338 ImageEditor.Toolbar.prototype.addCheckbox = function( | |
| 1339 name, title, handler, value) { | |
| 1340 | |
| 1341 var checkbox = /** @type {!HTMLElement} */ | |
| 1342 (document.createElement('paper-checkbox')); | |
| 1343 checkbox.textContent = strf(title); | |
| 1344 checkbox.addEventListener('change', handler, false); | |
| 1345 checkbox.checked = value; | |
| 1346 checkbox.classList.add('checkbox', name); | |
| 1347 | |
| 1348 this.add(checkbox); | |
| 1349 | |
| 1350 return checkbox; | |
| 1351 }; | |
| 1352 | |
| 1353 /** | |
| 1354 * Add a input field. | |
| 1355 * | |
| 1356 * @param {string} name Input name | |
| 1357 * @param {string} title Input title | |
| 1358 * @param {function(Event)} handler onInput and onChange handler | |
| 1359 * @param {function(Event)} onblur onBlur handler | |
| 1360 * @param {string|number} value Default value | |
| 1361 * @param {string=} opt_unit Unit for an input field | |
| 1362 * @return {!HTMLElement} Input Element | |
| 1363 */ | |
| 1364 ImageEditor.Toolbar.prototype.addInput = function( | |
| 1365 name, title, handler, onblur, value, opt_unit) { | |
| 1366 | |
| 1367 var input = /** @type {!HTMLElement} */ (document.createElement('div')); | |
| 1368 input.classList.add('input', name); | |
| 1369 | |
| 1370 var text = document.createElement('paper-input'); | |
| 1371 text.setAttribute('label', strf(title)); | |
| 1372 text.classList.add('text', name); | |
| 1373 text.value = value; | |
| 1374 | |
| 1375 // We should listen to not only 'change' event, but also 'input' because we | |
| 1376 // want to update values as soon as the user types characters. | |
| 1377 text.addEventListener('input', handler, false); | |
| 1378 text.addEventListener('change', handler, false); | |
| 1379 text.addEventListener('blur', onblur, true); | |
|
fukino
2016/09/06 10:50:35
true -> false.
harukam
2016/09/09 10:37:42
Done.
| |
| 1380 input.appendChild(text); | |
| 1381 | |
| 1382 if(opt_unit) { | |
| 1383 var unit_label = document.createElement('span'); | |
| 1384 unit_label.textContent = opt_unit; | |
| 1385 unit_label.classList.add('unit_label'); | |
| 1386 input.appendChild(unit_label); | |
| 1387 } | |
| 1388 | |
| 1389 input.name = name; | |
| 1390 input.getValue = function(text) { | |
| 1391 return text.value; | |
| 1392 }.bind(this, text); | |
| 1393 input.setValue = function(text, value) { | |
| 1394 text.value = value; | |
| 1395 }.bind(this, text); | |
| 1396 | |
| 1397 this.add(input); | |
| 1398 | |
| 1399 return input; | |
| 1400 }; | |
| 1401 | |
| 1402 /** | |
| 1301 * Add a range control (scalar value picker). | 1403 * Add a range control (scalar value picker). |
| 1302 * | 1404 * |
| 1303 * @param {string} name An option name. | 1405 * @param {string} name An option name. |
| 1304 * @param {string} title An option title. | 1406 * @param {string} title An option title. |
| 1305 * @param {number} min Min value of the option. | 1407 * @param {number} min Min value of the option. |
| 1306 * @param {number} value Default value of the option. | 1408 * @param {number} value Default value of the option. |
| 1307 * @param {number} max Max value of the options. | 1409 * @param {number} max Max value of the options. |
| 1308 * @param {number=} opt_scale A number to multiply by when setting | 1410 * @param {number=} opt_scale A number to multiply by when setting |
| 1309 * min/value/max in DOM. | 1411 * min/value/max in DOM. |
| 1310 * @param {boolean=} opt_showNumeric True if numeric value should be displayed. | 1412 * @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 | 1630 |
| 1529 /** | 1631 /** |
| 1530 * Hide the prompt. | 1632 * Hide the prompt. |
| 1531 */ | 1633 */ |
| 1532 ImageEditor.Prompt.prototype.hide = function() { | 1634 ImageEditor.Prompt.prototype.hide = function() { |
| 1533 if (!this.prompt_) return; | 1635 if (!this.prompt_) return; |
| 1534 this.prompt_.setAttribute('state', 'fadeout'); | 1636 this.prompt_.setAttribute('state', 'fadeout'); |
| 1535 // Allow some time for the animation to play out. | 1637 // Allow some time for the animation to play out. |
| 1536 this.setTimer(this.reset.bind(this), 500); | 1638 this.setTimer(this.reset.bind(this), 500); |
| 1537 }; | 1639 }; |
| OLD | NEW |