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 /** @const */ var Command = cr.ui.Command; | 6 /** @const */ var Command = cr.ui.Command; |
7 | 7 |
8 /** | 8 /** |
9 * Creates a new menu item element. | 9 * Creates a new menu item element. |
10 * @param {Object=} opt_propertyBag Optional properties. | 10 * @param {Object=} opt_propertyBag Optional properties. |
(...skipping 22 matching lines...) Expand all Loading... |
33 var commandId; | 33 var commandId; |
34 if ((commandId = this.getAttribute('command'))) | 34 if ((commandId = this.getAttribute('command'))) |
35 this.command = commandId; | 35 this.command = commandId; |
36 | 36 |
37 this.addEventListener('mouseup', this.handleMouseUp_); | 37 this.addEventListener('mouseup', this.handleMouseUp_); |
38 | 38 |
39 // Adding the 'custom-appearance' class prevents widgets.css from changing | 39 // Adding the 'custom-appearance' class prevents widgets.css from changing |
40 // the appearance of this element. | 40 // the appearance of this element. |
41 this.classList.add('custom-appearance'); | 41 this.classList.add('custom-appearance'); |
42 | 42 |
| 43 this.setAttribute('role', 'menuitem'); |
| 44 |
43 var iconUrl; | 45 var iconUrl; |
44 if ((iconUrl = this.getAttribute('icon'))) | 46 if ((iconUrl = this.getAttribute('icon'))) |
45 this.iconUrl = iconUrl; | 47 this.iconUrl = iconUrl; |
46 }, | 48 }, |
47 | 49 |
48 /** | 50 /** |
49 * The command associated with this menu item. If this is set to a string | 51 * The command associated with this menu item. If this is set to a string |
50 * of the form "#element-id" then the element is looked up in the document | 52 * of the form "#element-id" then the element is looked up in the document |
51 * of the command. | 53 * of the command. |
52 * @type {cr.ui.Command} | 54 * @type {cr.ui.Command} |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 * Handles mouseup events. This dispatches an activate event; if there is an | 119 * Handles mouseup events. This dispatches an activate event; if there is an |
118 * associated command, that command is executed. | 120 * associated command, that command is executed. |
119 * @param {Event} e The mouseup event object. | 121 * @param {Event} e The mouseup event object. |
120 * @private | 122 * @private |
121 */ | 123 */ |
122 handleMouseUp_: function(e) { | 124 handleMouseUp_: function(e) { |
123 if (!this.disabled && !this.isSeparator() && this.selected) { | 125 if (!this.disabled && !this.isSeparator() && this.selected) { |
124 // Store |contextElement| since it'll be removed by {Menu} on handling | 126 // Store |contextElement| since it'll be removed by {Menu} on handling |
125 // 'activate' event. | 127 // 'activate' event. |
126 var contextElement = this.parentNode.contextElement; | 128 var contextElement = this.parentNode.contextElement; |
| 129 var activationEvent = cr.doc.createEvent('Event'); |
| 130 activationEvent.initEvent('activate', true, true); |
| 131 activationEvent.originalEvent = e; |
127 // Dispatch command event followed by executing the command object. | 132 // Dispatch command event followed by executing the command object. |
128 if (cr.dispatchSimpleEvent(this, 'activate', true, true)) { | 133 if (this.dispatchEvent(activationEvent)) { |
129 var command = this.command; | 134 var command = this.command; |
130 if (command) | 135 if (command) |
131 command.execute(contextElement); | 136 command.execute(contextElement); |
132 } | 137 } |
133 } | 138 } |
134 }, | 139 }, |
135 | 140 |
136 /** | 141 /** |
137 * Updates command according to the node on which this menu was invoked. | 142 * Updates command according to the node on which this menu was invoked. |
138 * @param {Node=} opt_node Node on which menu was opened. | 143 * @param {Node=} opt_node Node on which menu was opened. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 * Whether the menu item is checked or not. | 192 * Whether the menu item is checked or not. |
188 * @type {boolean} | 193 * @type {boolean} |
189 */ | 194 */ |
190 cr.defineProperty(MenuItem, 'checked', cr.PropertyKind.BOOL_ATTR); | 195 cr.defineProperty(MenuItem, 'checked', cr.PropertyKind.BOOL_ATTR); |
191 | 196 |
192 // Export | 197 // Export |
193 return { | 198 return { |
194 MenuItem: MenuItem | 199 MenuItem: MenuItem |
195 }; | 200 }; |
196 }); | 201 }); |
OLD | NEW |