ProfileLauncherView.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * Copyright (C) 2011 Google Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. *
  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
  13. * distribution.
  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.
  17. *
  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.
  29. */
  30. /**
  31. * @constructor
  32. * @extends {WebInspector.View}
  33. * @param {!WebInspector.ProfilesPanel} profilesPanel
  34. */
  35. WebInspector.ProfileLauncherView = function(profilesPanel)
  36. {
  37. WebInspector.View.call(this);
  38. this._panel = profilesPanel;
  39. this.element.addStyleClass("profile-launcher-view");
  40. this.element.addStyleClass("panel-enabler-view");
  41. this._contentElement = this.element.createChild("div", "profile-launcher-view-content");
  42. this._innerContentElement = this._contentElement.createChild("div");
  43. this._controlButton = this._contentElement.createChild("button", "control-profiling");
  44. this._controlButton.addEventListener("click", this._controlButtonClicked.bind(this), false);
  45. }
  46. WebInspector.ProfileLauncherView.prototype = {
  47. /**
  48. * @param {WebInspector.ProfileType} profileType
  49. */
  50. addProfileType: function(profileType)
  51. {
  52. var descriptionElement = this._innerContentElement.createChild("h1");
  53. descriptionElement.textContent = profileType.description;
  54. var decorationElement = profileType.decorationElement();
  55. if (decorationElement)
  56. this._innerContentElement.appendChild(decorationElement);
  57. this._isInstantProfile = profileType.isInstantProfile();
  58. this._isEnabled = profileType.isEnabled();
  59. },
  60. _controlButtonClicked: function()
  61. {
  62. this._panel.toggleRecordButton();
  63. },
  64. _updateControls: function()
  65. {
  66. if (this._isEnabled)
  67. this._controlButton.removeAttribute("disabled");
  68. else
  69. this._controlButton.setAttribute("disabled", "");
  70. if (this._isInstantProfile) {
  71. this._controlButton.removeStyleClass("running");
  72. this._controlButton.textContent = WebInspector.UIString("Take Snapshot");
  73. } else if (this._isProfiling) {
  74. this._controlButton.addStyleClass("running");
  75. this._controlButton.textContent = WebInspector.UIString("Stop");
  76. } else {
  77. this._controlButton.removeStyleClass("running");
  78. this._controlButton.textContent = WebInspector.UIString("Start");
  79. }
  80. },
  81. profileStarted: function()
  82. {
  83. this._isProfiling = true;
  84. this._updateControls();
  85. },
  86. profileFinished: function()
  87. {
  88. this._isProfiling = false;
  89. this._updateControls();
  90. },
  91. /**
  92. * @param {WebInspector.ProfileType} profileType
  93. */
  94. updateProfileType: function(profileType)
  95. {
  96. this._isInstantProfile = profileType.isInstantProfile();
  97. this._isEnabled = profileType.isEnabled();
  98. this._updateControls();
  99. },
  100. __proto__: WebInspector.View.prototype
  101. }
  102. /**
  103. * @constructor
  104. * @extends {WebInspector.ProfileLauncherView}
  105. * @param {!WebInspector.ProfilesPanel} profilesPanel
  106. */
  107. WebInspector.MultiProfileLauncherView = function(profilesPanel)
  108. {
  109. WebInspector.ProfileLauncherView.call(this, profilesPanel);
  110. var header = this._innerContentElement.createChild("h1");
  111. header.textContent = WebInspector.UIString("Select profiling type");
  112. this._profileTypeSelectorForm = this._innerContentElement.createChild("form");
  113. this._innerContentElement.createChild("div", "flexible-space");
  114. }
  115. WebInspector.MultiProfileLauncherView.EventTypes = {
  116. ProfileTypeSelected: "profile-type-selected"
  117. }
  118. WebInspector.MultiProfileLauncherView.prototype = {
  119. /**
  120. * @override
  121. * @param {WebInspector.ProfileType} profileType
  122. */
  123. addProfileType: function(profileType)
  124. {
  125. var checked = !this._profileTypeSelectorForm.children.length;
  126. var labelElement = this._profileTypeSelectorForm.createChild("label");
  127. labelElement.textContent = profileType.name;
  128. var optionElement = document.createElement("input");
  129. labelElement.insertBefore(optionElement, labelElement.firstChild);
  130. optionElement.type = "radio";
  131. optionElement.name = "profile-type";
  132. optionElement.style.hidden = true;
  133. if (checked) {
  134. optionElement.checked = checked;
  135. this.dispatchEventToListeners(WebInspector.MultiProfileLauncherView.EventTypes.ProfileTypeSelected, profileType);
  136. }
  137. optionElement.addEventListener("change", this._profileTypeChanged.bind(this, profileType), false);
  138. var descriptionElement = labelElement.createChild("p");
  139. descriptionElement.textContent = profileType.description;
  140. var decorationElement = profileType.decorationElement();
  141. if (decorationElement)
  142. labelElement.appendChild(decorationElement);
  143. },
  144. _controlButtonClicked: function()
  145. {
  146. this._panel.toggleRecordButton();
  147. },
  148. _updateControls: function()
  149. {
  150. WebInspector.ProfileLauncherView.prototype._updateControls.call(this);
  151. var items = this._profileTypeSelectorForm.elements;
  152. for (var i = 0; i < items.length; ++i) {
  153. if (items[i].type === "radio")
  154. items[i].disabled = this._isProfiling;
  155. }
  156. },
  157. /**
  158. * @param {WebInspector.ProfileType} profileType
  159. */
  160. _profileTypeChanged: function(profileType, event)
  161. {
  162. this.dispatchEventToListeners(WebInspector.MultiProfileLauncherView.EventTypes.ProfileTypeSelected, profileType);
  163. this._isInstantProfile = profileType.isInstantProfile();
  164. this._isEnabled = profileType.isEnabled();
  165. this._updateControls();
  166. },
  167. profileStarted: function()
  168. {
  169. this._isProfiling = true;
  170. this._updateControls();
  171. },
  172. profileFinished: function()
  173. {
  174. this._isProfiling = false;
  175. this._updateControls();
  176. },
  177. __proto__: WebInspector.ProfileLauncherView.prototype
  178. }