| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // require: event_target.js | 5 // require: event_target.js |
| 6 | 6 |
| 7 cr.define('cr.ui', function() { | 7 cr.define('cr.ui', function() { |
| 8 /** @const */ var EventTarget = cr.EventTarget; | 8 /** @const */ var EventTarget = cr.EventTarget; |
| 9 /** @const */ var Menu = cr.ui.Menu; | 9 /** @const */ var Menu = cr.ui.Menu; |
| 10 | 10 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 * Handles event callbacks. | 130 * Handles event callbacks. |
| 131 * @param {!Event} e The event object. | 131 * @param {!Event} e The event object. |
| 132 */ | 132 */ |
| 133 handleEvent: function(e) { | 133 handleEvent: function(e) { |
| 134 // Keep track of keydown state so that we can use that to determine the | 134 // Keep track of keydown state so that we can use that to determine the |
| 135 // reason for the contextmenu event. | 135 // reason for the contextmenu event. |
| 136 switch (e.type) { | 136 switch (e.type) { |
| 137 case 'keydown': | 137 case 'keydown': |
| 138 this.keyIsDown_ = !e.ctrlKey && !e.altKey && | 138 this.keyIsDown_ = !e.ctrlKey && !e.altKey && |
| 139 // context menu key or Shift-F10 | 139 // context menu key or Shift-F10 |
| 140 (e.keyCode == 93 && !e.shiftKey || | 140 (e.keyCode == 93 && !e.shiftKey || e.key == 'F10' && e.shiftKey); |
| 141 e.keyIdentifier == 'F10' && e.shiftKey); | |
| 142 break; | 141 break; |
| 143 | 142 |
| 144 case 'keyup': | 143 case 'keyup': |
| 145 this.keyIsDown_ = false; | 144 this.keyIsDown_ = false; |
| 146 break; | 145 break; |
| 147 } | 146 } |
| 148 | 147 |
| 149 // Context menu is handled even when we have no menu. | 148 // Context menu is handled even when we have no menu. |
| 150 if (e.type != 'contextmenu' && !this.menu) | 149 if (e.type != 'contextmenu' && !this.menu) |
| 151 return; | 150 return; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 162 else | 161 else |
| 163 e.preventDefault(); | 162 e.preventDefault(); |
| 164 break; | 163 break; |
| 165 | 164 |
| 166 case 'touchstart': | 165 case 'touchstart': |
| 167 if (!this.menu.contains(e.target)) | 166 if (!this.menu.contains(e.target)) |
| 168 this.hideMenu(); | 167 this.hideMenu(); |
| 169 break; | 168 break; |
| 170 | 169 |
| 171 case 'keydown': | 170 case 'keydown': |
| 172 // keyIdentifier does not report 'Esc' correctly | 171 if (e.key == 'Escape') { |
| 173 if (e.keyCode == 27 /* Esc */) { | |
| 174 this.hideMenu(); | 172 this.hideMenu(); |
| 175 e.stopPropagation(); | 173 e.stopPropagation(); |
| 176 e.preventDefault(); | 174 e.preventDefault(); |
| 177 | 175 |
| 178 // If the menu is visible we let it handle all the keyboard events. | 176 // If the menu is visible we let it handle all the keyboard events. |
| 179 } else if (this.menu) { | 177 } else if (this.menu) { |
| 180 this.menu.handleKeyDown(e); | 178 this.menu.handleKeyDown(e); |
| 181 e.preventDefault(); | 179 e.preventDefault(); |
| 182 e.stopPropagation(); | 180 e.stopPropagation(); |
| 183 } | 181 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 * The singleton context menu handler. | 283 * The singleton context menu handler. |
| 286 * @type {!ContextMenuHandler} | 284 * @type {!ContextMenuHandler} |
| 287 */ | 285 */ |
| 288 var contextMenuHandler = new ContextMenuHandler; | 286 var contextMenuHandler = new ContextMenuHandler; |
| 289 | 287 |
| 290 // Export | 288 // Export |
| 291 return { | 289 return { |
| 292 contextMenuHandler: contextMenuHandler, | 290 contextMenuHandler: contextMenuHandler, |
| 293 }; | 291 }; |
| 294 }); | 292 }); |
| OLD | NEW |