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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/profiler/ProfileLauncherView.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 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer 11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 12 * in the documentation and/or other materials provided with the
13 * distribution. 13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its 14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from 15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission. 16 * this software without specific prior written permission.
17 * 17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30
31 /** 30 /**
32 * @constructor
33 * @extends {WebInspector.VBox}
34 * @implements {WebInspector.TargetManager.Observer} 31 * @implements {WebInspector.TargetManager.Observer}
35 * @param {!WebInspector.ProfilesPanel} profilesPanel 32 * @unrestricted
36 */ 33 */
37 WebInspector.ProfileLauncherView = function(profilesPanel) 34 WebInspector.ProfileLauncherView = class extends WebInspector.VBox {
38 { 35 /**
39 WebInspector.VBox.call(this); 36 * @param {!WebInspector.ProfilesPanel} profilesPanel
37 */
38 constructor(profilesPanel) {
39 super();
40 40
41 this._panel = profilesPanel; 41 this._panel = profilesPanel;
42 42
43 this.element.classList.add("profile-launcher-view"); 43 this.element.classList.add('profile-launcher-view');
44 this.element.classList.add("panel-enabler-view"); 44 this.element.classList.add('panel-enabler-view');
45 45
46 this._contentElement = this.element.createChild("div", "profile-launcher-vie w-content"); 46 this._contentElement = this.element.createChild('div', 'profile-launcher-vie w-content');
47 this._innerContentElement = this._contentElement.createChild("div"); 47 this._innerContentElement = this._contentElement.createChild('div');
48 var targetSpan = this._contentElement.createChild("span"); 48 var targetSpan = this._contentElement.createChild('span');
49 var selectTargetText = targetSpan.createChild("span"); 49 var selectTargetText = targetSpan.createChild('span');
50 selectTargetText.textContent = WebInspector.UIString("Target:"); 50 selectTargetText.textContent = WebInspector.UIString('Target:');
51 var targetsSelect = targetSpan.createChild("select", "chrome-select"); 51 var targetsSelect = targetSpan.createChild('select', 'chrome-select');
52 new WebInspector.TargetsComboBoxController(targetsSelect, targetSpan); 52 new WebInspector.TargetsComboBoxController(targetsSelect, targetSpan);
53 this._controlButton = createTextButton("", this._controlButtonClicked.bind(t his), "control-profiling"); 53 this._controlButton = createTextButton('', this._controlButtonClicked.bind(t his), 'control-profiling');
54 this._contentElement.appendChild(this._controlButton); 54 this._contentElement.appendChild(this._controlButton);
55 this._recordButtonEnabled = true; 55 this._recordButtonEnabled = true;
56 this._loadButton = createTextButton(WebInspector.UIString("Load"), this._loa dButtonClicked.bind(this), "load-profile"); 56 this._loadButton =
57 createTextButton(WebInspector.UIString('Load'), this._loadButtonClicked. bind(this), 'load-profile');
57 this._contentElement.appendChild(this._loadButton); 58 this._contentElement.appendChild(this._loadButton);
58 WebInspector.targetManager.observeTargets(this); 59 WebInspector.targetManager.observeTargets(this);
60 }
61
62 /**
63 * @return {?WebInspector.SearchableView}
64 */
65 searchableView() {
66 return null;
67 }
68
69 /**
70 * @override
71 * @param {!WebInspector.Target} target
72 */
73 targetAdded(target) {
74 this._updateLoadButtonLayout();
75 }
76
77 /**
78 * @override
79 * @param {!WebInspector.Target} target
80 */
81 targetRemoved(target) {
82 this._updateLoadButtonLayout();
83 }
84
85 _updateLoadButtonLayout() {
86 this._loadButton.classList.toggle(
87 'multi-target', WebInspector.targetManager.targets(WebInspector.Target.C apability.JS).length > 1);
88 }
89
90 /**
91 * @param {!WebInspector.ProfileType} profileType
92 */
93 addProfileType(profileType) {
94 var descriptionElement = this._innerContentElement.createChild('h1');
95 descriptionElement.textContent = profileType.description;
96 var decorationElement = profileType.decorationElement();
97 if (decorationElement)
98 this._innerContentElement.appendChild(decorationElement);
99 this._isInstantProfile = profileType.isInstantProfile();
100 this._isEnabled = profileType.isEnabled();
101 }
102
103 _controlButtonClicked() {
104 this._panel.toggleRecord();
105 }
106
107 _loadButtonClicked() {
108 this._panel.showLoadFromFileDialog();
109 }
110
111 _updateControls() {
112 if (this._isEnabled && this._recordButtonEnabled)
113 this._controlButton.removeAttribute('disabled');
114 else
115 this._controlButton.setAttribute('disabled', '');
116 this._controlButton.title = this._recordButtonEnabled ? '' : WebInspector.an otherProfilerActiveLabel();
117 if (this._isInstantProfile) {
118 this._controlButton.classList.remove('running');
119 this._controlButton.textContent = WebInspector.UIString('Take Snapshot');
120 } else if (this._isProfiling) {
121 this._controlButton.classList.add('running');
122 this._controlButton.textContent = WebInspector.UIString('Stop');
123 } else {
124 this._controlButton.classList.remove('running');
125 this._controlButton.textContent = WebInspector.UIString('Start');
126 }
127 }
128
129 profileStarted() {
130 this._isProfiling = true;
131 this._updateControls();
132 }
133
134 profileFinished() {
135 this._isProfiling = false;
136 this._updateControls();
137 }
138
139 /**
140 * @param {!WebInspector.ProfileType} profileType
141 * @param {boolean} recordButtonEnabled
142 */
143 updateProfileType(profileType, recordButtonEnabled) {
144 this._isInstantProfile = profileType.isInstantProfile();
145 this._recordButtonEnabled = recordButtonEnabled;
146 this._isEnabled = profileType.isEnabled();
147 this._updateControls();
148 }
59 }; 149 };
60 150
61 WebInspector.ProfileLauncherView.prototype = {
62 /**
63 * @return {?WebInspector.SearchableView}
64 */
65 searchableView: function()
66 {
67 return null;
68 },
69
70 /**
71 * @override
72 * @param {!WebInspector.Target} target
73 */
74 targetAdded: function(target)
75 {
76 this._updateLoadButtonLayout();
77 },
78
79 /**
80 * @override
81 * @param {!WebInspector.Target} target
82 */
83 targetRemoved: function(target)
84 {
85 this._updateLoadButtonLayout();
86 },
87
88 _updateLoadButtonLayout: function()
89 {
90 this._loadButton.classList.toggle("multi-target", WebInspector.targetMan ager.targets(WebInspector.Target.Capability.JS).length > 1);
91 },
92
93 /**
94 * @param {!WebInspector.ProfileType} profileType
95 */
96 addProfileType: function(profileType)
97 {
98 var descriptionElement = this._innerContentElement.createChild("h1");
99 descriptionElement.textContent = profileType.description;
100 var decorationElement = profileType.decorationElement();
101 if (decorationElement)
102 this._innerContentElement.appendChild(decorationElement);
103 this._isInstantProfile = profileType.isInstantProfile();
104 this._isEnabled = profileType.isEnabled();
105 },
106
107 _controlButtonClicked: function()
108 {
109 this._panel.toggleRecord();
110 },
111
112 _loadButtonClicked: function()
113 {
114 this._panel.showLoadFromFileDialog();
115 },
116
117 _updateControls: function()
118 {
119 if (this._isEnabled && this._recordButtonEnabled)
120 this._controlButton.removeAttribute("disabled");
121 else
122 this._controlButton.setAttribute("disabled", "");
123 this._controlButton.title = this._recordButtonEnabled ? "" : WebInspecto r.anotherProfilerActiveLabel();
124 if (this._isInstantProfile) {
125 this._controlButton.classList.remove("running");
126 this._controlButton.textContent = WebInspector.UIString("Take Snapsh ot");
127 } else if (this._isProfiling) {
128 this._controlButton.classList.add("running");
129 this._controlButton.textContent = WebInspector.UIString("Stop");
130 } else {
131 this._controlButton.classList.remove("running");
132 this._controlButton.textContent = WebInspector.UIString("Start");
133 }
134 },
135
136 profileStarted: function()
137 {
138 this._isProfiling = true;
139 this._updateControls();
140 },
141
142 profileFinished: function()
143 {
144 this._isProfiling = false;
145 this._updateControls();
146 },
147
148 /**
149 * @param {!WebInspector.ProfileType} profileType
150 * @param {boolean} recordButtonEnabled
151 */
152 updateProfileType: function(profileType, recordButtonEnabled)
153 {
154 this._isInstantProfile = profileType.isInstantProfile();
155 this._recordButtonEnabled = recordButtonEnabled;
156 this._isEnabled = profileType.isEnabled();
157 this._updateControls();
158 },
159
160 __proto__: WebInspector.VBox.prototype
161 };
162
163
164 /** 151 /**
165 * @constructor 152 * @unrestricted
166 * @extends {WebInspector.ProfileLauncherView}
167 * @param {!WebInspector.ProfilesPanel} profilesPanel
168 */ 153 */
169 WebInspector.MultiProfileLauncherView = function(profilesPanel) 154 WebInspector.MultiProfileLauncherView = class extends WebInspector.ProfileLaunch erView {
170 { 155 /**
171 WebInspector.ProfileLauncherView.call(this, profilesPanel); 156 * @param {!WebInspector.ProfilesPanel} profilesPanel
172 157 */
173 this._selectedProfileTypeSetting = WebInspector.settings.createSetting("sele ctedProfileType", "CPU"); 158 constructor(profilesPanel) {
174 159 super(profilesPanel);
175 var header = this._innerContentElement.createChild("h1"); 160
176 header.textContent = WebInspector.UIString("Select profiling type"); 161 this._selectedProfileTypeSetting = WebInspector.settings.createSetting('sele ctedProfileType', 'CPU');
177 162
178 this._profileTypeSelectorForm = this._innerContentElement.createChild("form" ); 163 var header = this._innerContentElement.createChild('h1');
179 164 header.textContent = WebInspector.UIString('Select profiling type');
180 this._innerContentElement.createChild("div", "flexible-space"); 165
166 this._profileTypeSelectorForm = this._innerContentElement.createChild('form' );
167
168 this._innerContentElement.createChild('div', 'flexible-space');
181 169
182 this._typeIdToOptionElement = {}; 170 this._typeIdToOptionElement = {};
171 }
172
173 /**
174 * @override
175 * @param {!WebInspector.ProfileType} profileType
176 */
177 addProfileType(profileType) {
178 var labelElement = createRadioLabel('profile-type', profileType.name);
179 this._profileTypeSelectorForm.appendChild(labelElement);
180 var optionElement = labelElement.radioElement;
181 this._typeIdToOptionElement[profileType.id] = optionElement;
182 optionElement._profileType = profileType;
183 optionElement.style.hidden = true;
184 optionElement.addEventListener('change', this._profileTypeChanged.bind(this, profileType), false);
185 var descriptionElement = labelElement.createChild('p');
186 descriptionElement.textContent = profileType.description;
187 var decorationElement = profileType.decorationElement();
188 if (decorationElement)
189 labelElement.appendChild(decorationElement);
190 }
191
192 restoreSelectedProfileType() {
193 var typeId = this._selectedProfileTypeSetting.get();
194 if (!(typeId in this._typeIdToOptionElement))
195 typeId = Object.keys(this._typeIdToOptionElement)[0];
196 this._typeIdToOptionElement[typeId].checked = true;
197 var type = this._typeIdToOptionElement[typeId]._profileType;
198 this.dispatchEventToListeners(WebInspector.MultiProfileLauncherView.Events.P rofileTypeSelected, type);
199 }
200
201 /**
202 * @override
203 */
204 _controlButtonClicked() {
205 this._panel.toggleRecord();
206 }
207
208 /**
209 * @override
210 */
211 _updateControls() {
212 super._updateControls();
213 var items = this._profileTypeSelectorForm.elements;
214 for (var i = 0; i < items.length; ++i) {
215 if (items[i].type === 'radio')
216 items[i].disabled = this._isProfiling;
217 }
218 }
219
220 /**
221 * @param {!WebInspector.ProfileType} profileType
222 */
223 _profileTypeChanged(profileType) {
224 this.dispatchEventToListeners(WebInspector.MultiProfileLauncherView.Events.P rofileTypeSelected, profileType);
225 this._isInstantProfile = profileType.isInstantProfile();
226 this._isEnabled = profileType.isEnabled();
227 this._updateControls();
228 this._selectedProfileTypeSetting.set(profileType.id);
229 }
230
231 /**
232 * @override
233 */
234 profileStarted() {
235 this._isProfiling = true;
236 this._updateControls();
237 }
238
239 /**
240 * @override
241 */
242 profileFinished() {
243 this._isProfiling = false;
244 this._updateControls();
245 }
183 }; 246 };
184 247
185 /** @enum {symbol} */ 248 /** @enum {symbol} */
186 WebInspector.MultiProfileLauncherView.Events = { 249 WebInspector.MultiProfileLauncherView.Events = {
187 ProfileTypeSelected: Symbol("ProfileTypeSelected") 250 ProfileTypeSelected: Symbol('ProfileTypeSelected')
188 }; 251 };
189
190 WebInspector.MultiProfileLauncherView.prototype = {
191 /**
192 * @override
193 * @param {!WebInspector.ProfileType} profileType
194 */
195 addProfileType: function(profileType)
196 {
197 var labelElement = createRadioLabel("profile-type", profileType.name);
198 this._profileTypeSelectorForm.appendChild(labelElement);
199 var optionElement = labelElement.radioElement;
200 this._typeIdToOptionElement[profileType.id] = optionElement;
201 optionElement._profileType = profileType;
202 optionElement.style.hidden = true;
203 optionElement.addEventListener("change", this._profileTypeChanged.bind(t his, profileType), false);
204 var descriptionElement = labelElement.createChild("p");
205 descriptionElement.textContent = profileType.description;
206 var decorationElement = profileType.decorationElement();
207 if (decorationElement)
208 labelElement.appendChild(decorationElement);
209 },
210
211 restoreSelectedProfileType: function()
212 {
213 var typeId = this._selectedProfileTypeSetting.get();
214 if (!(typeId in this._typeIdToOptionElement))
215 typeId = Object.keys(this._typeIdToOptionElement)[0];
216 this._typeIdToOptionElement[typeId].checked = true;
217 var type = this._typeIdToOptionElement[typeId]._profileType;
218 this.dispatchEventToListeners(WebInspector.MultiProfileLauncherView.Even ts.ProfileTypeSelected, type);
219 },
220
221 _controlButtonClicked: function()
222 {
223 this._panel.toggleRecord();
224 },
225
226 _updateControls: function()
227 {
228 WebInspector.ProfileLauncherView.prototype._updateControls.call(this);
229 var items = this._profileTypeSelectorForm.elements;
230 for (var i = 0; i < items.length; ++i) {
231 if (items[i].type === "radio")
232 items[i].disabled = this._isProfiling;
233 }
234 },
235
236 /**
237 * @param {!WebInspector.ProfileType} profileType
238 */
239 _profileTypeChanged: function(profileType)
240 {
241 this.dispatchEventToListeners(WebInspector.MultiProfileLauncherView.Even ts.ProfileTypeSelected, profileType);
242 this._isInstantProfile = profileType.isInstantProfile();
243 this._isEnabled = profileType.isEnabled();
244 this._updateControls();
245 this._selectedProfileTypeSetting.set(profileType.id);
246 },
247
248 profileStarted: function()
249 {
250 this._isProfiling = true;
251 this._updateControls();
252 },
253
254 profileFinished: function()
255 {
256 this._isProfiling = false;
257 this._updateControls();
258 },
259
260 __proto__: WebInspector.ProfileLauncherView.prototype
261 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698