2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
33 * @extends {WebInspector.VBox}
34 * @param {!WebInspector.ProfilesPanel} profilesPanel
36 WebInspector.ProfileLauncherView = function(profilesPanel)
38 WebInspector.VBox.call(this);
40 this._panel = profilesPanel;
42 this.element.classList.add("profile-launcher-view");
43 this.element.classList.add("panel-enabler-view");
45 this._contentElement = this.element.createChild("div", "profile-launcher-view-content");
46 this._innerContentElement = this._contentElement.createChild("div");
48 this._controlButton = this._contentElement.createChild("button", "control-profiling");
49 this._controlButton.addEventListener("click", this._controlButtonClicked.bind(this), false);
51 this._loadButton = this._contentElement.createChild("button", "load-profile");
52 this._loadButton.textContent = WebInspector.UIString("Load");
53 this._loadButton.addEventListener("click", this._loadButtonClicked.bind(this), false);
56 WebInspector.ProfileLauncherView.prototype = {
58 * @param {!WebInspector.ProfileType} profileType
60 addProfileType: function(profileType)
62 var descriptionElement = this._innerContentElement.createChild("h1");
63 descriptionElement.textContent = profileType.description;
64 var decorationElement = profileType.decorationElement();
65 if (decorationElement)
66 this._innerContentElement.appendChild(decorationElement);
67 this._isInstantProfile = profileType.isInstantProfile();
68 this._isEnabled = profileType.isEnabled();
69 this._profileTypeId = profileType.id;
72 _controlButtonClicked: function()
74 this._panel.toggleRecordButton();
77 _loadButtonClicked: function()
79 this._panel.showLoadFromFileDialog();
82 _updateControls: function()
85 this._controlButton.removeAttribute("disabled");
87 this._controlButton.setAttribute("disabled", "");
88 if (this._isInstantProfile) {
89 this._controlButton.classList.remove("running");
90 this._controlButton.textContent = WebInspector.UIString("Take Snapshot");
91 } else if (this._isProfiling) {
92 this._controlButton.classList.add("running");
93 this._controlButton.textContent = WebInspector.UIString("Stop");
95 this._controlButton.classList.remove("running");
96 this._controlButton.textContent = WebInspector.UIString("Start");
100 profileStarted: function()
102 this._isProfiling = true;
103 this._updateControls();
106 profileFinished: function()
108 this._isProfiling = false;
109 this._updateControls();
113 * @param {!WebInspector.ProfileType} profileType
115 updateProfileType: function(profileType)
117 this._isInstantProfile = profileType.isInstantProfile();
118 this._isEnabled = profileType.isEnabled();
119 this._profileTypeId = profileType.id;
120 this._updateControls();
123 __proto__: WebInspector.VBox.prototype
129 * @extends {WebInspector.ProfileLauncherView}
130 * @param {!WebInspector.ProfilesPanel} profilesPanel
132 WebInspector.MultiProfileLauncherView = function(profilesPanel)
134 WebInspector.ProfileLauncherView.call(this, profilesPanel);
136 WebInspector.settings.selectedProfileType = WebInspector.settings.createSetting("selectedProfileType", "CPU");
138 var header = this._innerContentElement.createChild("h1");
139 header.textContent = WebInspector.UIString("Select profiling type");
141 this._profileTypeSelectorForm = this._innerContentElement.createChild("form");
143 this._innerContentElement.createChild("div", "flexible-space");
145 this._typeIdToOptionElement = {};
148 WebInspector.MultiProfileLauncherView.EventTypes = {
149 ProfileTypeSelected: "profile-type-selected"
152 WebInspector.MultiProfileLauncherView.prototype = {
155 * @param {!WebInspector.ProfileType} profileType
157 addProfileType: function(profileType)
159 var labelElement = this._profileTypeSelectorForm.createChild("label");
160 labelElement.textContent = profileType.name;
161 var optionElement = document.createElement("input");
162 labelElement.insertBefore(optionElement, labelElement.firstChild);
163 this._typeIdToOptionElement[profileType.id] = optionElement;
164 optionElement._profileType = profileType;
165 optionElement.type = "radio";
166 optionElement.name = "profile-type";
167 optionElement.style.hidden = true;
168 optionElement.addEventListener("change", this._profileTypeChanged.bind(this, profileType), false);
169 var descriptionElement = labelElement.createChild("p");
170 descriptionElement.textContent = profileType.description;
171 var decorationElement = profileType.decorationElement();
172 if (decorationElement)
173 labelElement.appendChild(decorationElement);
176 restoreSelectedProfileType: function()
178 var typeId = WebInspector.settings.selectedProfileType.get();
179 if (!(typeId in this._typeIdToOptionElement))
180 typeId = Object.keys(this._typeIdToOptionElement)[0];
181 this._typeIdToOptionElement[typeId].checked = true;
182 var type = this._typeIdToOptionElement[typeId]._profileType;
183 this.dispatchEventToListeners(WebInspector.MultiProfileLauncherView.EventTypes.ProfileTypeSelected, type);
186 _controlButtonClicked: function()
188 this._panel.toggleRecordButton();
191 _updateControls: function()
193 WebInspector.ProfileLauncherView.prototype._updateControls.call(this);
194 var items = this._profileTypeSelectorForm.elements;
195 for (var i = 0; i < items.length; ++i) {
196 if (items[i].type === "radio")
197 items[i].disabled = this._isProfiling;
202 * @param {!WebInspector.ProfileType} profileType
204 _profileTypeChanged: function(profileType, event)
206 this.dispatchEventToListeners(WebInspector.MultiProfileLauncherView.EventTypes.ProfileTypeSelected, profileType);
207 this._isInstantProfile = profileType.isInstantProfile();
208 this._isEnabled = profileType.isEnabled();
209 this._profileTypeId = profileType.id;
210 this._updateControls();
211 WebInspector.settings.selectedProfileType.set(profileType.id);
214 profileStarted: function()
216 this._isProfiling = true;
217 this._updateControls();
220 profileFinished: function()
222 this._isProfiling = false;
223 this._updateControls();
226 __proto__: WebInspector.ProfileLauncherView.prototype