Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/profiler/TargetsComboBoxController.js

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
5 /** 4 /**
6 * @constructor
7 * @implements {WebInspector.TargetManager.Observer} 5 * @implements {WebInspector.TargetManager.Observer}
8 * @param {!Element} selectElement 6 * @unrestricted
9 * @param {!Element} elementToHide
10 */ 7 */
11 WebInspector.TargetsComboBoxController = function(selectElement, elementToHide) 8 WebInspector.TargetsComboBoxController = class {
12 { 9 /**
13 elementToHide.classList.add("hidden"); 10 * @param {!Element} selectElement
14 selectElement.addEventListener("change", this._onComboBoxSelectionChange.bin d(this), false); 11 * @param {!Element} elementToHide
12 */
13 constructor(selectElement, elementToHide) {
14 elementToHide.classList.add('hidden');
15 selectElement.addEventListener('change', this._onComboBoxSelectionChange.bin d(this), false);
15 this._selectElement = selectElement; 16 this._selectElement = selectElement;
16 this._elementToHide = elementToHide; 17 this._elementToHide = elementToHide;
17 /** @type {!Map.<!WebInspector.Target, !Element>} */ 18 /** @type {!Map.<!WebInspector.Target, !Element>} */
18 this._targetToOption = new Map(); 19 this._targetToOption = new Map();
19 20
20 WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._targ etChangedExternally, this); 21 WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._targ etChangedExternally, this);
21 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event s.NameChanged, this._targetNameChanged, this); 22 WebInspector.targetManager.addEventListener(
23 WebInspector.TargetManager.Events.NameChanged, this._targetNameChanged, this);
22 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Capabili ty.JS); 24 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Capabili ty.JS);
25 }
26
27 /**
28 * @override
29 * @param {!WebInspector.Target} target
30 */
31 targetAdded(target) {
32 var option = this._selectElement.createChild('option');
33 option.text = target.name();
34 option.__target = target;
35 this._targetToOption.set(target, option);
36 if (WebInspector.context.flavor(WebInspector.Target) === target)
37 this._selectElement.selectedIndex = Array.prototype.indexOf.call(/** @type {?} */ (this._selectElement), option);
38
39 this._updateVisibility();
40 }
41
42 /**
43 * @override
44 * @param {!WebInspector.Target} target
45 */
46 targetRemoved(target) {
47 var option = this._targetToOption.remove(target);
48 this._selectElement.removeChild(option);
49 this._updateVisibility();
50 }
51
52 /**
53 * @param {!WebInspector.Event} event
54 */
55 _targetNameChanged(event) {
56 var target = /** @type {!WebInspector.Target} */ (event.data);
57 var option = this._targetToOption.get(target);
58 option.text = target.name();
59 }
60
61 _onComboBoxSelectionChange() {
62 var selectedOption = this._selectElement[this._selectElement.selectedIndex];
63 if (!selectedOption)
64 return;
65
66 WebInspector.context.setFlavor(WebInspector.Target, selectedOption.__target) ;
67 }
68
69 _updateVisibility() {
70 var hidden = this._selectElement.childElementCount === 1;
71 this._elementToHide.classList.toggle('hidden', hidden);
72 }
73
74 /**
75 * @param {!WebInspector.Event} event
76 */
77 _targetChangedExternally(event) {
78 var target = /** @type {?WebInspector.Target} */ (event.data);
79 if (target) {
80 var option = /** @type {!Element} */ (this._targetToOption.get(target));
81 this._select(option);
82 }
83 }
84
85 /**
86 * @param {!Element} option
87 */
88 _select(option) {
89 this._selectElement.selectedIndex = Array.prototype.indexOf.call(/** @type { ?} */ (this._selectElement), option);
90 }
23 }; 91 };
24
25 WebInspector.TargetsComboBoxController.prototype = {
26
27 /**
28 * @override
29 * @param {!WebInspector.Target} target
30 */
31 targetAdded: function(target)
32 {
33 var option = this._selectElement.createChild("option");
34 option.text = target.name();
35 option.__target = target;
36 this._targetToOption.set(target, option);
37 if (WebInspector.context.flavor(WebInspector.Target) === target)
38 this._selectElement.selectedIndex = Array.prototype.indexOf.call(/** @type {?} */ (this._selectElement), option);
39
40 this._updateVisibility();
41 },
42
43 /**
44 * @override
45 * @param {!WebInspector.Target} target
46 */
47 targetRemoved: function(target)
48 {
49 var option = this._targetToOption.remove(target);
50 this._selectElement.removeChild(option);
51 this._updateVisibility();
52 },
53
54 /**
55 * @param {!WebInspector.Event} event
56 */
57 _targetNameChanged: function(event)
58 {
59 var target = /** @type {!WebInspector.Target} */ (event.data);
60 var option = this._targetToOption.get(target);
61 option.text = target.name();
62 },
63
64 _onComboBoxSelectionChange: function()
65 {
66 var selectedOption = this._selectElement[this._selectElement.selectedInd ex];
67 if (!selectedOption)
68 return;
69
70 WebInspector.context.setFlavor(WebInspector.Target, selectedOption.__tar get);
71 },
72
73 _updateVisibility: function()
74 {
75 var hidden = this._selectElement.childElementCount === 1;
76 this._elementToHide.classList.toggle("hidden", hidden);
77 },
78
79 /**
80 * @param {!WebInspector.Event} event
81 */
82 _targetChangedExternally: function(event)
83 {
84 var target = /** @type {?WebInspector.Target} */ (event.data);
85 if (target) {
86 var option = /** @type {!Element} */ (this._targetToOption.get(targe t));
87 this._select(option);
88 }
89 },
90
91 /**
92 * @param {!Element} option
93 */
94 _select: function(option)
95 {
96 this._selectElement.selectedIndex = Array.prototype.indexOf.call(/** @ty pe {?} */ (this._selectElement), option);
97 }
98
99 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698