Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * @unrestricted | 5 * @unrestricted |
| 6 */ | 6 */ |
| 7 UI.DropDownMenu = class extends Common.Object { | 7 UI.DropDownMenu = class extends Common.Object { |
| 8 /** | 8 /** |
| 9 * @param {!Element} element | 9 * @param {!Element} element |
| 10 */ | 10 */ |
| 11 constructor(element) { | 11 constructor(element) { |
| 12 super(); | 12 super(); |
| 13 /** @type {!Array.<!UI.DropDownMenu.Item>} */ | 13 /** @type {!Array.<!UI.DropDownMenu.Item>} */ |
| 14 this._items = []; | 14 this._items = []; |
| 15 | 15 |
| 16 element.addEventListener('mousedown', this._onMouseDown.bind(this)); | 16 element.addEventListener('mousedown', this._onMouseDown.bind(this)); |
| 17 } | 17 } |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * @param {!Event} event | 20 * @param {!Event} event |
| 21 */ | 21 */ |
| 22 _onMouseDown(event) { | 22 _onMouseDown(event) { |
| 23 if (event.which !== 1) | 23 if (event.which !== 1) |
| 24 return; | 24 return; |
| 25 | |
| 26 // Remove any selections to avoid native context menu items, for example 'Co py'. | |
| 27 var selection = UI.inspectorView.element.window().getSelection(); | |
|
lushnikov
2017/03/03 04:11:00
it would be nice if we can create context menus wi
| |
| 28 selection.removeAllRanges(); | |
| 29 | |
| 25 var menu = new UI.ContextMenu(event); | 30 var menu = new UI.ContextMenu(event); |
| 26 for (var item of this._items) | 31 for (var item of this._items) |
| 27 menu.appendCheckboxItem(item.title, this._itemHandler.bind(this, item.id), item.id === this._selectedItemId); | 32 menu.appendCheckboxItem(item.title, this._itemHandler.bind(this, item.id), item.id === this._selectedItemId); |
| 28 menu.show(); | 33 menu.show(); |
| 29 } | 34 } |
| 30 | 35 |
| 31 /** | 36 /** |
| 32 * @param {string} id | 37 * @param {string} id |
| 33 */ | 38 */ |
| 34 _itemHandler(id) { | 39 _itemHandler(id) { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 56 } | 61 } |
| 57 }; | 62 }; |
| 58 | 63 |
| 59 /** @typedef {{id: string, title: string}} */ | 64 /** @typedef {{id: string, title: string}} */ |
| 60 UI.DropDownMenu.Item; | 65 UI.DropDownMenu.Item; |
| 61 | 66 |
| 62 /** @enum {symbol} */ | 67 /** @enum {symbol} */ |
| 63 UI.DropDownMenu.Events = { | 68 UI.DropDownMenu.Events = { |
| 64 ItemSelected: Symbol('ItemSelected') | 69 ItemSelected: Symbol('ItemSelected') |
| 65 }; | 70 }; |
| OLD | NEW |