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

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

Issue 342443002: [DevTools] Ability to emulate touch or user agent, even when device emulation is turned off. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 }, 78 },
79 79
80 __proto__: WebInspector.VBox.prototype 80 __proto__: WebInspector.VBox.prototype
81 } 81 }
82 82
83 /** 83 /**
84 * @constructor 84 * @constructor
85 * @extends {WebInspector.VBox} 85 * @extends {WebInspector.VBox}
86 * @param {string} id 86 * @param {string} id
87 * @param {string} name 87 * @param {string} name
88 * @param {!Array.<!WebInspector.Setting>} settings 88 * @param {!Array.<!WebInspector.Setting|function():boolean>} settings
89 */ 89 */
90 WebInspector.OverridesView.Tab = function(id, name, settings) 90 WebInspector.OverridesView.Tab = function(id, name, settings)
91 { 91 {
92 WebInspector.VBox.call(this); 92 WebInspector.VBox.call(this);
93 this._id = id; 93 this._id = id;
94 this._name = name; 94 this._name = name;
95 this._settings = settings; 95 this._settings = settings;
96 for (var i = 0; i < settings.length; ++i) 96 for (var i = 0; i < settings.length; ++i) {
97 settings[i].addChangeListener(this._updateActiveState, this); 97 if (settings[i] instanceof WebInspector.Setting)
pfeldman 2014/06/17 11:42:43 What else could it be?
98 settings[i].addChangeListener(this.updateActiveState, this);
99 }
98 } 100 }
99 101
100 WebInspector.OverridesView.Tab.prototype = { 102 WebInspector.OverridesView.Tab.prototype = {
101 /** 103 /**
102 * @param {!WebInspector.TabbedPane} tabbedPane 104 * @param {!WebInspector.TabbedPane} tabbedPane
103 */ 105 */
104 appendAsTab: function(tabbedPane) 106 appendAsTab: function(tabbedPane)
105 { 107 {
106 this._tabbedPane = tabbedPane; 108 this._tabbedPane = tabbedPane;
107 tabbedPane.appendTab(this._id, this._name, this); 109 tabbedPane.appendTab(this._id, this._name, this);
108 this._updateActiveState(); 110 this.updateActiveState();
109 }, 111 },
110 112
111 _updateActiveState: function() 113 updateActiveState: function()
112 { 114 {
115 if (!this._tabbedPane)
116 return;
113 var active = false; 117 var active = false;
114 for (var i = 0; !active && i < this._settings.length; ++i) 118 for (var i = 0; !active && i < this._settings.length; ++i) {
115 active = this._settings[i].get(); 119 if (this._settings[i] instanceof WebInspector.Setting) {
pfeldman 2014/06/17 11:42:43 Lets not do this.
dgozman 2014/06/17 12:02:20 Fixed.
120 active = this._settings[i].get();
121 } else {
122 var getter = /** @type function() */ (this._settings[i]);
123 active = getter();
124 }
125 }
116 this._tabbedPane.element.classList.toggle("overrides-activate-" + this._ id, active); 126 this._tabbedPane.element.classList.toggle("overrides-activate-" + this._ id, active);
117 this._tabbedPane.changeTabTitle(this._id, active ? this._name + " \u2713 " : this._name); 127 this._tabbedPane.changeTabTitle(this._id, active ? this._name + " \u2713 " : this._name);
118 }, 128 },
119 129
120 /** 130 /**
121 * @param {string} name 131 * @param {string} name
122 * @param {!WebInspector.Setting} setting 132 * @param {!WebInspector.Setting} setting
123 * @param {function(boolean)=} callback 133 * @param {function(boolean)=} callback
124 */ 134 */
125 _createSettingCheckbox: function(name, setting, callback) 135 _createSettingCheckbox: function(name, setting, callback)
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 __proto__: WebInspector.OverridesView.Tab.prototype 281 __proto__: WebInspector.OverridesView.Tab.prototype
272 } 282 }
273 283
274 284
275 /** 285 /**
276 * @constructor 286 * @constructor
277 * @extends {WebInspector.OverridesView.Tab} 287 * @extends {WebInspector.OverridesView.Tab}
278 */ 288 */
279 WebInspector.OverridesView.NetworkTab = function() 289 WebInspector.OverridesView.NetworkTab = function()
280 { 290 {
281 WebInspector.OverridesView.Tab.call(this, "network", WebInspector.UIString(" Network"), [WebInspector.overridesSupport.settings.emulateNetworkConditions, Web Inspector.overridesSupport.settings.overrideUserAgent]); 291 WebInspector.OverridesView.Tab.call(this, "network", WebInspector.UIString(" Network"), [WebInspector.overridesSupport.settings.emulateNetworkConditions, thi s._isUserAgentOverrideEnabled.bind(this)]);
282 this.element.classList.add("overrides-network"); 292 this.element.classList.add("overrides-network");
283 this.element.appendChild(this._createSettingCheckbox(WebInspector.UIString(" Limit network throughput"), WebInspector.overridesSupport.settings.emulateNetwor kConditions)); 293 this.element.appendChild(this._createSettingCheckbox(WebInspector.UIString(" Limit network throughput"), WebInspector.overridesSupport.settings.emulateNetwor kConditions));
284 this.element.appendChild(this._createNetworkConditionsElement()); 294 this.element.appendChild(this._createNetworkConditionsElement());
285 this.element.appendChild(this._createSettingCheckbox(WebInspector.UIString(" Spoof user agent"), WebInspector.overridesSupport.settings.overrideUserAgent)); 295 this._createUserAgentSection();
286 this.element.appendChild(this._createUserAgentSelectRowElement());
287 } 296 }
288 297
289 WebInspector.OverridesView.NetworkTab.prototype = { 298 WebInspector.OverridesView.NetworkTab.prototype = {
290 /** 299 /**
291 * @return {!Element} 300 * @return {!Element}
292 */ 301 */
293 _createNetworkConditionsElement: function() 302 _createNetworkConditionsElement: function()
294 { 303 {
295 var fieldsetElement = WebInspector.SettingsUI.createSettingFieldset(WebI nspector.overridesSupport.settings.emulateNetworkConditions); 304 var fieldsetElement = WebInspector.SettingsUI.createSettingFieldset(WebI nspector.overridesSupport.settings.emulateNetworkConditions);
296 305
297 var networkThroughput = WebInspector.overridesSupport.createNetworkThrou ghputSelect(document); 306 var networkThroughput = WebInspector.overridesSupport.createNetworkThrou ghputSelect(document);
298 fieldsetElement.appendChild(networkThroughput); 307 fieldsetElement.appendChild(networkThroughput);
299 fieldsetElement.createChild("br"); 308 fieldsetElement.createChild("br");
300 309
301 var networkDomains = WebInspector.SettingsUI.createSettingInputField("Fo r domains:", WebInspector.overridesSupport.settings.networkConditionsDomains, fa lse, 0, "", WebInspector.OverridesSupport.networkDomainsValidator, false); 310 var networkDomains = WebInspector.SettingsUI.createSettingInputField("Fo r domains:", WebInspector.overridesSupport.settings.networkConditionsDomains, fa lse, 0, "", WebInspector.OverridesSupport.networkDomainsValidator, false);
302 networkDomains.querySelector("input").placeholder = WebInspector.UIStrin g("Leave empty to limit all domains"); 311 networkDomains.querySelector("input").placeholder = WebInspector.UIStrin g("Leave empty to limit all domains");
303 fieldsetElement.appendChild(networkDomains); 312 fieldsetElement.appendChild(networkDomains);
304 313
305 return fieldsetElement; 314 return fieldsetElement;
306 }, 315 },
307 316
308 /** 317 /**
309 * @return {!Element} 318 * @return {boolean}
310 */ 319 */
311 _createUserAgentSelectRowElement: function() 320 _isUserAgentOverrideEnabled: function()
312 { 321 {
313 var fieldsetElement = WebInspector.SettingsUI.createSettingFieldset(WebI nspector.overridesSupport.settings.overrideUserAgent); 322 return !!WebInspector.overridesSupport.userAgentOverride();
314 var userAgentSelectAndInput = WebInspector.overridesSupport.createUserAg entSelectAndInput(document); 323 },
315 fieldsetElement.appendChild(userAgentSelectAndInput.select); 324
325 _onUserAgentOverrideEnabledChanged: function()
326 {
327 this.updateActiveState();
328 var enabled = !!WebInspector.overridesSupport.userAgentOverride();
329 if (this._userAgentCheckbox.checked !== enabled)
330 this._userAgentCheckbox.checked = enabled;
331 this._userAgentFieldset.disabled = !enabled;
332 },
333
334 _updateUserAgentOnDeviceUserAgentChanged: function()
pfeldman 2014/06/17 11:42:43 Looking at the code this belongs to the OverridesS
dgozman 2014/06/17 12:02:20 Done.
335 {
336 var userAgent = WebInspector.overridesSupport.settings.deviceUserAgent.g et();
337 if (WebInspector.overridesSupport.isEmulateDeviceEnabled() && userAgent && WebInspector.overridesSupport.settings.userAgent.get() !== userAgent)
338 WebInspector.overridesSupport.settings.userAgent.set(userAgent);
339 var enabled = WebInspector.overridesSupport.isEmulateDeviceEnabled() && !!WebInspector.overridesSupport.settings.deviceUserAgent.get();
340 if (WebInspector.overridesSupport.settings.overrideUserAgent.get() !== e nabled)
341 WebInspector.overridesSupport.settings.overrideUserAgent.set(enabled );
342 },
343
344 /**
345 * @param {boolean} enabled
346 */
347 _setOverrideUserAgentEnabled: function(enabled)
pfeldman 2014/06/17 11:42:43 ditto
dgozman 2014/06/17 12:02:20 Done.
348 {
349 WebInspector.overridesSupport.settings.overrideUserAgent.set(enabled);
350 if (WebInspector.overridesSupport.isEmulateDeviceEnabled())
351 WebInspector.overridesSupport.settings.deviceUserAgent.set(enabled ? WebInspector.overridesSupport.settings.userAgent.get() : "");
352 },
353
354 /**
355 * @param {string} userAgent
356 */
357 _setUserAgentValue: function(userAgent)
358 {
359 WebInspector.overridesSupport.settings.userAgent.set(userAgent);
360 if (WebInspector.overridesSupport.isEmulateDeviceEnabled())
361 WebInspector.overridesSupport.settings.deviceUserAgent.set(userAgent );
362 },
363
364 _createUserAgentSection: function()
365 {
366 var settings = [WebInspector.overridesSupport.settings.emulateDevice, We bInspector.settings.responsiveDesign.enabled, WebInspector.overridesSupport.sett ings.deviceUserAgent];
367 for (var i = 0; i < settings.length; i++) {
368 settings[i].addChangeListener(this._onUserAgentOverrideEnabledChange d.bind(this));
369 settings[i].addChangeListener(this._updateUserAgentOnDeviceUserAgent Changed.bind(this));
370 }
371 WebInspector.overridesSupport.settings.overrideUserAgent.addChangeListen er(this._onUserAgentOverrideEnabledChanged.bind(this));
372 WebInspector.overridesSupport.settings.userAgent.addChangeListener(this. _onUserAgentOverrideEnabledChanged.bind(this));
373
374 var label = this.element.createChild("label");
375 var checkbox = label.createChild("input");
376 checkbox.type = "checkbox";
377 checkbox.name = WebInspector.UIString("Spoof user agent");
378 label.createTextChild(WebInspector.UIString("Spoof user agent"));
379
380 /**
381 * @this {!WebInspector.OverridesView.NetworkTab}
382 */
383 function checkboxChanged()
384 {
385 this._setOverrideUserAgentEnabled(checkbox.checked);
386 }
387 checkbox.addEventListener("change", checkboxChanged.bind(this), false);
388
389 var fieldsetElement = this.element.createChild("fieldset");
390 this._createUserAgentSelectAndInput(fieldsetElement, settings.concat([We bInspector.overridesSupport.settings.userAgent]));
391
392 this._userAgentFieldset = fieldsetElement;
393 this._userAgentCheckbox = checkbox;
394 this._onUserAgentOverrideEnabledChanged();
395 },
396
397 /**
398 * @param {!Element} fieldsetElement
399 * @param {!Array.<!WebInspector.Setting>} settings
400 */
401 _createUserAgentSelectAndInput: function(fieldsetElement, settings)
402 {
403 var userAgents = WebInspector.OverridesSupport._userAgents.concat([[WebI nspector.UIString("Other"), "Other"]]);
404
405 var userAgentSelectElement = fieldsetElement.createChild("select");
406 for (var i = 0; i < userAgents.length; ++i)
407 userAgentSelectElement.add(new Option(userAgents[i][0], userAgents[i ][1]));
408 userAgentSelectElement.selectedIndex = 0;
409
316 fieldsetElement.createChild("br"); 410 fieldsetElement.createChild("br");
317 fieldsetElement.appendChild(userAgentSelectAndInput.input); 411
318 return fieldsetElement; 412 var otherUserAgentElement = fieldsetElement.createChild("input");
413 otherUserAgentElement.type = "text";
414 otherUserAgentElement.value = otherUserAgentElement.title = WebInspector .overridesSupport.userAgentOverride();
415
416 /**
417 * @this {!WebInspector.OverridesView.NetworkTab}
418 */
419 function userAgentSelected()
420 {
421 var value = userAgentSelectElement.options[userAgentSelectElement.se lectedIndex].value;
422 if (value !== "Other") {
423 this._setUserAgentValue(value);
424 otherUserAgentElement.value = value;
425 otherUserAgentElement.title = value;
426 otherUserAgentElement.disabled = true;
427 } else {
428 otherUserAgentElement.disabled = false;
429 otherUserAgentElement.focus();
430 }
431 }
432 var userAgentSelectedBound = userAgentSelected.bind(this);
433
434 function settingChanged()
435 {
436 var deviceUserAgent = WebInspector.overridesSupport.isEmulateDeviceE nabled() ? WebInspector.overridesSupport.settings.deviceUserAgent.get() : "";
437 var value = deviceUserAgent || WebInspector.overridesSupport.setting s.userAgent.get();
438 var options = userAgentSelectElement.options;
439 var selectionRestored = false;
440 for (var i = 0; i < options.length; ++i) {
441 if (options[i].value === value) {
442 userAgentSelectElement.selectedIndex = i;
443 selectionRestored = true;
444 break;
445 }
446 }
447
448 otherUserAgentElement.disabled = selectionRestored;
449 if (!selectionRestored)
450 userAgentSelectElement.selectedIndex = options.length - 1;
451
452 if (otherUserAgentElement.value !== value) {
453 otherUserAgentElement.value = value;
454 otherUserAgentElement.title = value;
455 }
456 }
457
458 function textKeyDown(event)
459 {
460 if (isEnterKey(event))
461 textChangedBound();
462 }
463
464 function textDoubleClicked()
465 {
466 userAgentSelectElement.selectedIndex = userAgents.length - 1;
467 userAgentSelectedBound();
468 }
469
470 /**
471 * @this {!WebInspector.OverridesView.NetworkTab}
472 */
473 function textChanged()
474 {
475 this._setUserAgentValue(otherUserAgentElement.value);
476 }
477 var textChangedBound = textChanged.bind(this);
478
479 settingChanged();
480 for (var i = 0; i < settings.length; i++)
481 settings[i].addChangeListener(settingChanged);
482
483 userAgentSelectElement.addEventListener("change", userAgentSelectedBound , false);
484 otherUserAgentElement.addEventListener("dblclick", textDoubleClicked, tr ue);
485 otherUserAgentElement.addEventListener("blur", textChangedBound, false);
486 otherUserAgentElement.addEventListener("keydown", textKeyDown, false);
319 }, 487 },
320 488
321 __proto__: WebInspector.OverridesView.Tab.prototype 489 __proto__: WebInspector.OverridesView.Tab.prototype
322 } 490 }
323 491
324 492
325 /** 493 /**
326 * @constructor 494 * @constructor
327 * @extends {WebInspector.OverridesView.Tab} 495 * @extends {WebInspector.OverridesView.Tab}
328 */ 496 */
329 WebInspector.OverridesView.SensorsTab = function() 497 WebInspector.OverridesView.SensorsTab = function()
330 { 498 {
331 var settings = [WebInspector.overridesSupport.settings.overrideGeolocation, WebInspector.overridesSupport.settings.overrideDeviceOrientation]; 499 var settings = [WebInspector.overridesSupport.settings.overrideGeolocation, WebInspector.overridesSupport.settings.overrideDeviceOrientation];
332 if (!WebInspector.overridesSupport.hasTouchInputs() && !WebInspector.overrid esSupport.responsiveDesignAvailable()) 500 if (!WebInspector.overridesSupport.hasTouchInputs())
333 settings.push(WebInspector.overridesSupport.settings.emulateTouchEvents) ; 501 settings.push(this._isTouchEnabled.bind(this));
334 WebInspector.OverridesView.Tab.call(this, "sensors", WebInspector.UIString(" Sensors"), settings); 502 WebInspector.OverridesView.Tab.call(this, "sensors", WebInspector.UIString(" Sensors"), settings);
335 503
336 this.element.classList.add("overrides-sensors"); 504 this.element.classList.add("overrides-sensors");
337 this.registerRequiredCSS("accelerometer.css"); 505 this.registerRequiredCSS("accelerometer.css");
338 if (!WebInspector.overridesSupport.hasTouchInputs() && !WebInspector.overrid esSupport.responsiveDesignAvailable()) 506 if (!WebInspector.overridesSupport.hasTouchInputs())
339 this.element.appendChild(this._createSettingCheckbox(WebInspector.UIStri ng("Emulate touch screen"), WebInspector.overridesSupport.settings.emulateTouchE vents)); 507 this.element.appendChild(this._createTouchCheckbox());
340 this._appendGeolocationOverrideControl(); 508 this._appendGeolocationOverrideControl();
341 this._apendDeviceOrientationOverrideControl(); 509 this._apendDeviceOrientationOverrideControl();
342 } 510 }
343 511
344 WebInspector.OverridesView.SensorsTab.prototype = { 512 WebInspector.OverridesView.SensorsTab.prototype = {
513 /**
514 * @return {boolean}
515 */
516 _isTouchEnabled: function()
517 {
518 return WebInspector.overridesSupport.isTouchEmulationEnabled();
519 },
520
521 _onTouchEmulationChanged: function()
522 {
523 this.updateActiveState();
524 var enabled = WebInspector.overridesSupport.isTouchEmulationEnabled();
525 if (this._touchCheckbox.checked !== enabled)
526 this._touchCheckbox.checked = enabled;
527 },
528
529 _updateSensorsTouchOnDeviceTouchChanged: function()
530 {
531 var enabled = WebInspector.overridesSupport.isEmulateDeviceEnabled() && WebInspector.overridesSupport.settings.deviceTouch.get();
532 if (WebInspector.overridesSupport.settings.sensorsTouch.get() !== enable d)
533 WebInspector.overridesSupport.settings.sensorsTouch.set(enabled);
534 },
535
536 /**
537 * @return {!Element}
538 */
539 _createTouchCheckbox: function()
540 {
541 var settings = [WebInspector.overridesSupport.settings.emulateDevice, We bInspector.settings.responsiveDesign.enabled, WebInspector.overridesSupport.sett ings.deviceTouch];
542 for (var i = 0; i < settings.length; i++) {
543 settings[i].addChangeListener(this._onTouchEmulationChanged.bind(thi s));
544 settings[i].addChangeListener(this._updateSensorsTouchOnDeviceTouchC hanged.bind(this));
545 }
546 WebInspector.overridesSupport.settings.sensorsTouch.addChangeListener(th is._onTouchEmulationChanged.bind(this));
547
548 var input = document.createElement("input");
549 input.type = "checkbox";
550 input.name = WebInspector.UIString("Emulate touch screen");
551 this._touchCheckbox = input;
552
553 var label = document.createElement("label");
554 label.appendChild(input);
555 label.createTextChild(WebInspector.UIString("Emulate touch screen"));
556
557 function inputChanged()
558 {
559 var enabled = input.checked;
560 WebInspector.overridesSupport.settings.sensorsTouch.set(enabled);
561 if (WebInspector.overridesSupport.isEmulateDeviceEnabled())
562 WebInspector.overridesSupport.settings.deviceTouch.set(enabled);
563 }
564 input.addEventListener("change", inputChanged, false);
565
566 this._onTouchEmulationChanged();
567
568 return label;
569 },
570
345 _appendGeolocationOverrideControl: function() 571 _appendGeolocationOverrideControl: function()
346 { 572 {
347 const geolocationSetting = WebInspector.overridesSupport.settings.geoloc ationOverride.get(); 573 const geolocationSetting = WebInspector.overridesSupport.settings.geoloc ationOverride.get();
348 var geolocation = WebInspector.OverridesSupport.GeolocationPosition.pars eSetting(geolocationSetting); 574 var geolocation = WebInspector.OverridesSupport.GeolocationPosition.pars eSetting(geolocationSetting);
349 this.element.appendChild(this._createSettingCheckbox(WebInspector.UIStri ng("Emulate geolocation coordinates"), WebInspector.overridesSupport.settings.ov errideGeolocation, this._geolocationOverrideCheckboxClicked.bind(this))); 575 this.element.appendChild(this._createSettingCheckbox(WebInspector.UIStri ng("Emulate geolocation coordinates"), WebInspector.overridesSupport.settings.ov errideGeolocation, this._geolocationOverrideCheckboxClicked.bind(this)));
350 this.element.appendChild(this._createGeolocationOverrideElement(geolocat ion)); 576 this.element.appendChild(this._createGeolocationOverrideElement(geolocat ion));
351 this._geolocationOverrideCheckboxClicked(WebInspector.overridesSupport.s ettings.overrideGeolocation.get()); 577 this._geolocationOverrideCheckboxClicked(WebInspector.overridesSupport.s ettings.overrideGeolocation.get());
352 }, 578 },
353 579
354 /** 580 /**
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 818
593 __proto__ : WebInspector.OverridesView.Tab.prototype 819 __proto__ : WebInspector.OverridesView.Tab.prototype
594 } 820 }
595 821
596 /** @enum {string} */ 822 /** @enum {string} */
597 WebInspector.OverridesView.SensorsTab.DeviceOrientationModificationSource = { 823 WebInspector.OverridesView.SensorsTab.DeviceOrientationModificationSource = {
598 UserInput: "userInput", 824 UserInput: "userInput",
599 UserDrag: "userDrag", 825 UserDrag: "userDrag",
600 ResetButton: "resetButton" 826 ResetButton: "resetButton"
601 } 827 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/ResponsiveDesignView.js ('k') | Source/devtools/front_end/sdk/OverridesSupport.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698