Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / devtools / front_end / ui / DropDownMenu.js
blob201d61c9b049a1882750b0ac71f6079e4dbac191
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.
5 /**
6 * @constructor
7 * @extends {WebInspector.Object}
8 * @param {!Element} element
9 */
10 WebInspector.DropDownMenu = function(element)
12 /** @type {!Array.<!WebInspector.DropDownMenu.Item>} */
13 this._items = [];
15 element.addEventListener("mousedown", this._onMouseDown.bind(this));
18 /** @typedef {{id: string, title: string}} */
19 WebInspector.DropDownMenu.Item;
21 /** @enum {string} */
22 WebInspector.DropDownMenu.Events = {
23 ItemSelected: "ItemSelected"
26 WebInspector.DropDownMenu.prototype = {
27 /**
28 * @param {!Event} event
30 _onMouseDown: function(event)
32 if (event.which !== 1)
33 return;
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);
37 menu.show();
40 /**
41 * @param {string} id
43 _itemHandler: function(id)
45 this.dispatchEventToListeners(WebInspector.DropDownMenu.Events.ItemSelected, id);
48 /**
49 * @param {string} id
50 * @param {string} title
52 addItem: function(id, title)
54 this._items.push({id: id, title: title});
57 /**
58 * @param {string} id
60 selectItem: function(id)
62 this._selectedItemId = id;
65 clear: function()
67 this._items = [];
68 delete this._selectedItemId;
71 __proto__: WebInspector.Object.prototype