Chromium Code Reviews| Index: ui/file_manager/gallery/js/image_editor/image_editor.js |
| diff --git a/ui/file_manager/gallery/js/image_editor/image_editor.js b/ui/file_manager/gallery/js/image_editor/image_editor.js |
| index 9db0b9aaa2483838fbd7ffd5cf00855c8a1439cd..647c90ae02a7ce2af34fca44fffbc36947645221 100644 |
| --- a/ui/file_manager/gallery/js/image_editor/image_editor.js |
| +++ b/ui/file_manager/gallery/js/image_editor/image_editor.js |
| @@ -519,6 +519,11 @@ ImageEditor.Mode.prototype.markUpdated = function() { |
| ImageEditor.Mode.prototype.isUpdated = function() { return this.updated_; }; |
| /** |
| + * @return {boolean} True if a key event should be consumed by the mode. |
| + */ |
| +ImageEditor.Mode.prototype.isConsumingKeyEvents = function() { return false; }; |
| + |
| +/** |
| * Resets the mode to a clean state. |
| */ |
| ImageEditor.Mode.prototype.reset = function() { |
| @@ -679,6 +684,17 @@ ImageEditor.prototype.leaveModeInternal_ = function(commit, leaveToSwitchMode) { |
| if (!this.currentMode_) |
| return; |
| + // If the current mode is 'Resize', and commit is required, |
| + // leaving mode should be stopped when an input value is not valid. |
| + if(commit && this.currentMode_.name === 'resize') { |
| + var resizeMode = /** @type {!ImageEditor.Mode.Resize} */ |
| + (this.currentMode_); |
| + if(!resizeMode.isInputValid()) { |
| + resizeMode.showAlertDialog(); |
| + return; |
| + } |
| + } |
| + |
| this.modeToolbar_.show(false); |
| // If it leaves to switch mode, do not restore screen size since the next mode |
| @@ -748,6 +764,10 @@ ImageEditor.prototype.enterModeByName_ = function(name) { |
| * @return {boolean} True if handled. |
| */ |
| ImageEditor.prototype.onKeyDown = function(event) { |
| + if (this.currentMode_ && this.currentMode_.isConsumingKeyEvents()) { |
|
fukino
2016/09/16 02:24:49
{} is not necessary
harukam
2016/09/16 05:21:58
Done.
|
| + return false; |
|
fukino
2016/09/16 02:24:49
The key is handled in currentMode, so returning tr
harukam
2016/09/16 05:21:58
The event cannot be consumed by preventDefault() i
|
| + } |
| + |
| switch (util.getKeyModifiers(event) + event.key) { |
| case 'Escape': |
| case 'Enter': |
| @@ -1298,6 +1318,53 @@ ImageEditor.Toolbar.prototype.addButton = function( |
| }; |
| /** |
| + * Add a input field. |
| + * |
| + * @param {string} name Input name |
| + * @param {string} title Input title |
| + * @param {function(Event)} handler onInput and onChange handler |
| + * @param {string|number} value Default value |
| + * @param {string=} opt_unit Unit for an input field |
| + * @return {!HTMLElement} Input Element |
| + */ |
| +ImageEditor.Toolbar.prototype.addInput = function( |
| + name, title, handler, value, opt_unit) { |
| + |
| + var input = /** @type {!HTMLElement} */ (document.createElement('div')); |
| + input.classList.add('input', name); |
| + |
| + var text = document.createElement('paper-input'); |
| + text.setAttribute('label', strf(title)); |
| + text.classList.add('text', name); |
| + text.value = value; |
| + |
| + // We should listen to not only 'change' event, but also 'input' because we |
| + // want to update values as soon as the user types characters. |
| + text.addEventListener('input', handler, false); |
| + text.addEventListener('change', handler, false); |
| + input.appendChild(text); |
| + |
| + if(opt_unit) { |
| + var unit_label = document.createElement('span'); |
| + unit_label.textContent = opt_unit; |
| + unit_label.classList.add('unit_label'); |
| + input.appendChild(unit_label); |
| + } |
| + |
| + input.name = name; |
| + input.getValue = function(text) { |
| + return text.value; |
| + }.bind(this, text); |
| + input.setValue = function(text, value) { |
| + text.value = value; |
| + }.bind(this, text); |
| + |
| + this.add(input); |
| + |
| + return input; |
| +}; |
| + |
| +/** |
| * Add a range control (scalar value picker). |
| * |
| * @param {string} name An option name. |