OverridesView.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /*
  2. * Copyright (C) 2012 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. */
  34. WebInspector.OverridesView = function()
  35. {
  36. WebInspector.View.call(this);
  37. this.registerRequiredCSS("helpScreen.css");
  38. this.element.addStyleClass("fill");
  39. this.element.addStyleClass("help-window-main");
  40. this.element.addStyleClass("settings-tab-container");
  41. var paneContent = this.element.createChild("div", "tabbed-pane-content");
  42. var headerTitle = paneContent.createChild("header").createChild("h3");
  43. headerTitle.appendChild(document.createTextNode(WebInspector.UIString("Overrides")));
  44. var wrapper = paneContent.createChild("div", "help-container-wrapper overrides-view");
  45. var topContainer = wrapper.createChild("div", "settings-tab help-content");
  46. var enableOptionsContainer = topContainer.createChild("div", "help-block");
  47. var enableOnStartupField = WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Enable on DevTools startup"), WebInspector.settings.enableOverridesOnStartup);
  48. enableOnStartupField.id = "enable-devtools-on-startup";
  49. this._enableOnStartupField = enableOnStartupField;
  50. var enableLabel = this._createNonPersistedCheckbox(WebInspector.UIString("Enable"), this._setOverridesActive.bind(this));
  51. var enableCheckbox = enableLabel.getElementsByTagName("input")[0];
  52. enableCheckbox.checked = WebInspector.settings.enableOverridesOnStartup.get();
  53. enableOptionsContainer.appendChild(enableLabel);
  54. enableOptionsContainer.appendChild(enableOnStartupField);
  55. var mainContainer = topContainer.createChild("fieldset", "help-container");
  56. this._mainContainer = mainContainer;
  57. function appendBlock(contentElements)
  58. {
  59. var blockElement = mainContainer.createChild("div", "help-block");
  60. for (var i = 0; i < contentElements.length; ++i)
  61. blockElement.appendChild(contentElements[i]);
  62. }
  63. this.containerElement = topContainer;
  64. appendBlock([this._createUserAgentControl()]);
  65. appendBlock([this._createDeviceMetricsControl()]);
  66. appendBlock([this._createGeolocationOverrideControl()]);
  67. appendBlock([this._createDeviceOrientationOverrideControl()]);
  68. appendBlock([WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Emulate touch events"), WebInspector.settings.emulateTouchEvents)]);
  69. appendBlock([this._createMediaEmulationElement()]);
  70. this._setOverridesActive(enableCheckbox.checked);
  71. this._statusElement = document.createElement("span");
  72. this._statusElement.textContent = WebInspector.UIString("Overrides");
  73. }
  74. WebInspector.OverridesView.showInDrawer = function()
  75. {
  76. if (!WebInspector.OverridesView._view)
  77. WebInspector.OverridesView._view = new WebInspector.OverridesView();
  78. var view = WebInspector.OverridesView._view;
  79. WebInspector.showViewInDrawer(view._statusElement, view);
  80. }
  81. WebInspector.OverridesView.prototype = {
  82. /**
  83. * @param {boolean} active
  84. */
  85. _setOverridesActive: function(active)
  86. {
  87. WebInspector.overridesSupport.setOverridesActive(active);
  88. this._mainContainer.disabled = !active;
  89. this._enableOnStartupField.disabled = !active;
  90. },
  91. /**
  92. * @param {string} name
  93. * @param {!WebInspector.Setting} setting
  94. * @param {function(boolean)} callback
  95. */
  96. _createSettingCheckbox: function(name, setting, callback)
  97. {
  98. var checkbox = WebInspector.SettingsTab.createCheckbox(name, setting.get.bind(setting), listener);
  99. function listener(value)
  100. {
  101. setting.set(value);
  102. if (callback)
  103. callback(value);
  104. }
  105. return checkbox;
  106. },
  107. /**
  108. * @return {Element}
  109. */
  110. _createUserAgentControl: function()
  111. {
  112. var checkbox = WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("User Agent"), WebInspector.settings.overrideUserAgent);
  113. checkbox.appendChild(this._createUserAgentSelectRowElement());
  114. return checkbox;
  115. },
  116. /**
  117. * @return {Element}
  118. */
  119. _createUserAgentSelectRowElement: function()
  120. {
  121. var userAgent = WebInspector.settings.userAgent.get();
  122. // When present, the third element lists device metrics separated by 'x':
  123. // - screen width,
  124. // - screen height,
  125. // - font scale factor.
  126. const userAgents = [
  127. ["Internet Explorer 10", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)"],
  128. ["Internet Explorer 9", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"],
  129. ["Internet Explorer 8", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)"],
  130. ["Internet Explorer 7", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"],
  131. ["Firefox 7 \u2014 Windows", "Mozilla/5.0 (Windows NT 6.1; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"],
  132. ["Firefox 7 \u2014 Mac", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"],
  133. ["Firefox 4 \u2014 Windows", "Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"],
  134. ["Firefox 4 \u2014 Mac", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"],
  135. ["Firefox 14 \u2014 Android Mobile", "Mozilla/5.0 (Android; Mobile; rv:14.0) Gecko/14.0 Firefox/14.0"],
  136. ["Firefox 14 \u2014 Android Tablet", "Mozilla/5.0 (Android; Tablet; rv:14.0) Gecko/14.0 Firefox/14.0"],
  137. ["Chrome \u2014 Android Mobile", "Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19"],
  138. ["Chrome \u2014 Android Tablet", "Mozilla/5.0 (Linux; Android 4.1.2; Nexus 7 Build/JZ054K) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19"],
  139. ["iPhone \u2014 iOS 6", "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25", "640x1136x1"],
  140. ["iPhone \u2014 iOS 5", "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3", "640x960x1"],
  141. ["iPhone \u2014 iOS 4", "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5", "640x960x1"],
  142. ["iPad \u2014 iOS 6", "Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25", "1024x768x1"],
  143. ["iPad \u2014 iOS 5", "Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3", "1024x768x1"],
  144. ["iPad \u2014 iOS 4", "Mozilla/5.0 (iPad; CPU OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5", "1024x768x1"],
  145. ["Android 2.3 \u2014 Nexus S", "Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; Nexus S Build/GRK39F) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1", "480x800x1.1"],
  146. ["Android 4.0.2 \u2014 Galaxy Nexus", "Mozilla/5.0 (Linux; U; Android 4.0.2; en-us; Galaxy Nexus Build/ICL53F) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30", "720x1280x1.1"],
  147. ["BlackBerry \u2014 PlayBook 2.1", "Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML, like Gecko) Version/7.2.1.0 Safari/536.2+", "1024x600x1"],
  148. ["BlackBerry \u2014 9900", "Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0.187 Mobile Safari/534.11+", "640x480x1"],
  149. ["BlackBerry \u2014 BB10", "Mozilla/5.0 (BB10; Touch) AppleWebKit/537.1+ (KHTML, like Gecko) Version/10.0.0.1337 Mobile Safari/537.1+", "768x1280x1"],
  150. ["MeeGo \u2014 Nokia N9", "Mozilla/5.0 (MeeGo; NokiaN9) AppleWebKit/534.13 (KHTML, like Gecko) NokiaBrowser/8.5.0 Mobile Safari/534.13", "480x854x1"],
  151. [WebInspector.UIString("Other..."), "Other"]
  152. ];
  153. var fieldsetElement = WebInspector.SettingsTab.createSettingFieldset(WebInspector.settings.overrideUserAgent);
  154. var p = fieldsetElement.createChild("p");
  155. this._selectElement = p.createChild("select");
  156. this._otherUserAgentElement = p.createChild("input");
  157. this._otherUserAgentElement.type = "text";
  158. this._otherUserAgentElement.value = userAgent;
  159. this._otherUserAgentElement.title = userAgent;
  160. var selectionRestored = false;
  161. for (var i = 0; i < userAgents.length; ++i) {
  162. var agent = userAgents[i];
  163. var option = new Option(agent[0], agent[1]);
  164. option._metrics = agent[2] ? agent[2] : "";
  165. this._selectElement.add(option);
  166. if (userAgent === agent[1]) {
  167. this._selectElement.selectedIndex = i;
  168. selectionRestored = true;
  169. }
  170. }
  171. if (!selectionRestored) {
  172. if (!userAgent)
  173. this._selectElement.selectedIndex = 0;
  174. else
  175. this._selectElement.selectedIndex = userAgents.length - 1;
  176. }
  177. this._selectElement.addEventListener("change", this._selectionChanged.bind(this, true), false);
  178. fieldsetElement.addEventListener("dblclick", textDoubleClicked.bind(this), false);
  179. this._otherUserAgentElement.addEventListener("blur", textChanged.bind(this), false);
  180. function textDoubleClicked()
  181. {
  182. this._selectElement.selectedIndex = userAgents.length - 1;
  183. this._selectionChanged();
  184. }
  185. function textChanged()
  186. {
  187. WebInspector.settings.userAgent.set(this._otherUserAgentElement.value);
  188. }
  189. return fieldsetElement;
  190. },
  191. /**
  192. * @param {boolean=} isUserGesture
  193. */
  194. _selectionChanged: function(isUserGesture)
  195. {
  196. var value = this._selectElement.options[this._selectElement.selectedIndex].value;
  197. if (value !== "Other") {
  198. WebInspector.settings.userAgent.set(value);
  199. this._otherUserAgentElement.value = value;
  200. this._otherUserAgentElement.title = value;
  201. this._otherUserAgentElement.disabled = true;
  202. } else {
  203. this._otherUserAgentElement.disabled = false;
  204. this._otherUserAgentElement.focus();
  205. }
  206. if (isUserGesture) {
  207. var metrics = this._selectElement.options[this._selectElement.selectedIndex]._metrics;
  208. this._setDeviceMetricsOverride(WebInspector.OverridesSupport.DeviceMetrics.parseSetting(metrics), false);
  209. }
  210. },
  211. /**
  212. * Creates an input element under the parentElement with the given id and defaultText.
  213. * It also sets an onblur event listener.
  214. * @param {Element} parentElement
  215. * @param {string} id
  216. * @param {string} defaultText
  217. * @param {function(*)} eventListener
  218. * @param {boolean=} numeric
  219. * @return {Element} element
  220. */
  221. _createInput: function(parentElement, id, defaultText, eventListener, numeric)
  222. {
  223. var element = parentElement.createChild("input");
  224. element.id = id;
  225. element.type = "text";
  226. element.maxLength = 12;
  227. element.style.width = "80px";
  228. element.value = defaultText;
  229. element.align = "right";
  230. if (numeric)
  231. element.className = "numeric";
  232. element.addEventListener("blur", eventListener, false);
  233. return element;
  234. },
  235. /**
  236. * @param {string} title
  237. * @param {function(boolean)} callback
  238. */
  239. _createNonPersistedCheckbox: function(title, callback)
  240. {
  241. var labelElement = document.createElement("label");
  242. var checkboxElement = labelElement.createChild("input");
  243. checkboxElement.type = "checkbox";
  244. checkboxElement.checked = false;
  245. checkboxElement.addEventListener("click", onclick, false);
  246. labelElement.appendChild(document.createTextNode(title));
  247. return labelElement;
  248. function onclick()
  249. {
  250. callback(checkboxElement.checked);
  251. }
  252. },
  253. /**
  254. * @return {Element}
  255. */
  256. _createDeviceMetricsControl: function()
  257. {
  258. const metricsSetting = WebInspector.settings.deviceMetrics.get();
  259. var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(metricsSetting);
  260. var checkbox = this._createSettingCheckbox(WebInspector.UIString("Device metrics"), WebInspector.settings.overrideDeviceMetrics, this._onMetricsCheckboxClicked.bind(this));
  261. checkbox.appendChild(this._createDeviceMetricsElement(metrics));
  262. this._onMetricsCheckboxClicked(WebInspector.settings.overrideDeviceMetrics.get());
  263. return checkbox;
  264. },
  265. /**
  266. * @param {boolean} enabled
  267. */
  268. _onMetricsCheckboxClicked: function(enabled)
  269. {
  270. if (enabled && !this._widthOverrideElement.value)
  271. this._widthOverrideElement.focus();
  272. },
  273. _applyDeviceMetricsUserInput: function()
  274. {
  275. this._setDeviceMetricsOverride(WebInspector.OverridesSupport.DeviceMetrics.parseUserInput(this._widthOverrideElement.value.trim(), this._heightOverrideElement.value.trim(), this._fontScaleFactorOverrideElement.value.trim()), true);
  276. },
  277. /**
  278. * @param {?WebInspector.OverridesSupport.DeviceMetrics} metrics
  279. * @param {boolean} userInputModified
  280. */
  281. _setDeviceMetricsOverride: function(metrics, userInputModified)
  282. {
  283. function setValid(condition, element)
  284. {
  285. if (condition)
  286. element.removeStyleClass("error-input");
  287. else
  288. element.addStyleClass("error-input");
  289. }
  290. setValid(metrics && metrics.isWidthValid(), this._widthOverrideElement);
  291. setValid(metrics && metrics.isHeightValid(), this._heightOverrideElement);
  292. setValid(metrics && metrics.isFontScaleFactorValid(), this._fontScaleFactorOverrideElement);
  293. if (!metrics)
  294. return;
  295. if (!userInputModified) {
  296. this._widthOverrideElement.value = metrics.widthToInput();
  297. this._heightOverrideElement.value = metrics.heightToInput();
  298. this._fontScaleFactorOverrideElement.value = metrics.fontScaleFactorToInput();
  299. }
  300. if (metrics.isValid()) {
  301. var value = metrics.toSetting();
  302. if (value !== WebInspector.settings.deviceMetrics.get())
  303. WebInspector.settings.deviceMetrics.set(value);
  304. }
  305. },
  306. /**
  307. * @param {WebInspector.OverridesSupport.DeviceMetrics} metrics
  308. */
  309. _createDeviceMetricsElement: function(metrics)
  310. {
  311. var fieldsetElement = WebInspector.SettingsTab.createSettingFieldset(WebInspector.settings.overrideDeviceMetrics);
  312. fieldsetElement.id = "metrics-override-section";
  313. var p = fieldsetElement.createChild("p");
  314. function swapDimensionsClicked(event)
  315. {
  316. var widthValue = this._widthOverrideElement.value;
  317. this._widthOverrideElement.value = this._heightOverrideElement.value;
  318. this._heightOverrideElement.value = widthValue;
  319. this._applyDeviceMetricsUserInput();
  320. }
  321. var tableElement = p.createChild("table", "nowrap");
  322. var rowElement = tableElement.createChild("tr");
  323. var cellElement = rowElement.createChild("td");
  324. cellElement.appendChild(document.createTextNode(WebInspector.UIString("Screen resolution:")));
  325. cellElement = rowElement.createChild("td");
  326. this._widthOverrideElement = this._createInput(cellElement, "metrics-override-width", String(metrics.width || screen.width), this._applyDeviceMetricsUserInput.bind(this), true);
  327. cellElement.appendChild(document.createTextNode(" \u00D7 ")); // MULTIPLICATION SIGN.
  328. this._heightOverrideElement = this._createInput(cellElement, "metrics-override-height", String(metrics.height || screen.height), this._applyDeviceMetricsUserInput.bind(this), true);
  329. cellElement.appendChild(document.createTextNode(" \u2014 ")); // EM DASH.
  330. this._swapDimensionsElement = cellElement.createChild("button");
  331. this._swapDimensionsElement.appendChild(document.createTextNode(" \u21C4 ")); // RIGHTWARDS ARROW OVER LEFTWARDS ARROW.
  332. this._swapDimensionsElement.title = WebInspector.UIString("Swap dimensions");
  333. this._swapDimensionsElement.addEventListener("click", swapDimensionsClicked.bind(this), false);
  334. rowElement = tableElement.createChild("tr");
  335. cellElement = rowElement.createChild("td");
  336. cellElement.appendChild(document.createTextNode(WebInspector.UIString("Font scale factor:")));
  337. cellElement = rowElement.createChild("td");
  338. this._fontScaleFactorOverrideElement = this._createInput(cellElement, "metrics-override-font-scale", String(metrics.fontScaleFactor || 1), this._applyDeviceMetricsUserInput.bind(this), true);
  339. rowElement = tableElement.createChild("tr");
  340. cellElement = rowElement.createChild("td");
  341. cellElement.colSpan = 2;
  342. var checkbox = WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Fit in window"), WebInspector.settings.deviceFitWindow, true);
  343. cellElement.appendChild(checkbox);
  344. return fieldsetElement;
  345. },
  346. /**
  347. * @return {Element}
  348. */
  349. _createGeolocationOverrideControl: function()
  350. {
  351. const geolocationSetting = WebInspector.settings.geolocationOverride.get();
  352. var geolocation = WebInspector.OverridesSupport.GeolocationPosition.parseSetting(geolocationSetting);
  353. var checkbox = this._createSettingCheckbox(WebInspector.UIString("Override Geolocation"), WebInspector.settings.overrideGeolocation, this._geolocationOverrideCheckboxClicked.bind(this));
  354. var geolocationSectionElement = this._createGeolocationOverrideElement(geolocation);
  355. checkbox.appendChild(geolocationSectionElement);
  356. this._geolocationOverrideCheckboxClicked(WebInspector.settings.overrideGeolocation.get());
  357. return checkbox;
  358. },
  359. /**
  360. * @param {boolean} enabled
  361. */
  362. _geolocationOverrideCheckboxClicked: function(enabled)
  363. {
  364. if (enabled && !this._latitudeElement.value)
  365. this._latitudeElement.focus();
  366. },
  367. _applyGeolocationUserInput: function()
  368. {
  369. this._setGeolocationPosition(WebInspector.OverridesSupport.GeolocationPosition.parseUserInput(this._latitudeElement.value.trim(), this._longitudeElement.value.trim(), this._geolocationErrorElement.checked), true);
  370. },
  371. /**
  372. * @param {?WebInspector.OverridesSupport.GeolocationPosition} geolocation
  373. * @param {boolean} userInputModified
  374. */
  375. _setGeolocationPosition: function(geolocation, userInputModified)
  376. {
  377. if (!geolocation)
  378. return;
  379. if (!userInputModified) {
  380. this._latitudeElement.value = geolocation.latitude;
  381. this._longitudeElement.value = geolocation.longitude;
  382. }
  383. var value = geolocation.toSetting();
  384. WebInspector.settings.geolocationOverride.set(value);
  385. },
  386. /**
  387. * @param {WebInspector.OverridesSupport.GeolocationPosition} geolocation
  388. * @return {Element}
  389. */
  390. _createGeolocationOverrideElement: function(geolocation)
  391. {
  392. var fieldsetElement = WebInspector.SettingsTab.createSettingFieldset(WebInspector.settings.overrideGeolocation);
  393. fieldsetElement.id = "geolocation-override-section";
  394. var p = fieldsetElement.createChild("p");
  395. var tableElement = p.createChild("table");
  396. var rowElement = tableElement.createChild("tr");
  397. var cellElement = rowElement.createChild("td");
  398. cellElement.appendChild(document.createTextNode(WebInspector.UIString("Geolocation Position") + ":"));
  399. cellElement = rowElement.createChild("td");
  400. cellElement.appendChild(document.createTextNode(WebInspector.UIString("Lat = ")));
  401. this._latitudeElement = this._createInput(cellElement, "geolocation-override-latitude", String(geolocation.latitude), this._applyGeolocationUserInput.bind(this), true);
  402. cellElement.appendChild(document.createTextNode(" , "));
  403. cellElement.appendChild(document.createTextNode(WebInspector.UIString("Lon = ")));
  404. this._longitudeElement = this._createInput(cellElement, "geolocation-override-longitude", String(geolocation.longitude), this._applyGeolocationUserInput.bind(this), true);
  405. rowElement = tableElement.createChild("tr");
  406. cellElement = rowElement.createChild("td");
  407. cellElement.colSpan = 2;
  408. var geolocationErrorLabelElement = document.createElement("label");
  409. var geolocationErrorCheckboxElement = geolocationErrorLabelElement.createChild("input");
  410. geolocationErrorCheckboxElement.id = "geolocation-error";
  411. geolocationErrorCheckboxElement.type = "checkbox";
  412. geolocationErrorCheckboxElement.checked = !geolocation || geolocation.error;
  413. geolocationErrorCheckboxElement.addEventListener("click", this._applyGeolocationUserInput.bind(this), false);
  414. geolocationErrorLabelElement.appendChild(document.createTextNode(WebInspector.UIString("Emulate position unavailable")));
  415. this._geolocationErrorElement = geolocationErrorCheckboxElement;
  416. cellElement.appendChild(geolocationErrorLabelElement);
  417. return fieldsetElement;
  418. },
  419. /**
  420. * @return {Element}
  421. */
  422. _createDeviceOrientationOverrideControl: function()
  423. {
  424. const deviceOrientationSetting = WebInspector.settings.deviceOrientationOverride.get();
  425. var deviceOrientation = WebInspector.OverridesSupport.DeviceOrientation.parseSetting(deviceOrientationSetting);
  426. var checkbox = this._createSettingCheckbox(WebInspector.UIString("Override Device Orientation"), WebInspector.settings.overrideDeviceOrientation, this._deviceOrientationOverrideCheckboxClicked.bind(this));
  427. var deviceOrientationSectionElement = this._createDeviceOrientationOverrideElement(deviceOrientation);
  428. checkbox.appendChild(deviceOrientationSectionElement);
  429. this._deviceOrientationOverrideCheckboxClicked(WebInspector.settings.overrideDeviceOrientation.get());
  430. return checkbox;
  431. },
  432. /**
  433. * @param {boolean} enabled
  434. */
  435. _deviceOrientationOverrideCheckboxClicked: function(enabled)
  436. {
  437. if (enabled && !this._alphaElement.value)
  438. this._alphaElement.focus();
  439. },
  440. _applyDeviceOrientationUserInput: function()
  441. {
  442. this._setDeviceOrientation(WebInspector.OverridesSupport.DeviceOrientation.parseUserInput(this._alphaElement.value.trim(), this._betaElement.value.trim(), this._gammaElement.value.trim()), true);
  443. },
  444. /**
  445. * @param {?WebInspector.OverridesSupport.DeviceOrientation} deviceOrientation
  446. * @param {boolean} userInputModified
  447. */
  448. _setDeviceOrientation: function(deviceOrientation, userInputModified)
  449. {
  450. if (!deviceOrientation)
  451. return;
  452. if (!userInputModified) {
  453. this._alphaElement.value = deviceOrientation.alpha;
  454. this._betaElement.value = deviceOrientation.beta;
  455. this._gammaElement.value = deviceOrientation.gamma;
  456. }
  457. var value = deviceOrientation.toSetting();
  458. WebInspector.settings.deviceOrientationOverride.set(value);
  459. },
  460. /**
  461. * @param {WebInspector.OverridesSupport.DeviceOrientation} deviceOrientation
  462. */
  463. _createDeviceOrientationOverrideElement: function(deviceOrientation)
  464. {
  465. var fieldsetElement = WebInspector.SettingsTab.createSettingFieldset(WebInspector.settings.overrideDeviceOrientation);
  466. fieldsetElement.id = "device-orientation-override-section";
  467. var p = fieldsetElement.createChild("p");
  468. var tableElement = p.createChild("table");
  469. var rowElement = tableElement.createChild("tr");
  470. var cellElement = rowElement.createChild("td");
  471. cellElement.appendChild(document.createTextNode("\u03B1: "));
  472. this._alphaElement = this._createInput(cellElement, "device-orientation-override-alpha", String(deviceOrientation.alpha), this._applyDeviceOrientationUserInput.bind(this), true);
  473. cellElement.appendChild(document.createTextNode(" \u03B2: "));
  474. this._betaElement = this._createInput(cellElement, "device-orientation-override-beta", String(deviceOrientation.beta), this._applyDeviceOrientationUserInput.bind(this), true);
  475. cellElement.appendChild(document.createTextNode(" \u03B3: "));
  476. this._gammaElement = this._createInput(cellElement, "device-orientation-override-gamma", String(deviceOrientation.gamma), this._applyDeviceOrientationUserInput.bind(this), true);
  477. return fieldsetElement;
  478. },
  479. _createMediaEmulationElement: function()
  480. {
  481. var checkbox = WebInspector.SettingsTab.createSettingCheckbox(WebInspector.UIString("Emulate CSS media"), WebInspector.settings.overrideCSSMedia);
  482. var fieldsetElement = WebInspector.SettingsTab.createSettingFieldset(WebInspector.settings.overrideCSSMedia);
  483. checkbox.appendChild(fieldsetElement);
  484. var p = fieldsetElement.createChild("p");
  485. var mediaSelectElement = p.createChild("select");
  486. var mediaTypes = WebInspector.CSSStyleModel.MediaTypes;
  487. var defaultMedia = WebInspector.settings.emulatedCSSMedia.get();
  488. for (var i = 0; i < mediaTypes.length; ++i) {
  489. var mediaType = mediaTypes[i];
  490. if (mediaType === "all") {
  491. // "all" is not a device-specific media type.
  492. continue;
  493. }
  494. var option = document.createElement("option");
  495. option.text = mediaType;
  496. option.value = mediaType;
  497. mediaSelectElement.add(option);
  498. if (mediaType === defaultMedia)
  499. mediaSelectElement.selectedIndex = mediaSelectElement.options.length - 1;
  500. }
  501. mediaSelectElement.addEventListener("change", this._emulateMediaChanged.bind(this, mediaSelectElement), false);
  502. return checkbox;
  503. },
  504. _emulateMediaChanged: function(select)
  505. {
  506. var media = select.options[select.selectedIndex].value;
  507. WebInspector.settings.emulatedCSSMedia.set(media);
  508. },
  509. __proto__: WebInspector.View.prototype
  510. }