| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 }, | 79 }, |
| 80 | 80 |
| 81 /** | 81 /** |
| 82 * Clears menu. | 82 * Clears menu. |
| 83 */ | 83 */ |
| 84 clear: function() { | 84 clear: function() { |
| 85 this.textContent = ''; | 85 this.textContent = ''; |
| 86 }, | 86 }, |
| 87 | 87 |
| 88 /** | 88 /** |
| 89 * Walks up the ancestors of |el| until a menu item belonging to this menu | 89 * Walks up the ancestors of |node| 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 {Node} node The node 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(node) { |
| 96 while (el && el.parentNode != this) { | 96 while (node && node.parentNode != this) { |
| 97 el = el.parentNode; | 97 node = node.parentNode; |
| 98 } | 98 } |
| 99 return el ? assertInstanceof(el, MenuItem) : null; | 99 return node ? assertInstanceof(node, 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_(/** @type {Element} */(e.target)); |
| 109 this.selectedItem = overItem; | 109 this.selectedItem = overItem; |
| 110 }, | 110 }, |
| 111 | 111 |
| 112 /** | 112 /** |
| 113 * Handles mouseout events and deselects any selected item. | 113 * Handles mouseout events and deselects any selected item. |
| 114 * @param {Event} e The mouseout event. | 114 * @param {Event} e The mouseout event. |
| 115 * @private | 115 * @private |
| 116 */ | 116 */ |
| 117 handleMouseOut_: function(e) { | 117 handleMouseOut_: function(e) { |
| 118 this.selectedItem = null; | 118 this.selectedItem = null; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 oldSelectedItem.selected = false; | 260 oldSelectedItem.selected = false; |
| 261 oldSelectedItem.blur(); | 261 oldSelectedItem.blur(); |
| 262 } | 262 } |
| 263 var item = this.selectedItem; | 263 var item = this.selectedItem; |
| 264 if (item) | 264 if (item) |
| 265 item.selected = true; | 265 item.selected = true; |
| 266 } | 266 } |
| 267 | 267 |
| 268 /** | 268 /** |
| 269 * The selected menu item. | 269 * The selected menu item. |
| 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 |