| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 {WebInspector.TargetManager.Observer} | 5 * @implements {SDK.TargetManager.Observer} |
| 6 * @unrestricted | 6 * @unrestricted |
| 7 */ | 7 */ |
| 8 WebInspector.TargetsComboBoxController = class { | 8 Profiler.TargetsComboBoxController = class { |
| 9 /** | 9 /** |
| 10 * @param {!Element} selectElement | 10 * @param {!Element} selectElement |
| 11 * @param {!Element} elementToHide | 11 * @param {!Element} elementToHide |
| 12 */ | 12 */ |
| 13 constructor(selectElement, elementToHide) { | 13 constructor(selectElement, elementToHide) { |
| 14 elementToHide.classList.add('hidden'); | 14 elementToHide.classList.add('hidden'); |
| 15 selectElement.addEventListener('change', this._onComboBoxSelectionChange.bin
d(this), false); | 15 selectElement.addEventListener('change', this._onComboBoxSelectionChange.bin
d(this), false); |
| 16 this._selectElement = selectElement; | 16 this._selectElement = selectElement; |
| 17 this._elementToHide = elementToHide; | 17 this._elementToHide = elementToHide; |
| 18 /** @type {!Map.<!WebInspector.Target, !Element>} */ | 18 /** @type {!Map.<!SDK.Target, !Element>} */ |
| 19 this._targetToOption = new Map(); | 19 this._targetToOption = new Map(); |
| 20 | 20 |
| 21 WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._targ
etChangedExternally, this); | 21 UI.context.addFlavorChangeListener(SDK.Target, this._targetChangedExternally
, this); |
| 22 WebInspector.targetManager.addEventListener( | 22 SDK.targetManager.addEventListener( |
| 23 WebInspector.TargetManager.Events.NameChanged, this._targetNameChanged,
this); | 23 SDK.TargetManager.Events.NameChanged, this._targetNameChanged, this); |
| 24 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Capabili
ty.JS); | 24 SDK.targetManager.observeTargets(this, SDK.Target.Capability.JS); |
| 25 } | 25 } |
| 26 | 26 |
| 27 /** | 27 /** |
| 28 * @override | 28 * @override |
| 29 * @param {!WebInspector.Target} target | 29 * @param {!SDK.Target} target |
| 30 */ | 30 */ |
| 31 targetAdded(target) { | 31 targetAdded(target) { |
| 32 var option = this._selectElement.createChild('option'); | 32 var option = this._selectElement.createChild('option'); |
| 33 option.text = target.name(); | 33 option.text = target.name(); |
| 34 option.__target = target; | 34 option.__target = target; |
| 35 this._targetToOption.set(target, option); | 35 this._targetToOption.set(target, option); |
| 36 if (WebInspector.context.flavor(WebInspector.Target) === target) | 36 if (UI.context.flavor(SDK.Target) === target) |
| 37 this._selectElement.selectedIndex = Array.prototype.indexOf.call(/** @type
{?} */ (this._selectElement), option); | 37 this._selectElement.selectedIndex = Array.prototype.indexOf.call(/** @type
{?} */ (this._selectElement), option); |
| 38 | 38 |
| 39 this._updateVisibility(); | 39 this._updateVisibility(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * @override | 43 * @override |
| 44 * @param {!WebInspector.Target} target | 44 * @param {!SDK.Target} target |
| 45 */ | 45 */ |
| 46 targetRemoved(target) { | 46 targetRemoved(target) { |
| 47 var option = this._targetToOption.remove(target); | 47 var option = this._targetToOption.remove(target); |
| 48 this._selectElement.removeChild(option); | 48 this._selectElement.removeChild(option); |
| 49 this._updateVisibility(); | 49 this._updateVisibility(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * @param {!WebInspector.Event} event | 53 * @param {!Common.Event} event |
| 54 */ | 54 */ |
| 55 _targetNameChanged(event) { | 55 _targetNameChanged(event) { |
| 56 var target = /** @type {!WebInspector.Target} */ (event.data); | 56 var target = /** @type {!SDK.Target} */ (event.data); |
| 57 var option = this._targetToOption.get(target); | 57 var option = this._targetToOption.get(target); |
| 58 option.text = target.name(); | 58 option.text = target.name(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 _onComboBoxSelectionChange() { | 61 _onComboBoxSelectionChange() { |
| 62 var selectedOption = this._selectElement[this._selectElement.selectedIndex]; | 62 var selectedOption = this._selectElement[this._selectElement.selectedIndex]; |
| 63 if (!selectedOption) | 63 if (!selectedOption) |
| 64 return; | 64 return; |
| 65 | 65 |
| 66 WebInspector.context.setFlavor(WebInspector.Target, selectedOption.__target)
; | 66 UI.context.setFlavor(SDK.Target, selectedOption.__target); |
| 67 } | 67 } |
| 68 | 68 |
| 69 _updateVisibility() { | 69 _updateVisibility() { |
| 70 var hidden = this._selectElement.childElementCount === 1; | 70 var hidden = this._selectElement.childElementCount === 1; |
| 71 this._elementToHide.classList.toggle('hidden', hidden); | 71 this._elementToHide.classList.toggle('hidden', hidden); |
| 72 } | 72 } |
| 73 | 73 |
| 74 /** | 74 /** |
| 75 * @param {!WebInspector.Event} event | 75 * @param {!Common.Event} event |
| 76 */ | 76 */ |
| 77 _targetChangedExternally(event) { | 77 _targetChangedExternally(event) { |
| 78 var target = /** @type {?WebInspector.Target} */ (event.data); | 78 var target = /** @type {?SDK.Target} */ (event.data); |
| 79 if (target) { | 79 if (target) { |
| 80 var option = /** @type {!Element} */ (this._targetToOption.get(target)); | 80 var option = /** @type {!Element} */ (this._targetToOption.get(target)); |
| 81 this._select(option); | 81 this._select(option); |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| 85 /** | 85 /** |
| 86 * @param {!Element} option | 86 * @param {!Element} option |
| 87 */ | 87 */ |
| 88 _select(option) { | 88 _select(option) { |
| 89 this._selectElement.selectedIndex = Array.prototype.indexOf.call(/** @type {
?} */ (this._selectElement), option); | 89 this._selectElement.selectedIndex = Array.prototype.indexOf.call(/** @type {
?} */ (this._selectElement), option); |
| 90 } | 90 } |
| 91 }; | 91 }; |
| OLD | NEW |