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. 4 5 /** 6 * @constructor 7 * @extends {WebInspector.SidebarPane} 8 * @implements {WebInspector.TargetManager.Observer} 9 */ 10 WebInspector.ThreadsSidebarPane = function() 11 { 12 WebInspector.SidebarPane.call(this, WebInspector.UIString("Threads")); 13 /** @type {!Map.<!WebInspector.Target, !WebInspector.Placard>} */ 14 this._targetsToPlacards = new Map(); 15 /** @type {!Map.<!WebInspector.Placard, !WebInspector.Target>} */ 16 this._placardsToTargets = new Map(); 17 /** @type {?WebInspector.Placard} */ 18 this._selectedPlacard = null; 19 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebInspector.DebuggerModel.Events.DebuggerPaused, this._onDebuggerStateChanged, this); 20 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebInspector.DebuggerModel.Events.DebuggerResumed, this._onDebuggerStateChanged, this); 21 WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._targetChanged, this); 22 WebInspector.targetManager.observeTargets(this); 23 } 24 25 WebInspector.ThreadsSidebarPane.prototype = { 26 27 /** 28 * @param {!WebInspector.Target} target 29 */ 30 targetAdded: function(target) 31 { 32 var placard = new WebInspector.Placard(target.name(), ""); 33 placard.element.addEventListener("click", this._onPlacardClick.bind(this, placard), false); 34 var currentTarget = WebInspector.context.flavor(WebInspector.Target); 35 if (currentTarget === target) 36 this._selectPlacard(placard); 37 38 this._targetsToPlacards.set(target, placard); 39 this._placardsToTargets.set(placard, target); 40 this.bodyElement.appendChild(placard.element); 41 this._updateDebuggerState(target); 42 }, 43 44 /** 45 * @param {!WebInspector.Target} target 46 */ 47 targetRemoved: function(target) 48 { 49 var placard = this._targetsToPlacards.remove(target); 50 this._placardsToTargets.remove(placard); 51 this.bodyElement.removeChild(placard.element); 52 }, 53 54 /** 55 * @param {!WebInspector.Event} event 56 */ 57 _targetChanged: function(event) 58 { 59 var newTarget = /** @type {!WebInspector.Target} */(event.data); 60 var placard = /** @type {!WebInspector.Placard} */ (this._targetsToPlacards.get(newTarget)); 61 this._selectPlacard(placard); 62 }, 63 64 /** 65 * @param {!WebInspector.Event} event 66 */ 67 _onDebuggerStateChanged: function(event) 68 { 69 var debuggerModel = /** @type {!WebInspector.DebuggerModel} */ (event.target); 70 this._updateDebuggerState(debuggerModel.target()); 71 }, 72 73 /** 74 * @param {!WebInspector.Target} target 75 */ 76 _updateDebuggerState: function(target) 77 { 78 var placard = this._targetsToPlacards.get(target); 79 placard.subtitle = target.debuggerModel.isPaused() ? WebInspector.UIString("paused") : WebInspector.UIString(""); 80 }, 81 82 /** 83 * @param {!WebInspector.Placard} placard 84 */ 85 _selectPlacard: function(placard) 86 { 87 if (placard === this._selectedPlacard) 88 return; 89 90 if (this._selectedPlacard) 91 this._selectedPlacard.selected = false; 92 93 this._selectedPlacard = placard; 94 placard.selected = true; 95 }, 96 97 /** 98 * @param {!WebInspector.Placard} placard 99 */ 100 _onPlacardClick: function(placard) 101 { 102 WebInspector.context.setFlavor(WebInspector.Target, this._placardsToTargets.get(placard)); 103 placard.element.scrollIntoViewIfNeeded(); 104 }, 105 106 107 __proto__: WebInspector.SidebarPane.prototype 108 }