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

Side by Side Diff: Source/devtools/front_end/elements/OverridesView.js

Issue 340723005: [DevTools] Remove unnecessary emulation checkboxes and simplify UX. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 25 matching lines...) Expand all
36 { 36 {
37 WebInspector.VBox.call(this); 37 WebInspector.VBox.call(this);
38 this.registerRequiredCSS("overrides.css"); 38 this.registerRequiredCSS("overrides.css");
39 this.registerRequiredCSS("helpScreen.css"); 39 this.registerRequiredCSS("helpScreen.css");
40 this.element.classList.add("overrides-view"); 40 this.element.classList.add("overrides-view");
41 41
42 this._tabbedPane = new WebInspector.TabbedPane(); 42 this._tabbedPane = new WebInspector.TabbedPane();
43 this._tabbedPane.shrinkableTabs = false; 43 this._tabbedPane.shrinkableTabs = false;
44 this._tabbedPane.verticalTabLayout = true; 44 this._tabbedPane.verticalTabLayout = true;
45 45
46 if (!WebInspector.overridesSupport.isInspectingDevice()) 46 if (!WebInspector.overridesSupport.isInspectingDevice()) {
47 new WebInspector.OverridesView.DeviceTab().appendAsTab(this._tabbedPane) ; 47 new WebInspector.OverridesView.DeviceTab().appendAsTab(this._tabbedPane) ;
48 new WebInspector.OverridesView.MediaTab().appendAsTab(this._tabbedPane); 48 new WebInspector.OverridesView.MediaTab().appendAsTab(this._tabbedPane);
49 }
49 new WebInspector.OverridesView.NetworkTab().appendAsTab(this._tabbedPane); 50 new WebInspector.OverridesView.NetworkTab().appendAsTab(this._tabbedPane);
50 new WebInspector.OverridesView.SensorsTab().appendAsTab(this._tabbedPane); 51 new WebInspector.OverridesView.SensorsTab().appendAsTab(this._tabbedPane);
51 52
52 this._lastSelectedTabSetting = WebInspector.settings.createSetting("lastSele ctedEmulateTab", "device"); 53 this._lastSelectedTabSetting = WebInspector.settings.createSetting("lastSele ctedEmulateTab", "device");
53 this._tabbedPane.selectTab(this._lastSelectedTabSetting.get()); 54 this._tabbedPane.selectTab(this._lastSelectedTabSetting.get());
54 this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSele cted, this._tabSelected, this); 55 this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSele cted, this._tabSelected, this);
55 this._tabbedPane.show(this.element); 56 this._tabbedPane.show(this.element);
56 57
57 this._warningFooter = this.element.createChild("div", "overrides-footer"); 58 this._warningFooter = this.element.createChild("div", "overrides-footer");
58 this._overridesWarningUpdated(); 59 this._overridesWarningUpdated();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 143
143 __proto__: WebInspector.VBox.prototype 144 __proto__: WebInspector.VBox.prototype
144 } 145 }
145 146
146 /** 147 /**
147 * @constructor 148 * @constructor
148 * @extends {WebInspector.OverridesView.Tab} 149 * @extends {WebInspector.OverridesView.Tab}
149 */ 150 */
150 WebInspector.OverridesView.DeviceTab = function() 151 WebInspector.OverridesView.DeviceTab = function()
151 { 152 {
152 WebInspector.OverridesView.Tab.call(this, "device", WebInspector.UIString("D evice"), [WebInspector.overridesSupport.settings.emulateDevice]); 153 WebInspector.OverridesView.Tab.call(this, "device", WebInspector.UIString("D evice"), [], [function(){return true;}]);
153 this.element.classList.add("overrides-device"); 154 this.element.classList.add("overrides-device");
154 155
155 this.element.appendChild(WebInspector.SettingsUI.createSettingCheckbox(WebIn spector.UIString("Device"), WebInspector.overridesSupport.settings.emulateDevice , true));
156 this.element.appendChild(this._createDeviceElement()); 156 this.element.appendChild(this._createDeviceElement());
157 157
158 var footnote = this.element.createChild("p", "help-footnote"); 158 var footnote = this.element.createChild("p", "help-footnote");
159 var footnoteLink = footnote.createChild("a"); 159 var footnoteLink = footnote.createChild("a");
160 footnoteLink.href = "https://developers.google.com/chrome-developer-tools/do cs/mobile-emulation"; 160 footnoteLink.href = "https://developers.google.com/chrome-developer-tools/do cs/mobile-emulation";
161 footnoteLink.target = "_blank"; 161 footnoteLink.target = "_blank";
162 footnoteLink.createTextChild(WebInspector.UIString("More information about s creen emulation")); 162 footnoteLink.createTextChild(WebInspector.UIString("More information about s creen emulation"));
163 } 163 }
164 164
165 WebInspector.OverridesView.DeviceTab.prototype = { 165 WebInspector.OverridesView.DeviceTab.prototype = {
166 _createDeviceElement: function() 166 _createDeviceElement: function()
167 { 167 {
168 var fieldsetElement = WebInspector.SettingsUI.createSettingFieldset(WebI nspector.overridesSupport.settings.emulateDevice); 168 var fieldsetElement = document.createElement("fieldset");
169 fieldsetElement.id = "metrics-override-section"; 169 fieldsetElement.id = "metrics-override-section";
170 170
171 fieldsetElement.createChild("span").textContent = WebInspector.UIString( "Device:");
171 fieldsetElement.appendChild(WebInspector.overridesSupport.createDeviceSe lect(document)); 172 fieldsetElement.appendChild(WebInspector.overridesSupport.createDeviceSe lect(document));
172 173
173 var tableElement = fieldsetElement.createChild("table", "nowrap"); 174 var tableElement = fieldsetElement.createChild("table", "nowrap");
174 175
175 var rowElement = tableElement.createChild("tr"); 176 var rowElement = tableElement.createChild("tr");
176 var cellElement = rowElement.createChild("td"); 177 var cellElement = rowElement.createChild("td");
177 cellElement.appendChild(document.createTextNode(WebInspector.UIString("R esolution:"))); 178 cellElement.appendChild(document.createTextNode(WebInspector.UIString("R esolution:")));
178 cellElement = rowElement.createChild("td"); 179 cellElement = rowElement.createChild("td");
179 180
180 var widthOverrideInput = WebInspector.SettingsUI.createSettingInputField ("", WebInspector.overridesSupport.settings.deviceWidth, true, 4, "80px", WebIns pector.OverridesSupport.integerInputValidator, true); 181 var widthOverrideInput = WebInspector.SettingsUI.createSettingInputField ("", WebInspector.overridesSupport.settings.deviceWidth, true, 4, "80px", WebIns pector.OverridesSupport.deviceSizeValidator, true, true, WebInspector.UIString(" --"));
181 cellElement.appendChild(widthOverrideInput); 182 cellElement.appendChild(widthOverrideInput);
182 this._swapDimensionsElement = cellElement.createChild("button", "overrid es-swap"); 183 this._swapDimensionsElement = cellElement.createChild("button", "overrid es-swap");
183 this._swapDimensionsElement.appendChild(document.createTextNode(" \u21C4 ")); // RIGHTWARDS ARROW OVER LEFTWARDS ARROW. 184 this._swapDimensionsElement.appendChild(document.createTextNode(" \u21C4 ")); // RIGHTWARDS ARROW OVER LEFTWARDS ARROW.
184 this._swapDimensionsElement.title = WebInspector.UIString("Swap dimensio ns"); 185 this._swapDimensionsElement.title = WebInspector.UIString("Swap dimensio ns");
185 this._swapDimensionsElement.addEventListener("click", WebInspector.overr idesSupport.swapDimensions.bind(WebInspector.overridesSupport), false); 186 this._swapDimensionsElement.addEventListener("click", WebInspector.overr idesSupport.swapDimensions.bind(WebInspector.overridesSupport), false);
186 this._swapDimensionsElement.tabIndex = -1; 187 this._swapDimensionsElement.tabIndex = -1;
187 var heightOverrideInput = WebInspector.SettingsUI.createSettingInputFiel d("", WebInspector.overridesSupport.settings.deviceHeight, true, 4, "80px", WebI nspector.OverridesSupport.integerInputValidator, true); 188 var heightOverrideInput = WebInspector.SettingsUI.createSettingInputFiel d("", WebInspector.overridesSupport.settings.deviceHeight, true, 4, "80px", WebI nspector.OverridesSupport.deviceSizeValidator, true, true, WebInspector.UIString ("--"));
188 cellElement.appendChild(heightOverrideInput); 189 cellElement.appendChild(heightOverrideInput);
189 190
190 rowElement = tableElement.createChild("tr"); 191 rowElement = tableElement.createChild("tr");
191 cellElement = rowElement.createChild("td"); 192 cellElement = rowElement.createChild("td");
192 cellElement.colSpan = 4; 193 cellElement.colSpan = 4;
193 194
194 rowElement = tableElement.createChild("tr"); 195 rowElement = tableElement.createChild("tr");
195 rowElement.title = WebInspector.UIString("Ratio between a device's physi cal pixels and device-independent pixels."); 196 rowElement.title = WebInspector.UIString("Ratio between a device's physi cal pixels and device-independent pixels.");
196 rowElement.createChild("td").appendChild(document.createTextNode(WebInsp ector.UIString("Device pixel ratio:"))); 197 rowElement.createChild("td").appendChild(document.createTextNode(WebInsp ector.UIString("Device pixel ratio:")));
197 rowElement.createChild("td").appendChild(WebInspector.SettingsUI.createS ettingInputField("", WebInspector.overridesSupport.settings.deviceScaleFactor, t rue, 4, "80px", WebInspector.OverridesSupport.doubleInputValidator, true)); 198 rowElement.createChild("td").appendChild(WebInspector.SettingsUI.createS ettingInputField("", WebInspector.overridesSupport.settings.deviceScaleFactor, t rue, 4, "80px", WebInspector.OverridesSupport.deviceScaleFactorValidator, true, true, WebInspector.UIString("--")));
198 199
199 var viewportCheckbox = this._createSettingCheckbox(WebInspector.UIString ("Emulate mobile"), WebInspector.overridesSupport.settings.emulateViewport); 200 var viewportCheckbox = this._createSettingCheckbox(WebInspector.UIString ("Emulate mobile"), WebInspector.overridesSupport.settings.emulateViewport);
200 viewportCheckbox.title = WebInspector.UIString("Enable meta viewport, ov erlay scrollbars and default 980px body width"); 201 viewportCheckbox.title = WebInspector.UIString("Enable meta viewport, ov erlay scrollbars and default 980px body width");
201 fieldsetElement.appendChild(viewportCheckbox); 202 fieldsetElement.appendChild(viewportCheckbox);
202 203
203 // FIXME: move text autosizing to the "misc" tab together with css media , and separate it from device emulation. 204 // FIXME: move text autosizing to the "misc" tab together with css media , and separate it from device emulation.
204 var textAutosizingOverrideElement = this._createSettingCheckbox(WebInspe ctor.UIString("Enable text autosizing "), WebInspector.overridesSupport.settings .deviceTextAutosizing); 205 var textAutosizingOverrideElement = this._createSettingCheckbox(WebInspe ctor.UIString("Enable text autosizing "), WebInspector.overridesSupport.settings .deviceTextAutosizing);
205 textAutosizingOverrideElement.title = WebInspector.UIString("Text autosi zing is the feature that boosts font sizes on mobile devices."); 206 textAutosizingOverrideElement.title = WebInspector.UIString("Text autosi zing is the feature that boosts font sizes on mobile devices.");
206 fieldsetElement.appendChild(textAutosizingOverrideElement); 207 fieldsetElement.appendChild(textAutosizingOverrideElement);
207 208
208 fieldsetElement.appendChild(this._createSettingCheckbox(WebInspector.UIS tring("Shrink to fit"), WebInspector.overridesSupport.settings.deviceFitWindow)) ; 209 if (!WebInspector.overridesSupport.responsiveDesignAvailable())
210 fieldsetElement.appendChild(this._createSettingCheckbox(WebInspector .UIString("Shrink to fit"), WebInspector.overridesSupport.settings.deviceFitWind ow));
209 211
210 return fieldsetElement; 212 return fieldsetElement;
211 }, 213 },
212 214
213 __proto__: WebInspector.OverridesView.Tab.prototype 215 __proto__: WebInspector.OverridesView.Tab.prototype
214 } 216 }
215 217
216 /** 218 /**
217 * @constructor 219 * @constructor
218 * @extends {WebInspector.OverridesView.Tab} 220 * @extends {WebInspector.OverridesView.Tab}
219 */ 221 */
220 WebInspector.OverridesView.MediaTab = function() 222 WebInspector.OverridesView.MediaTab = function()
221 { 223 {
222 var settings = [WebInspector.overridesSupport.settings.overrideCSSMedia]; 224 var settings = [WebInspector.overridesSupport.settings.overrideCSSMedia];
223 WebInspector.OverridesView.Tab.call(this, "media", WebInspector.UIString("Me dia"), settings); 225 WebInspector.OverridesView.Tab.call(this, "media", WebInspector.UIString("Me dia"), settings);
224 this.element.classList.add("overrides-media"); 226 this.element.classList.add("overrides-media");
225 227
226 this._createMediaEmulationFragment(); 228 this._createMediaEmulationFragment();
227 } 229 }
228 230
229 WebInspector.OverridesView.MediaTab.prototype = { 231 WebInspector.OverridesView.MediaTab.prototype = {
230 _createMediaEmulationFragment: function() 232 _createMediaEmulationFragment: function()
231 { 233 {
232 var checkbox = WebInspector.SettingsUI.createSettingCheckbox(WebInspecto r.UIString("CSS media"), WebInspector.overridesSupport.settings.overrideCSSMedia , true); 234 var checkbox = WebInspector.SettingsUI.createSettingCheckbox(WebInspecto r.UIString("CSS media"), WebInspector.overridesSupport.settings.overrideCSSMedia , true);
233 var fieldsetElement = WebInspector.SettingsUI.createSettingFieldset(WebI nspector.overridesSupport.settings.overrideCSSMedia); 235 var fieldsetElement = WebInspector.SettingsUI.createSettingFieldset(WebI nspector.overridesSupport.settings.overrideCSSMedia);
234 if (WebInspector.overridesSupport.isInspectingDevice())
235 fieldsetElement.disabled = true;
236
237 var mediaSelectElement = fieldsetElement.createChild("select"); 236 var mediaSelectElement = fieldsetElement.createChild("select");
238 var mediaTypes = WebInspector.CSSStyleModel.MediaTypes; 237 var mediaTypes = WebInspector.CSSStyleModel.MediaTypes;
239 var defaultMedia = WebInspector.overridesSupport.settings.emulatedCSSMed ia.get(); 238 var defaultMedia = WebInspector.overridesSupport.settings.emulatedCSSMed ia.get();
240 for (var i = 0; i < mediaTypes.length; ++i) { 239 for (var i = 0; i < mediaTypes.length; ++i) {
241 var mediaType = mediaTypes[i]; 240 var mediaType = mediaTypes[i];
242 if (mediaType === "all") { 241 if (mediaType === "all") {
243 // "all" is not a device-specific media type. 242 // "all" is not a device-specific media type.
244 continue; 243 continue;
245 } 244 }
246 var option = document.createElement("option"); 245 var option = document.createElement("option");
(...skipping 20 matching lines...) Expand all
267 __proto__: WebInspector.OverridesView.Tab.prototype 266 __proto__: WebInspector.OverridesView.Tab.prototype
268 } 267 }
269 268
270 269
271 /** 270 /**
272 * @constructor 271 * @constructor
273 * @extends {WebInspector.OverridesView.Tab} 272 * @extends {WebInspector.OverridesView.Tab}
274 */ 273 */
275 WebInspector.OverridesView.NetworkTab = function() 274 WebInspector.OverridesView.NetworkTab = function()
276 { 275 {
277 var flags = []; 276 var predicates = [this._userAgentOverrideEnabled.bind(this)];
278 if (WebInspector.experimentsSettings.networkConditions.isEnabled()) 277 if (WebInspector.experimentsSettings.networkConditions.isEnabled())
279 flags.push(WebInspector.overridesSupport.settings.emulateNetworkCondition s); 278 predicates.push(this._networkThroughputIsLimited.bind(this));
280 WebInspector.OverridesView.Tab.call(this, "network", WebInspector.UIString(" Network"), flags, [this._isUserAgentOverrideEnabled.bind(this)]); 279 WebInspector.OverridesView.Tab.call(this, "network", WebInspector.UIString(" Network"), [], predicates);
281 this.element.classList.add("overrides-network"); 280 this.element.classList.add("overrides-network");
282 if (WebInspector.experimentsSettings.networkConditions.isEnabled()) { 281 if (WebInspector.experimentsSettings.networkConditions.isEnabled())
283 this.element.appendChild(this._createSettingCheckbox(WebInspector.UIStri ng("Limit network throughput"), WebInspector.overridesSupport.settings.emulateNe tworkConditions)); 282 this._createNetworkConditionsElement();
284 this.element.appendChild(this._createNetworkConditionsElement());
285 }
286 this._createUserAgentSection(); 283 this._createUserAgentSection();
287 } 284 }
288 285
289 WebInspector.OverridesView.NetworkTab.prototype = { 286 WebInspector.OverridesView.NetworkTab.prototype = {
290 /** 287 /**
291 * @return {!Element} 288 * @return {boolean}
292 */ 289 */
290 _networkThroughputIsLimited: function()
291 {
292 return WebInspector.overridesSupport.networkThroughputIsLimited();
293 },
294
293 _createNetworkConditionsElement: function() 295 _createNetworkConditionsElement: function()
294 { 296 {
295 var fieldsetElement = WebInspector.SettingsUI.createSettingFieldset(WebI nspector.overridesSupport.settings.emulateNetworkConditions); 297 var fieldsetElement = this.element.createChild("fieldset");
298 fieldsetElement.createChild("span").textContent = WebInspector.UIString( "Limit network throughput:");
296 299
297 var networkThroughput = WebInspector.overridesSupport.createNetworkThrou ghputSelect(document); 300 var networkThroughput = WebInspector.overridesSupport.createNetworkThrou ghputSelect(document);
298 fieldsetElement.appendChild(networkThroughput); 301 fieldsetElement.appendChild(networkThroughput);
299 fieldsetElement.createChild("br");
300 302
301 var networkDomains = WebInspector.SettingsUI.createSettingInputField("Fo r domains:", WebInspector.overridesSupport.settings.networkConditionsDomains, fa lse, 0, "", WebInspector.OverridesSupport.networkDomainsValidator, false); 303 var networkDomains = WebInspector.SettingsUI.createSettingInputField("Fo r domains:", WebInspector.overridesSupport.settings.networkConditionsDomains, fa lse, 0, "", WebInspector.OverridesSupport.networkDomainsValidator, false, false, WebInspector.UIString("Leave empty to limit all domains"));
302 networkDomains.querySelector("input").placeholder = WebInspector.UIStrin g("Leave empty to limit all domains");
303 fieldsetElement.appendChild(networkDomains); 304 fieldsetElement.appendChild(networkDomains);
304 305
305 return fieldsetElement; 306 WebInspector.overridesSupport.settings.networkConditionsThroughput.addCh angeListener(this.updateActiveState, this);
306 }, 307 },
307 308
308 /** 309 /**
309 * @return {boolean} 310 * @return {boolean}
310 */ 311 */
311 _isUserAgentOverrideEnabled: function() 312 _userAgentOverrideEnabled: function()
312 { 313 {
313 return !!WebInspector.overridesSupport.userAgentOverride(); 314 return !!WebInspector.overridesSupport.settings.userAgent.get();
314 },
315
316 _onUserAgentOverrideEnabledChanged: function()
317 {
318 this.updateActiveState();
319 var enabled = !!WebInspector.overridesSupport.userAgentOverride();
320 if (this._userAgentCheckbox.checked !== enabled)
321 this._userAgentCheckbox.checked = enabled;
322 this._userAgentFieldset.disabled = !enabled;
323 }, 315 },
324 316
325 _createUserAgentSection: function() 317 _createUserAgentSection: function()
326 { 318 {
327 var settings = [WebInspector.overridesSupport.settings.emulateDevice, We bInspector.settings.responsiveDesignEnabled, WebInspector.overridesSupport.setti ngs.deviceUserAgent]; 319 var fieldsetElement = this.element.createChild("fieldset");
328 for (var i = 0; i < settings.length; i++) { 320 var userAgentInput = WebInspector.SettingsUI.createSettingInputField("Sp oof user agent:", WebInspector.overridesSupport.settings.userAgent, false, 0, "" , undefined, false, false, WebInspector.UIString("no override"));
329 settings[i].addChangeListener(this._onUserAgentOverrideEnabledChange d.bind(this)); 321 fieldsetElement.appendChild(userAgentInput);
330 settings[i].addChangeListener(WebInspector.overridesSupport.updateUs erAgentToMatchDeviceUserAgent.bind(WebInspector.overridesSupport));
331 }
332 WebInspector.overridesSupport.settings.overrideUserAgent.addChangeListen er(this._onUserAgentOverrideEnabledChanged.bind(this));
333 WebInspector.overridesSupport.settings.userAgent.addChangeListener(this. _onUserAgentOverrideEnabledChanged.bind(this));
334 322
335 var label = this.element.createChild("label"); 323 WebInspector.overridesSupport.settings.userAgent.addChangeListener(this. updateActiveState, this);
336 var checkbox = label.createChild("input");
337 checkbox.type = "checkbox";
338 checkbox.name = WebInspector.UIString("Spoof user agent");
339 label.createTextChild(WebInspector.UIString("Spoof user agent"));
340
341 function checkboxChanged()
342 {
343 var enabled = checkbox.checked;
344 WebInspector.overridesSupport.settings.overrideUserAgent.set(enabled );
345 if (WebInspector.overridesSupport.isEmulateDeviceEnabled())
346 WebInspector.overridesSupport.settings.deviceUserAgent.set(enabl ed ? WebInspector.overridesSupport.settings.userAgent.get() : "");
347 }
348 checkbox.addEventListener("change", checkboxChanged, false);
349
350 var fieldsetElement = this.element.createChild("fieldset");
351 this._createUserAgentSelectAndInput(fieldsetElement, settings.concat([We bInspector.overridesSupport.settings.userAgent]));
352
353 this._userAgentFieldset = fieldsetElement;
354 this._userAgentCheckbox = checkbox;
355 this._onUserAgentOverrideEnabledChanged();
356 },
357
358 /**
359 * @param {!Element} fieldsetElement
360 * @param {!Array.<!WebInspector.Setting>} settings
361 */
362 _createUserAgentSelectAndInput: function(fieldsetElement, settings)
363 {
364 var userAgents = WebInspector.OverridesSupport._userAgents.concat([[WebI nspector.UIString("Other"), "Other"]]);
365
366 var userAgentSelectElement = fieldsetElement.createChild("select");
367 for (var i = 0; i < userAgents.length; ++i)
368 userAgentSelectElement.add(new Option(userAgents[i][0], userAgents[i ][1]));
369 userAgentSelectElement.selectedIndex = 0;
370
371 fieldsetElement.createChild("br");
372
373 var otherUserAgentElement = fieldsetElement.createChild("input");
374 otherUserAgentElement.type = "text";
375 otherUserAgentElement.value = otherUserAgentElement.title = WebInspector .overridesSupport.userAgentOverride();
376
377 /**
378 * @param {string} userAgent
379 */
380 function setUserAgentValue(userAgent)
381 {
382 WebInspector.overridesSupport.settings.userAgent.set(userAgent);
383 if (WebInspector.overridesSupport.isEmulateDeviceEnabled())
384 WebInspector.overridesSupport.settings.deviceUserAgent.set(userA gent);
385 }
386
387 function userAgentSelected()
388 {
389 var value = userAgentSelectElement.options[userAgentSelectElement.se lectedIndex].value;
390 if (value !== "Other") {
391 setUserAgentValue(value);
392 otherUserAgentElement.value = value;
393 otherUserAgentElement.title = value;
394 otherUserAgentElement.disabled = true;
395 } else {
396 otherUserAgentElement.disabled = false;
397 otherUserAgentElement.focus();
398 }
399 }
400
401 function settingChanged()
402 {
403 var deviceUserAgent = WebInspector.overridesSupport.isEmulateDeviceE nabled() ? WebInspector.overridesSupport.settings.deviceUserAgent.get() : "";
404 var value = deviceUserAgent || WebInspector.overridesSupport.setting s.userAgent.get();
405 var options = userAgentSelectElement.options;
406 var selectionRestored = false;
407 for (var i = 0; i < options.length; ++i) {
408 if (options[i].value === value) {
409 userAgentSelectElement.selectedIndex = i;
410 selectionRestored = true;
411 break;
412 }
413 }
414
415 otherUserAgentElement.disabled = selectionRestored;
416 if (!selectionRestored)
417 userAgentSelectElement.selectedIndex = options.length - 1;
418
419 if (otherUserAgentElement.value !== value) {
420 otherUserAgentElement.value = value;
421 otherUserAgentElement.title = value;
422 }
423 }
424
425 function textKeyDown(event)
426 {
427 if (isEnterKey(event))
428 textChanged();
429 }
430
431 function textDoubleClicked()
432 {
433 userAgentSelectElement.selectedIndex = userAgents.length - 1;
434 userAgentSelected();
435 }
436
437 function textChanged()
438 {
439 setUserAgentValue(otherUserAgentElement.value);
440 }
441
442 settingChanged();
443 for (var i = 0; i < settings.length; i++)
444 settings[i].addChangeListener(settingChanged);
445
446 userAgentSelectElement.addEventListener("change", userAgentSelected, fal se);
447 otherUserAgentElement.addEventListener("dblclick", textDoubleClicked, tr ue);
448 otherUserAgentElement.addEventListener("blur", textChanged, false);
449 otherUserAgentElement.addEventListener("keydown", textKeyDown, false);
450 }, 324 },
451 325
452 __proto__: WebInspector.OverridesView.Tab.prototype 326 __proto__: WebInspector.OverridesView.Tab.prototype
453 } 327 }
454 328
455 329
456 /** 330 /**
457 * @constructor 331 * @constructor
458 * @extends {WebInspector.OverridesView.Tab} 332 * @extends {WebInspector.OverridesView.Tab}
459 */ 333 */
460 WebInspector.OverridesView.SensorsTab = function() 334 WebInspector.OverridesView.SensorsTab = function()
461 { 335 {
462 var settings = [WebInspector.overridesSupport.settings.overrideGeolocation, WebInspector.overridesSupport.settings.overrideDeviceOrientation]; 336 var settings = [WebInspector.overridesSupport.settings.overrideGeolocation, WebInspector.overridesSupport.settings.overrideDeviceOrientation];
463 var predicates = !WebInspector.overridesSupport.hasTouchInputs() ? [this._is TouchEnabled.bind(this)] : []; 337 if (!WebInspector.overridesSupport.hasTouchInputs())
464 WebInspector.OverridesView.Tab.call(this, "sensors", WebInspector.UIString(" Sensors"), settings, predicates); 338 settings.push(WebInspector.overridesSupport.settings.emulateTouch);
339 WebInspector.OverridesView.Tab.call(this, "sensors", WebInspector.UIString(" Sensors"), settings);
465 340
466 this.element.classList.add("overrides-sensors"); 341 this.element.classList.add("overrides-sensors");
467 this.registerRequiredCSS("accelerometer.css"); 342 this.registerRequiredCSS("accelerometer.css");
468 if (!WebInspector.overridesSupport.hasTouchInputs()) 343 if (!WebInspector.overridesSupport.hasTouchInputs())
469 this.element.appendChild(this._createTouchCheckbox()); 344 this.element.appendChild(this._createSettingCheckbox(WebInspector.UIStri ng("Emulate touch screen"), WebInspector.overridesSupport.settings.emulateTouch, undefined));
470 this._appendGeolocationOverrideControl(); 345 this._appendGeolocationOverrideControl();
471 this._apendDeviceOrientationOverrideControl(); 346 this._apendDeviceOrientationOverrideControl();
472 } 347 }
473 348
474 WebInspector.OverridesView.SensorsTab.prototype = { 349 WebInspector.OverridesView.SensorsTab.prototype = {
475 /**
476 * @return {boolean}
477 */
478 _isTouchEnabled: function()
479 {
480 return WebInspector.overridesSupport.isTouchEmulationEnabled();
481 },
482
483 _onTouchEmulationChanged: function()
484 {
485 this.updateActiveState();
486 var enabled = WebInspector.overridesSupport.isTouchEmulationEnabled();
487 if (this._touchCheckbox.checked !== enabled)
488 this._touchCheckbox.checked = enabled;
489 },
490
491 /**
492 * @return {!Element}
493 */
494 _createTouchCheckbox: function()
495 {
496 var settings = [WebInspector.overridesSupport.settings.emulateDevice, We bInspector.settings.responsiveDesignEnabled, WebInspector.overridesSupport.setti ngs.deviceTouch];
497 for (var i = 0; i < settings.length; i++) {
498 settings[i].addChangeListener(this._onTouchEmulationChanged.bind(thi s));
499 settings[i].addChangeListener(WebInspector.overridesSupport.updateSe nsorsTouchToMatchDeviceTouch.bind(WebInspector.overridesSupport));
500 }
501 WebInspector.overridesSupport.settings.sensorsTouch.addChangeListener(th is._onTouchEmulationChanged.bind(this));
502
503 var input = document.createElement("input");
504 input.type = "checkbox";
505 input.name = WebInspector.UIString("Emulate touch screen");
506 this._touchCheckbox = input;
507
508 var label = document.createElement("label");
509 label.appendChild(input);
510 label.createTextChild(WebInspector.UIString("Emulate touch screen"));
511
512 function inputChanged()
513 {
514 var enabled = input.checked;
515 WebInspector.overridesSupport.settings.sensorsTouch.set(enabled);
516 if (WebInspector.overridesSupport.isEmulateDeviceEnabled())
517 WebInspector.overridesSupport.settings.deviceTouch.set(enabled);
518 }
519 input.addEventListener("change", inputChanged, false);
520
521 this._onTouchEmulationChanged();
522
523 return label;
524 },
525
526 _appendGeolocationOverrideControl: function() 350 _appendGeolocationOverrideControl: function()
527 { 351 {
528 const geolocationSetting = WebInspector.overridesSupport.settings.geoloc ationOverride.get(); 352 const geolocationSetting = WebInspector.overridesSupport.settings.geoloc ationOverride.get();
529 var geolocation = WebInspector.OverridesSupport.GeolocationPosition.pars eSetting(geolocationSetting); 353 var geolocation = WebInspector.OverridesSupport.GeolocationPosition.pars eSetting(geolocationSetting);
530 this.element.appendChild(this._createSettingCheckbox(WebInspector.UIStri ng("Emulate geolocation coordinates"), WebInspector.overridesSupport.settings.ov errideGeolocation, this._geolocationOverrideCheckboxClicked.bind(this))); 354 this.element.appendChild(this._createSettingCheckbox(WebInspector.UIStri ng("Emulate geolocation coordinates"), WebInspector.overridesSupport.settings.ov errideGeolocation, this._geolocationOverrideCheckboxClicked.bind(this)));
531 this.element.appendChild(this._createGeolocationOverrideElement(geolocat ion)); 355 this.element.appendChild(this._createGeolocationOverrideElement(geolocat ion));
532 this._geolocationOverrideCheckboxClicked(WebInspector.overridesSupport.s ettings.overrideGeolocation.get()); 356 this._geolocationOverrideCheckboxClicked(WebInspector.overridesSupport.s ettings.overrideGeolocation.get());
533 }, 357 },
534 358
535 /** 359 /**
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 597
774 __proto__ : WebInspector.OverridesView.Tab.prototype 598 __proto__ : WebInspector.OverridesView.Tab.prototype
775 } 599 }
776 600
777 /** @enum {string} */ 601 /** @enum {string} */
778 WebInspector.OverridesView.SensorsTab.DeviceOrientationModificationSource = { 602 WebInspector.OverridesView.SensorsTab.DeviceOrientationModificationSource = {
779 UserInput: "userInput", 603 UserInput: "userInput",
780 UserDrag: "userDrag", 604 UserDrag: "userDrag",
781 ResetButton: "resetButton" 605 ResetButton: "resetButton"
782 } 606 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/common/Settings.js ('k') | Source/devtools/front_end/main/AdvancedApp.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698