Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / devtools / front_end / sources / ThreadsSidebarPane.js
blobc33f1d129463c5e89827d61fbb2a09fabaa4eb66
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.SidebarPane}
8  * @implements {WebInspector.TargetManager.Observer}
9  */
10 WebInspector.ThreadsSidebarPane = function()
12     WebInspector.SidebarPane.call(this, WebInspector.UIString("Threads"));
13     this.setVisible(false);
15     /** @type {!Map.<!WebInspector.DebuggerModel, !WebInspector.UIList.Item>} */
16     this._debuggerModelToListItems = new Map();
17     /** @type {!Map.<!WebInspector.UIList.Item, !WebInspector.Target>} */
18     this._listItemsToTargets = new Map();
19     /** @type {?WebInspector.UIList.Item} */
20     this._selectedListItem = null;
21     this.threadList = new WebInspector.UIList();
22     this.threadList.show(this.element);
23     WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebInspector.DebuggerModel.Events.DebuggerPaused, this._onDebuggerStateChanged, this);
24     WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebInspector.DebuggerModel.Events.DebuggerResumed, this._onDebuggerStateChanged, this);
25     WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._targetChanged, this);
26     WebInspector.targetManager.observeTargets(this);
29 WebInspector.ThreadsSidebarPane.prototype = {
30     /**
31      * @override
32      * @param {!WebInspector.Target} target
33      */
34     targetAdded: function(target)
35     {
36         var debuggerModel = WebInspector.DebuggerModel.fromTarget(target)
37         if (!debuggerModel) {
38             this._updateVisibility();
39             return;
40         }
41         var listItem = new WebInspector.UIList.Item(target.name(), "");
42         listItem.element.addEventListener("click", this._onListItemClick.bind(this, listItem), false);
43         var currentTarget = WebInspector.context.flavor(WebInspector.Target);
44         if (currentTarget === target)
45             this._selectListItem(listItem);
47         this._debuggerModelToListItems.set(debuggerModel, listItem);
48         this._listItemsToTargets.set(listItem, target);
49         this.threadList.addItem(listItem);
50         this._updateDebuggerState(debuggerModel);
51         this._updateVisibility();
52     },
54     _updateVisibility: function()
55     {
56         this._wasVisibleAtLeastOnce = this._wasVisibleAtLeastOnce || this._debuggerModelToListItems.size > 1;
57         this.setVisible(this._wasVisibleAtLeastOnce);
58     },
60     /**
61      * @override
62      * @param {!WebInspector.Target} target
63      */
64     targetRemoved: function(target)
65     {
66         var debuggerModel = WebInspector.DebuggerModel.fromTarget(target)
67         if (!debuggerModel)
68             return;
69         var listItem = this._debuggerModelToListItems.remove(debuggerModel);
70         if (listItem) {
71             this._listItemsToTargets.remove(listItem);
72             this.threadList.removeItem(listItem);
73         }
74         this._updateVisibility();
75     },
77     /**
78      * @param {!WebInspector.Event} event
79      */
80     _targetChanged: function(event)
81     {
82         var newTarget = /** @type {!WebInspector.Target} */(event.data);
83         var debuggerModel = WebInspector.DebuggerModel.fromTarget(newTarget)
84         if (!debuggerModel)
85             return;
86         var listItem =  /** @type {!WebInspector.UIList.Item} */ (this._debuggerModelToListItems.get(debuggerModel));
87         this._selectListItem(listItem);
88     },
90     /**
91      * @param {!WebInspector.Event} event
92      */
93     _onDebuggerStateChanged: function(event)
94     {
95         var debuggerModel = /** @type {!WebInspector.DebuggerModel} */ (event.target);
96         this._updateDebuggerState(debuggerModel);
97     },
99     /**
100      * @param {!WebInspector.DebuggerModel} debuggerModel
101      */
102     _updateDebuggerState: function(debuggerModel)
103     {
104         var listItem = this._debuggerModelToListItems.get(debuggerModel);
105         listItem.setSubtitle(WebInspector.UIString(debuggerModel.isPaused() ? "paused" : ""));
106     },
108     /**
109      * @param {!WebInspector.UIList.Item} listItem
110      */
111     _selectListItem: function(listItem)
112     {
113         if (listItem === this._selectedListItem)
114             return;
116         if (this._selectedListItem)
117             this._selectedListItem.setSelected(false);
119         this._selectedListItem = listItem;
120         listItem.setSelected(true);
121     },
123     /**
124      * @param {!WebInspector.UIList.Item} listItem
125      */
126     _onListItemClick: function(listItem)
127     {
128         WebInspector.context.setFlavor(WebInspector.Target, this._listItemsToTargets.get(listItem));
129         listItem.element.scrollIntoViewIfNeeded();
130     },
133     __proto__: WebInspector.SidebarPane.prototype