| 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 25 matching lines...) Expand all Loading... |
| 36 * event). | 36 * event). |
| 37 * @param {!cr.ui.Menu} menu The menu to show. | 37 * @param {!cr.ui.Menu} menu The menu to show. |
| 38 */ | 38 */ |
| 39 showMenu: function(e, menu) { | 39 showMenu: function(e, menu) { |
| 40 menu.updateCommands(assertInstanceof(e.currentTarget, Node)); | 40 menu.updateCommands(assertInstanceof(e.currentTarget, Node)); |
| 41 if (!menu.hasVisibleItems()) | 41 if (!menu.hasVisibleItems()) |
| 42 return; | 42 return; |
| 43 | 43 |
| 44 this.menu_ = menu; | 44 this.menu_ = menu; |
| 45 menu.classList.remove('hide-delayed'); | 45 menu.classList.remove('hide-delayed'); |
| 46 menu.hidden = false; | 46 menu.show(); |
| 47 menu.contextElement = e.currentTarget; | 47 menu.contextElement = e.currentTarget; |
| 48 | 48 |
| 49 // When the menu is shown we steal a lot of events. | 49 // When the menu is shown we steal a lot of events. |
| 50 var doc = menu.ownerDocument; | 50 var doc = menu.ownerDocument; |
| 51 var win = doc.defaultView; | 51 var win = doc.defaultView; |
| 52 this.showingEvents_.add(doc, 'keydown', this, true); | 52 this.showingEvents_.add(doc, 'keydown', this, true); |
| 53 this.showingEvents_.add(doc, 'mousedown', this, true); | 53 this.showingEvents_.add(doc, 'mousedown', this, true); |
| 54 this.showingEvents_.add(doc, 'touchstart', this, true); | 54 this.showingEvents_.add(doc, 'touchstart', this, true); |
| 55 this.showingEvents_.add(doc, 'focus', this); | 55 this.showingEvents_.add(doc, 'focus', this); |
| 56 this.showingEvents_.add(win, 'popstate', this); | 56 this.showingEvents_.add(win, 'popstate', this); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 73 */ | 73 */ |
| 74 hideMenu: function(opt_hideType) { | 74 hideMenu: function(opt_hideType) { |
| 75 var menu = this.menu; | 75 var menu = this.menu; |
| 76 if (!menu) | 76 if (!menu) |
| 77 return; | 77 return; |
| 78 | 78 |
| 79 if (opt_hideType == cr.ui.HideType.DELAYED) | 79 if (opt_hideType == cr.ui.HideType.DELAYED) |
| 80 menu.classList.add('hide-delayed'); | 80 menu.classList.add('hide-delayed'); |
| 81 else | 81 else |
| 82 menu.classList.remove('hide-delayed'); | 82 menu.classList.remove('hide-delayed'); |
| 83 menu.hidden = true; | 83 menu.hide(); |
| 84 var originalContextElement = menu.contextElement; | 84 var originalContextElement = menu.contextElement; |
| 85 menu.contextElement = null; | 85 menu.contextElement = null; |
| 86 this.showingEvents_.removeAll(); | 86 this.showingEvents_.removeAll(); |
| 87 menu.selectedIndex = -1; | 87 menu.selectedIndex = -1; |
| 88 this.menu_ = null; | 88 this.menu_ = null; |
| 89 | 89 |
| 90 // On windows we might hide the menu in a right mouse button up and if | 90 // On windows we might hide the menu in a right mouse button up and if |
| 91 // that is the case we wait some short period before we allow the menu | 91 // that is the case we wait some short period before we allow the menu |
| 92 // to be shown again. | 92 // to be shown again. |
| 93 this.hideTimestamp_ = cr.isWindows ? Date.now() : 0; | 93 this.hideTimestamp_ = cr.isWindows ? Date.now() : 0; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 * The singleton context menu handler. | 280 * The singleton context menu handler. |
| 281 * @type {!ContextMenuHandler} | 281 * @type {!ContextMenuHandler} |
| 282 */ | 282 */ |
| 283 var contextMenuHandler = new ContextMenuHandler; | 283 var contextMenuHandler = new ContextMenuHandler; |
| 284 | 284 |
| 285 // Export | 285 // Export |
| 286 return { | 286 return { |
| 287 contextMenuHandler: contextMenuHandler, | 287 contextMenuHandler: contextMenuHandler, |
| 288 }; | 288 }; |
| 289 }); | 289 }); |
| OLD | NEW |