OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 /** | 4 /** |
5 * @implements {SDK.SDKModelObserver<!SDK.RuntimeModel>} | 5 * @implements {SDK.SDKModelObserver<!SDK.RuntimeModel>} |
6 * @unrestricted | 6 * @unrestricted |
7 */ | 7 */ |
8 Console.ConsoleContextSelector = class { | 8 Console.ConsoleContextSelector = class { |
9 /** | 9 /** |
10 * @param {!Element} selectElement | 10 * @param {!Element} selectElement |
11 */ | 11 */ |
12 constructor(selectElement) { | 12 constructor(selectElement) { |
13 this._selectElement = selectElement; | 13 this._selectElement = selectElement; |
14 /** | 14 /** |
15 * @type {!Map.<!SDK.ExecutionContext, !Element>} | 15 * @type {!Map.<!SDK.ExecutionContext, !Element>} |
16 */ | 16 */ |
17 this._optionByExecutionContext = new Map(); | 17 this._optionByExecutionContext = new Map(); |
18 | 18 |
19 SDK.targetManager.addModelListener( | 19 SDK.targetManager.addModelListener( |
20 SDK.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextCreated, this.
_onExecutionContextCreated, this); | 20 SDK.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextCreated, this.
_onExecutionContextCreated, this); |
21 SDK.targetManager.addModelListener( | 21 SDK.targetManager.addModelListener( |
22 SDK.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextChanged, this.
_onExecutionContextChanged, this); | 22 SDK.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextChanged, this.
_onExecutionContextChanged, this); |
23 SDK.targetManager.addModelListener( | 23 SDK.targetManager.addModelListener( |
24 SDK.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextDestroyed, thi
s._onExecutionContextDestroyed, this); | 24 SDK.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextDestroyed, thi
s._onExecutionContextDestroyed, this); |
25 | 25 |
26 this._selectElement.addEventListener('change', this._executionContextChanged
.bind(this), false); | 26 this._selectElement.addEventListener('change', this._executionContextChanged
.bind(this), false); |
27 UI.context.addFlavorChangeListener(SDK.ExecutionContext, this._executionCont
extChangedExternally, this); | 27 UI.context.addFlavorChangeListener(SDK.ExecutionContext, this._executionCont
extChangedExternally, this); |
| 28 UI.context.addFlavorChangeListener(SDK.DebuggerModel.CallFrame, this._callFr
ameSelectedInUI, this); |
28 SDK.targetManager.observeModels(SDK.RuntimeModel, this); | 29 SDK.targetManager.observeModels(SDK.RuntimeModel, this); |
| 30 SDK.targetManager.addModelListener( |
| 31 SDK.DebuggerModel, SDK.DebuggerModel.Events.CallFrameSelected, this._cal
lFrameSelectedInModel, this); |
29 } | 32 } |
30 | 33 |
31 /** | 34 /** |
32 * @param {!SDK.ExecutionContext} executionContext | 35 * @param {!SDK.ExecutionContext} executionContext |
33 * @return {string} | 36 * @return {string} |
34 */ | 37 */ |
35 _titleFor(executionContext) { | 38 _titleFor(executionContext) { |
36 var target = executionContext.target(); | 39 var target = executionContext.target(); |
37 var depth = 0; | 40 var depth = 0; |
38 var label = executionContext.label() ? target.decorateLabel(executionContext
.label()) : ''; | 41 var label = executionContext.label() ? target.decorateLabel(executionContext
.label()) : ''; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 newOption.__executionContext = executionContext; | 84 newOption.__executionContext = executionContext; |
82 newOption.text = this._titleFor(executionContext); | 85 newOption.text = this._titleFor(executionContext); |
83 this._optionByExecutionContext.set(executionContext, newOption); | 86 this._optionByExecutionContext.set(executionContext, newOption); |
84 var options = this._selectElement.options; | 87 var options = this._selectElement.options; |
85 var contexts = Array.prototype.map.call(options, mapping); | 88 var contexts = Array.prototype.map.call(options, mapping); |
86 var index = contexts.lowerBound(executionContext, executionContext.runtimeMo
del.executionContextComparator()); | 89 var index = contexts.lowerBound(executionContext, executionContext.runtimeMo
del.executionContextComparator()); |
87 this._selectElement.insertBefore(newOption, options[index]); | 90 this._selectElement.insertBefore(newOption, options[index]); |
88 | 91 |
89 if (executionContext === UI.context.flavor(SDK.ExecutionContext)) | 92 if (executionContext === UI.context.flavor(SDK.ExecutionContext)) |
90 this._select(newOption); | 93 this._select(newOption); |
| 94 this._updateOptionDisabledState(newOption); |
91 | 95 |
92 /** | 96 /** |
93 * @param {!Element} option | 97 * @param {!Element} option |
94 * @return {!SDK.ExecutionContext} | 98 * @return {!SDK.ExecutionContext} |
95 */ | 99 */ |
96 function mapping(option) { | 100 function mapping(option) { |
97 return option.__executionContext; | 101 return option.__executionContext; |
98 } | 102 } |
99 } | 103 } |
100 | 104 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 } | 222 } |
219 | 223 |
220 /** | 224 /** |
221 * @return {?Element} | 225 * @return {?Element} |
222 */ | 226 */ |
223 _selectedOption() { | 227 _selectedOption() { |
224 if (this._selectElement.selectedIndex >= 0) | 228 if (this._selectElement.selectedIndex >= 0) |
225 return this._selectElement[this._selectElement.selectedIndex]; | 229 return this._selectElement[this._selectElement.selectedIndex]; |
226 return null; | 230 return null; |
227 } | 231 } |
| 232 |
| 233 /** |
| 234 * @param {!Common.Event} event |
| 235 */ |
| 236 _callFrameSelectedInModel(event) { |
| 237 var debuggerModel = /** @type {!SDK.DebuggerModel} */ (event.data); |
| 238 var options = this._selectElement.options; |
| 239 for (var i = 0; i < options.length; i++) { |
| 240 if (options[i].__executionContext.debuggerModel === debuggerModel) |
| 241 this._updateOptionDisabledState(options[i]); |
| 242 } |
| 243 } |
| 244 |
| 245 /** |
| 246 * @param {!Element} option |
| 247 */ |
| 248 _updateOptionDisabledState(option) { |
| 249 var executionContext = option.__executionContext; |
| 250 var callFrame = executionContext.debuggerModel.selectedCallFrame(); |
| 251 var callFrameContext = callFrame && callFrame.script.executionContext(); |
| 252 option.disabled = callFrameContext && executionContext !== callFrameContext; |
| 253 } |
| 254 |
| 255 _callFrameSelectedInUI() { |
| 256 var callFrame = UI.context.flavor(SDK.DebuggerModel.CallFrame); |
| 257 var callFrameContext = callFrame && callFrame.script.executionContext(); |
| 258 if (callFrameContext) |
| 259 UI.context.setFlavor(SDK.ExecutionContext, callFrameContext); |
| 260 } |
228 }; | 261 }; |
OLD | NEW |