| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 | 508 |
| 509 /** | 509 /** |
| 510 * @param {string} deviceMetrics | 510 * @param {string} deviceMetrics |
| 511 * @param {string} userAgent | 511 * @param {string} userAgent |
| 512 */ | 512 */ |
| 513 emulateDevice: function(deviceMetrics, userAgent) | 513 emulateDevice: function(deviceMetrics, userAgent) |
| 514 { | 514 { |
| 515 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(d
eviceMetrics); | 515 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(d
eviceMetrics); |
| 516 this._deviceMetricsChangedListenerMuted = true; | 516 this._deviceMetricsChangedListenerMuted = true; |
| 517 this._userAgentChangedListenerMuted = true; | 517 this._userAgentChangedListenerMuted = true; |
| 518 this.settings.userAgent.set(userAgent); | 518 this.settings.deviceUserAgent.set(userAgent); |
| 519 this.settings.deviceWidth.set(metrics.width); | 519 this.settings.deviceWidth.set(metrics.width); |
| 520 this.settings.deviceHeight.set(metrics.height); | 520 this.settings.deviceHeight.set(metrics.height); |
| 521 this.settings.deviceScaleFactor.set(metrics.deviceScaleFactor); | 521 this.settings.deviceScaleFactor.set(metrics.deviceScaleFactor); |
| 522 this.settings.deviceTextAutosizing.set(metrics.textAutosizing); | 522 this.settings.deviceTextAutosizing.set(metrics.textAutosizing); |
| 523 this.settings.overrideUserAgent.set(true); | 523 this.settings.deviceTouch.set(true); |
| 524 this.settings.emulateTouchEvents.set(true); | |
| 525 this.settings.emulateViewport.set(true); | 524 this.settings.emulateViewport.set(true); |
| 526 this.settings.emulateDevice.set(true); | 525 this.settings.emulateDevice.set(true); |
| 527 delete this._deviceMetricsChangedListenerMuted; | 526 delete this._deviceMetricsChangedListenerMuted; |
| 528 delete this._userAgentChangedListenerMuted; | 527 delete this._userAgentChangedListenerMuted; |
| 529 | 528 |
| 530 if (this._initialized) { | 529 if (this._initialized) { |
| 531 this._deviceMetricsChanged(); | 530 this._deviceMetricsChanged(); |
| 532 this._userAgentChanged(); | 531 this._userAgentChanged(); |
| 533 } | 532 } |
| 534 }, | 533 }, |
| 535 | 534 |
| 536 /** | 535 /** |
| 537 * @param {string} deviceMetrics | 536 * @param {string} deviceMetrics |
| 538 * @param {string} userAgent | 537 * @param {string} userAgent |
| 539 * @return {boolean} | 538 * @return {boolean} |
| 540 */ | 539 */ |
| 541 isEmulatingDevice: function(deviceMetrics, userAgent) | 540 isEmulatingDevice: function(deviceMetrics, userAgent) |
| 542 { | 541 { |
| 543 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(d
eviceMetrics); | 542 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(d
eviceMetrics); |
| 544 return this.settings.userAgent.get() === userAgent | 543 return this.settings.deviceUserAgent.get() === userAgent |
| 545 && this.settings.deviceWidth.get() === metrics.width | 544 && this.settings.deviceWidth.get() === metrics.width |
| 546 && this.settings.deviceHeight.get() === metrics.height | 545 && this.settings.deviceHeight.get() === metrics.height |
| 547 && this.settings.deviceScaleFactor.get() === metrics.deviceScaleFact
or | 546 && this.settings.deviceScaleFactor.get() === metrics.deviceScaleFact
or |
| 548 && this.settings.deviceTextAutosizing.get() === metrics.textAutosizi
ng | 547 && this.settings.deviceTextAutosizing.get() === metrics.textAutosizi
ng |
| 549 && this.settings.emulateTouchEvents.get() | 548 && this.settings.deviceTouch.get() |
| 550 && this.settings.emulateViewport.get(); | 549 && this.settings.emulateViewport.get(); |
| 551 }, | 550 }, |
| 552 | 551 |
| 553 resetEmulatedDevice: function() | |
| 554 { | |
| 555 this._deviceMetricsChangedListenerMuted = true; | |
| 556 this._userAgentChangedListenerMuted = true; | |
| 557 this.settings.emulateDevice.set(false); | |
| 558 this.settings.overrideUserAgent.set(false); | |
| 559 this.settings.emulateTouchEvents.set(false); | |
| 560 this.settings.emulateViewport.set(false); | |
| 561 delete this._deviceMetricsChangedListenerMuted; | |
| 562 delete this._userAgentChangedListenerMuted; | |
| 563 | |
| 564 if (this._initialized) { | |
| 565 this._deviceMetricsChanged(); | |
| 566 this._userAgentChanged(); | |
| 567 } | |
| 568 }, | |
| 569 | |
| 570 reset: function() | |
| 571 { | |
| 572 this.settings.overrideDeviceOrientation.set(false); | |
| 573 this.settings.overrideGeolocation.set(false); | |
| 574 this.settings.overrideCSSMedia.set(false); | |
| 575 this.resetEmulatedDevice(); | |
| 576 }, | |
| 577 | |
| 578 applyInitialOverrides: function() | 552 applyInitialOverrides: function() |
| 579 { | 553 { |
| 580 if (!this._target) { | 554 if (!this._target) { |
| 581 this._applyInitialOverridesOnTargetAdded = true; | 555 this._applyInitialOverridesOnTargetAdded = true; |
| 582 return; | 556 return; |
| 583 } | 557 } |
| 584 | 558 |
| 585 this._initialized = true; | 559 this._initialized = true; |
| 586 | 560 |
| 561 this._addEmulateDeviceListener(this._userAgentChanged); |
| 562 this.settings.deviceUserAgent.addChangeListener(this._userAgentChanged,
this); |
| 587 this.settings.overrideUserAgent.addChangeListener(this._userAgentChanged
, this); | 563 this.settings.overrideUserAgent.addChangeListener(this._userAgentChanged
, this); |
| 588 this.settings.userAgent.addChangeListener(this._userAgentChanged, this); | 564 this.settings.userAgent.addChangeListener(this._userAgentChanged, this); |
| 589 this.settings.emulateDevice.addChangeListener(this._updateUserAgentAndTo
uchOnEmulateDeviceChanged, this); | |
| 590 | 565 |
| 591 this.settings.emulateDevice.addChangeListener(this._deviceMetricsChanged
, this); | 566 this._addEmulateDeviceListener(this._deviceMetricsChanged); |
| 592 this.settings.deviceWidth.addChangeListener(this._deviceMetricsChanged,
this); | 567 this.settings.deviceWidth.addChangeListener(this._deviceMetricsChanged,
this); |
| 593 this.settings.deviceHeight.addChangeListener(this._deviceMetricsChanged,
this); | 568 this.settings.deviceHeight.addChangeListener(this._deviceMetricsChanged,
this); |
| 594 this.settings.deviceScaleFactor.addChangeListener(this._deviceMetricsCha
nged, this); | 569 this.settings.deviceScaleFactor.addChangeListener(this._deviceMetricsCha
nged, this); |
| 595 this.settings.deviceTextAutosizing.addChangeListener(this._deviceMetrics
Changed, this); | 570 this.settings.deviceTextAutosizing.addChangeListener(this._deviceMetrics
Changed, this); |
| 596 this.settings.emulateViewport.addChangeListener(this._deviceMetricsChang
ed, this); | 571 this.settings.emulateViewport.addChangeListener(this._deviceMetricsChang
ed, this); |
| 597 this.settings.deviceFitWindow.addChangeListener(this._deviceMetricsChang
ed, this); | 572 this.settings.deviceFitWindow.addChangeListener(this._deviceMetricsChang
ed, this); |
| 598 WebInspector.settings.responsiveDesign.enabled.addChangeListener(this._d
eviceMetricsChanged, this); | |
| 599 | 573 |
| 600 this.settings.overrideGeolocation.addChangeListener(this._geolocationPos
itionChanged, this); | 574 this.settings.overrideGeolocation.addChangeListener(this._geolocationPos
itionChanged, this); |
| 601 this.settings.geolocationOverride.addChangeListener(this._geolocationPos
itionChanged, this); | 575 this.settings.geolocationOverride.addChangeListener(this._geolocationPos
itionChanged, this); |
| 602 | 576 |
| 603 this.settings.overrideDeviceOrientation.addChangeListener(this._deviceOr
ientationChanged, this); | 577 this.settings.overrideDeviceOrientation.addChangeListener(this._deviceOr
ientationChanged, this); |
| 604 this.settings.deviceOrientationOverride.addChangeListener(this._deviceOr
ientationChanged, this); | 578 this.settings.deviceOrientationOverride.addChangeListener(this._deviceOr
ientationChanged, this); |
| 605 | 579 |
| 606 this.settings.emulateDevice.addChangeListener(this._emulateTouchEventsCh
anged, this); | 580 this._addEmulateDeviceListener(this._emulateTouchEventsChanged); |
| 607 this.settings.emulateTouchEvents.addChangeListener(this._emulateTouchEve
ntsChanged, this); | 581 this.settings.deviceTouch.addChangeListener(this._emulateTouchEventsChan
ged, this); |
| 608 this.settings.emulateDevice.addChangeListener(this._updateUserAgentAndTo
uchOnEmulateDeviceChanged, this); | 582 this.settings.sensorsTouch.addChangeListener(this._emulateTouchEventsCha
nged, this); |
| 609 | 583 |
| 610 this.settings.overrideCSSMedia.addChangeListener(this._cssMediaChanged,
this); | 584 this.settings.overrideCSSMedia.addChangeListener(this._cssMediaChanged,
this); |
| 611 this.settings.emulatedCSSMedia.addChangeListener(this._cssMediaChanged,
this); | 585 this.settings.emulatedCSSMedia.addChangeListener(this._cssMediaChanged,
this); |
| 612 | 586 |
| 613 this.settings.emulateNetworkConditions.addChangeListener(this._networkCo
nditionsChanged, this); | 587 this.settings.emulateNetworkConditions.addChangeListener(this._networkCo
nditionsChanged, this); |
| 614 this.settings.networkConditionsDomains.addChangeListener(this._networkCo
nditionsChanged, this); | 588 this.settings.networkConditionsDomains.addChangeListener(this._networkCo
nditionsChanged, this); |
| 615 this.settings.networkConditionsThroughput.addChangeListener(this._networ
kConditionsChanged, this); | 589 this.settings.networkConditionsThroughput.addChangeListener(this._networ
kConditionsChanged, this); |
| 616 | 590 |
| 617 WebInspector.settings.showMetricsRulers.addChangeListener(this._showRule
rsChanged, this); | 591 WebInspector.settings.showMetricsRulers.addChangeListener(this._showRule
rsChanged, this); |
| 618 | 592 |
| 619 if (this.settings.overrideDeviceOrientation.get()) | 593 if (this.settings.overrideDeviceOrientation.get()) |
| 620 this._deviceOrientationChanged(); | 594 this._deviceOrientationChanged(); |
| 621 | 595 |
| 622 if (this.settings.overrideGeolocation.get()) | 596 if (this.settings.overrideGeolocation.get()) |
| 623 this._geolocationPositionChanged(); | 597 this._geolocationPositionChanged(); |
| 624 | 598 |
| 625 if (this.settings.emulateTouchEvents.get() && (this.settings.emulateDevi
ce.get() || !this._responsiveDesignAvailable)) | 599 if (this.isTouchEmulationEnabled()) |
| 626 this._emulateTouchEventsChanged(); | 600 this._emulateTouchEventsChanged(); |
| 627 | 601 |
| 628 if (this.settings.overrideCSSMedia.get()) | 602 if (this.settings.overrideCSSMedia.get()) |
| 629 this._cssMediaChanged(); | 603 this._cssMediaChanged(); |
| 630 | 604 |
| 631 if (this.settings.emulateDevice.get()) | 605 if (this.settings.emulateDevice.get()) |
| 632 this._deviceMetricsChanged(); | 606 this._deviceMetricsChanged(); |
| 633 | 607 |
| 634 if (this.settings.overrideUserAgent.get()) | 608 if (this.userAgentOverride()) |
| 635 this._userAgentChanged(); | 609 this._userAgentChanged(); |
| 636 | 610 |
| 637 if (this.settings.emulateNetworkConditions.get()) | 611 if (this.settings.emulateNetworkConditions.get()) |
| 638 this._networkConditionsChanged(); | 612 this._networkConditionsChanged(); |
| 639 | 613 |
| 640 this._showRulersChanged(); | 614 this._showRulersChanged(); |
| 641 }, | 615 }, |
| 642 | 616 |
| 643 _updateUserAgentAndTouchOnEmulateDeviceChanged: function() | 617 /** |
| 618 * @param {function(this:WebInspector.OverridesSupport)} listener |
| 619 */ |
| 620 _addEmulateDeviceListener: function(listener) |
| 644 { | 621 { |
| 645 var value = this.settings.emulateDevice.get(); | 622 this.settings.emulateDevice.addChangeListener(listener, this); |
| 646 if (this.settings.overrideUserAgent.get() !== value) | 623 WebInspector.settings.responsiveDesign.enabled.addChangeListener(listene
r, this); |
| 647 this.settings.overrideUserAgent.set(value); | |
| 648 if (this.settings.emulateTouchEvents.get() !== value && !this._responsiv
eDesignAvailable) | |
| 649 this.settings.emulateTouchEvents.set(value); | |
| 650 }, | 624 }, |
| 651 | 625 |
| 652 _userAgentChanged: function() | 626 _userAgentChanged: function() |
| 653 { | 627 { |
| 654 if (this._userAgentChangedListenerMuted) | 628 if (this._userAgentChangedListenerMuted) |
| 655 return; | 629 return; |
| 656 var userAgent = this.settings.overrideUserAgent.get() ? this.settings.us
erAgent.get() : ""; | 630 var userAgent = this.userAgentOverride(); |
| 657 NetworkAgent.setUserAgentOverride(userAgent); | 631 NetworkAgent.setUserAgentOverride(userAgent); |
| 658 if (this._userAgent !== userAgent) | 632 if (this._userAgent !== userAgent) |
| 659 this._updateUserAgentWarningMessage(WebInspector.UIString("You might
need to reload the page for proper user agent spoofing and viewport rendering."
)); | 633 this._updateUserAgentWarningMessage(WebInspector.UIString("You might
need to reload the page for proper user agent spoofing and viewport rendering."
)); |
| 660 this._userAgent = userAgent; | 634 this._userAgent = userAgent; |
| 661 this.maybeHasActiveOverridesChanged(); | 635 this.maybeHasActiveOverridesChanged(); |
| 662 }, | 636 }, |
| 663 | 637 |
| 664 _onPageResizerAvailableSizeChanged: function() | 638 _onPageResizerAvailableSizeChanged: function() |
| 665 { | 639 { |
| 666 if (this._initialized) | 640 if (this._initialized) |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 return; | 765 return; |
| 792 } | 766 } |
| 793 | 767 |
| 794 var deviceOrientation = WebInspector.OverridesSupport.DeviceOrientation.
parseSetting(this.settings.deviceOrientationOverride.get()); | 768 var deviceOrientation = WebInspector.OverridesSupport.DeviceOrientation.
parseSetting(this.settings.deviceOrientationOverride.get()); |
| 795 PageAgent.setDeviceOrientationOverride(deviceOrientation.alpha, deviceOr
ientation.beta, deviceOrientation.gamma); | 769 PageAgent.setDeviceOrientationOverride(deviceOrientation.alpha, deviceOr
ientation.beta, deviceOrientation.gamma); |
| 796 this.maybeHasActiveOverridesChanged(); | 770 this.maybeHasActiveOverridesChanged(); |
| 797 }, | 771 }, |
| 798 | 772 |
| 799 _emulateTouchEventsChanged: function() | 773 _emulateTouchEventsChanged: function() |
| 800 { | 774 { |
| 801 if (this.hasTouchInputs() && this.settings.emulateTouchEvents.get()) | 775 var emulateTouch = this.isTouchEmulationEnabled(); |
| 802 return; | |
| 803 | |
| 804 var emulateTouch = this.settings.emulateTouchEvents.get() && (this.setti
ngs.emulateDevice.get() || !this._responsiveDesignAvailable); | |
| 805 var targets = WebInspector.targetManager.targets(); | 776 var targets = WebInspector.targetManager.targets(); |
| 806 for (var i = 0; i < targets.length; ++i) | 777 for (var i = 0; i < targets.length; ++i) |
| 807 targets[i].domModel.emulateTouchEventObjects(emulateTouch); | 778 targets[i].domModel.emulateTouchEventObjects(emulateTouch); |
| 808 this.maybeHasActiveOverridesChanged(); | 779 this.maybeHasActiveOverridesChanged(); |
| 809 }, | 780 }, |
| 810 | 781 |
| 811 _cssMediaChanged: function() | 782 _cssMediaChanged: function() |
| 812 { | 783 { |
| 813 if (this.isInspectingDevice() && this.settings.overrideCSSMedia.get()) | 784 if (this.isInspectingDevice() && this.settings.overrideCSSMedia.get()) |
| 814 return; | 785 return; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 * @return {boolean} | 825 * @return {boolean} |
| 855 */ | 826 */ |
| 856 hasActiveOverrides: function() | 827 hasActiveOverrides: function() |
| 857 { | 828 { |
| 858 return this._hasActiveOverrides; | 829 return this._hasActiveOverrides; |
| 859 }, | 830 }, |
| 860 | 831 |
| 861 maybeHasActiveOverridesChanged: function() | 832 maybeHasActiveOverridesChanged: function() |
| 862 { | 833 { |
| 863 var hasActiveOverrides = | 834 var hasActiveOverrides = |
| 864 this.settings.overrideUserAgent.get() || | 835 !!this.userAgentOverride() || |
| 865 (this.settings.emulateDevice.get() && !this.isInspectingDevice()) || | 836 (this.settings.emulateDevice.get() && !this.isInspectingDevice()) || |
| 866 this.settings.overrideGeolocation.get() || | 837 this.settings.overrideGeolocation.get() || |
| 867 this.settings.overrideDeviceOrientation.get() || | 838 this.settings.overrideDeviceOrientation.get() || |
| 868 (this.settings.emulateTouchEvents.get() && this.settings.emulateDevi
ce.get() && !this.hasTouchInputs()) || | 839 this.isTouchEmulationEnabled() || |
| 869 (this.settings.overrideCSSMedia.get() && !this.isInspectingDevice())
; | 840 (this.settings.overrideCSSMedia.get() && !this.isInspectingDevice())
; |
| 870 if (this._hasActiveOverrides !== hasActiveOverrides) { | 841 if (this._hasActiveOverrides !== hasActiveOverrides) { |
| 871 this._hasActiveOverrides = hasActiveOverrides; | 842 this._hasActiveOverrides = hasActiveOverrides; |
| 872 this.dispatchEventToListeners(WebInspector.OverridesSupport.Events.H
asActiveOverridesChanged); | 843 this.dispatchEventToListeners(WebInspector.OverridesSupport.Events.H
asActiveOverridesChanged); |
| 873 } | 844 } |
| 874 }, | 845 }, |
| 875 | 846 |
| 876 _onMainFrameNavigated: function() | 847 _onMainFrameNavigated: function() |
| 877 { | 848 { |
| 878 if (this._initialized) | 849 if (this._initialized) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 922 this.settings.userAgent = WebInspector.settings.createSetting("userAgent
", ""); | 893 this.settings.userAgent = WebInspector.settings.createSetting("userAgent
", ""); |
| 923 | 894 |
| 924 this.settings.emulateDevice = WebInspector.settings.createSetting("emula
teDevice", false); | 895 this.settings.emulateDevice = WebInspector.settings.createSetting("emula
teDevice", false); |
| 925 this.settings.deviceWidth = WebInspector.settings.createSetting("deviceW
idth", 800); | 896 this.settings.deviceWidth = WebInspector.settings.createSetting("deviceW
idth", 800); |
| 926 this.settings.deviceHeight = WebInspector.settings.createSetting("device
Height", 600); | 897 this.settings.deviceHeight = WebInspector.settings.createSetting("device
Height", 600); |
| 927 this.settings.deviceScaleFactor = WebInspector.settings.createSetting("d
eviceScaleFactor", window.devicePixelRatio); | 898 this.settings.deviceScaleFactor = WebInspector.settings.createSetting("d
eviceScaleFactor", window.devicePixelRatio); |
| 928 this.settings.deviceTextAutosizing = WebInspector.settings.createSetting
("deviceTextAutosizing", true); | 899 this.settings.deviceTextAutosizing = WebInspector.settings.createSetting
("deviceTextAutosizing", true); |
| 929 this.settings.deviceFitWindow = WebInspector.settings.createSetting("dev
iceFitWindow", true); | 900 this.settings.deviceFitWindow = WebInspector.settings.createSetting("dev
iceFitWindow", true); |
| 930 // FIXME: rename viewport to mobile everywhere in the code. | 901 // FIXME: rename viewport to mobile everywhere in the code. |
| 931 this.settings.emulateViewport = WebInspector.settings.createSetting("emu
lateViewport", false); | 902 this.settings.emulateViewport = WebInspector.settings.createSetting("emu
lateViewport", false); |
| 932 this.settings.emulateTouchEvents = WebInspector.settings.createSetting("
emulateTouchEvents", false); | 903 this.settings.deviceTouch = WebInspector.settings.createSetting("deviceT
ouch", false); |
| 904 this.settings.deviceUserAgent = WebInspector.settings.createSetting("dev
iceUserAgent", false); |
| 933 | 905 |
| 934 this.settings.overrideGeolocation = WebInspector.settings.createSetting(
"overrideGeolocation", false); | 906 this.settings.overrideGeolocation = WebInspector.settings.createSetting(
"overrideGeolocation", false); |
| 935 this.settings.geolocationOverride = WebInspector.settings.createSetting(
"geolocationOverride", ""); | 907 this.settings.geolocationOverride = WebInspector.settings.createSetting(
"geolocationOverride", ""); |
| 936 this.settings.overrideDeviceOrientation = WebInspector.settings.createSe
tting("overrideDeviceOrientation", false); | 908 this.settings.overrideDeviceOrientation = WebInspector.settings.createSe
tting("overrideDeviceOrientation", false); |
| 937 this.settings.deviceOrientationOverride = WebInspector.settings.createSe
tting("deviceOrientationOverride", ""); | 909 this.settings.deviceOrientationOverride = WebInspector.settings.createSe
tting("deviceOrientationOverride", ""); |
| 938 this.settings.overrideCSSMedia = WebInspector.settings.createSetting("ov
errideCSSMedia", false); | 910 this.settings.overrideCSSMedia = WebInspector.settings.createSetting("ov
errideCSSMedia", false); |
| 939 this.settings.emulatedCSSMedia = WebInspector.settings.createSetting("em
ulatedCSSMedia", "print"); | 911 this.settings.emulatedCSSMedia = WebInspector.settings.createSetting("em
ulatedCSSMedia", "print"); |
| 912 this.settings.sensorsTouch = WebInspector.settings.createSetting("sensor
sTouch", false); |
| 940 | 913 |
| 941 this.settings.emulateNetworkConditions = WebInspector.settings.createSet
ting("emulateNetworkConditions", false); | 914 this.settings.emulateNetworkConditions = WebInspector.settings.createSet
ting("emulateNetworkConditions", false); |
| 942 this.settings.networkConditionsDomains = WebInspector.settings.createSet
ting("networkConditionsDomains", ""); | 915 this.settings.networkConditionsDomains = WebInspector.settings.createSet
ting("networkConditionsDomains", ""); |
| 943 this.settings.networkConditionsThroughput = WebInspector.settings.create
Setting("networkConditionsThroughput", 0); | 916 this.settings.networkConditionsThroughput = WebInspector.settings.create
Setting("networkConditionsThroughput", 0); |
| 944 | 917 |
| 945 this.maybeHasActiveOverridesChanged(); | 918 this.maybeHasActiveOverridesChanged(); |
| 946 | 919 |
| 947 if (this._applyInitialOverridesOnTargetAdded) { | 920 if (this._applyInitialOverridesOnTargetAdded) { |
| 948 delete this._applyInitialOverridesOnTargetAdded; | 921 delete this._applyInitialOverridesOnTargetAdded; |
| 949 this.applyInitialOverrides(); | 922 this.applyInitialOverrides(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 970 * @return {boolean} | 943 * @return {boolean} |
| 971 */ | 944 */ |
| 972 isInspectingDevice: function() | 945 isInspectingDevice: function() |
| 973 { | 946 { |
| 974 return !!this._target && this._target.isMobile(); | 947 return !!this._target && this._target.isMobile(); |
| 975 }, | 948 }, |
| 976 | 949 |
| 977 /** | 950 /** |
| 978 * @return {boolean} | 951 * @return {boolean} |
| 979 */ | 952 */ |
| 953 isEmulateDeviceEnabled: function() |
| 954 { |
| 955 return this.settings.emulateDevice.get() && (!this._responsiveDesignAvai
lable || WebInspector.settings.responsiveDesign.enabled.get()); |
| 956 }, |
| 957 |
| 958 /** |
| 959 * @return {boolean} |
| 960 */ |
| 961 isTouchEmulationEnabled: function() |
| 962 { |
| 963 return !this.hasTouchInputs() && ((this.isEmulateDeviceEnabled() && this
.settings.deviceTouch.get()) || this.settings.sensorsTouch.get()); |
| 964 }, |
| 965 |
| 966 /** |
| 967 * @return {string} |
| 968 */ |
| 969 userAgentOverride: function() |
| 970 { |
| 971 return this.isEmulateDeviceEnabled() ? this.settings.deviceUserAgent.get
() : (this.settings.overrideUserAgent.get() ? this.settings.userAgent.get() : ""
); |
| 972 }, |
| 973 |
| 974 /** |
| 975 * @return {boolean} |
| 976 */ |
| 980 hasTouchInputs: function() | 977 hasTouchInputs: function() |
| 981 { | 978 { |
| 982 return !!this._target && this._target.hasTouchInputs; | 979 return !!this._target && this._target.hasTouchInputs; |
| 983 }, | 980 }, |
| 984 | 981 |
| 985 /** | 982 /** |
| 986 * Compute the font scale factor. | 983 * Compute the font scale factor. |
| 987 * | 984 * |
| 988 * Chromium on Android uses a device scale adjustment for fonts used in text
autosizing for | 985 * Chromium on Android uses a device scale adjustment for fonts used in text
autosizing for |
| 989 * improved legibility. This function computes this adjusted value for text
autosizing. | 986 * improved legibility. This function computes this adjusted value for text
autosizing. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 | 1042 |
| 1046 deviceSelectElement.addEventListener("change", deviceSelected, false); | 1043 deviceSelectElement.addEventListener("change", deviceSelected, false); |
| 1047 | 1044 |
| 1048 var emulatedSettingChangedMuted = false; | 1045 var emulatedSettingChangedMuted = false; |
| 1049 WebInspector.overridesSupport.settings.deviceWidth.addChangeListener(emu
latedSettingChanged); | 1046 WebInspector.overridesSupport.settings.deviceWidth.addChangeListener(emu
latedSettingChanged); |
| 1050 WebInspector.overridesSupport.settings.deviceHeight.addChangeListener(em
ulatedSettingChanged); | 1047 WebInspector.overridesSupport.settings.deviceHeight.addChangeListener(em
ulatedSettingChanged); |
| 1051 WebInspector.overridesSupport.settings.deviceScaleFactor.addChangeListen
er(emulatedSettingChanged); | 1048 WebInspector.overridesSupport.settings.deviceScaleFactor.addChangeListen
er(emulatedSettingChanged); |
| 1052 WebInspector.overridesSupport.settings.deviceTextAutosizing.addChangeLis
tener(emulatedSettingChanged); | 1049 WebInspector.overridesSupport.settings.deviceTextAutosizing.addChangeLis
tener(emulatedSettingChanged); |
| 1053 WebInspector.overridesSupport.settings.emulateViewport.addChangeListener
(emulatedSettingChanged); | 1050 WebInspector.overridesSupport.settings.emulateViewport.addChangeListener
(emulatedSettingChanged); |
| 1054 WebInspector.overridesSupport.settings.deviceFitWindow.addChangeListener
(emulatedSettingChanged); | 1051 WebInspector.overridesSupport.settings.deviceFitWindow.addChangeListener
(emulatedSettingChanged); |
| 1055 WebInspector.overridesSupport.settings.emulateTouchEvents.addChangeListe
ner(emulatedSettingChanged); | 1052 WebInspector.overridesSupport.settings.deviceTouch.addChangeListener(emu
latedSettingChanged); |
| 1056 WebInspector.overridesSupport.settings.overrideUserAgent.addChangeListen
er(emulatedSettingChanged); | 1053 WebInspector.overridesSupport.settings.deviceUserAgent.addChangeListener
(emulatedSettingChanged); |
| 1057 WebInspector.overridesSupport.settings.userAgent.addChangeListener(emula
tedSettingChanged); | |
| 1058 emulatedSettingChanged(); | 1054 emulatedSettingChanged(); |
| 1059 | 1055 |
| 1060 function deviceSelected() | 1056 function deviceSelected() |
| 1061 { | 1057 { |
| 1062 if (deviceSelectElement.selectedIndex === devices.length - 1) | 1058 if (deviceSelectElement.selectedIndex === devices.length - 1) |
| 1063 return; | 1059 return; |
| 1064 | 1060 |
| 1065 var option = deviceSelectElement.options[deviceSelectElement.selecte
dIndex]; | 1061 var option = deviceSelectElement.options[deviceSelectElement.selecte
dIndex]; |
| 1066 emulatedSettingChangedMuted = true; | 1062 emulatedSettingChangedMuted = true; |
| 1067 WebInspector.overridesSupport.emulateDevice(option.metrics, option.u
serAgent); | 1063 WebInspector.overridesSupport.emulateDevice(option.metrics, option.u
serAgent); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1082 } | 1078 } |
| 1083 } | 1079 } |
| 1084 deviceSelectElement.selectedIndex = index; | 1080 deviceSelectElement.selectedIndex = index; |
| 1085 } | 1081 } |
| 1086 | 1082 |
| 1087 return deviceSelectElement; | 1083 return deviceSelectElement; |
| 1088 }, | 1084 }, |
| 1089 | 1085 |
| 1090 /** | 1086 /** |
| 1091 * @param {!Document} document | 1087 * @param {!Document} document |
| 1092 * @return {{select: !Element, input: !Element}} | |
| 1093 */ | |
| 1094 createUserAgentSelectAndInput: function(document) | |
| 1095 { | |
| 1096 var overrideUserAgentSetting = WebInspector.overridesSupport.settings.ov
errideUserAgent; | |
| 1097 var userAgentSetting = WebInspector.overridesSupport.settings.userAgent; | |
| 1098 var userAgents = WebInspector.OverridesSupport._userAgents.concat([[WebI
nspector.UIString("Other"), "Other"]]); | |
| 1099 | |
| 1100 var userAgentSelectElement = document.createElement("select"); | |
| 1101 for (var i = 0; i < userAgents.length; ++i) | |
| 1102 userAgentSelectElement.add(new Option(userAgents[i][0], userAgents[i
][1])); | |
| 1103 userAgentSelectElement.selectedIndex = 0; | |
| 1104 | |
| 1105 var otherUserAgentElement = document.createElement("input"); | |
| 1106 otherUserAgentElement.type = "text"; | |
| 1107 otherUserAgentElement.value = userAgentSetting.get(); | |
| 1108 otherUserAgentElement.title = userAgentSetting.get(); | |
| 1109 | |
| 1110 settingChanged(); | |
| 1111 userAgentSetting.addChangeListener(settingChanged); | |
| 1112 userAgentSelectElement.addEventListener("change", userAgentSelected, fal
se); | |
| 1113 | |
| 1114 otherUserAgentElement.addEventListener("dblclick", textDoubleClicked, tr
ue); | |
| 1115 otherUserAgentElement.addEventListener("blur", textChanged, false); | |
| 1116 otherUserAgentElement.addEventListener("keydown", textKeyDown, false); | |
| 1117 | |
| 1118 function userAgentSelected() | |
| 1119 { | |
| 1120 var value = userAgentSelectElement.options[userAgentSelectElement.se
lectedIndex].value; | |
| 1121 if (value !== "Other") { | |
| 1122 userAgentSetting.removeChangeListener(settingChanged); | |
| 1123 userAgentSetting.set(value); | |
| 1124 userAgentSetting.addChangeListener(settingChanged); | |
| 1125 otherUserAgentElement.value = value; | |
| 1126 otherUserAgentElement.title = value; | |
| 1127 otherUserAgentElement.readOnly = true; | |
| 1128 } else { | |
| 1129 otherUserAgentElement.readOnly = !overrideUserAgentSetting.get()
; | |
| 1130 otherUserAgentElement.focus(); | |
| 1131 } | |
| 1132 overrideUserAgentSetting.set(true); | |
| 1133 } | |
| 1134 | |
| 1135 function settingChanged() | |
| 1136 { | |
| 1137 var value = userAgentSetting.get(); | |
| 1138 var options = userAgentSelectElement.options; | |
| 1139 var selectionRestored = false; | |
| 1140 for (var i = 0; i < options.length; ++i) { | |
| 1141 if (options[i].value === value) { | |
| 1142 userAgentSelectElement.selectedIndex = i; | |
| 1143 selectionRestored = true; | |
| 1144 break; | |
| 1145 } | |
| 1146 } | |
| 1147 | |
| 1148 otherUserAgentElement.readOnly = !overrideUserAgentSetting.get() ||
selectionRestored; | |
| 1149 if (!selectionRestored) | |
| 1150 userAgentSelectElement.selectedIndex = options.length - 1; | |
| 1151 | |
| 1152 if (otherUserAgentElement.value !== value) { | |
| 1153 otherUserAgentElement.value = value; | |
| 1154 otherUserAgentElement.title = value; | |
| 1155 } | |
| 1156 } | |
| 1157 | |
| 1158 function textKeyDown(event) | |
| 1159 { | |
| 1160 if (isEnterKey(event)) | |
| 1161 textChanged(); | |
| 1162 } | |
| 1163 | |
| 1164 function textDoubleClicked() | |
| 1165 { | |
| 1166 userAgentSelectElement.selectedIndex = userAgents.length - 1; | |
| 1167 userAgentSelected(); | |
| 1168 } | |
| 1169 | |
| 1170 function textChanged() | |
| 1171 { | |
| 1172 if (userAgentSetting.get() !== otherUserAgentElement.value) | |
| 1173 userAgentSetting.set(otherUserAgentElement.value); | |
| 1174 } | |
| 1175 | |
| 1176 overrideUserAgentSetting.addChangeListener(overrideUserAgentChanged); | |
| 1177 function overrideUserAgentChanged() | |
| 1178 { | |
| 1179 otherUserAgentElement.readOnly = !overrideUserAgentSetting.get() ||
(userAgentSelectElement.options[userAgentSelectElement.selectedIndex].value !==
"Other"); | |
| 1180 } | |
| 1181 | |
| 1182 return { select: userAgentSelectElement, input: otherUserAgentElement }; | |
| 1183 }, | |
| 1184 | |
| 1185 /** | |
| 1186 * @param {!Document} document | |
| 1187 * @return {!Element} | 1088 * @return {!Element} |
| 1188 */ | 1089 */ |
| 1189 createNetworkThroughputSelect: function(document) | 1090 createNetworkThroughputSelect: function(document) |
| 1190 { | 1091 { |
| 1191 var throughputSetting = WebInspector.overridesSupport.settings.networkCo
nditionsThroughput; | 1092 var throughputSetting = WebInspector.overridesSupport.settings.networkCo
nditionsThroughput; |
| 1192 var emulateNetworkSetting = WebInspector.overridesSupport.settings.emula
teNetworkConditions; | 1093 var emulateNetworkSetting = WebInspector.overridesSupport.settings.emula
teNetworkConditions; |
| 1193 var throughputSelectElement = document.createElement("select"); | 1094 var throughputSelectElement = document.createElement("select"); |
| 1194 var presets = WebInspector.OverridesSupport._networkThroughputPresets; | 1095 var presets = WebInspector.OverridesSupport._networkThroughputPresets; |
| 1195 for (var i = 0; i < presets.length; ++i) | 1096 for (var i = 0; i < presets.length; ++i) |
| 1196 throughputSelectElement.add(new Option(presets[i][0], presets[i][1])
); | 1097 throughputSelectElement.add(new Option(presets[i][0], presets[i][1])
); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1229 }, | 1130 }, |
| 1230 | 1131 |
| 1231 __proto__: WebInspector.Object.prototype | 1132 __proto__: WebInspector.Object.prototype |
| 1232 } | 1133 } |
| 1233 | 1134 |
| 1234 | 1135 |
| 1235 /** | 1136 /** |
| 1236 * @type {!WebInspector.OverridesSupport} | 1137 * @type {!WebInspector.OverridesSupport} |
| 1237 */ | 1138 */ |
| 1238 WebInspector.overridesSupport; | 1139 WebInspector.overridesSupport; |
| OLD | NEW |