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}
9 WebInspector.DropDownMenu = function()
11 this.element = createElementWithClass("select", "drop-down-menu");
12 this.element.addEventListener("mousedown", this._onBeforeMouseDown.bind(this), true);
13 this.element.addEventListener("mousedown", consumeEvent, false);
14 this.element.addEventListener("change", this._onChange.bind(this), false);
17 WebInspector.DropDownMenu.Events = {
18 BeforeShow: "BeforeShow",
19 ItemSelected: "ItemSelected"
22 WebInspector.DropDownMenu.prototype = {
23 _onBeforeMouseDown: function()
25 this.dispatchEventToListeners(WebInspector.DropDownMenu.Events.BeforeShow, null);
30 var options = this.element.options;
31 var selectedOption = options[this.element.selectedIndex];
32 this.dispatchEventToListeners(WebInspector.DropDownMenu.Events.ItemSelected, selectedOption.id);
37 * @param {string} title
39 addItem: function(id, title)
41 var option = new Option(title);
43 this.element.appendChild(option);
49 selectItem: function(id)
51 var children = this.element.children;
52 for (var i = 0; i < children.length; ++i) {
53 var child = children[i];
54 if (child.id === id) {
55 this.element.selectedIndex = i;
59 this.element.selectedIndex = -1;
64 this.element.removeChildren();
67 __proto__: WebInspector.Object.prototype