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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 * Handles mouseup events. This dispatches an activate event; if there is an | 178 * Handles mouseup events. This dispatches an activate event; if there is an |
177 * associated command, that command is executed. | 179 * associated command, that command is executed. |
178 * @param {Event} e The mouseup event object. | 180 * @param {Event} e The mouseup event object. |
179 * @private | 181 * @private |
180 */ | 182 */ |
181 handleMouseUp_: function(e) { | 183 handleMouseUp_: function(e) { |
182 if (!this.disabled && !this.isSeparator() && this.selected) { | 184 if (!this.disabled && !this.isSeparator() && this.selected) { |
183 // Store |contextElement| since it'll be removed by {Menu} on handling | 185 // Store |contextElement| since it'll be removed by {Menu} on handling |
184 // 'activate' event. | 186 // 'activate' event. |
185 var contextElement = this.parentNode.contextElement; | 187 var contextElement = this.parentNode.contextElement; |
| 188 var activationEvent = cr.doc.createEvent('Event'); |
| 189 activationEvent.initEvent('activate', true, true); |
| 190 activationEvent.originalEvent = e; |
186 // Dispatch command event followed by executing the command object. | 191 // Dispatch command event followed by executing the command object. |
187 if (cr.dispatchSimpleEvent(this, 'activate', true, true)) { | 192 if (this.dispatchEvent(activationEvent)) { |
188 var command = this.command; | 193 var command = this.command; |
189 if (command) { | 194 if (command) { |
190 command.execute(contextElement); | 195 command.execute(contextElement); |
191 cr.ui.swallowDoubleClick(e); | 196 cr.ui.swallowDoubleClick(e); |
192 } | 197 } |
193 } | 198 } |
194 } | 199 } |
195 }, | 200 }, |
196 | 201 |
197 /** | 202 /** |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 * Whether the menu item is checked or not. | 253 * Whether the menu item is checked or not. |
249 * @type {boolean} | 254 * @type {boolean} |
250 */ | 255 */ |
251 cr.defineProperty(MenuItem, 'checked', cr.PropertyKind.BOOL_ATTR); | 256 cr.defineProperty(MenuItem, 'checked', cr.PropertyKind.BOOL_ATTR); |
252 | 257 |
253 // Export | 258 // Export |
254 return { | 259 return { |
255 MenuItem: MenuItem | 260 MenuItem: MenuItem |
256 }; | 261 }; |
257 }); | 262 }); |
OLD | NEW |