| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All Rights Reserved. | 2 * Copyright (C) 2011 Google Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 */ | 31 */ |
| 32 WebInspector.SoftContextMenu = function(items, itemSelectedCallback, parentMenu) | 32 WebInspector.SoftContextMenu = function(items, itemSelectedCallback, parentMenu) |
| 33 { | 33 { |
| 34 this._items = items; | 34 this._items = items; |
| 35 this._itemSelectedCallback = itemSelectedCallback; | 35 this._itemSelectedCallback = itemSelectedCallback; |
| 36 this._parentMenu = parentMenu; | 36 this._parentMenu = parentMenu; |
| 37 } | 37 } |
| 38 | 38 |
| 39 WebInspector.SoftContextMenu.prototype = { | 39 WebInspector.SoftContextMenu.prototype = { |
| 40 /** | 40 /** |
| 41 * @param {!Document} document |
| 41 * @param {number} x | 42 * @param {number} x |
| 42 * @param {number} y | 43 * @param {number} y |
| 43 */ | 44 */ |
| 44 show: function(x, y) | 45 show: function(document, x, y) |
| 45 { | 46 { |
| 47 this._document = document; |
| 46 this._x = x; | 48 this._x = x; |
| 47 this._y = y; | 49 this._y = y; |
| 48 this._time = new Date().getTime(); | 50 this._time = new Date().getTime(); |
| 49 | 51 |
| 50 // Create context menu. | 52 // Create context menu. |
| 51 this._contextMenuElement = createElementWithClass("div", "soft-context-m
enu"); | 53 this._contextMenuElement = createElementWithClass("div", "soft-context-m
enu"); |
| 52 this._contextMenuElement.tabIndex = 0; | 54 this._contextMenuElement.tabIndex = 0; |
| 53 this._contextMenuElement.style.top = y + "px"; | 55 this._contextMenuElement.style.top = y + "px"; |
| 54 this._contextMenuElement.style.left = x + "px"; | 56 this._contextMenuElement.style.left = x + "px"; |
| 55 | 57 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 _showSubMenu: function(menuItemElement) | 185 _showSubMenu: function(menuItemElement) |
| 184 { | 186 { |
| 185 if (menuItemElement._subMenuTimer) { | 187 if (menuItemElement._subMenuTimer) { |
| 186 clearTimeout(menuItemElement._subMenuTimer); | 188 clearTimeout(menuItemElement._subMenuTimer); |
| 187 delete menuItemElement._subMenuTimer; | 189 delete menuItemElement._subMenuTimer; |
| 188 } | 190 } |
| 189 if (this._subMenu) | 191 if (this._subMenu) |
| 190 return; | 192 return; |
| 191 | 193 |
| 192 this._subMenu = new WebInspector.SoftContextMenu(menuItemElement._subIte
ms, this._itemSelectedCallback, this); | 194 this._subMenu = new WebInspector.SoftContextMenu(menuItemElement._subIte
ms, this._itemSelectedCallback, this); |
| 193 this._subMenu.show(this._x + menuItemElement.offsetWidth - 3, this._y +
menuItemElement.offsetTop - 1); | 195 this._subMenu.show(this._document, this._x + menuItemElement.offsetWidth
- 3, this._y + menuItemElement.offsetTop - 1); |
| 194 }, | 196 }, |
| 195 | 197 |
| 196 _hideSubMenu: function() | 198 _hideSubMenu: function() |
| 197 { | 199 { |
| 198 if (!this._subMenu) | 200 if (!this._subMenu) |
| 199 return; | 201 return; |
| 200 this._subMenu._discardSubMenus(); | 202 this._subMenu._discardSubMenus(); |
| 201 this._focus(); | 203 this._focus(); |
| 202 }, | 204 }, |
| 203 | 205 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 * @param {!Event=} event | 310 * @param {!Event=} event |
| 309 */ | 311 */ |
| 310 _discardMenu: function(closeParentMenus, event) | 312 _discardMenu: function(closeParentMenus, event) |
| 311 { | 313 { |
| 312 if (this._subMenu && !closeParentMenus) | 314 if (this._subMenu && !closeParentMenus) |
| 313 return; | 315 return; |
| 314 if (this._glassPaneElement) { | 316 if (this._glassPaneElement) { |
| 315 var glassPane = this._glassPaneElement; | 317 var glassPane = this._glassPaneElement; |
| 316 delete this._glassPaneElement; | 318 delete this._glassPaneElement; |
| 317 // This can re-enter discardMenu due to blur. | 319 // This can re-enter discardMenu due to blur. |
| 318 document.body.removeChild(glassPane); | 320 this._document.body.removeChild(glassPane); |
| 319 if (this._parentMenu) { | 321 if (this._parentMenu) { |
| 320 delete this._parentMenu._subMenu; | 322 delete this._parentMenu._subMenu; |
| 321 if (closeParentMenus) | 323 if (closeParentMenus) |
| 322 this._parentMenu._discardMenu(closeParentMenus, event); | 324 this._parentMenu._discardMenu(closeParentMenus, event); |
| 323 } | 325 } |
| 324 | 326 |
| 325 if (event) | 327 if (event) |
| 326 event.consume(true); | 328 event.consume(true); |
| 327 } else if (this._parentMenu && this._contextMenuElement.parentElement) { | 329 } else if (this._parentMenu && this._contextMenuElement.parentElement) { |
| 328 this._discardSubMenus(); | 330 this._discardSubMenus(); |
| 329 if (closeParentMenus) | 331 if (closeParentMenus) |
| 330 this._parentMenu._discardMenu(closeParentMenus, event); | 332 this._parentMenu._discardMenu(closeParentMenus, event); |
| 331 | 333 |
| 332 if (event) | 334 if (event) |
| 333 event.consume(true); | 335 event.consume(true); |
| 334 } | 336 } |
| 335 }, | 337 }, |
| 336 | 338 |
| 337 _discardSubMenus: function() | 339 _discardSubMenus: function() |
| 338 { | 340 { |
| 339 if (this._subMenu) | 341 if (this._subMenu) |
| 340 this._subMenu._discardSubMenus(); | 342 this._subMenu._discardSubMenus(); |
| 341 this._contextMenuElement.remove(); | 343 this._contextMenuElement.remove(); |
| 342 if (this._parentMenu) | 344 if (this._parentMenu) |
| 343 delete this._parentMenu._subMenu; | 345 delete this._parentMenu._subMenu; |
| 344 } | 346 } |
| 345 } | 347 } |
| OLD | NEW |