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

Side by Side Diff: Source/devtools/front_end/sources/TargetsToolbar.js

Issue 338283004: DevTools: Use TargetsToolbar instead of ThreadToolbar (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address vsevik's comments Created 6 years, 6 months 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 | Annotate | Revision Log
OLDNEW
(Empty)
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 * @implements {WebInspector.TargetManager.Observer}
8 */
9 WebInspector.TargetsToolbar = function()
10 {
11 this.element = document.createElement("div");
12 this.element.className = "status-bar scripts-debug-toolbar targets-toolbar h idden";
13 this._comboBox = new WebInspector.StatusBarComboBox(this._onComboBoxSelectio nChange.bind(this));
14 this.element.appendChild(this._comboBox.element);
15
16 /** @type {!Map.<!WebInspector.Target, !Element>} */
17 this._targetToOption = new Map();
18 if (!WebInspector.experimentsSettings.workersInMainWindow.isEnabled())
19 return;
20
21 WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._targ etChangedExternally, this);
22 WebInspector.targetManager.observeTargets(this);
23 }
24
25 WebInspector.TargetsToolbar.prototype = {
26
27 /**
28 * @param {!WebInspector.Target} target
29 */
30 targetAdded: function(target)
31 {
32 var option = this._comboBox.createOption(target.name());
33 option.__target = target;
34 this._targetToOption.put(target, option);
35 if (WebInspector.context.flavor(WebInspector.Target) === target)
36 this._comboBox.select(option);
37
38 this._alterVisibility();
39 },
40
41 /**
42 * @param {!WebInspector.Target} target
43 */
44 targetRemoved: function(target)
45 {
46 var option = this._targetToOption.remove(target);
47 this._comboBox.removeOption(option);
48 this._alterVisibility();
49 },
50
51 _onComboBoxSelectionChange: function()
52 {
53 var selectedOption = this._comboBox.selectedOption();
54 if (!selectedOption)
55 return;
56
57 WebInspector.context.setFlavor(WebInspector.Target, selectedOption.__tar get);
58 },
59
60 _alterVisibility: function()
vsevik 2014/06/19 07:52:42 _updateVisibility
sergeyv 2014/06/19 10:54:44 Done.
61 {
62 var hidden = this._comboBox.size() === 1;
63 this.element.classList.toggle("hidden", hidden);
64 },
65
66 /**
67 * @param {!WebInspector.Event} event
68 */
69 _targetChangedExternally: function(event)
vsevik 2014/06/19 07:52:42 ditto
sergeyv 2014/06/19 10:54:44 Done.
70 {
71 var target = /** @type {?WebInspector.Target} */ (event.data);
72 if (target) {
73 var option = /** @type {!Element} */ (this._targetToOption.get(targe t));
74 this._comboBox.select(option);
75 }
76 }
77
78 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698