Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 * @fileoverview | 6 * @fileoverview |
| 7 * 'settings-display-overscan-dialog' is the dialog for display overscan | 7 * 'settings-display-overscan-dialog' is the dialog for display overscan |
| 8 * adjustments. | 8 * adjustments. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 comitted_: Boolean, | 23 comitted_: Boolean, |
| 24 }, | 24 }, |
| 25 | 25 |
| 26 /** | 26 /** |
| 27 * Keyboard event handler for overscan adjustments. | 27 * Keyboard event handler for overscan adjustments. |
| 28 * @type {?function(!Event)} | 28 * @type {?function(!Event)} |
| 29 * @private | 29 * @private |
| 30 */ | 30 */ |
| 31 keyHandler_: null, | 31 keyHandler_: null, |
| 32 | 32 |
| 33 /** @override */ | 33 open: function() { |
| 34 attached: function() { | |
| 35 this.keyHandler_ = this.handleKeyEvent_.bind(this); | 34 this.keyHandler_ = this.handleKeyEvent_.bind(this); |
| 36 window.addEventListener('keydown', this.keyHandler_); | 35 this.addEventListener('keydown', this.keyHandler_); |
| 37 }, | |
| 38 | |
| 39 /** @override */ | |
| 40 detached: function() { | |
| 41 window.removeEventListener('keydown', this.keyHandler_); | |
| 42 }, | |
| 43 | |
| 44 open: function() { | |
| 45 this.comitted_ = false; | 36 this.comitted_ = false; |
| 46 this.$.dialog.showModal(); | 37 this.$.dialog.showModal(); |
| 47 }, | 38 }, |
| 48 | 39 |
| 49 close: function() { | 40 close: function() { |
| 41 this.removeEventListener('keydown', this.keyHandler_); | |
| 42 | |
| 50 this.displayId = ''; // Will trigger displayIdChanged_. | 43 this.displayId = ''; // Will trigger displayIdChanged_. |
| 51 | 44 |
| 52 if (this.$.dialog.open) | 45 if (this.$.dialog.open) |
| 53 this.$.dialog.close(); | 46 this.$.dialog.close(); |
| 54 }, | 47 }, |
| 55 | 48 |
| 56 /** @private */ | 49 /** @private */ |
| 57 displayIdChanged_: function(newValue, oldValue) { | 50 displayIdChanged_: function(newValue, oldValue) { |
| 58 if (oldValue && !this.comitted_) { | 51 if (oldValue && !this.comitted_) { |
| 59 settings.display.systemDisplayApi.overscanCalibrationReset(oldValue); | 52 settings.display.systemDisplayApi.overscanCalibrationReset(oldValue); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 76 this.displayId); | 69 this.displayId); |
| 77 this.comitted_ = true; | 70 this.comitted_ = true; |
| 78 this.close(); | 71 this.close(); |
| 79 }, | 72 }, |
| 80 | 73 |
| 81 /** | 74 /** |
| 82 * @param {Event} event | 75 * @param {Event} event |
| 83 * @private | 76 * @private |
| 84 */ | 77 */ |
| 85 handleKeyEvent_: function(event) { | 78 handleKeyEvent_: function(event) { |
| 86 switch (event.keyCode) { | 79 if (event.altKey || event.ctrlKey || event.metaKey) |
| 87 case 37: // left arrow | 80 return; |
| 88 if (event.shiftKey) | 81 if (this.handleKeyCode_(event.keyCode, event.shiftKey)) |
| 89 this.move_(-1, 0); | 82 event.preventDefault(); |
| 90 else | 83 }, |
| 91 this.resize_(1, 0); | 84 |
| 92 break; | 85 /** |
| 93 case 38: // up arrow | 86 * @param {number} keyCode |
| 94 if (event.shiftKey) | 87 * @param {boolean} shiftKey |
| 95 this.move_(0, -1); | 88 * @return {boolean} |
| 96 else | 89 * @private |
| 97 this.resize_(0, -1); | 90 */ |
| 98 break; | 91 handleKeyCode_: function(keyCode, shiftKey) { |
| 99 case 39: // right arrow | 92 if (shiftKey) { |
| 100 if (event.shiftKey) | 93 switch (keyCode) { |
| 101 this.move_(1, 0); | 94 case 37: // left arrow |
| 102 else | 95 return this.move_(-1, 0); |
| 103 this.resize_(-1, 0); | 96 case 38: // up arrow |
| 104 break; | 97 return this.move_(0, -1); |
| 105 case 40: // down arrow | 98 case 39: // right arrow |
| 106 if (event.shiftKey) | 99 return this.move_(1, 0); |
| 107 this.move_(0, 1); | 100 case 40: // down arrow |
| 108 else | 101 return this.move_(0, 1); |
| 109 this.resize_(0, 1); | 102 } |
| 110 break; | 103 } else { |
| 111 default: | 104 switch (keyCode) { |
|
Dan Beam
2016/09/28 22:10:38
// Only preventDefault() for keys that do somethin
| |
| 112 return; | 105 case 37: // left arrow |
| 106 return this.resize_(1, 0); | |
| 107 case 38: // up arrow | |
| 108 return this.resize_(0, -1); | |
| 109 case 39: // right arrow | |
| 110 return this.resize_(-1, 0); | |
| 111 case 40: // down arrow | |
| 112 return this.resize_(0, 1); | |
| 113 } | |
| 113 } | 114 } |
| 114 event.preventDefault(); | 115 return false; |
| 115 }, | 116 }, |
| 116 | 117 |
| 117 /** | 118 /** |
| 118 * @param {number} x | 119 * @param {number} x |
| 119 * @param {number} y | 120 * @param {number} y |
| 121 * @return {boolean} Always returns true for simplifed switch handling. | |
| 120 * @private | 122 * @private |
| 121 */ | 123 */ |
| 122 move_: function(x, y) { | 124 move_: function(x, y) { |
| 123 /** @type {!chrome.system.display.Insets} */ var delta = { | 125 /** @type {!chrome.system.display.Insets} */ var delta = { |
| 124 left: x, | 126 left: x, |
| 125 top: y, | 127 top: y, |
| 126 right: x ? -x : 0, // negating 0 will produce a double. | 128 right: x ? -x : 0, // negating 0 will produce a double. |
| 127 bottom: y ? -y : 0, | 129 bottom: y ? -y : 0, |
| 128 }; | 130 }; |
| 129 settings.display.systemDisplayApi.overscanCalibrationAdjust( | 131 settings.display.systemDisplayApi.overscanCalibrationAdjust( |
| 130 this.displayId, delta); | 132 this.displayId, delta); |
| 133 return true; | |
| 131 }, | 134 }, |
| 132 | 135 |
| 133 /** | 136 /** |
| 134 * @param {number} x | 137 * @param {number} x |
| 135 * @param {number} y | 138 * @param {number} y |
| 139 * @return {boolean} Always returns true for simplifed switch handling. | |
| 136 * @private | 140 * @private |
| 137 */ | 141 */ |
| 138 resize_: function(x, y) { | 142 resize_: function(x, y) { |
| 139 /** @type {!chrome.system.display.Insets} */ var delta = { | 143 /** @type {!chrome.system.display.Insets} */ var delta = { |
| 140 left: x, | 144 left: x, |
| 141 top: y, | 145 top: y, |
| 142 right: x, | 146 right: x, |
| 143 bottom: y, | 147 bottom: y, |
| 144 }; | 148 }; |
| 145 settings.display.systemDisplayApi.overscanCalibrationAdjust( | 149 settings.display.systemDisplayApi.overscanCalibrationAdjust( |
| 146 this.displayId, delta); | 150 this.displayId, delta); |
| 151 return true; | |
| 147 } | 152 } |
| 148 }); | 153 }); |
| OLD | NEW |