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 cr.define('cr.ui', function() { | 5 cr.define('cr.ui', function() { |
6 | 6 |
7 /** @const */ var MenuItem = cr.ui.MenuItem; | 7 /** @const */ var MenuItem = cr.ui.MenuItem; |
8 | 8 |
9 /** | 9 /** |
10 * Creates a new menu element. Menu dispatches all commands on the element it | 10 * Creates a new menu element. Menu dispatches all commands on the element it |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 * Walks up the ancestors of |el| until a menu item belonging to this menu | 89 * Walks up the ancestors of |el| until a menu item belonging to this menu |
90 * is found. | 90 * is found. |
91 * @param {Element} el The element to start searching from. | 91 * @param {Element} el The element to start searching from. |
92 * @return {cr.ui.MenuItem} The found menu item or null. | 92 * @return {cr.ui.MenuItem} The found menu item or null. |
93 * @private | 93 * @private |
94 */ | 94 */ |
95 findMenuItem_: function(el) { | 95 findMenuItem_: function(el) { |
96 while (el && el.parentNode != this) { | 96 while (el && el.parentNode != this) { |
97 el = el.parentNode; | 97 el = el.parentNode; |
98 } | 98 } |
99 return assertInstanceof(el, MenuItem); | 99 return el ? assertInstanceof(el, MenuItem) : null; |
100 }, | 100 }, |
101 | 101 |
102 /** | 102 /** |
103 * Handles mouseover events and selects the hovered item. | 103 * Handles mouseover events and selects the hovered item. |
104 * @param {Event} e The mouseover event. | 104 * @param {Event} e The mouseover event. |
105 * @private | 105 * @private |
106 */ | 106 */ |
107 handleMouseOver_: function(e) { | 107 handleMouseOver_: function(e) { |
108 var overItem = this.findMenuItem_(e.target); | 108 var overItem = this.findMenuItem_(e.target); |
109 this.selectedItem = overItem; | 109 this.selectedItem = overItem; |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 * @type {number} | 270 * @type {number} |
271 */ | 271 */ |
272 cr.defineProperty(Menu, 'selectedIndex', cr.PropertyKind.JS, | 272 cr.defineProperty(Menu, 'selectedIndex', cr.PropertyKind.JS, |
273 selectedIndexChanged); | 273 selectedIndexChanged); |
274 | 274 |
275 // Export | 275 // Export |
276 return { | 276 return { |
277 Menu: Menu | 277 Menu: Menu |
278 }; | 278 }; |
279 }); | 279 }); |
OLD | NEW |