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

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: 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
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>} settings
89 * @param {!Array.<function():boolean>=} predicates
89 */ 90 */
90 WebInspector.OverridesView.Tab = function(id, name, settings) 91 WebInspector.OverridesView.Tab = function(id, name, settings, predicates)
91 { 92 {
92 WebInspector.VBox.call(this); 93 WebInspector.VBox.call(this);
93 this._id = id; 94 this._id = id;
94 this._name = name; 95 this._name = name;
95 this._settings = settings; 96 this._settings = settings;
97 this._predicates = predicates || [];
96 for (var i = 0; i < settings.length; ++i) 98 for (var i = 0; i < settings.length; ++i)
97 settings[i].addChangeListener(this._updateActiveState, this); 99 settings[i].addChangeListener(this.updateActiveState, this);
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 active = this._settings[i].get();
120 for (var i = 0; !active && i < this._predicates.length; ++i)
121 active = this._predicates[i]();
116 this._tabbedPane.element.classList.toggle("overrides-activate-" + this._ id, active); 122 this._tabbedPane.element.classList.toggle("overrides-activate-" + this._ id, active);
117 this._tabbedPane.changeTabTitle(this._id, active ? this._name + " \u2713 " : this._name); 123 this._tabbedPane.changeTabTitle(this._id, active ? this._name + " \u2713 " : this._name);
118 }, 124 },
119 125
120 /** 126 /**
121 * @param {string} name 127 * @param {string} name
122 * @param {!WebInspector.Setting} setting 128 * @param {!WebInspector.Setting} setting
123 * @param {function(boolean)=} callback 129 * @param {function(boolean)=} callback
124 */ 130 */
125 _createSettingCheckbox: function(name, setting, callback) 131 _createSettingCheckbox: function(name, setting, callback)
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 __proto__: WebInspector.OverridesView.Tab.prototype 277 __proto__: WebInspector.OverridesView.Tab.prototype
272 } 278 }
273 279
274 280
275 /** 281 /**
276 * @constructor 282 * @constructor
277 * @extends {WebInspector.OverridesView.Tab} 283 * @extends {WebInspector.OverridesView.Tab}
278 */ 284 */
279 WebInspector.OverridesView.NetworkTab = function() 285 WebInspector.OverridesView.NetworkTab = function()
280 { 286 {
281 WebInspector.OverridesView.Tab.call(this, "network", WebInspector.UIString(" Network"), [WebInspector.overridesSupport.settings.emulateNetworkConditions, Web Inspector.overridesSupport.settings.overrideUserAgent]); 287 WebInspector.OverridesView.Tab.call(this, "network", WebInspector.UIString(" Network"), [WebInspector.overridesSupport.settings.emulateNetworkConditions], [t his._isUserAgentOverrideEnabled.bind(this)]);
282 this.element.classList.add("overrides-network"); 288 this.element.classList.add("overrides-network");
283 this.element.appendChild(this._createSettingCheckbox(WebInspector.UIString(" Limit network throughput"), WebInspector.overridesSupport.settings.emulateNetwor kConditions)); 289 this.element.appendChild(this._createSettingCheckbox(WebInspector.UIString(" Limit network throughput"), WebInspector.overridesSupport.settings.emulateNetwor kConditions));
284 this.element.appendChild(this._createNetworkConditionsElement()); 290 this.element.appendChild(this._createNetworkConditionsElement());
285 this.element.appendChild(this._createSettingCheckbox(WebInspector.UIString(" Spoof user agent"), WebInspector.overridesSupport.settings.overrideUserAgent)); 291 this._createUserAgentSection();
286 this.element.appendChild(this._createUserAgentSelectRowElement());
287 } 292 }
288 293
289 WebInspector.OverridesView.NetworkTab.prototype = { 294 WebInspector.OverridesView.NetworkTab.prototype = {
290 /** 295 /**
291 * @return {!Element} 296 * @return {!Element}
292 */ 297 */
293 _createNetworkConditionsElement: function() 298 _createNetworkConditionsElement: function()
294 { 299 {
295 var fieldsetElement = WebInspector.SettingsUI.createSettingFieldset(WebI nspector.overridesSupport.settings.emulateNetworkConditions); 300 var fieldsetElement = WebInspector.SettingsUI.createSettingFieldset(WebI nspector.overridesSupport.settings.emulateNetworkConditions);
296 301
297 var networkThroughput = WebInspector.overridesSupport.createNetworkThrou ghputSelect(document); 302 var networkThroughput = WebInspector.overridesSupport.createNetworkThrou ghputSelect(document);
298 fieldsetElement.appendChild(networkThroughput); 303 fieldsetElement.appendChild(networkThroughput);
299 fieldsetElement.createChild("br"); 304 fieldsetElement.createChild("br");
300 305
301 var networkDomains = WebInspector.SettingsUI.createSettingInputField("Fo r domains:", WebInspector.overridesSupport.settings.networkConditionsDomains, fa lse, 0, "", WebInspector.OverridesSupport.networkDomainsValidator, false); 306 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"); 307 networkDomains.querySelector("input").placeholder = WebInspector.UIStrin g("Leave empty to limit all domains");
303 fieldsetElement.appendChild(networkDomains); 308 fieldsetElement.appendChild(networkDomains);
304 309
305 return fieldsetElement; 310 return fieldsetElement;
306 }, 311 },
307 312
308 /** 313 /**
309 * @return {!Element} 314 * @return {boolean}
310 */ 315 */
311 _createUserAgentSelectRowElement: function() 316 _isUserAgentOverrideEnabled: function()
312 { 317 {
313 var fieldsetElement = WebInspector.SettingsUI.createSettingFieldset(WebI nspector.overridesSupport.settings.overrideUserAgent); 318 return !!WebInspector.overridesSupport.userAgentOverride();
314 var userAgentSelectAndInput = WebInspector.overridesSupport.createUserAg entSelectAndInput(document); 319 },
315 fieldsetElement.appendChild(userAgentSelectAndInput.select); 320
321 _onUserAgentOverrideEnabledChanged: function()
322 {
323 this.updateActiveState();
324 var enabled = !!WebInspector.overridesSupport.userAgentOverride();
325 if (this._userAgentCheckbox.checked !== enabled)
326 this._userAgentCheckbox.checked = enabled;
327 this._userAgentFieldset.disabled = !enabled;
328 },
329
330 _createUserAgentSection: function()
331 {
332 var settings = [WebInspector.overridesSupport.settings.emulateDevice, We bInspector.settings.responsiveDesign.enabled, WebInspector.overridesSupport.sett ings.deviceUserAgent];
333 for (var i = 0; i < settings.length; i++) {
334 settings[i].addChangeListener(this._onUserAgentOverrideEnabledChange d.bind(this));
335 settings[i].addChangeListener(WebInspector.overridesSupport.updateUs erAgentToMatchDeviceUserAgent.bind(WebInspector.overridesSupport));
336 }
337 WebInspector.overridesSupport.settings.overrideUserAgent.addChangeListen er(this._onUserAgentOverrideEnabledChanged.bind(this));
338 WebInspector.overridesSupport.settings.userAgent.addChangeListener(this. _onUserAgentOverrideEnabledChanged.bind(this));
339
340 var label = this.element.createChild("label");
341 var checkbox = label.createChild("input");
342 checkbox.type = "checkbox";
343 checkbox.name = WebInspector.UIString("Spoof user agent");
344 label.createTextChild(WebInspector.UIString("Spoof user agent"));
345
346 function checkboxChanged()
347 {
348 var enabled = checkbox.checked;
349 WebInspector.overridesSupport.settings.overrideUserAgent.set(enabled );
350 if (WebInspector.overridesSupport.isEmulateDeviceEnabled())
351 WebInspector.overridesSupport.settings.deviceUserAgent.set(enabl ed ? WebInspector.overridesSupport.settings.userAgent.get() : "");
352 }
353 checkbox.addEventListener("change", checkboxChanged, false);
354
355 var fieldsetElement = this.element.createChild("fieldset");
356 this._createUserAgentSelectAndInput(fieldsetElement, settings.concat([We bInspector.overridesSupport.settings.userAgent]));
357
358 this._userAgentFieldset = fieldsetElement;
359 this._userAgentCheckbox = checkbox;
360 this._onUserAgentOverrideEnabledChanged();
361 },
362
363 /**
364 * @param {!Element} fieldsetElement
365 * @param {!Array.<!WebInspector.Setting>} settings
366 */
367 _createUserAgentSelectAndInput: function(fieldsetElement, settings)
368 {
369 var userAgents = WebInspector.OverridesSupport._userAgents.concat([[WebI nspector.UIString("Other"), "Other"]]);
370
371 var userAgentSelectElement = fieldsetElement.createChild("select");
372 for (var i = 0; i < userAgents.length; ++i)
373 userAgentSelectElement.add(new Option(userAgents[i][0], userAgents[i ][1]));
374 userAgentSelectElement.selectedIndex = 0;
375
316 fieldsetElement.createChild("br"); 376 fieldsetElement.createChild("br");
317 fieldsetElement.appendChild(userAgentSelectAndInput.input); 377
318 return fieldsetElement; 378 var otherUserAgentElement = fieldsetElement.createChild("input");
379 otherUserAgentElement.type = "text";
380 otherUserAgentElement.value = otherUserAgentElement.title = WebInspector .overridesSupport.userAgentOverride();
381
382 /**
383 * @param {string} userAgent
384 */
385 function setUserAgentValue(userAgent)
386 {
387 WebInspector.overridesSupport.settings.userAgent.set(userAgent);
388 if (WebInspector.overridesSupport.isEmulateDeviceEnabled())
389 WebInspector.overridesSupport.settings.deviceUserAgent.set(userA gent);
390 }
391
392 function userAgentSelected()
393 {
394 var value = userAgentSelectElement.options[userAgentSelectElement.se lectedIndex].value;
395 if (value !== "Other") {
396 setUserAgentValue(value);
397 otherUserAgentElement.value = value;
398 otherUserAgentElement.title = value;
399 otherUserAgentElement.disabled = true;
400 } else {
401 otherUserAgentElement.disabled = false;
402 otherUserAgentElement.focus();
403 }
404 }
405
406 function settingChanged()
407 {
408 var deviceUserAgent = WebInspector.overridesSupport.isEmulateDeviceE nabled() ? WebInspector.overridesSupport.settings.deviceUserAgent.get() : "";
409 var value = deviceUserAgent || WebInspector.overridesSupport.setting s.userAgent.get();
410 var options = userAgentSelectElement.options;
411 var selectionRestored = false;
412 for (var i = 0; i < options.length; ++i) {
413 if (options[i].value === value) {
414 userAgentSelectElement.selectedIndex = i;
415 selectionRestored = true;
416 break;
417 }
418 }
419
420 otherUserAgentElement.disabled = selectionRestored;
421 if (!selectionRestored)
422 userAgentSelectElement.selectedIndex = options.length - 1;
423
424 if (otherUserAgentElement.value !== value) {
425 otherUserAgentElement.value = value;
426 otherUserAgentElement.title = value;
427 }
428 }
429
430 function textKeyDown(event)
431 {
432 if (isEnterKey(event))
433 textChanged();
434 }
435
436 function textDoubleClicked()
437 {
438 userAgentSelectElement.selectedIndex = userAgents.length - 1;
439 userAgentSelected();
440 }
441
442 function textChanged()
443 {
444 setUserAgentValue(otherUserAgentElement.value);
445 }
446
447 settingChanged();
448 for (var i = 0; i < settings.length; i++)
449 settings[i].addChangeListener(settingChanged);
450
451 userAgentSelectElement.addEventListener("change", userAgentSelected, fal se);
452 otherUserAgentElement.addEventListener("dblclick", textDoubleClicked, tr ue);
453 otherUserAgentElement.addEventListener("blur", textChanged, false);
454 otherUserAgentElement.addEventListener("keydown", textKeyDown, false);
319 }, 455 },
320 456
321 __proto__: WebInspector.OverridesView.Tab.prototype 457 __proto__: WebInspector.OverridesView.Tab.prototype
322 } 458 }
323 459
324 460
325 /** 461 /**
326 * @constructor 462 * @constructor
327 * @extends {WebInspector.OverridesView.Tab} 463 * @extends {WebInspector.OverridesView.Tab}
328 */ 464 */
329 WebInspector.OverridesView.SensorsTab = function() 465 WebInspector.OverridesView.SensorsTab = function()
330 { 466 {
331 var settings = [WebInspector.overridesSupport.settings.overrideGeolocation, WebInspector.overridesSupport.settings.overrideDeviceOrientation]; 467 var settings = [WebInspector.overridesSupport.settings.overrideGeolocation, WebInspector.overridesSupport.settings.overrideDeviceOrientation];
332 if (!WebInspector.overridesSupport.hasTouchInputs() && !WebInspector.overrid esSupport.responsiveDesignAvailable()) 468 var predicates = !WebInspector.overridesSupport.hasTouchInputs() ? [this._is TouchEnabled.bind(this)] : [];
333 settings.push(WebInspector.overridesSupport.settings.emulateTouchEvents) ; 469 WebInspector.OverridesView.Tab.call(this, "sensors", WebInspector.UIString(" Sensors"), settings, predicates);
334 WebInspector.OverridesView.Tab.call(this, "sensors", WebInspector.UIString(" Sensors"), settings);
335 470
336 this.element.classList.add("overrides-sensors"); 471 this.element.classList.add("overrides-sensors");
337 this.registerRequiredCSS("accelerometer.css"); 472 this.registerRequiredCSS("accelerometer.css");
338 if (!WebInspector.overridesSupport.hasTouchInputs() && !WebInspector.overrid esSupport.responsiveDesignAvailable()) 473 if (!WebInspector.overridesSupport.hasTouchInputs())
339 this.element.appendChild(this._createSettingCheckbox(WebInspector.UIStri ng("Emulate touch screen"), WebInspector.overridesSupport.settings.emulateTouchE vents)); 474 this.element.appendChild(this._createTouchCheckbox());
340 this._appendGeolocationOverrideControl(); 475 this._appendGeolocationOverrideControl();
341 this._apendDeviceOrientationOverrideControl(); 476 this._apendDeviceOrientationOverrideControl();
342 } 477 }
343 478
344 WebInspector.OverridesView.SensorsTab.prototype = { 479 WebInspector.OverridesView.SensorsTab.prototype = {
480 /**
481 * @return {boolean}
482 */
483 _isTouchEnabled: function()
484 {
485 return WebInspector.overridesSupport.isTouchEmulationEnabled();
486 },
487
488 _onTouchEmulationChanged: function()
489 {
490 this.updateActiveState();
491 var enabled = WebInspector.overridesSupport.isTouchEmulationEnabled();
492 if (this._touchCheckbox.checked !== enabled)
493 this._touchCheckbox.checked = enabled;
494 },
495
496 /**
497 * @return {!Element}
498 */
499 _createTouchCheckbox: function()
500 {
501 var settings = [WebInspector.overridesSupport.settings.emulateDevice, We bInspector.settings.responsiveDesign.enabled, WebInspector.overridesSupport.sett ings.deviceTouch];
502 for (var i = 0; i < settings.length; i++) {
503 settings[i].addChangeListener(this._onTouchEmulationChanged.bind(thi s));
504 settings[i].addChangeListener(WebInspector.overridesSupport.updateSe nsorsTouchToMatchDeviceTouch.bind(WebInspector.overridesSupport));
505 }
506 WebInspector.overridesSupport.settings.sensorsTouch.addChangeListener(th is._onTouchEmulationChanged.bind(this));
507
508 var input = document.createElement("input");
509 input.type = "checkbox";
510 input.name = WebInspector.UIString("Emulate touch screen");
511 this._touchCheckbox = input;
512
513 var label = document.createElement("label");
514 label.appendChild(input);
515 label.createTextChild(WebInspector.UIString("Emulate touch screen"));
516
517 function inputChanged()
518 {
519 var enabled = input.checked;
520 WebInspector.overridesSupport.settings.sensorsTouch.set(enabled);
521 if (WebInspector.overridesSupport.isEmulateDeviceEnabled())
522 WebInspector.overridesSupport.settings.deviceTouch.set(enabled);
523 }
524 input.addEventListener("change", inputChanged, false);
525
526 this._onTouchEmulationChanged();
527
528 return label;
529 },
530
345 _appendGeolocationOverrideControl: function() 531 _appendGeolocationOverrideControl: function()
346 { 532 {
347 const geolocationSetting = WebInspector.overridesSupport.settings.geoloc ationOverride.get(); 533 const geolocationSetting = WebInspector.overridesSupport.settings.geoloc ationOverride.get();
348 var geolocation = WebInspector.OverridesSupport.GeolocationPosition.pars eSetting(geolocationSetting); 534 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))); 535 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)); 536 this.element.appendChild(this._createGeolocationOverrideElement(geolocat ion));
351 this._geolocationOverrideCheckboxClicked(WebInspector.overridesSupport.s ettings.overrideGeolocation.get()); 537 this._geolocationOverrideCheckboxClicked(WebInspector.overridesSupport.s ettings.overrideGeolocation.get());
352 }, 538 },
353 539
354 /** 540 /**
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 778
593 __proto__ : WebInspector.OverridesView.Tab.prototype 779 __proto__ : WebInspector.OverridesView.Tab.prototype
594 } 780 }
595 781
596 /** @enum {string} */ 782 /** @enum {string} */
597 WebInspector.OverridesView.SensorsTab.DeviceOrientationModificationSource = { 783 WebInspector.OverridesView.SensorsTab.DeviceOrientationModificationSource = {
598 UserInput: "userInput", 784 UserInput: "userInput",
599 UserDrag: "userDrag", 785 UserDrag: "userDrag",
600 ResetButton: "resetButton" 786 ResetButton: "resetButton"
601 } 787 }
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