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 |
11 /** | 11 /** |
12 * Handles context menus. | 12 * Handles context menus. |
13 * @constructor | 13 * @constructor |
14 * @extends {cr.EventTarget} | 14 * @extends {cr.EventTarget} |
15 * @implements {EventListener} | 15 * @implements {EventListener} |
16 */ | 16 */ |
17 function ContextMenuHandler() { this.showingEvents_ = new EventTracker(); } | 17 function ContextMenuHandler() { |
| 18 this.showingEvents_ = new EventTracker(); |
| 19 } |
18 | 20 |
19 ContextMenuHandler.prototype = { | 21 ContextMenuHandler.prototype = { |
20 __proto__: EventTarget.prototype, | 22 __proto__: EventTarget.prototype, |
21 | 23 |
22 /** | 24 /** |
23 * The menu that we are currently showing. | 25 * The menu that we are currently showing. |
24 * @type {cr.ui.Menu} | 26 * @type {cr.ui.Menu} |
25 */ | 27 */ |
26 menu_: null, get menu() { return this.menu_; }, | 28 menu_: null, |
| 29 get menu() { |
| 30 return this.menu_; |
| 31 }, |
27 | 32 |
28 /** | 33 /** |
29 * Shows a menu as a context menu. | 34 * Shows a menu as a context menu. |
30 * @param {!Event} e The event triggering the show (usually a contextmenu | 35 * @param {!Event} e The event triggering the show (usually a contextmenu |
31 * event). | 36 * event). |
32 * @param {!cr.ui.Menu} menu The menu to show. | 37 * @param {!cr.ui.Menu} menu The menu to show. |
33 */ | 38 */ |
34 showMenu: function(e, menu) { | 39 showMenu: function(e, menu) { |
35 menu.updateCommands(assertInstanceof(e.currentTarget, Node)); | 40 menu.updateCommands(assertInstanceof(e.currentTarget, Node)); |
36 if (!menu.hasVisibleItems()) | 41 if (!menu.hasVisibleItems()) |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 /** | 215 /** |
211 * Adds a contextMenu property to an element or element class. | 216 * Adds a contextMenu property to an element or element class. |
212 * @param {!Element|!Function} elementOrClass The element or class to add | 217 * @param {!Element|!Function} elementOrClass The element or class to add |
213 * the contextMenu property to. | 218 * the contextMenu property to. |
214 */ | 219 */ |
215 addContextMenuProperty: function(elementOrClass) { | 220 addContextMenuProperty: function(elementOrClass) { |
216 var target = typeof elementOrClass == 'function' ? | 221 var target = typeof elementOrClass == 'function' ? |
217 elementOrClass.prototype : | 222 elementOrClass.prototype : |
218 elementOrClass; | 223 elementOrClass; |
219 | 224 |
220 target.__defineGetter__( | 225 target.__defineGetter__('contextMenu', function() { |
221 'contextMenu', function() { return this.contextMenu_; }); | 226 return this.contextMenu_; |
| 227 }); |
222 target.__defineSetter__('contextMenu', function(menu) { | 228 target.__defineSetter__('contextMenu', function(menu) { |
223 var oldContextMenu = this.contextMenu; | 229 var oldContextMenu = this.contextMenu; |
224 | 230 |
225 if (typeof menu == 'string' && menu[0] == '#') { | 231 if (typeof menu == 'string' && menu[0] == '#') { |
226 menu = this.ownerDocument.getElementById(menu.slice(1)); | 232 menu = this.ownerDocument.getElementById(menu.slice(1)); |
227 cr.ui.decorate(menu, Menu); | 233 cr.ui.decorate(menu, Menu); |
228 } | 234 } |
229 | 235 |
230 if (menu === oldContextMenu) | 236 if (menu === oldContextMenu) |
231 return; | 237 return; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 * The singleton context menu handler. | 283 * The singleton context menu handler. |
278 * @type {!ContextMenuHandler} | 284 * @type {!ContextMenuHandler} |
279 */ | 285 */ |
280 var contextMenuHandler = new ContextMenuHandler; | 286 var contextMenuHandler = new ContextMenuHandler; |
281 | 287 |
282 // Export | 288 // Export |
283 return { | 289 return { |
284 contextMenuHandler: contextMenuHandler, | 290 contextMenuHandler: contextMenuHandler, |
285 }; | 291 }; |
286 }); | 292 }); |
OLD | NEW |