SettingsScreen.js 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233
  1. /*
  2. * Copyright (C) 2013 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. * @param {!function()} onHide
  33. * @extends {WebInspector.HelpScreen}
  34. */
  35. WebInspector.SettingsScreen = function(onHide)
  36. {
  37. WebInspector.HelpScreen.call(this);
  38. this.element.id = "settings-screen";
  39. /** @type {function()} */
  40. this._onHide = onHide;
  41. this._tabbedPane = new WebInspector.TabbedPane();
  42. this._tabbedPane.element.addStyleClass("help-window-main");
  43. var settingsLabelElement = document.createElement("div");
  44. settingsLabelElement.className = "help-window-label";
  45. settingsLabelElement.createTextChild(WebInspector.UIString("Settings"));
  46. this._tabbedPane.element.insertBefore(settingsLabelElement, this._tabbedPane.element.firstChild);
  47. this._tabbedPane.element.appendChild(this._createCloseButton());
  48. this._tabbedPane.appendTab(WebInspector.SettingsScreen.Tabs.General, WebInspector.UIString("General"), new WebInspector.GenericSettingsTab());
  49. if (!WebInspector.experimentsSettings.showOverridesInDrawer.isEnabled())
  50. this._tabbedPane.appendTab(WebInspector.SettingsScreen.Tabs.Overrides, WebInspector.UIString("Overrides"), new WebInspector.OverridesSettingsTab());
  51. this._tabbedPane.appendTab(WebInspector.SettingsScreen.Tabs.Workspace, WebInspector.UIString("Workspace"), new WebInspector.WorkspaceSettingsTab());
  52. if (WebInspector.experimentsSettings.experimentsEnabled)
  53. this._tabbedPane.appendTab(WebInspector.SettingsScreen.Tabs.Experiments, WebInspector.UIString("Experiments"), new WebInspector.ExperimentsSettingsTab());
  54. this._tabbedPane.appendTab(WebInspector.SettingsScreen.Tabs.Shortcuts, WebInspector.UIString("Shortcuts"), WebInspector.shortcutsScreen.createShortcutsTabView());
  55. this._tabbedPane.shrinkableTabs = false;
  56. this._tabbedPane.verticalTabLayout = true;
  57. this._lastSelectedTabSetting = WebInspector.settings.createSetting("lastSelectedSettingsTab", WebInspector.SettingsScreen.Tabs.General);
  58. this.selectTab(this._lastSelectedTabSetting.get());
  59. this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSelected, this._tabSelected, this);
  60. }
  61. /**
  62. * @param {string} text
  63. * @return {?string}
  64. */
  65. WebInspector.SettingsScreen.regexValidator = function(text)
  66. {
  67. var regex;
  68. try {
  69. regex = new RegExp(text);
  70. } catch (e) {
  71. }
  72. return regex ? null : "Invalid pattern";
  73. }
  74. /**
  75. * @param {number} min
  76. * @param {number} max
  77. * @param {string} text
  78. * @return {?string}
  79. */
  80. WebInspector.SettingsScreen.integerValidator = function(min, max, text)
  81. {
  82. var value = parseInt(text, 10);
  83. if (isNaN(value))
  84. return "Invalid number format";
  85. if (value < min || value > max)
  86. return "Value is out of range [" + min + ", " + max + "]";
  87. return null;
  88. }
  89. WebInspector.SettingsScreen.Tabs = {
  90. General: "general",
  91. Overrides: "overrides",
  92. Workspace: "workspace",
  93. Experiments: "experiments",
  94. Shortcuts: "shortcuts"
  95. }
  96. WebInspector.SettingsScreen.prototype = {
  97. /**
  98. * @param {string} tabId
  99. */
  100. selectTab: function(tabId)
  101. {
  102. this._tabbedPane.selectTab(tabId);
  103. },
  104. /**
  105. * @param {WebInspector.Event} event
  106. */
  107. _tabSelected: function(event)
  108. {
  109. this._lastSelectedTabSetting.set(this._tabbedPane.selectedTabId);
  110. },
  111. /**
  112. * @override
  113. */
  114. wasShown: function()
  115. {
  116. this._tabbedPane.show(this.element);
  117. WebInspector.HelpScreen.prototype.wasShown.call(this);
  118. },
  119. /**
  120. * @override
  121. */
  122. isClosingKey: function(keyCode)
  123. {
  124. return [
  125. WebInspector.KeyboardShortcut.Keys.Enter.code,
  126. WebInspector.KeyboardShortcut.Keys.Esc.code,
  127. ].indexOf(keyCode) >= 0;
  128. },
  129. /**
  130. * @override
  131. */
  132. willHide: function()
  133. {
  134. this._onHide();
  135. WebInspector.HelpScreen.prototype.willHide.call(this);
  136. },
  137. __proto__: WebInspector.HelpScreen.prototype
  138. }
  139. /**
  140. * @constructor
  141. * @extends {WebInspector.View}
  142. * @param {string} name
  143. * @param {string=} id
  144. */
  145. WebInspector.SettingsTab = function(name, id)
  146. {
  147. WebInspector.View.call(this);
  148. this.element.className = "settings-tab-container";
  149. if (id)
  150. this.element.id = id;
  151. var header = this.element.createChild("header");
  152. header.createChild("h3").appendChild(document.createTextNode(name));
  153. this.containerElement = this.element.createChild("div", "help-container-wrapper").createChild("div", "settings-tab help-content help-container");
  154. }
  155. /**
  156. * @param {string} name
  157. * @param {function(): *} getter
  158. * @param {function(*)} setter
  159. * @param {boolean=} omitParagraphElement
  160. * @param {Element=} inputElement
  161. * @param {string=} tooltip
  162. * @return {Element}
  163. */
  164. WebInspector.SettingsTab.createCheckbox = function(name, getter, setter, omitParagraphElement, inputElement, tooltip)
  165. {
  166. var input = inputElement || document.createElement("input");
  167. input.type = "checkbox";
  168. input.name = name;
  169. input.checked = getter();
  170. function listener()
  171. {
  172. setter(input.checked);
  173. }
  174. input.addEventListener("click", listener, false);
  175. var label = document.createElement("label");
  176. label.appendChild(input);
  177. label.appendChild(document.createTextNode(name));
  178. if (tooltip)
  179. label.title = tooltip;
  180. if (omitParagraphElement)
  181. return label;
  182. var p = document.createElement("p");
  183. p.appendChild(label);
  184. return p;
  185. }
  186. /**
  187. * @param {string} name
  188. * @param {WebInspector.Setting} setting
  189. * @param {boolean=} omitParagraphElement
  190. * @param {Element=} inputElement
  191. * @param {string=} tooltip
  192. * @return {Element}
  193. */
  194. WebInspector.SettingsTab.createSettingCheckbox = function(name, setting, omitParagraphElement, inputElement, tooltip)
  195. {
  196. return WebInspector.SettingsTab.createCheckbox(name, setting.get.bind(setting), setting.set.bind(setting), omitParagraphElement, inputElement, tooltip);
  197. }
  198. /**
  199. * @param {WebInspector.Setting} setting
  200. * @return {Element}
  201. */
  202. WebInspector.SettingsTab.createSettingFieldset = function(setting)
  203. {
  204. var fieldset = document.createElement("fieldset");
  205. fieldset.disabled = !setting.get();
  206. setting.addChangeListener(settingChanged);
  207. return fieldset;
  208. function settingChanged()
  209. {
  210. fieldset.disabled = !setting.get();
  211. }
  212. }
  213. WebInspector.SettingsTab.prototype = {
  214. /**
  215. * @param {string=} name
  216. * @return {!Element}
  217. */
  218. _appendSection: function(name)
  219. {
  220. var block = this.containerElement.createChild("div", "help-block");
  221. if (name)
  222. block.createChild("div", "help-section-title").textContent = name;
  223. return block;
  224. },
  225. _createSelectSetting: function(name, options, setting)
  226. {
  227. var p = document.createElement("p");
  228. var labelElement = p.createChild("label");
  229. labelElement.textContent = name;
  230. var select = p.createChild("select");
  231. var settingValue = setting.get();
  232. for (var i = 0; i < options.length; ++i) {
  233. var option = options[i];
  234. select.add(new Option(option[0], option[1]));
  235. if (settingValue === option[1])
  236. select.selectedIndex = i;
  237. }
  238. function changeListener(e)
  239. {
  240. setting.set(e.target.value);
  241. }
  242. select.addEventListener("change", changeListener, false);
  243. return p;
  244. },
  245. /**
  246. * @param {string} label
  247. * @param {WebInspector.Setting} setting
  248. * @param {boolean} numeric
  249. * @param {number=} maxLength
  250. * @param {string=} width
  251. * @param {function(string):?string=} validatorCallback
  252. */
  253. _createInputSetting: function(label, setting, numeric, maxLength, width, validatorCallback)
  254. {
  255. var p = document.createElement("p");
  256. var labelElement = p.createChild("label");
  257. labelElement.textContent = label;
  258. var inputElement = p.createChild("input");
  259. inputElement.value = setting.get();
  260. inputElement.type = "text";
  261. if (numeric)
  262. inputElement.className = "numeric";
  263. if (maxLength)
  264. inputElement.maxLength = maxLength;
  265. if (width)
  266. inputElement.style.width = width;
  267. if (validatorCallback) {
  268. var errorMessageLabel = p.createChild("div");
  269. errorMessageLabel.addStyleClass("field-error-message");
  270. errorMessageLabel.style.color = "DarkRed";
  271. inputElement.oninput = function()
  272. {
  273. var error = validatorCallback(inputElement.value);
  274. if (!error)
  275. error = "";
  276. errorMessageLabel.textContent = error;
  277. };
  278. }
  279. function onBlur()
  280. {
  281. setting.set(numeric ? Number(inputElement.value) : inputElement.value);
  282. }
  283. inputElement.addEventListener("blur", onBlur, false);
  284. return p;
  285. },
  286. _createCustomSetting: function(name, element)
  287. {
  288. var p = document.createElement("p");
  289. var fieldsetElement = document.createElement("fieldset");
  290. fieldsetElement.createChild("label").textContent = name;
  291. fieldsetElement.appendChild(element);
  292. p.appendChild(fieldsetElement);
  293. return p;
  294. },
  295. __proto__: WebInspector.View.prototype
  296. }
  297. /**
  298. * @constructor
  299. * @extends {WebInspector.SettingsTab}
  300. */
  301. WebInspector.GenericSettingsTab = function()
  302. {
  303. WebInspector.SettingsTab.call(this, WebInspector.UIString("General"), "general-tab-content");
  304. var p = this._appendSection();
  305. p.appendChild(WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Disable cache (while DevTools is open)"), WebInspector.settings.cacheDisabled));
  306. var disableJSElement = WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Disable JavaScript"), WebInspector.settings.javaScriptDisabled);
  307. p.appendChild(disableJSElement);
  308. WebInspector.settings.javaScriptDisabled.addChangeListener(this._javaScriptDisabledChanged, this);
  309. this._disableJSCheckbox = disableJSElement.getElementsByTagName("input")[0];
  310. this._updateScriptDisabledCheckbox();
  311. p = this._appendSection(WebInspector.UIString("Appearance"));
  312. p.appendChild(WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Split panels vertically when docked to right"), WebInspector.settings.splitVerticallyWhenDockedToRight));
  313. p = this._appendSection(WebInspector.UIString("Elements"));
  314. var colorFormatElement = this._createSelectSetting(WebInspector.UIString("Color format"), [
  315. [ WebInspector.UIString("As authored"), WebInspector.Color.Format.Original ],
  316. [ "HEX: #DAC0DE", WebInspector.Color.Format.HEX ],
  317. [ "RGB: rgb(128, 255, 255)", WebInspector.Color.Format.RGB ],
  318. [ "HSL: hsl(300, 80%, 90%)", WebInspector.Color.Format.HSL ]
  319. ], WebInspector.settings.colorFormat);
  320. p.appendChild(colorFormatElement);
  321. p.appendChild(WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Show user agent styles"), WebInspector.settings.showUserAgentStyles));
  322. p.appendChild(WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Word wrap"), WebInspector.settings.domWordWrap));
  323. p.appendChild(WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Show Shadow DOM"), WebInspector.settings.showShadowDOM));
  324. p.appendChild(WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Show rulers"), WebInspector.settings.showMetricsRulers));
  325. p = this._appendSection(WebInspector.UIString("Rendering"));
  326. p.appendChild(WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Show paint rectangles"), WebInspector.settings.showPaintRects));
  327. this._forceCompositingModeCheckbox = document.createElement("input");
  328. var checkbox = WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Force accelerated compositing"), WebInspector.settings.forceCompositingMode, false, this._forceCompositingModeCheckbox);
  329. p.appendChild(checkbox);
  330. WebInspector.settings.forceCompositingMode.addChangeListener(this._forceCompositingModeChanged, this);
  331. var fieldset = WebInspector.SettingsTab.createSettingFieldset(WebInspector.settings.forceCompositingMode);
  332. this._showCompositedLayersBordersCheckbox = document.createElement("input");
  333. fieldset.appendChild(WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Show composited layer borders"), WebInspector.settings.showDebugBorders, false, this._showCompositedLayersBordersCheckbox));
  334. this._showFPSCheckbox = document.createElement("input");
  335. fieldset.appendChild(WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Show FPS meter"), WebInspector.settings.showFPSCounter, false, this._showFPSCheckbox));
  336. this._continousPaintingCheckbox = document.createElement("input");
  337. fieldset.appendChild(WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Enable continuous page repainting"), WebInspector.settings.continuousPainting, false, this._continousPaintingCheckbox));
  338. this._showScrollBottleneckRectsCheckbox = document.createElement("input");
  339. var tooltip = WebInspector.UIString("Shows areas of the page that slow down scrolling:\nTouch and mousewheel event listeners can delay scrolling.\nSome areas need to repaint their content when scrolled.");
  340. fieldset.appendChild(WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Show potential scroll bottlenecks"), WebInspector.settings.showScrollBottleneckRects, false, this._showScrollBottleneckRectsCheckbox, tooltip));
  341. checkbox.appendChild(fieldset);
  342. this._forceCompositingModeChanged();
  343. p = this._appendSection(WebInspector.UIString("Sources"));
  344. p.appendChild(WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Search in content scripts"), WebInspector.settings.searchInContentScripts));
  345. p.appendChild(WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Enable JS source maps"), WebInspector.settings.jsSourceMapsEnabled));
  346. checkbox = WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Enable CSS source maps"), WebInspector.settings.cssSourceMapsEnabled);
  347. p.appendChild(checkbox);
  348. fieldset = WebInspector.SettingsTab.createSettingFieldset(WebInspector.settings.cssSourceMapsEnabled);
  349. var autoReloadCSSCheckbox = fieldset.createChild("input");
  350. fieldset.appendChild(WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Auto-reload generated CSS"), WebInspector.settings.cssReloadEnabled, false, autoReloadCSSCheckbox));
  351. checkbox.appendChild(fieldset);
  352. var indentationElement = this._createSelectSetting(WebInspector.UIString("Default indentation"), [
  353. [ WebInspector.UIString("2 spaces"), WebInspector.TextUtils.Indent.TwoSpaces ],
  354. [ WebInspector.UIString("4 spaces"), WebInspector.TextUtils.Indent.FourSpaces ],
  355. [ WebInspector.UIString("8 spaces"), WebInspector.TextUtils.Indent.EightSpaces ],
  356. [ WebInspector.UIString("Tab character"), WebInspector.TextUtils.Indent.TabCharacter ]
  357. ], WebInspector.settings.textEditorIndent);
  358. p.appendChild(indentationElement);
  359. p.appendChild(WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Detect indentation"), WebInspector.settings.textEditorAutoDetectIndent));
  360. p.appendChild(WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Show whitespace characters"), WebInspector.settings.showWhitespacesInEditor));
  361. if (WebInspector.experimentsSettings.frameworksDebuggingSupport.isEnabled()) {
  362. checkbox = WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Skip stepping through sources with particular names"), WebInspector.settings.skipStackFramesSwitch);
  363. fieldset = WebInspector.SettingsTab.createSettingFieldset(WebInspector.settings.skipStackFramesSwitch);
  364. fieldset.appendChild(this._createInputSetting(WebInspector.UIString("Pattern"), WebInspector.settings.skipStackFramesPattern, false, 1000, "100px", WebInspector.SettingsScreen.regexValidator));
  365. checkbox.appendChild(fieldset);
  366. p.appendChild(checkbox);
  367. }
  368. WebInspector.settings.skipStackFramesSwitch.addChangeListener(this._skipStackFramesSwitchOrPatternChanged, this);
  369. WebInspector.settings.skipStackFramesPattern.addChangeListener(this._skipStackFramesSwitchOrPatternChanged, this);
  370. p = this._appendSection(WebInspector.UIString("Profiler"));
  371. p.appendChild(WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Show advanced heap snapshot properties"), WebInspector.settings.showAdvancedHeapSnapshotProperties));
  372. p = this._appendSection(WebInspector.UIString("Timeline"));
  373. checkbox = WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Limit number of captured JS stack frames"), WebInspector.settings.timelineLimitStackFramesFlag);
  374. p.appendChild(checkbox);
  375. fieldset = WebInspector.SettingsTab.createSettingFieldset(WebInspector.settings.timelineLimitStackFramesFlag);
  376. var frameCountValidator = WebInspector.SettingsScreen.integerValidator.bind(this, 0, 99);
  377. fieldset.appendChild(this._createInputSetting(WebInspector.UIString("Frames to capture"), WebInspector.settings.timelineStackFramesToCapture, true, 2, "2em", frameCountValidator));
  378. checkbox.appendChild(fieldset);
  379. p.appendChild(WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Show CPU activity on the ruler"), WebInspector.settings.showCpuOnTimelineRuler));
  380. p = this._appendSection(WebInspector.UIString("Console"));
  381. p.appendChild(WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Log XMLHttpRequests"), WebInspector.settings.monitoringXHREnabled));
  382. p.appendChild(WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Preserve log upon navigation"), WebInspector.settings.preserveConsoleLog));
  383. if (WebInspector.extensionServer.hasExtensions()) {
  384. var handlerSelector = new WebInspector.HandlerSelector(WebInspector.openAnchorLocationRegistry);
  385. p = this._appendSection(WebInspector.UIString("Extensions"));
  386. p.appendChild(this._createCustomSetting(WebInspector.UIString("Open links in"), handlerSelector.element));
  387. }
  388. p = this._appendSection();
  389. var panelShortcutTitle = WebInspector.UIString("Enable %s + 1-9 shortcut to switch panels", WebInspector.isMac() ? "Cmd" : "Ctrl");
  390. p.appendChild(WebInspector.SettingsTab.createSettingCheckbox(panelShortcutTitle, WebInspector.settings.shortcutPanelSwitch));
  391. }
  392. WebInspector.GenericSettingsTab.prototype = {
  393. /**
  394. * @param {WebInspector.Event=} event
  395. */
  396. _forceCompositingModeChanged: function(event)
  397. {
  398. var compositing = event ? !!event.data : WebInspector.settings.forceCompositingMode.get();
  399. if (!compositing) {
  400. this._showFPSCheckbox.checked = false;
  401. this._continousPaintingCheckbox.checked = false;
  402. this._showCompositedLayersBordersCheckbox.checked = false;
  403. this._showScrollBottleneckRectsCheckbox.checked = false;
  404. WebInspector.settings.showFPSCounter.set(false);
  405. WebInspector.settings.continuousPainting.set(false);
  406. WebInspector.settings.showDebugBorders.set(false);
  407. WebInspector.settings.showScrollBottleneckRects.set(false);
  408. }
  409. this._forceCompositingModeCheckbox.checked = compositing;
  410. },
  411. _updateScriptDisabledCheckbox: function()
  412. {
  413. function executionStatusCallback(error, status)
  414. {
  415. if (error || !status)
  416. return;
  417. switch (status) {
  418. case "forbidden":
  419. this._disableJSCheckbox.checked = true;
  420. this._disableJSCheckbox.disabled = true;
  421. break;
  422. case "disabled":
  423. this._disableJSCheckbox.checked = true;
  424. break;
  425. default:
  426. this._disableJSCheckbox.checked = false;
  427. break;
  428. }
  429. }
  430. PageAgent.getScriptExecutionStatus(executionStatusCallback.bind(this));
  431. },
  432. _javaScriptDisabledChanged: function()
  433. {
  434. // We need to manually update the checkbox state, since enabling JavaScript in the page can actually uncover the "forbidden" state.
  435. PageAgent.setScriptExecutionDisabled(WebInspector.settings.javaScriptDisabled.get(), this._updateScriptDisabledCheckbox.bind(this));
  436. },
  437. _skipStackFramesSwitchOrPatternChanged: function()
  438. {
  439. WebInspector.DebuggerModel.applySkipStackFrameSettings();
  440. },
  441. __proto__: WebInspector.SettingsTab.prototype
  442. }
  443. /**
  444. * @constructor
  445. * @extends {WebInspector.SettingsTab}
  446. */
  447. WebInspector.OverridesSettingsTab = function()
  448. {
  449. WebInspector.SettingsTab.call(this, WebInspector.UIString("Overrides"), "overrides-tab-content");
  450. this._view = new WebInspector.OverridesView();
  451. this.containerElement.parentElement.appendChild(this._view.containerElement);
  452. this.containerElement.remove();
  453. this.containerElement = this._view.containerElement;
  454. }
  455. WebInspector.OverridesSettingsTab.prototype = {
  456. __proto__: WebInspector.SettingsTab.prototype
  457. }
  458. /**
  459. * @constructor
  460. * @extends {WebInspector.SettingsTab}
  461. */
  462. WebInspector.WorkspaceSettingsTab = function()
  463. {
  464. WebInspector.SettingsTab.call(this, WebInspector.UIString("Workspace"), "workspace-tab-content");
  465. WebInspector.isolatedFileSystemManager.addEventListener(WebInspector.IsolatedFileSystemManager.Events.FileSystemAdded, this._fileSystemAdded, this);
  466. WebInspector.isolatedFileSystemManager.addEventListener(WebInspector.IsolatedFileSystemManager.Events.FileSystemRemoved, this._fileSystemRemoved, this);
  467. this._commonSection = this._appendSection(WebInspector.UIString("Common"));
  468. var folderExcludePatternInput = this._createInputSetting(WebInspector.UIString("Folder exclude pattern"), WebInspector.settings.workspaceFolderExcludePattern, false, 0, "270px", WebInspector.SettingsScreen.regexValidator);
  469. this._commonSection.appendChild(folderExcludePatternInput);
  470. this._fileSystemsSection = this._appendSection(WebInspector.UIString("Folders"));
  471. this._fileSystemsListContainer = this._fileSystemsSection.createChild("p", "settings-list-container");
  472. this._addFileSystemRowElement = this._fileSystemsSection.createChild("div");
  473. var addFileSystemButton = this._addFileSystemRowElement.createChild("input", "text-button");
  474. addFileSystemButton.type = "button";
  475. addFileSystemButton.value = WebInspector.UIString("Add folder\u2026");
  476. addFileSystemButton.addEventListener("click", this._addFileSystemClicked.bind(this));
  477. this._editFileSystemButton = this._addFileSystemRowElement.createChild("input", "text-button");
  478. this._editFileSystemButton.type = "button";
  479. this._editFileSystemButton.value = WebInspector.UIString("Edit\u2026");
  480. this._editFileSystemButton.addEventListener("click", this._editFileSystemClicked.bind(this));
  481. this._updateEditFileSystemButtonState();
  482. this._reset();
  483. }
  484. WebInspector.WorkspaceSettingsTab.prototype = {
  485. wasShown: function()
  486. {
  487. WebInspector.SettingsTab.prototype.wasShown.call(this);
  488. this._reset();
  489. },
  490. _reset: function()
  491. {
  492. this._resetFileSystems();
  493. },
  494. _resetFileSystems: function()
  495. {
  496. this._fileSystemsListContainer.removeChildren();
  497. var fileSystemPaths = WebInspector.isolatedFileSystemManager.mapping().fileSystemPaths();
  498. delete this._fileSystemsList;
  499. if (!fileSystemPaths.length) {
  500. var noFileSystemsMessageElement = this._fileSystemsListContainer.createChild("div", "no-file-systems-message");
  501. noFileSystemsMessageElement.textContent = WebInspector.UIString("You have no file systems added.");
  502. return;
  503. }
  504. this._fileSystemsList = new WebInspector.SettingsList(["path"], this._renderFileSystem.bind(this));
  505. this._fileSystemsList.element.addStyleClass("file-systems-list");
  506. this._fileSystemsList.addEventListener(WebInspector.SettingsList.Events.Selected, this._fileSystemSelected.bind(this));
  507. this._fileSystemsList.addEventListener(WebInspector.SettingsList.Events.Removed, this._fileSystemRemovedfromList.bind(this));
  508. this._fileSystemsList.addEventListener(WebInspector.SettingsList.Events.DoubleClicked, this._fileSystemDoubleClicked.bind(this));
  509. this._fileSystemsListContainer.appendChild(this._fileSystemsList.element);
  510. for (var i = 0; i < fileSystemPaths.length; ++i)
  511. this._fileSystemsList.addItem(fileSystemPaths[i]);
  512. this._updateEditFileSystemButtonState();
  513. },
  514. _updateEditFileSystemButtonState: function()
  515. {
  516. this._editFileSystemButton.disabled = !this._selectedFileSystemPath();
  517. },
  518. /**
  519. * @param {WebInspector.Event} event
  520. */
  521. _fileSystemSelected: function(event)
  522. {
  523. this._updateEditFileSystemButtonState();
  524. },
  525. /**
  526. * @param {WebInspector.Event} event
  527. */
  528. _fileSystemDoubleClicked: function(event)
  529. {
  530. var id = /** @type{?string} */ (event.data);
  531. this._editFileSystem(id);
  532. },
  533. /**
  534. * @param {WebInspector.Event=} event
  535. */
  536. _editFileSystemClicked: function(event)
  537. {
  538. this._editFileSystem(this._selectedFileSystemPath());
  539. },
  540. /**
  541. * @param {?string} id
  542. */
  543. _editFileSystem: function(id)
  544. {
  545. WebInspector.EditFileSystemDialog.show(document.body, id);
  546. },
  547. /**
  548. * @param {function(Event)} handler
  549. * @return {Element}
  550. */
  551. _createRemoveButton: function(handler)
  552. {
  553. var removeButton = document.createElement("button");
  554. removeButton.addStyleClass("button");
  555. removeButton.addStyleClass("remove-item-button");
  556. removeButton.value = WebInspector.UIString("Remove");
  557. if (handler)
  558. removeButton.addEventListener("click", handler, false);
  559. else
  560. removeButton.disabled = true;
  561. return removeButton;
  562. },
  563. /**
  564. * @param {Element} columnElement
  565. * @param {string} column
  566. * @param {?string} id
  567. */
  568. _renderFileSystem: function(columnElement, column, id)
  569. {
  570. if (!id)
  571. return "";
  572. var fileSystemPath = id;
  573. var textElement = columnElement.createChild("span", "list-column-text");
  574. var pathElement = textElement.createChild("span", "file-system-path");
  575. pathElement.title = fileSystemPath;
  576. const maxTotalPathLength = 55;
  577. const maxFolderNameLength = 30;
  578. var lastIndexOfSlash = fileSystemPath.lastIndexOf(WebInspector.isWin() ? "\\" : "/");
  579. var folderName = fileSystemPath.substr(lastIndexOfSlash + 1);
  580. var folderPath = fileSystemPath.substr(0, lastIndexOfSlash + 1);
  581. folderPath = folderPath.trimMiddle(maxTotalPathLength - Math.min(maxFolderNameLength, folderName.length));
  582. folderName = folderName.trimMiddle(maxFolderNameLength);
  583. var folderPathElement = pathElement.createChild("span");
  584. folderPathElement.textContent = folderPath;
  585. var nameElement = pathElement.createChild("span", "file-system-path-name");
  586. nameElement.textContent = folderName;
  587. },
  588. /**
  589. * @param {WebInspector.Event} event
  590. */
  591. _fileSystemRemovedfromList: function(event)
  592. {
  593. var id = /** @type{?string} */ (event.data);
  594. if (!id)
  595. return;
  596. WebInspector.isolatedFileSystemManager.removeFileSystem(id);
  597. },
  598. _addFileSystemClicked: function()
  599. {
  600. WebInspector.isolatedFileSystemManager.addFileSystem();
  601. },
  602. _fileSystemAdded: function(event)
  603. {
  604. var fileSystem = /** @type {WebInspector.IsolatedFileSystem} */ (event.data);
  605. if (!this._fileSystemsList)
  606. this._reset();
  607. else
  608. this._fileSystemsList.addItem(fileSystem.path());
  609. },
  610. _fileSystemRemoved: function(event)
  611. {
  612. var fileSystem = /** @type {WebInspector.IsolatedFileSystem} */ (event.data);
  613. var selectedFileSystemPath = this._selectedFileSystemPath();
  614. if (this._fileSystemsList.itemForId(fileSystem.path()))
  615. this._fileSystemsList.removeItem(fileSystem.path());
  616. if (!this._fileSystemsList.itemIds().length)
  617. this._reset();
  618. this._updateEditFileSystemButtonState();
  619. },
  620. _selectedFileSystemPath: function()
  621. {
  622. return this._fileSystemsList ? this._fileSystemsList.selectedId() : null;
  623. },
  624. __proto__: WebInspector.SettingsTab.prototype
  625. }
  626. /**
  627. * @constructor
  628. * @extends {WebInspector.SettingsTab}
  629. */
  630. WebInspector.ExperimentsSettingsTab = function()
  631. {
  632. WebInspector.SettingsTab.call(this, WebInspector.UIString("Experiments"), "experiments-tab-content");
  633. var experiments = WebInspector.experimentsSettings.experiments;
  634. if (experiments.length) {
  635. var experimentsSection = this._appendSection();
  636. experimentsSection.appendChild(this._createExperimentsWarningSubsection());
  637. for (var i = 0; i < experiments.length; ++i)
  638. experimentsSection.appendChild(this._createExperimentCheckbox(experiments[i]));
  639. }
  640. }
  641. WebInspector.ExperimentsSettingsTab.prototype = {
  642. /**
  643. * @return {Element} element
  644. */
  645. _createExperimentsWarningSubsection: function()
  646. {
  647. var subsection = document.createElement("div");
  648. var warning = subsection.createChild("span", "settings-experiments-warning-subsection-warning");
  649. warning.textContent = WebInspector.UIString("WARNING:");
  650. subsection.appendChild(document.createTextNode(" "));
  651. var message = subsection.createChild("span", "settings-experiments-warning-subsection-message");
  652. message.textContent = WebInspector.UIString("These experiments could be dangerous and may require restart.");
  653. return subsection;
  654. },
  655. _createExperimentCheckbox: function(experiment)
  656. {
  657. var input = document.createElement("input");
  658. input.type = "checkbox";
  659. input.name = experiment.name;
  660. input.checked = experiment.isEnabled();
  661. function listener()
  662. {
  663. experiment.setEnabled(input.checked);
  664. }
  665. input.addEventListener("click", listener, false);
  666. var p = document.createElement("p");
  667. var label = document.createElement("label");
  668. label.appendChild(input);
  669. label.appendChild(document.createTextNode(WebInspector.UIString(experiment.title)));
  670. p.appendChild(label);
  671. return p;
  672. },
  673. __proto__: WebInspector.SettingsTab.prototype
  674. }
  675. /**
  676. * @constructor
  677. */
  678. WebInspector.SettingsController = function()
  679. {
  680. this._statusBarButton = new WebInspector.StatusBarButton(WebInspector.UIString("Settings"), "settings-status-bar-item");
  681. if (WebInspector.experimentsSettings.showOverridesInDrawer.isEnabled())
  682. this._statusBarButton.element.addEventListener("mousedown", this._mouseDown.bind(this), false);
  683. else
  684. this._statusBarButton.element.addEventListener("mouseup", this._mouseUp.bind(this), false);
  685. /** @type {?WebInspector.SettingsScreen} */
  686. this._settingsScreen;
  687. }
  688. WebInspector.SettingsController.prototype =
  689. {
  690. get statusBarItem()
  691. {
  692. return this._statusBarButton.element;
  693. },
  694. /**
  695. * @param {Event} event
  696. */
  697. _mouseDown: function(event)
  698. {
  699. var contextMenu = new WebInspector.ContextMenu(event);
  700. contextMenu.appendItem(WebInspector.UIString("Overrides"), showOverrides.bind(this));
  701. contextMenu.appendItem(WebInspector.UIString("Settings"), showSettings.bind(this));
  702. function showOverrides()
  703. {
  704. if (this._settingsScreenVisible)
  705. this._hideSettingsScreen();
  706. WebInspector.OverridesView.showInDrawer();
  707. }
  708. function showSettings()
  709. {
  710. if (!this._settingsScreenVisible)
  711. this.showSettingsScreen();
  712. }
  713. contextMenu.showSoftMenu();
  714. },
  715. /**
  716. * @param {Event} event
  717. */
  718. _mouseUp: function(event)
  719. {
  720. this.showSettingsScreen();
  721. },
  722. _onHideSettingsScreen: function()
  723. {
  724. delete this._settingsScreenVisible;
  725. },
  726. /**
  727. * @param {string=} tabId
  728. */
  729. showSettingsScreen: function(tabId)
  730. {
  731. if (!this._settingsScreen)
  732. this._settingsScreen = new WebInspector.SettingsScreen(this._onHideSettingsScreen.bind(this));
  733. if (tabId)
  734. this._settingsScreen.selectTab(tabId);
  735. this._settingsScreen.showModal();
  736. this._settingsScreenVisible = true;
  737. },
  738. _hideSettingsScreen: function()
  739. {
  740. if (this._settingsScreen)
  741. this._settingsScreen.hide();
  742. },
  743. resize: function()
  744. {
  745. if (this._settingsScreen && this._settingsScreen.isShowing())
  746. this._settingsScreen.doResize();
  747. }
  748. }
  749. /**
  750. * @constructor
  751. * @extends {WebInspector.Object}
  752. * @param {function(Element, string, ?string)} itemRenderer
  753. */
  754. WebInspector.SettingsList = function(columns, itemRenderer)
  755. {
  756. this.element = document.createElement("div");
  757. this.element.addStyleClass("settings-list");
  758. this.element.tabIndex = -1;
  759. this._itemRenderer = itemRenderer;
  760. this._listItems = {};
  761. this._ids = [];
  762. this._columns = columns;
  763. }
  764. WebInspector.SettingsList.Events = {
  765. Selected: "Selected",
  766. Removed: "Removed",
  767. DoubleClicked: "DoubleClicked",
  768. }
  769. WebInspector.SettingsList.prototype = {
  770. /**
  771. * @param {?string} itemId
  772. * @param {?string=} beforeId
  773. * @return {Element}
  774. */
  775. addItem: function(itemId, beforeId)
  776. {
  777. var listItem = document.createElement("div");
  778. listItem._id = itemId;
  779. listItem.addStyleClass("settings-list-item");
  780. if (typeof beforeId !== undefined)
  781. this.element.insertBefore(listItem, this._listItems[beforeId]);
  782. else
  783. this.element.appendChild(listItem);
  784. var listItemContents = listItem.createChild("div", "settings-list-item-contents");
  785. var listItemColumnsElement = listItemContents.createChild("div", "settings-list-item-columns");
  786. listItem.columnElements = {};
  787. for (var i = 0; i < this._columns.length; ++i) {
  788. var columnElement = listItemColumnsElement.createChild("div", "list-column");
  789. var columnId = this._columns[i];
  790. listItem.columnElements[columnId] = columnElement;
  791. this._itemRenderer(columnElement, columnId, itemId);
  792. }
  793. var removeItemButton = this._createRemoveButton(removeItemClicked.bind(this));
  794. listItemContents.addEventListener("click", this.selectItem.bind(this, itemId), false);
  795. listItemContents.addEventListener("dblclick", this._onDoubleClick.bind(this, itemId), false);
  796. listItemContents.appendChild(removeItemButton);
  797. this._listItems[itemId] = listItem;
  798. if (typeof beforeId !== undefined)
  799. this._ids.splice(this._ids.indexOf(beforeId), 0, itemId);
  800. else
  801. this._ids.push(itemId);
  802. function removeItemClicked(event)
  803. {
  804. removeItemButton.disabled = true;
  805. this.removeItem(itemId);
  806. this.dispatchEventToListeners(WebInspector.SettingsList.Events.Removed, itemId);
  807. event.consume();
  808. }
  809. return listItem;
  810. },
  811. /**
  812. * @param {?string} id
  813. */
  814. removeItem: function(id)
  815. {
  816. this._listItems[id].remove();
  817. delete this._listItems[id];
  818. this._ids.remove(id);
  819. if (id === this._selectedId) {
  820. delete this._selectedId;
  821. if (this._ids.length)
  822. this.selectItem(this._ids[0]);
  823. }
  824. },
  825. /**
  826. * @return {Array.<?string>}
  827. */
  828. itemIds: function()
  829. {
  830. return this._ids.slice();
  831. },
  832. /**
  833. * @return {Array.<string>}
  834. */
  835. columns: function()
  836. {
  837. return this._columns.slice();
  838. },
  839. /**
  840. * @return {?string}
  841. */
  842. selectedId: function()
  843. {
  844. return this._selectedId;
  845. },
  846. /**
  847. * @return {Element}
  848. */
  849. selectedItem: function()
  850. {
  851. return this._selectedId ? this._listItems[this._selectedId] : null;
  852. },
  853. /**
  854. * @param {string} itemId
  855. * @return {Element}
  856. */
  857. itemForId: function(itemId)
  858. {
  859. return this._listItems[itemId];
  860. },
  861. /**
  862. * @param {?string} id
  863. * @param {Event=} event
  864. */
  865. _onDoubleClick: function(id, event)
  866. {
  867. this.dispatchEventToListeners(WebInspector.SettingsList.Events.DoubleClicked, id);
  868. },
  869. /**
  870. * @param {?string} id
  871. * @param {Event=} event
  872. */
  873. selectItem: function(id, event)
  874. {
  875. if (typeof this._selectedId !== "undefined") {
  876. this._listItems[this._selectedId].removeStyleClass("selected");
  877. }
  878. this._selectedId = id;
  879. if (typeof this._selectedId !== "undefined") {
  880. this._listItems[this._selectedId].addStyleClass("selected");
  881. }
  882. this.dispatchEventToListeners(WebInspector.SettingsList.Events.Selected, id);
  883. if (event)
  884. event.consume();
  885. },
  886. /**
  887. * @param {function(Event)} handler
  888. * @return {Element}
  889. */
  890. _createRemoveButton: function(handler)
  891. {
  892. var removeButton = document.createElement("button");
  893. removeButton.addStyleClass("remove-item-button");
  894. removeButton.value = WebInspector.UIString("Remove");
  895. removeButton.addEventListener("click", handler, false);
  896. return removeButton;
  897. },
  898. __proto__: WebInspector.Object.prototype
  899. }
  900. /**
  901. * @constructor
  902. * @extends {WebInspector.SettingsList}
  903. * @param {function(?string, Object)} validateHandler
  904. * @param {function(?string, Object)} editHandler
  905. */
  906. WebInspector.EditableSettingsList = function(columns, valuesProvider, validateHandler, editHandler)
  907. {
  908. WebInspector.SettingsList.call(this, columns, this._renderColumn.bind(this));
  909. this._validateHandler = validateHandler;
  910. this._editHandler = editHandler;
  911. this._valuesProvider = valuesProvider;
  912. /** @type {!Object.<string, HTMLInputElement>} */
  913. this._addInputElements = {};
  914. /** @type {!Object.<string, !Object.<string, HTMLInputElement>>} */
  915. this._editInputElements = {};
  916. /** @type {Object.<string, Object.<string, HTMLSpanElement>>} */
  917. this._textElements = {};
  918. this._addMappingItem = this.addItem(null);
  919. this._addMappingItem.addStyleClass("item-editing");
  920. this._addMappingItem.addStyleClass("add-list-item");
  921. }
  922. WebInspector.EditableSettingsList.prototype = {
  923. /**
  924. * @param {?string} itemId
  925. * @param {?string=} beforeId
  926. * @return {Element}
  927. */
  928. addItem: function(itemId, beforeId)
  929. {
  930. var listItem = WebInspector.SettingsList.prototype.addItem.call(this, itemId, beforeId);
  931. listItem.addStyleClass("editable");
  932. return listItem;
  933. },
  934. /**
  935. * @param {Element} columnElement
  936. * @param {string} columnId
  937. * @param {?string} itemId
  938. */
  939. _renderColumn: function(columnElement, columnId, itemId)
  940. {
  941. columnElement.addStyleClass("settings-list-column-" + columnId);
  942. var placeholder = (columnId === "url") ? WebInspector.UIString("URL prefix") : WebInspector.UIString("Folder path");
  943. if (itemId === null) {
  944. var inputElement = columnElement.createChild("input", "list-column-editor");
  945. inputElement.placeholder = placeholder;
  946. inputElement.addEventListener("blur", this._onAddMappingInputBlur.bind(this));
  947. inputElement.addEventListener("input", this._validateEdit.bind(this, itemId));
  948. this._addInputElements[columnId] = inputElement;
  949. return;
  950. }
  951. if (!this._editInputElements[itemId])
  952. this._editInputElements[itemId] = {};
  953. if (!this._textElements[itemId])
  954. this._textElements[itemId] = {};
  955. var value = this._valuesProvider(itemId, columnId);
  956. var textElement = columnElement.createChild("span", "list-column-text");
  957. textElement.textContent = value;
  958. textElement.title = value;
  959. columnElement.addEventListener("click", rowClicked.bind(this), false);
  960. this._textElements[itemId][columnId] = textElement;
  961. var inputElement = columnElement.createChild("input", "list-column-editor");
  962. inputElement.value = value;
  963. inputElement.addEventListener("blur", this._editMappingBlur.bind(this, itemId));
  964. inputElement.addEventListener("input", this._validateEdit.bind(this, itemId));
  965. columnElement.inputElement = inputElement;
  966. this._editInputElements[itemId][columnId] = inputElement;
  967. function rowClicked(event)
  968. {
  969. if (itemId === this._editingId)
  970. return;
  971. event.consume();
  972. console.assert(!this._editingId);
  973. this._editingId = itemId;
  974. var listItem = this.itemForId(itemId);
  975. listItem.addStyleClass("item-editing");
  976. var inputElement = event.target.inputElement || this._editInputElements[itemId][this.columns()[0]];
  977. inputElement.focus();
  978. inputElement.select();
  979. }
  980. },
  981. /**
  982. * @param {?string} itemId
  983. * @return {Object}
  984. */
  985. _data: function(itemId)
  986. {
  987. var inputElements = this._inputElements(itemId);
  988. var data = {};
  989. var columns = this.columns();
  990. for (var i = 0; i < columns.length; ++i)
  991. data[columns[i]] = inputElements[columns[i]].value;
  992. return data;
  993. },
  994. /**
  995. * @param {?string} itemId
  996. * @return {Object.<string, HTMLInputElement>}
  997. */
  998. _inputElements: function(itemId)
  999. {
  1000. if (!itemId)
  1001. return this._addInputElements;
  1002. return this._editInputElements[itemId];
  1003. },
  1004. /**
  1005. * @param {?string} itemId
  1006. * @return {boolean}
  1007. */
  1008. _validateEdit: function(itemId)
  1009. {
  1010. var errorColumns = this._validateHandler(itemId, this._data(itemId));
  1011. var hasChanges = this._hasChanges(itemId);
  1012. var columns = this.columns();
  1013. for (var i = 0; i < columns.length; ++i) {
  1014. var columnId = columns[i];
  1015. var inputElement = this._inputElements(itemId)[columnId];
  1016. if (hasChanges && errorColumns.indexOf(columnId) !== -1)
  1017. inputElement.addStyleClass("editable-item-error");
  1018. else
  1019. inputElement.removeStyleClass("editable-item-error");
  1020. }
  1021. return !errorColumns.length;
  1022. },
  1023. /**
  1024. * @param {?string} itemId
  1025. * @return {boolean}
  1026. */
  1027. _hasChanges: function(itemId)
  1028. {
  1029. var hasChanges = false;
  1030. var columns = this.columns();
  1031. for (var i = 0; i < columns.length; ++i) {
  1032. var columnId = columns[i];
  1033. var oldValue = itemId ? this._textElements[itemId][columnId].textContent : "";
  1034. var newValue = this._inputElements(itemId)[columnId].value;
  1035. if (oldValue !== newValue) {
  1036. hasChanges = true;
  1037. break;
  1038. }
  1039. }
  1040. return hasChanges;
  1041. },
  1042. /**
  1043. * @param {string} itemId
  1044. */
  1045. _editMappingBlur: function(itemId, event)
  1046. {
  1047. var inputElements = Object.values(this._editInputElements[itemId]);
  1048. if (inputElements.indexOf(event.relatedTarget) !== -1)
  1049. return;
  1050. var listItem = this.itemForId(itemId);
  1051. listItem.removeStyleClass("item-editing");
  1052. delete this._editingId;
  1053. if (!this._hasChanges(itemId))
  1054. return;
  1055. if (!this._validateEdit(itemId)) {
  1056. var columns = this.columns();
  1057. for (var i = 0; i < columns.length; ++i) {
  1058. var columnId = columns[i];
  1059. var inputElement = this._editInputElements[itemId][columnId];
  1060. inputElement.value = this._textElements[itemId][columnId].textContent;
  1061. inputElement.removeStyleClass("editable-item-error");
  1062. }
  1063. return;
  1064. }
  1065. this._editHandler(itemId, this._data(itemId));
  1066. },
  1067. _onAddMappingInputBlur: function(event)
  1068. {
  1069. var inputElements = Object.values(this._addInputElements);
  1070. if (inputElements.indexOf(event.relatedTarget) !== -1)
  1071. return;
  1072. if (!this._hasChanges(null))
  1073. return;
  1074. if (!this._validateEdit(null))
  1075. return;
  1076. this._editHandler(null, this._data(null));
  1077. var columns = this.columns();
  1078. for (var i = 0; i < columns.length; ++i) {
  1079. var columnId = columns[i];
  1080. var inputElement = this._addInputElements[columnId];
  1081. inputElement.value = "";
  1082. }
  1083. },
  1084. __proto__: WebInspector.SettingsList.prototype
  1085. }