| 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 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @implements {WebInspector.TargetManager.Observer} | 7 * @implements {WebInspector.TargetManager.Observer} |
| 8 * @param {!Element} selectElement | 8 * @param {!Element} selectElement |
| 9 * @param {!Element} elementToHide | 9 * @param {!Element} elementToHide |
| 10 */ | 10 */ |
| 11 WebInspector.TargetsComboBoxController = function(selectElement, elementToHide) | 11 WebInspector.TargetsComboBoxController = function(selectElement, elementToHide) |
| 12 { | 12 { |
| 13 elementToHide.classList.add("hidden"); | 13 elementToHide.classList.add("hidden"); |
| 14 selectElement.addEventListener("change", this._onComboBoxSelectionChange.bin
d(this), false); | 14 selectElement.addEventListener("change", this._onComboBoxSelectionChange.bin
d(this), false); |
| 15 this._selectElement = selectElement; | 15 this._selectElement = selectElement; |
| 16 this._elementToHide = elementToHide; | 16 this._elementToHide = elementToHide; |
| 17 /** @type {!Map.<!WebInspector.Target, !Element>} */ | 17 /** @type {!Map.<!WebInspector.Target, !Element>} */ |
| 18 this._targetToOption = new Map(); | 18 this._targetToOption = new Map(); |
| 19 | 19 |
| 20 WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._targ
etChangedExternally, this); | 20 WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._targ
etChangedExternally, this); |
| 21 WebInspector.targetManager.observeTargets(this); | 21 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Capabili
ty.JS); |
| 22 } | 22 } |
| 23 | 23 |
| 24 WebInspector.TargetsComboBoxController.prototype = { | 24 WebInspector.TargetsComboBoxController.prototype = { |
| 25 | 25 |
| 26 /** | 26 /** |
| 27 * @override | 27 * @override |
| 28 * @param {!WebInspector.Target} target | 28 * @param {!WebInspector.Target} target |
| 29 */ | 29 */ |
| 30 targetAdded: function(target) | 30 targetAdded: function(target) |
| 31 { | 31 { |
| 32 if (!target.hasJSContext()) | |
| 33 return; | |
| 34 var option = this._selectElement.createChild("option"); | 32 var option = this._selectElement.createChild("option"); |
| 35 option.text = target.name(); | 33 option.text = target.name(); |
| 36 option.__target = target; | 34 option.__target = target; |
| 37 this._targetToOption.set(target, option); | 35 this._targetToOption.set(target, option); |
| 38 if (WebInspector.context.flavor(WebInspector.Target) === target) | 36 if (WebInspector.context.flavor(WebInspector.Target) === target) |
| 39 this._selectElement.selectedIndex = Array.prototype.indexOf.call(/**
@type {?} */ (this._selectElement), option); | 37 this._selectElement.selectedIndex = Array.prototype.indexOf.call(/**
@type {?} */ (this._selectElement), option); |
| 40 | 38 |
| 41 this._updateVisibility(); | 39 this._updateVisibility(); |
| 42 }, | 40 }, |
| 43 | 41 |
| 44 /** | 42 /** |
| 45 * @override | 43 * @override |
| 46 * @param {!WebInspector.Target} target | 44 * @param {!WebInspector.Target} target |
| 47 */ | 45 */ |
| 48 targetRemoved: function(target) | 46 targetRemoved: function(target) |
| 49 { | 47 { |
| 50 if (!target.hasJSContext()) | |
| 51 return; | |
| 52 var option = this._targetToOption.remove(target); | 48 var option = this._targetToOption.remove(target); |
| 53 this._selectElement.removeChild(option); | 49 this._selectElement.removeChild(option); |
| 54 this._updateVisibility(); | 50 this._updateVisibility(); |
| 55 }, | 51 }, |
| 56 | 52 |
| 57 _onComboBoxSelectionChange: function() | 53 _onComboBoxSelectionChange: function() |
| 58 { | 54 { |
| 59 var selectedOption = this._selectElement[this._selectElement.selectedInd
ex]; | 55 var selectedOption = this._selectElement[this._selectElement.selectedInd
ex]; |
| 60 if (!selectedOption) | 56 if (!selectedOption) |
| 61 return; | 57 return; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 83 | 79 |
| 84 /** | 80 /** |
| 85 * @param {!Element} option | 81 * @param {!Element} option |
| 86 */ | 82 */ |
| 87 _select: function(option) | 83 _select: function(option) |
| 88 { | 84 { |
| 89 this._selectElement.selectedIndex = Array.prototype.indexOf.call(/** @ty
pe {?} */ (this._selectElement), option); | 85 this._selectElement.selectedIndex = Array.prototype.indexOf.call(/** @ty
pe {?} */ (this._selectElement), option); |
| 90 } | 86 } |
| 91 | 87 |
| 92 } | 88 } |
| OLD | NEW |