Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: ui/file_manager/gallery/js/image_editor/image_editor.js

Issue 2299493002: Add an ability for resize in gallery. (Closed)
Patch Set: Add an ability for resize in gallery. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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') {
fukino 2016/09/05 13:44:34 I think this 'image-resize' should be 'resize'? Th
harukam 2016/09/06 08:10:29 Sorry, thanks.
690 var resizeMode = /** @type {!ImageEditor.Mode.Resize} */
691 (this.currentMode_);
692 if(!resizeMode.isInputValid()) {
693 this.showingAlertDialog_ = true;
694
695 resizeMode.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
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
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 and onChange 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
1367 // We should listen for not only 'change' event, but also 'input' because of
fukino 2016/09/05 13:44:34 listen to
harukam 2016/09/06 08:10:29 Acknowledged.
1368 // calling handler as fast as possible.
fukino 2016/09/05 13:44:34 "because of calling..." doesn't sound saying purpo
harukam 2016/09/06 08:10:29 It's helpful, thanks.
1369 text.addEventListener('input', handler, false);
1370 text.addEventListener('change', handler, false);
harukam 2016/09/05 10:37:00 I set a handler listening for 'change' event to ad
1371 input.appendChild(text);
1372
1373 if(opt_unit) {
1374 var unit_label = document.createElement('span');
1375 unit_label.textContent = opt_unit;
1376 unit_label.classList.add('unit_label');
1377 input.appendChild(unit_label);
1378 }
1379
1380 input.name = name;
1381 input.getValue = function(text) {
1382 return text.value;
1383 }.bind(this, text);
1384 input.setValue = function(text, value) {
1385 text.value = value;
1386 }.bind(this, text);
1387
1388 this.add(input);
1389
1390 return input;
1391 };
1392
1393 /**
1301 * Add a range control (scalar value picker). 1394 * Add a range control (scalar value picker).
1302 * 1395 *
1303 * @param {string} name An option name. 1396 * @param {string} name An option name.
1304 * @param {string} title An option title. 1397 * @param {string} title An option title.
1305 * @param {number} min Min value of the option. 1398 * @param {number} min Min value of the option.
1306 * @param {number} value Default value of the option. 1399 * @param {number} value Default value of the option.
1307 * @param {number} max Max value of the options. 1400 * @param {number} max Max value of the options.
1308 * @param {number=} opt_scale A number to multiply by when setting 1401 * @param {number=} opt_scale A number to multiply by when setting
1309 * min/value/max in DOM. 1402 * min/value/max in DOM.
1310 * @param {boolean=} opt_showNumeric True if numeric value should be displayed. 1403 * @param {boolean=} opt_showNumeric True if numeric value should be displayed.
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1528 1621
1529 /** 1622 /**
1530 * Hide the prompt. 1623 * Hide the prompt.
1531 */ 1624 */
1532 ImageEditor.Prompt.prototype.hide = function() { 1625 ImageEditor.Prompt.prototype.hide = function() {
1533 if (!this.prompt_) return; 1626 if (!this.prompt_) return;
1534 this.prompt_.setAttribute('state', 'fadeout'); 1627 this.prompt_.setAttribute('state', 'fadeout');
1535 // Allow some time for the animation to play out. 1628 // Allow some time for the animation to play out.
1536 this.setTimer(this.reset.bind(this), 500); 1629 this.setTimer(this.reset.bind(this), 500);
1537 }; 1630 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698