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
3 // found in the LICENSE file.
7 * @extends {WebInspector.Object}
8 * @param {!Element} element
10 WebInspector
.DropDownMenu = function(element
)
12 /** @type {!Array.<!WebInspector.DropDownMenu.Item>} */
15 element
.addEventListener("mousedown", this._onMouseDown
.bind(this));
18 /** @typedef {{id: string, title: string}} */
19 WebInspector
.DropDownMenu
.Item
;
22 WebInspector
.DropDownMenu
.Events
= {
23 ItemSelected
: "ItemSelected"
26 WebInspector
.DropDownMenu
.prototype = {
28 * @param {!Event} event
30 _onMouseDown: function(event
)
32 if (event
.which
!== 1)
34 var menu
= new WebInspector
.ContextMenu(event
);
35 for (var item
of this._items
)
36 menu
.appendCheckboxItem(item
.title
, this._itemHandler
.bind(this, item
.id
), item
.id
=== this._selectedItemId
);
43 _itemHandler: function(id
)
45 this.dispatchEventToListeners(WebInspector
.DropDownMenu
.Events
.ItemSelected
, id
);
50 * @param {string} title
52 addItem: function(id
, title
)
54 this._items
.push({id
: id
, title
: title
});
60 selectItem: function(id
)
62 this._selectedItemId
= id
;
68 delete this._selectedItemId
;
71 __proto__
: WebInspector
.Object
.prototype