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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 ["320 Kbps", 320 * 1024 / 8], | 473 ["320 Kbps", 320 * 1024 / 8], |
474 ["640 Kbps (3G)", 640 * 1024 / 8], | 474 ["640 Kbps (3G)", 640 * 1024 / 8], |
475 ["1 Mbps", 1024 * 1024 / 8], | 475 ["1 Mbps", 1024 * 1024 / 8], |
476 ["2 Mbps (802.11b)", 2048 * 1024 / 8] | 476 ["2 Mbps (802.11b)", 2048 * 1024 / 8] |
477 ]; | 477 ]; |
478 | 478 |
479 WebInspector.OverridesSupport.prototype = { | 479 WebInspector.OverridesSupport.prototype = { |
480 /** | 480 /** |
481 * @return {boolean} | 481 * @return {boolean} |
482 */ | 482 */ |
483 responsiveDesignAvailable: function() | 483 _responsiveDesignEnabledOrUnavailable: function() |
484 { | 484 { |
485 return this._responsiveDesignAvailable; | 485 return !this._responsiveDesignAvailable || WebInspector.settings.respons iveDesignEnabled.get(); |
486 }, | 486 }, |
487 | 487 |
488 /** | 488 /** |
489 * @param {?WebInspector.OverridesSupport.PageResizer} pageResizer | 489 * @param {?WebInspector.OverridesSupport.PageResizer} pageResizer |
490 */ | 490 */ |
491 setPageResizer: function(pageResizer) | 491 setPageResizer: function(pageResizer) |
492 { | 492 { |
493 if (pageResizer === this._pageResizer) | 493 if (pageResizer === this._pageResizer) |
494 return; | 494 return; |
495 | 495 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
566 this._addEmulateDeviceListener(this._deviceMetricsChanged); | 566 this._addEmulateDeviceListener(this._deviceMetricsChanged); |
567 this.settings.deviceWidth.addChangeListener(this._deviceMetricsChanged, this); | 567 this.settings.deviceWidth.addChangeListener(this._deviceMetricsChanged, this); |
568 this.settings.deviceHeight.addChangeListener(this._deviceMetricsChanged, this); | 568 this.settings.deviceHeight.addChangeListener(this._deviceMetricsChanged, this); |
569 this.settings.deviceScaleFactor.addChangeListener(this._deviceMetricsCha nged, this); | 569 this.settings.deviceScaleFactor.addChangeListener(this._deviceMetricsCha nged, this); |
570 this.settings.deviceTextAutosizing.addChangeListener(this._deviceMetrics Changed, this); | 570 this.settings.deviceTextAutosizing.addChangeListener(this._deviceMetrics Changed, this); |
571 this.settings.emulateViewport.addChangeListener(this._deviceMetricsChang ed, this); | 571 this.settings.emulateViewport.addChangeListener(this._deviceMetricsChang ed, this); |
572 this.settings.deviceFitWindow.addChangeListener(this._deviceMetricsChang ed, this); | 572 this.settings.deviceFitWindow.addChangeListener(this._deviceMetricsChang ed, this); |
573 | 573 |
574 this.settings.overrideGeolocation.addChangeListener(this._geolocationPos itionChanged, this); | 574 this.settings.overrideGeolocation.addChangeListener(this._geolocationPos itionChanged, this); |
575 this.settings.geolocationOverride.addChangeListener(this._geolocationPos itionChanged, this); | 575 this.settings.geolocationOverride.addChangeListener(this._geolocationPos itionChanged, this); |
576 WebInspector.settings.responsiveDesignEnabled.addChangeListener(this._ge olocationPositionChanged, this); | |
576 | 577 |
577 this.settings.overrideDeviceOrientation.addChangeListener(this._deviceOr ientationChanged, this); | 578 this.settings.overrideDeviceOrientation.addChangeListener(this._deviceOr ientationChanged, this); |
578 this.settings.deviceOrientationOverride.addChangeListener(this._deviceOr ientationChanged, this); | 579 this.settings.deviceOrientationOverride.addChangeListener(this._deviceOr ientationChanged, this); |
580 WebInspector.settings.responsiveDesignEnabled.addChangeListener(this._de viceOrientationChanged, this); | |
579 | 581 |
580 this._addEmulateDeviceListener(this._emulateTouchEventsChanged); | 582 this._addEmulateDeviceListener(this._emulateTouchEventsChanged); |
581 this.settings.deviceTouch.addChangeListener(this._emulateTouchEventsChan ged, this); | 583 this.settings.deviceTouch.addChangeListener(this._emulateTouchEventsChan ged, this); |
582 this.settings.sensorsTouch.addChangeListener(this._emulateTouchEventsCha nged, this); | 584 this.settings.sensorsTouch.addChangeListener(this._emulateTouchEventsCha nged, this); |
583 | 585 |
584 this.settings.overrideCSSMedia.addChangeListener(this._cssMediaChanged, this); | 586 this.settings.overrideCSSMedia.addChangeListener(this._cssMediaChanged, this); |
585 this.settings.emulatedCSSMedia.addChangeListener(this._cssMediaChanged, this); | 587 this.settings.emulatedCSSMedia.addChangeListener(this._cssMediaChanged, this); |
588 WebInspector.settings.responsiveDesignEnabled.addChangeListener(this._cs sMediaChanged, this); | |
586 | 589 |
587 this.settings.emulateNetworkConditions.addChangeListener(this._networkCo nditionsChanged, this); | 590 if (WebInspector.experimentsSettings.networkConditions.isEnabled()) { |
588 this.settings.networkConditionsDomains.addChangeListener(this._networkCo nditionsChanged, this); | 591 this.settings.emulateNetworkConditions.addChangeListener(this._netwo rkConditionsChanged, this); |
589 this.settings.networkConditionsThroughput.addChangeListener(this._networ kConditionsChanged, this); | 592 this.settings.networkConditionsDomains.addChangeListener(this._netwo rkConditionsChanged, this); |
593 this.settings.networkConditionsThroughput.addChangeListener(this._ne tworkConditionsChanged, this); | |
594 WebInspector.settings.responsiveDesignEnabled.addChangeListener(this ._networkConditionsChanged, this); | |
595 } | |
590 | 596 |
591 WebInspector.settings.showMetricsRulers.addChangeListener(this._showRule rsChanged, this); | 597 WebInspector.settings.showMetricsRulers.addChangeListener(this._showRule rsChanged, this); |
592 | 598 |
593 if (this.settings.overrideDeviceOrientation.get()) | 599 if (this.settings.overrideDeviceOrientation.get()) |
594 this._deviceOrientationChanged(); | 600 this._deviceOrientationChanged(); |
595 | 601 |
596 if (this.settings.overrideGeolocation.get()) | 602 if (this.settings.overrideGeolocation.get()) |
597 this._geolocationPositionChanged(); | 603 this._geolocationPositionChanged(); |
598 | 604 |
599 if (this.isTouchEmulationEnabled()) | 605 if (this.isTouchEmulationEnabled()) |
600 this._emulateTouchEventsChanged(); | 606 this._emulateTouchEventsChanged(); |
601 | 607 |
602 if (this.settings.overrideCSSMedia.get()) | 608 if (this.settings.overrideCSSMedia.get()) |
603 this._cssMediaChanged(); | 609 this._cssMediaChanged(); |
604 | 610 |
605 if (this.settings.emulateDevice.get()) | 611 if (this.settings.emulateDevice.get()) |
606 this._deviceMetricsChanged(); | 612 this._deviceMetricsChanged(); |
607 | 613 |
608 if (this.userAgentOverride()) | 614 if (this.userAgentOverride()) |
609 this._userAgentChanged(); | 615 this._userAgentChanged(); |
610 | 616 |
611 if (this.settings.emulateNetworkConditions.get()) | 617 if (WebInspector.experimentsSettings.networkConditions.isEnabled() && th is.settings.emulateNetworkConditions.get()) |
612 this._networkConditionsChanged(); | 618 this._networkConditionsChanged(); |
613 | 619 |
614 this._showRulersChanged(); | 620 this._showRulersChanged(); |
615 }, | 621 }, |
616 | 622 |
617 /** | 623 /** |
618 * @param {function(this:WebInspector.OverridesSupport)} listener | 624 * @param {function(this:WebInspector.OverridesSupport)} listener |
619 */ | 625 */ |
620 _addEmulateDeviceListener: function(listener) | 626 _addEmulateDeviceListener: function(listener) |
621 { | 627 { |
622 this.settings.emulateDevice.addChangeListener(listener, this); | 628 this.settings.emulateDevice.addChangeListener(listener, this); |
623 WebInspector.settings.responsiveDesign.enabled.addChangeListener(listene r, this); | 629 WebInspector.settings.responsiveDesignEnabled.addChangeListener(listener , this); |
624 }, | 630 }, |
625 | 631 |
626 _userAgentChanged: function() | 632 _userAgentChanged: function() |
627 { | 633 { |
628 if (this._userAgentChangedListenerMuted) | 634 if (this._userAgentChangedListenerMuted) |
629 return; | 635 return; |
630 var userAgent = this.userAgentOverride(); | 636 var userAgent = this.userAgentOverride(); |
631 NetworkAgent.setUserAgentOverride(userAgent); | 637 NetworkAgent.setUserAgentOverride(userAgent); |
632 if (this._userAgent !== userAgent) | 638 if (this._userAgent !== userAgent) |
633 this._updateUserAgentWarningMessage(WebInspector.UIString("You might need to reload the page for proper user agent spoofing and viewport rendering." )); | 639 this._updateUserAgentWarningMessage(WebInspector.UIString("You might need to reload the page for proper user agent spoofing and viewport rendering." )); |
(...skipping 20 matching lines...) Expand all Loading... | |
654 this.settings.deviceHeight.set(height); | 660 this.settings.deviceHeight.set(height); |
655 } | 661 } |
656 }, | 662 }, |
657 | 663 |
658 _deviceMetricsChanged: function() | 664 _deviceMetricsChanged: function() |
659 { | 665 { |
660 this._showRulersChanged(); | 666 this._showRulersChanged(); |
661 | 667 |
662 if (this._deviceMetricsChangedListenerMuted) | 668 if (this._deviceMetricsChangedListenerMuted) |
663 return; | 669 return; |
664 var responsiveDesignAvailableAndDisabled = this._responsiveDesignAvailab le && (!WebInspector.settings.responsiveDesign.enabled.get() || !this._pageResiz er); | |
665 var emulateDevice = this.settings.emulateDevice.get(); | 670 var emulateDevice = this.settings.emulateDevice.get(); |
666 if (responsiveDesignAvailableAndDisabled || !emulateDevice) { | 671 if (!emulateDevice) { |
dgozman
2014/06/17 16:20:48
This is now broken.
pfeldman
2014/06/17 16:25:03
Oops. Thanks.
| |
667 this._deviceMetricsThrottler.schedule(clearDeviceMetricsOverride.bin d(this)); | 672 this._deviceMetricsThrottler.schedule(clearDeviceMetricsOverride.bin d(this)); |
668 if (this._pageResizer && !emulateDevice) | 673 if (this._pageResizer && !emulateDevice) |
669 this._pageResizer.update(0, 0, 0); | 674 this._pageResizer.update(0, 0, 0); |
670 return; | 675 return; |
671 } | 676 } |
672 | 677 |
673 var dipWidth = emulateDevice ? this.settings.deviceWidth.get() : 0; | 678 var dipWidth = emulateDevice ? this.settings.deviceWidth.get() : 0; |
674 var dipHeight = emulateDevice ? this.settings.deviceHeight.get() : 0; | 679 var dipHeight = emulateDevice ? this.settings.deviceHeight.get() : 0; |
675 | 680 |
676 // Disable override without checks. | 681 // Disable override without checks. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
739 } | 744 } |
740 }, | 745 }, |
741 | 746 |
742 _deviceMetricsOverrideAppliedForTest: function() | 747 _deviceMetricsOverrideAppliedForTest: function() |
743 { | 748 { |
744 // Used for sniffing in tests. | 749 // Used for sniffing in tests. |
745 }, | 750 }, |
746 | 751 |
747 _geolocationPositionChanged: function() | 752 _geolocationPositionChanged: function() |
748 { | 753 { |
749 if (!this.settings.overrideGeolocation.get()) { | 754 if (!this._responsiveDesignEnabledOrUnavailable() || !this.settings.over rideGeolocation.get()) { |
750 GeolocationAgent.clearGeolocationOverride(); | 755 GeolocationAgent.clearGeolocationOverride(); |
751 return; | 756 return; |
752 } | 757 } |
753 var geolocation = WebInspector.OverridesSupport.GeolocationPosition.pars eSetting(this.settings.geolocationOverride.get()); | 758 var geolocation = WebInspector.OverridesSupport.GeolocationPosition.pars eSetting(this.settings.geolocationOverride.get()); |
754 if (geolocation.error) | 759 if (geolocation.error) |
755 GeolocationAgent.setGeolocationOverride(); | 760 GeolocationAgent.setGeolocationOverride(); |
756 else | 761 else |
757 GeolocationAgent.setGeolocationOverride(geolocation.latitude, geoloc ation.longitude, 150); | 762 GeolocationAgent.setGeolocationOverride(geolocation.latitude, geoloc ation.longitude, 150); |
758 this.maybeHasActiveOverridesChanged(); | 763 this.maybeHasActiveOverridesChanged(); |
759 }, | 764 }, |
760 | 765 |
761 _deviceOrientationChanged: function() | 766 _deviceOrientationChanged: function() |
762 { | 767 { |
763 if (!this.settings.overrideDeviceOrientation.get()) { | 768 if (!this._responsiveDesignEnabledOrUnavailable() || !this.settings.over rideDeviceOrientation.get()) { |
764 PageAgent.clearDeviceOrientationOverride(); | 769 PageAgent.clearDeviceOrientationOverride(); |
765 return; | 770 return; |
766 } | 771 } |
767 | 772 |
768 var deviceOrientation = WebInspector.OverridesSupport.DeviceOrientation. parseSetting(this.settings.deviceOrientationOverride.get()); | 773 var deviceOrientation = WebInspector.OverridesSupport.DeviceOrientation. parseSetting(this.settings.deviceOrientationOverride.get()); |
769 PageAgent.setDeviceOrientationOverride(deviceOrientation.alpha, deviceOr ientation.beta, deviceOrientation.gamma); | 774 PageAgent.setDeviceOrientationOverride(deviceOrientation.alpha, deviceOr ientation.beta, deviceOrientation.gamma); |
770 this.maybeHasActiveOverridesChanged(); | 775 this.maybeHasActiveOverridesChanged(); |
771 }, | 776 }, |
772 | 777 |
773 _emulateTouchEventsChanged: function() | 778 _emulateTouchEventsChanged: function() |
774 { | 779 { |
775 var emulateTouch = this.isTouchEmulationEnabled(); | 780 var emulateTouch = this.isTouchEmulationEnabled(); |
776 var targets = WebInspector.targetManager.targets(); | 781 var targets = WebInspector.targetManager.targets(); |
777 for (var i = 0; i < targets.length; ++i) | 782 for (var i = 0; i < targets.length; ++i) |
778 targets[i].domModel.emulateTouchEventObjects(emulateTouch); | 783 targets[i].domModel.emulateTouchEventObjects(emulateTouch); |
779 this.maybeHasActiveOverridesChanged(); | 784 this.maybeHasActiveOverridesChanged(); |
780 }, | 785 }, |
781 | 786 |
782 _cssMediaChanged: function() | 787 _cssMediaChanged: function() |
783 { | 788 { |
784 if (this.isInspectingDevice() && this.settings.overrideCSSMedia.get()) | 789 if (this.isInspectingDevice() && this.settings.overrideCSSMedia.get()) |
785 return; | 790 return; |
786 | 791 |
787 PageAgent.setEmulatedMedia(this.settings.overrideCSSMedia.get() ? this.s ettings.emulatedCSSMedia.get() : ""); | 792 PageAgent.setEmulatedMedia(this._responsiveDesignEnabledOrUnavailable() && this.settings.overrideCSSMedia.get() ? this.settings.emulatedCSSMedia.get() : ""); |
788 var targets = WebInspector.targetManager.targets(); | 793 var targets = WebInspector.targetManager.targets(); |
789 for (var i = 0; i < targets.length; ++i) | 794 for (var i = 0; i < targets.length; ++i) |
790 targets[i].cssModel.mediaQueryResultChanged(); | 795 targets[i].cssModel.mediaQueryResultChanged(); |
791 this.maybeHasActiveOverridesChanged(); | 796 this.maybeHasActiveOverridesChanged(); |
792 }, | 797 }, |
793 | 798 |
794 _networkConditionsChanged: function() | 799 _networkConditionsChanged: function() |
795 { | 800 { |
796 if (!this.settings.emulateNetworkConditions.get()) { | 801 if (!this._responsiveDesignEnabledOrUnavailable() || !this.settings.emul ateNetworkConditions.get()) { |
797 NetworkAgent.emulateNetworkConditions([], 0, false); | 802 NetworkAgent.emulateNetworkConditions([], 0, false); |
798 } else { | 803 } else { |
799 var domainsString = this.settings.networkConditionsDomains.get().tri m(); | 804 var domainsString = this.settings.networkConditionsDomains.get().tri m(); |
800 var domains = domainsString ? domainsString.split(",").map(function (s) { return s.trim(); }) : []; | 805 var domains = domainsString ? domainsString.split(",").map(function (s) { return s.trim(); }) : []; |
801 var throughput = this.settings.networkConditionsThroughput.get(); | 806 var throughput = this.settings.networkConditionsThroughput.get(); |
802 var offline = !throughput; | 807 var offline = !throughput; |
803 NetworkAgent.emulateNetworkConditions(domains, throughput, offline); | 808 NetworkAgent.emulateNetworkConditions(domains, throughput, offline); |
804 } | 809 } |
805 this.maybeHasActiveOverridesChanged(); | 810 this.maybeHasActiveOverridesChanged(); |
806 }, | 811 }, |
(...skipping 22 matching lines...) Expand all Loading... | |
829 return this._hasActiveOverrides; | 834 return this._hasActiveOverrides; |
830 }, | 835 }, |
831 | 836 |
832 maybeHasActiveOverridesChanged: function() | 837 maybeHasActiveOverridesChanged: function() |
833 { | 838 { |
834 var hasActiveOverrides = | 839 var hasActiveOverrides = |
835 !!this.userAgentOverride() || | 840 !!this.userAgentOverride() || |
836 (this.settings.emulateDevice.get() && !this.isInspectingDevice()) || | 841 (this.settings.emulateDevice.get() && !this.isInspectingDevice()) || |
837 this.settings.overrideGeolocation.get() || | 842 this.settings.overrideGeolocation.get() || |
838 this.settings.overrideDeviceOrientation.get() || | 843 this.settings.overrideDeviceOrientation.get() || |
844 this.settings.emulateNetworkConditions.get() || | |
839 this.isTouchEmulationEnabled() || | 845 this.isTouchEmulationEnabled() || |
840 (this.settings.overrideCSSMedia.get() && !this.isInspectingDevice()) ; | 846 (this.settings.overrideCSSMedia.get() && !this.isInspectingDevice()) ; |
841 if (this._hasActiveOverrides !== hasActiveOverrides) { | 847 if (this._hasActiveOverrides !== hasActiveOverrides) { |
842 this._hasActiveOverrides = hasActiveOverrides; | 848 this._hasActiveOverrides = hasActiveOverrides; |
843 this.dispatchEventToListeners(WebInspector.OverridesSupport.Events.H asActiveOverridesChanged); | 849 this.dispatchEventToListeners(WebInspector.OverridesSupport.Events.H asActiveOverridesChanged); |
844 } | 850 } |
845 }, | 851 }, |
846 | 852 |
847 _onMainFrameNavigated: function() | 853 _onMainFrameNavigated: function() |
848 { | 854 { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
945 isInspectingDevice: function() | 951 isInspectingDevice: function() |
946 { | 952 { |
947 return !!this._target && this._target.isMobile(); | 953 return !!this._target && this._target.isMobile(); |
948 }, | 954 }, |
949 | 955 |
950 /** | 956 /** |
951 * @return {boolean} | 957 * @return {boolean} |
952 */ | 958 */ |
953 isEmulateDeviceEnabled: function() | 959 isEmulateDeviceEnabled: function() |
954 { | 960 { |
955 return this.settings.emulateDevice.get() && (!this._responsiveDesignAvai lable || WebInspector.settings.responsiveDesign.enabled.get()); | 961 return this.settings.emulateDevice.get() && WebInspector.settings.respon siveDesignEnabled.get(); |
956 }, | 962 }, |
957 | 963 |
958 /** | 964 /** |
959 * @return {boolean} | 965 * @return {boolean} |
960 */ | 966 */ |
961 isTouchEmulationEnabled: function() | 967 isTouchEmulationEnabled: function() |
962 { | 968 { |
963 return !this.hasTouchInputs() && ((this.isEmulateDeviceEnabled() && this .settings.deviceTouch.get()) || this.settings.sensorsTouch.get()); | 969 return !this.hasTouchInputs() && ((this.isEmulateDeviceEnabled() && this .settings.deviceTouch.get()) || this.settings.sensorsTouch.get()); |
964 }, | 970 }, |
965 | 971 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1147 }, | 1153 }, |
1148 | 1154 |
1149 __proto__: WebInspector.Object.prototype | 1155 __proto__: WebInspector.Object.prototype |
1150 } | 1156 } |
1151 | 1157 |
1152 | 1158 |
1153 /** | 1159 /** |
1154 * @type {!WebInspector.OverridesSupport} | 1160 * @type {!WebInspector.OverridesSupport} |
1155 */ | 1161 */ |
1156 WebInspector.overridesSupport; | 1162 WebInspector.overridesSupport; |
OLD | NEW |