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 19 matching lines...) Expand all Loading... |
30 | 30 |
31 /** | 31 /** |
32 * @constructor | 32 * @constructor |
33 * @implements {WebInspector.TargetManager.Observer} | 33 * @implements {WebInspector.TargetManager.Observer} |
34 * @extends {WebInspector.Object} | 34 * @extends {WebInspector.Object} |
35 * @param {boolean} responsiveDesignAvailable | 35 * @param {boolean} responsiveDesignAvailable |
36 */ | 36 */ |
37 WebInspector.OverridesSupport = function(responsiveDesignAvailable) | 37 WebInspector.OverridesSupport = function(responsiveDesignAvailable) |
38 { | 38 { |
39 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod
el.EventTypes.MainFrameNavigated, this._onMainFrameNavigated.bind(this), this); | 39 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod
el.EventTypes.MainFrameNavigated, this._onMainFrameNavigated.bind(this), this); |
40 this._overrideDeviceResolution = false; | |
41 this._emulateViewportEnabled = false; | 40 this._emulateViewportEnabled = false; |
42 this._userAgent = ""; | 41 this._userAgent = ""; |
43 this._pageResizer = null; | 42 this._pageResizer = null; |
44 this._initialized = false; | 43 this._initialized = false; |
45 this._deviceMetricsThrottler = new WebInspector.Throttler(0); | 44 this._deviceMetricsThrottler = new WebInspector.Throttler(0); |
| 45 this._responsiveDesignAvailable = responsiveDesignAvailable; |
46 WebInspector.targetManager.observeTargets(this); | 46 WebInspector.targetManager.observeTargets(this); |
47 this._responsiveDesignAvailable = responsiveDesignAvailable; | |
48 } | 47 } |
49 | 48 |
50 WebInspector.OverridesSupport.Events = { | 49 WebInspector.OverridesSupport.Events = { |
51 OverridesWarningUpdated: "OverridesWarningUpdated", | 50 OverridesWarningUpdated: "OverridesWarningUpdated", |
52 HasActiveOverridesChanged: "HasActiveOverridesChanged", | 51 HasActiveOverridesChanged: "HasActiveOverridesChanged", |
53 } | 52 } |
54 | 53 |
55 /** | 54 /** |
56 * @interface | 55 * @interface |
57 * @extends {WebInspector.EventTarget} | 56 * @extends {WebInspector.EventTarget} |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 /** | 509 /** |
511 * @param {string} deviceMetrics | 510 * @param {string} deviceMetrics |
512 * @param {string} userAgent | 511 * @param {string} userAgent |
513 */ | 512 */ |
514 emulateDevice: function(deviceMetrics, userAgent) | 513 emulateDevice: function(deviceMetrics, userAgent) |
515 { | 514 { |
516 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(d
eviceMetrics); | 515 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(d
eviceMetrics); |
517 this._deviceMetricsChangedListenerMuted = true; | 516 this._deviceMetricsChangedListenerMuted = true; |
518 this._userAgentChangedListenerMuted = true; | 517 this._userAgentChangedListenerMuted = true; |
519 this.settings.userAgent.set(userAgent); | 518 this.settings.userAgent.set(userAgent); |
520 this.settings.overrideDeviceResolution.set(true); | |
521 this.settings.deviceWidth.set(metrics.width); | 519 this.settings.deviceWidth.set(metrics.width); |
522 this.settings.deviceHeight.set(metrics.height); | 520 this.settings.deviceHeight.set(metrics.height); |
523 this.settings.deviceScaleFactor.set(metrics.deviceScaleFactor); | 521 this.settings.deviceScaleFactor.set(metrics.deviceScaleFactor); |
524 this.settings.deviceTextAutosizing.set(metrics.textAutosizing); | 522 this.settings.deviceTextAutosizing.set(metrics.textAutosizing); |
525 this.settings.overrideUserAgent.set(true); | 523 this.settings.overrideUserAgent.set(true); |
526 this.settings.emulateTouchEvents.set(true); | 524 this.settings.emulateTouchEvents.set(true); |
527 this.settings.emulateViewport.set(true); | 525 this.settings.emulateViewport.set(true); |
| 526 this.settings.emulateDevice.set(true); |
528 delete this._deviceMetricsChangedListenerMuted; | 527 delete this._deviceMetricsChangedListenerMuted; |
529 delete this._userAgentChangedListenerMuted; | 528 delete this._userAgentChangedListenerMuted; |
530 | 529 |
531 if (this._initialized) { | 530 if (this._initialized) { |
532 this._deviceMetricsChanged(); | 531 this._deviceMetricsChanged(); |
533 this._userAgentChanged(); | 532 this._userAgentChanged(); |
534 } | 533 } |
535 }, | 534 }, |
536 | 535 |
| 536 /** |
| 537 * @param {string} deviceMetrics |
| 538 * @param {string} userAgent |
| 539 * @return {boolean} |
| 540 */ |
| 541 isEmulatingDevice: function(deviceMetrics, userAgent) |
| 542 { |
| 543 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(d
eviceMetrics); |
| 544 return this.settings.userAgent.get() === userAgent |
| 545 && this.settings.deviceWidth.get() === metrics.width |
| 546 && this.settings.deviceHeight.get() === metrics.height |
| 547 && this.settings.deviceScaleFactor.get() === metrics.deviceScaleFact
or |
| 548 && this.settings.deviceTextAutosizing.get() === metrics.textAutosizi
ng |
| 549 && this.settings.emulateTouchEvents.get() |
| 550 && this.settings.emulateViewport.get(); |
| 551 }, |
| 552 |
537 resetEmulatedDevice: function() | 553 resetEmulatedDevice: function() |
538 { | 554 { |
539 this._deviceMetricsChangedListenerMuted = true; | 555 this._deviceMetricsChangedListenerMuted = true; |
540 this._userAgentChangedListenerMuted = true; | 556 this._userAgentChangedListenerMuted = true; |
541 this.settings.overrideDeviceResolution.set(false); | 557 this.settings.emulateDevice.set(false); |
542 this.settings.overrideUserAgent.set(false); | 558 this.settings.overrideUserAgent.set(false); |
543 this.settings.emulateTouchEvents.set(false); | 559 this.settings.emulateTouchEvents.set(false); |
544 this.settings.emulateViewport.set(false); | 560 this.settings.emulateViewport.set(false); |
545 delete this._deviceMetricsChangedListenerMuted; | 561 delete this._deviceMetricsChangedListenerMuted; |
546 delete this._userAgentChangedListenerMuted; | 562 delete this._userAgentChangedListenerMuted; |
547 | 563 |
548 if (this._initialized) { | 564 if (this._initialized) { |
549 this._deviceMetricsChanged(); | 565 this._deviceMetricsChanged(); |
550 this._userAgentChanged(); | 566 this._userAgentChanged(); |
551 } | 567 } |
(...skipping 11 matching lines...) Expand all Loading... |
563 { | 579 { |
564 if (!this._target) { | 580 if (!this._target) { |
565 this._applyInitialOverridesOnTargetAdded = true; | 581 this._applyInitialOverridesOnTargetAdded = true; |
566 return; | 582 return; |
567 } | 583 } |
568 | 584 |
569 this._initialized = true; | 585 this._initialized = true; |
570 | 586 |
571 this.settings.overrideUserAgent.addChangeListener(this._userAgentChanged
, this); | 587 this.settings.overrideUserAgent.addChangeListener(this._userAgentChanged
, this); |
572 this.settings.userAgent.addChangeListener(this._userAgentChanged, this); | 588 this.settings.userAgent.addChangeListener(this._userAgentChanged, this); |
| 589 this.settings.emulateDevice.addChangeListener(this._updateUserAgentAndTo
uchOnEmulateDeviceChanged, this); |
573 | 590 |
574 this.settings.overrideDeviceResolution.addChangeListener(this._deviceMet
ricsChanged, this); | 591 this.settings.emulateDevice.addChangeListener(this._deviceMetricsChanged
, this); |
575 this.settings.deviceWidth.addChangeListener(this._deviceMetricsChanged,
this); | 592 this.settings.deviceWidth.addChangeListener(this._deviceMetricsChanged,
this); |
576 this.settings.deviceHeight.addChangeListener(this._deviceMetricsChanged,
this); | 593 this.settings.deviceHeight.addChangeListener(this._deviceMetricsChanged,
this); |
577 this.settings.deviceScaleFactor.addChangeListener(this._deviceMetricsCha
nged, this); | 594 this.settings.deviceScaleFactor.addChangeListener(this._deviceMetricsCha
nged, this); |
578 this.settings.deviceTextAutosizing.addChangeListener(this._deviceMetrics
Changed, this); | 595 this.settings.deviceTextAutosizing.addChangeListener(this._deviceMetrics
Changed, this); |
579 this.settings.emulateViewport.addChangeListener(this._deviceMetricsChang
ed, this); | 596 this.settings.emulateViewport.addChangeListener(this._deviceMetricsChang
ed, this); |
580 this.settings.deviceFitWindow.addChangeListener(this._deviceMetricsChang
ed, this); | 597 this.settings.deviceFitWindow.addChangeListener(this._deviceMetricsChang
ed, this); |
581 WebInspector.settings.responsiveDesign.enabled.addChangeListener(this._d
eviceMetricsChanged, this); | 598 WebInspector.settings.responsiveDesign.enabled.addChangeListener(this._d
eviceMetricsChanged, this); |
582 | 599 |
583 this.settings.overrideGeolocation.addChangeListener(this._geolocationPos
itionChanged, this); | 600 this.settings.overrideGeolocation.addChangeListener(this._geolocationPos
itionChanged, this); |
584 this.settings.geolocationOverride.addChangeListener(this._geolocationPos
itionChanged, this); | 601 this.settings.geolocationOverride.addChangeListener(this._geolocationPos
itionChanged, this); |
585 | 602 |
586 this.settings.overrideDeviceOrientation.addChangeListener(this._deviceOr
ientationChanged, this); | 603 this.settings.overrideDeviceOrientation.addChangeListener(this._deviceOr
ientationChanged, this); |
587 this.settings.deviceOrientationOverride.addChangeListener(this._deviceOr
ientationChanged, this); | 604 this.settings.deviceOrientationOverride.addChangeListener(this._deviceOr
ientationChanged, this); |
588 | 605 |
| 606 this.settings.emulateDevice.addChangeListener(this._emulateTouchEventsCh
anged, this); |
589 this.settings.emulateTouchEvents.addChangeListener(this._emulateTouchEve
ntsChanged, this); | 607 this.settings.emulateTouchEvents.addChangeListener(this._emulateTouchEve
ntsChanged, this); |
| 608 this.settings.emulateDevice.addChangeListener(this._updateUserAgentAndTo
uchOnEmulateDeviceChanged, this); |
590 | 609 |
591 this.settings.overrideCSSMedia.addChangeListener(this._cssMediaChanged,
this); | 610 this.settings.overrideCSSMedia.addChangeListener(this._cssMediaChanged,
this); |
592 this.settings.emulatedCSSMedia.addChangeListener(this._cssMediaChanged,
this); | 611 this.settings.emulatedCSSMedia.addChangeListener(this._cssMediaChanged,
this); |
593 | 612 |
594 this.settings.emulateNetworkConditions.addChangeListener(this._networkCo
nditionsChanged, this); | 613 this.settings.emulateNetworkConditions.addChangeListener(this._networkCo
nditionsChanged, this); |
595 this.settings.networkConditionsDomains.addChangeListener(this._networkCo
nditionsChanged, this); | 614 this.settings.networkConditionsDomains.addChangeListener(this._networkCo
nditionsChanged, this); |
596 this.settings.networkConditionsThroughput.addChangeListener(this._networ
kConditionsChanged, this); | 615 this.settings.networkConditionsThroughput.addChangeListener(this._networ
kConditionsChanged, this); |
597 | 616 |
598 WebInspector.settings.showMetricsRulers.addChangeListener(this._showRule
rsChanged, this); | 617 WebInspector.settings.showMetricsRulers.addChangeListener(this._showRule
rsChanged, this); |
599 | 618 |
600 if (this.settings.overrideDeviceOrientation.get()) | 619 if (this.settings.overrideDeviceOrientation.get()) |
601 this._deviceOrientationChanged(); | 620 this._deviceOrientationChanged(); |
602 | 621 |
603 if (this.settings.overrideGeolocation.get()) | 622 if (this.settings.overrideGeolocation.get()) |
604 this._geolocationPositionChanged(); | 623 this._geolocationPositionChanged(); |
605 | 624 |
606 if (this.settings.emulateTouchEvents.get()) | 625 if (this.settings.emulateTouchEvents.get() && (this.settings.emulateDevi
ce.get() || !this._responsiveDesignAvailable)) |
607 this._emulateTouchEventsChanged(); | 626 this._emulateTouchEventsChanged(); |
608 | 627 |
609 if (this.settings.overrideCSSMedia.get()) | 628 if (this.settings.overrideCSSMedia.get()) |
610 this._cssMediaChanged(); | 629 this._cssMediaChanged(); |
611 | 630 |
612 if (this.settings.overrideDeviceResolution.get() || this.settings.emulat
eViewport.get()) | 631 if (this.settings.emulateDevice.get()) |
613 this._deviceMetricsChanged(); | 632 this._deviceMetricsChanged(); |
614 | 633 |
615 if (this.settings.overrideUserAgent.get()) | 634 if (this.settings.overrideUserAgent.get()) |
616 this._userAgentChanged(); | 635 this._userAgentChanged(); |
617 | 636 |
618 if (this.settings.emulateNetworkConditions.get()) | 637 if (this.settings.emulateNetworkConditions.get()) |
619 this._networkConditionsChanged(); | 638 this._networkConditionsChanged(); |
620 | 639 |
621 this._showRulersChanged(); | 640 this._showRulersChanged(); |
622 }, | 641 }, |
623 | 642 |
| 643 _updateUserAgentAndTouchOnEmulateDeviceChanged: function() |
| 644 { |
| 645 var value = this.settings.emulateDevice.get(); |
| 646 if (this.settings.overrideUserAgent.get() !== value) |
| 647 this.settings.overrideUserAgent.set(value); |
| 648 if (this.settings.emulateTouchEvents.get() !== value && !this._responsiv
eDesignAvailable) |
| 649 this.settings.emulateTouchEvents.set(value); |
| 650 }, |
| 651 |
624 _userAgentChanged: function() | 652 _userAgentChanged: function() |
625 { | 653 { |
626 if (this._userAgentChangedListenerMuted) | 654 if (this._userAgentChangedListenerMuted) |
627 return; | 655 return; |
628 var userAgent = this.settings.overrideUserAgent.get() ? this.settings.us
erAgent.get() : ""; | 656 var userAgent = this.settings.overrideUserAgent.get() ? this.settings.us
erAgent.get() : ""; |
629 NetworkAgent.setUserAgentOverride(userAgent); | 657 NetworkAgent.setUserAgentOverride(userAgent); |
630 if (this._userAgent !== userAgent) | 658 if (this._userAgent !== userAgent) |
631 this._updateUserAgentWarningMessage(WebInspector.UIString("You might
need to reload the page for proper user agent spoofing and viewport rendering."
)); | 659 this._updateUserAgentWarningMessage(WebInspector.UIString("You might
need to reload the page for proper user agent spoofing and viewport rendering."
)); |
632 this._userAgent = userAgent; | 660 this._userAgent = userAgent; |
633 this.maybeHasActiveOverridesChanged(); | 661 this.maybeHasActiveOverridesChanged(); |
(...skipping 19 matching lines...) Expand all Loading... |
653 } | 681 } |
654 }, | 682 }, |
655 | 683 |
656 _deviceMetricsChanged: function() | 684 _deviceMetricsChanged: function() |
657 { | 685 { |
658 this._showRulersChanged(); | 686 this._showRulersChanged(); |
659 | 687 |
660 if (this._deviceMetricsChangedListenerMuted) | 688 if (this._deviceMetricsChangedListenerMuted) |
661 return; | 689 return; |
662 var responsiveDesignAvailableAndDisabled = this._responsiveDesignAvailab
le && (!WebInspector.settings.responsiveDesign.enabled.get() || !this._pageResiz
er); | 690 var responsiveDesignAvailableAndDisabled = this._responsiveDesignAvailab
le && (!WebInspector.settings.responsiveDesign.enabled.get() || !this._pageResiz
er); |
663 var overrideDeviceResolution = this.settings.overrideDeviceResolution.ge
t(); | 691 var emulateDevice = this.settings.emulateDevice.get(); |
664 var emulationEnabled = overrideDeviceResolution || this.settings.emulate
Viewport.get(); | 692 if (responsiveDesignAvailableAndDisabled || !emulateDevice) { |
665 if (responsiveDesignAvailableAndDisabled || !emulationEnabled) { | |
666 this._deviceMetricsThrottler.schedule(clearDeviceMetricsOverride.bin
d(this)); | 693 this._deviceMetricsThrottler.schedule(clearDeviceMetricsOverride.bin
d(this)); |
667 if (this._pageResizer && !emulationEnabled) | 694 if (this._pageResizer && !emulateDevice) |
668 this._pageResizer.update(0, 0, 0); | 695 this._pageResizer.update(0, 0, 0); |
669 return; | 696 return; |
670 } | 697 } |
671 | 698 |
672 var dipWidth = overrideDeviceResolution ? this.settings.deviceWidth.get(
) : 0; | 699 var dipWidth = emulateDevice ? this.settings.deviceWidth.get() : 0; |
673 var dipHeight = overrideDeviceResolution ? this.settings.deviceHeight.ge
t() : 0; | 700 var dipHeight = emulateDevice ? this.settings.deviceHeight.get() : 0; |
674 | 701 |
675 // Disable override without checks. | 702 // Disable override without checks. |
676 if (this.isInspectingDevice()) | 703 if (this.isInspectingDevice()) |
677 return; | 704 return; |
678 | 705 |
679 var overrideWidth = dipWidth; | 706 var overrideWidth = dipWidth; |
680 var overrideHeight = dipHeight; | 707 var overrideHeight = dipHeight; |
681 if (this._pageResizer) { | 708 if (this._pageResizer) { |
682 var available = this._pageResizer.availableDipSize(); | 709 var available = this._pageResizer.availableDipSize(); |
683 if (available.width >= dipWidth && available.height >= dipHeight) { | 710 if (available.width >= dipWidth && available.height >= dipHeight) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 */ | 748 */ |
722 function apiCallback(finishCallback, error) | 749 function apiCallback(finishCallback, error) |
723 { | 750 { |
724 if (error) { | 751 if (error) { |
725 this._updateDeviceMetricsWarningMessage(WebInspector.UIString("S
creen emulation is not available on this page.")); | 752 this._updateDeviceMetricsWarningMessage(WebInspector.UIString("S
creen emulation is not available on this page.")); |
726 this._deviceMetricsOverrideAppliedForTest(); | 753 this._deviceMetricsOverrideAppliedForTest(); |
727 finishCallback(); | 754 finishCallback(); |
728 return; | 755 return; |
729 } | 756 } |
730 | 757 |
731 var overrideDeviceResolution = this.settings.overrideDeviceResolutio
n.get(); | 758 var viewportEnabled = this.settings.emulateDevice.get() && this.sett
ings.emulateViewport.get(); |
732 var viewportEnabled = this.settings.emulateViewport.get(); | 759 if (this._emulateViewportEnabled !== viewportEnabled) |
733 if (this._overrideDeviceResolution !== overrideDeviceResolution || t
his._emulateViewportEnabled !== viewportEnabled) | |
734 this._updateDeviceMetricsWarningMessage(WebInspector.UIString("Y
ou might need to reload the page for proper user agent spoofing and viewport ren
dering.")); | 760 this._updateDeviceMetricsWarningMessage(WebInspector.UIString("Y
ou might need to reload the page for proper user agent spoofing and viewport ren
dering.")); |
735 this._overrideDeviceResolution = overrideDeviceResolution; | |
736 this._emulateViewportEnabled = viewportEnabled; | 761 this._emulateViewportEnabled = viewportEnabled; |
737 this._deviceMetricsOverrideAppliedForTest(); | 762 this._deviceMetricsOverrideAppliedForTest(); |
738 this.maybeHasActiveOverridesChanged(); | 763 this.maybeHasActiveOverridesChanged(); |
739 finishCallback(); | 764 finishCallback(); |
740 } | 765 } |
741 }, | 766 }, |
742 | 767 |
743 _deviceMetricsOverrideAppliedForTest: function() | 768 _deviceMetricsOverrideAppliedForTest: function() |
744 { | 769 { |
745 // Used for sniffing in tests. | 770 // Used for sniffing in tests. |
(...skipping 23 matching lines...) Expand all Loading... |
769 var deviceOrientation = WebInspector.OverridesSupport.DeviceOrientation.
parseSetting(this.settings.deviceOrientationOverride.get()); | 794 var deviceOrientation = WebInspector.OverridesSupport.DeviceOrientation.
parseSetting(this.settings.deviceOrientationOverride.get()); |
770 PageAgent.setDeviceOrientationOverride(deviceOrientation.alpha, deviceOr
ientation.beta, deviceOrientation.gamma); | 795 PageAgent.setDeviceOrientationOverride(deviceOrientation.alpha, deviceOr
ientation.beta, deviceOrientation.gamma); |
771 this.maybeHasActiveOverridesChanged(); | 796 this.maybeHasActiveOverridesChanged(); |
772 }, | 797 }, |
773 | 798 |
774 _emulateTouchEventsChanged: function() | 799 _emulateTouchEventsChanged: function() |
775 { | 800 { |
776 if (this.hasTouchInputs() && this.settings.emulateTouchEvents.get()) | 801 if (this.hasTouchInputs() && this.settings.emulateTouchEvents.get()) |
777 return; | 802 return; |
778 | 803 |
779 var emulateTouch = this.settings.emulateTouchEvents.get(); | 804 var emulateTouch = this.settings.emulateTouchEvents.get() && (this.setti
ngs.emulateDevice.get() || !this._responsiveDesignAvailable); |
780 var targets = WebInspector.targetManager.targets(); | 805 var targets = WebInspector.targetManager.targets(); |
781 for (var i = 0; i < targets.length; ++i) | 806 for (var i = 0; i < targets.length; ++i) |
782 targets[i].domModel.emulateTouchEventObjects(emulateTouch); | 807 targets[i].domModel.emulateTouchEventObjects(emulateTouch); |
783 this.maybeHasActiveOverridesChanged(); | 808 this.maybeHasActiveOverridesChanged(); |
784 }, | 809 }, |
785 | 810 |
786 _cssMediaChanged: function() | 811 _cssMediaChanged: function() |
787 { | 812 { |
788 if (this.isInspectingDevice() && this.settings.overrideCSSMedia.get()) | 813 if (this.isInspectingDevice() && this.settings.overrideCSSMedia.get()) |
789 return; | 814 return; |
(...skipping 17 matching lines...) Expand all Loading... |
807 NetworkAgent.emulateNetworkConditions(domains, throughput, offline); | 832 NetworkAgent.emulateNetworkConditions(domains, throughput, offline); |
808 } | 833 } |
809 this.maybeHasActiveOverridesChanged(); | 834 this.maybeHasActiveOverridesChanged(); |
810 }, | 835 }, |
811 | 836 |
812 /** | 837 /** |
813 * @return {boolean} | 838 * @return {boolean} |
814 */ | 839 */ |
815 showMetricsRulers: function() | 840 showMetricsRulers: function() |
816 { | 841 { |
817 var rulersInPageResizer = this._pageResizer && this.settings.overrideDev
iceResolution.get(); | 842 var rulersInPageResizer = this._pageResizer && this.settings.emulateDevi
ce.get(); |
818 return WebInspector.settings.showMetricsRulers.get() && !rulersInPageRes
izer; | 843 return WebInspector.settings.showMetricsRulers.get() && !rulersInPageRes
izer; |
819 }, | 844 }, |
820 | 845 |
821 _showRulersChanged: function() | 846 _showRulersChanged: function() |
822 { | 847 { |
823 if (WebInspector.experimentsSettings.responsiveDesign.isEnabled()) | 848 if (WebInspector.experimentsSettings.responsiveDesign.isEnabled()) |
824 return; | 849 return; |
825 PageAgent.setShowViewportSizeOnResize(true, this.showMetricsRulers()); | 850 PageAgent.setShowViewportSizeOnResize(true, this.showMetricsRulers()); |
826 }, | 851 }, |
827 | 852 |
828 /** | 853 /** |
829 * @return {boolean} | 854 * @return {boolean} |
830 */ | 855 */ |
831 hasActiveOverrides: function() | 856 hasActiveOverrides: function() |
832 { | 857 { |
833 return this._hasActiveOverrides; | 858 return this._hasActiveOverrides; |
834 }, | 859 }, |
835 | 860 |
836 maybeHasActiveOverridesChanged: function() | 861 maybeHasActiveOverridesChanged: function() |
837 { | 862 { |
838 var hasActiveOverrides = | 863 var hasActiveOverrides = |
839 this.settings.overrideUserAgent.get() || | 864 this.settings.overrideUserAgent.get() || |
840 ((this.settings.overrideDeviceResolution.get() || this.settings.emul
ateViewport.get()) && !this.isInspectingDevice()) || | 865 (this.settings.emulateDevice.get() && !this.isInspectingDevice()) || |
841 this.settings.overrideGeolocation.get() || | 866 this.settings.overrideGeolocation.get() || |
842 this.settings.overrideDeviceOrientation.get() || | 867 this.settings.overrideDeviceOrientation.get() || |
843 (this.settings.emulateTouchEvents.get() && !this.hasTouchInputs()) |
| | 868 (this.settings.emulateTouchEvents.get() && this.settings.emulateDevi
ce.get() && !this.hasTouchInputs()) || |
844 (this.settings.overrideCSSMedia.get() && !this.isInspectingDevice())
; | 869 (this.settings.overrideCSSMedia.get() && !this.isInspectingDevice())
; |
845 if (this._hasActiveOverrides !== hasActiveOverrides) { | 870 if (this._hasActiveOverrides !== hasActiveOverrides) { |
846 this._hasActiveOverrides = hasActiveOverrides; | 871 this._hasActiveOverrides = hasActiveOverrides; |
847 this.dispatchEventToListeners(WebInspector.OverridesSupport.Events.H
asActiveOverridesChanged); | 872 this.dispatchEventToListeners(WebInspector.OverridesSupport.Events.H
asActiveOverridesChanged); |
848 } | 873 } |
849 }, | 874 }, |
850 | 875 |
851 _onMainFrameNavigated: function() | 876 _onMainFrameNavigated: function() |
852 { | 877 { |
853 if (this._initialized) | 878 if (this._initialized) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 { | 914 { |
890 // FIXME: adapt this to multiple targets. | 915 // FIXME: adapt this to multiple targets. |
891 if (this._target) | 916 if (this._target) |
892 return; | 917 return; |
893 this._target = target; | 918 this._target = target; |
894 | 919 |
895 this.settings = {}; | 920 this.settings = {}; |
896 this.settings.overrideUserAgent = WebInspector.settings.createSetting("o
verrideUserAgent", false); | 921 this.settings.overrideUserAgent = WebInspector.settings.createSetting("o
verrideUserAgent", false); |
897 this.settings.userAgent = WebInspector.settings.createSetting("userAgent
", ""); | 922 this.settings.userAgent = WebInspector.settings.createSetting("userAgent
", ""); |
898 | 923 |
899 this.settings.overrideDeviceResolution = WebInspector.settings.createSet
ting("overrideDeviceResolution", false); | 924 this.settings.emulateDevice = WebInspector.settings.createSetting("emula
teDevice", false); |
900 this.settings.deviceWidth = WebInspector.settings.createSetting("deviceW
idth", 800); | 925 this.settings.deviceWidth = WebInspector.settings.createSetting("deviceW
idth", 800); |
901 this.settings.deviceHeight = WebInspector.settings.createSetting("device
Height", 600); | 926 this.settings.deviceHeight = WebInspector.settings.createSetting("device
Height", 600); |
902 this.settings.deviceScaleFactor = WebInspector.settings.createSetting("d
eviceScaleFactor", window.devicePixelRatio); | 927 this.settings.deviceScaleFactor = WebInspector.settings.createSetting("d
eviceScaleFactor", window.devicePixelRatio); |
903 this.settings.deviceTextAutosizing = WebInspector.settings.createSetting
("deviceTextAutosizing", true); | 928 this.settings.deviceTextAutosizing = WebInspector.settings.createSetting
("deviceTextAutosizing", true); |
904 | |
905 this.settings.deviceFitWindow = WebInspector.settings.createSetting("dev
iceFitWindow", true); | 929 this.settings.deviceFitWindow = WebInspector.settings.createSetting("dev
iceFitWindow", true); |
| 930 // FIXME: rename viewport to mobile everywhere in the code. |
906 this.settings.emulateViewport = WebInspector.settings.createSetting("emu
lateViewport", false); | 931 this.settings.emulateViewport = WebInspector.settings.createSetting("emu
lateViewport", false); |
907 this.settings.emulateTouchEvents = WebInspector.settings.createSetting("
emulateTouchEvents", false); | 932 this.settings.emulateTouchEvents = WebInspector.settings.createSetting("
emulateTouchEvents", false); |
| 933 |
908 this.settings.overrideGeolocation = WebInspector.settings.createSetting(
"overrideGeolocation", false); | 934 this.settings.overrideGeolocation = WebInspector.settings.createSetting(
"overrideGeolocation", false); |
909 this.settings.geolocationOverride = WebInspector.settings.createSetting(
"geolocationOverride", ""); | 935 this.settings.geolocationOverride = WebInspector.settings.createSetting(
"geolocationOverride", ""); |
910 this.settings.overrideDeviceOrientation = WebInspector.settings.createSe
tting("overrideDeviceOrientation", false); | 936 this.settings.overrideDeviceOrientation = WebInspector.settings.createSe
tting("overrideDeviceOrientation", false); |
911 this.settings.deviceOrientationOverride = WebInspector.settings.createSe
tting("deviceOrientationOverride", ""); | 937 this.settings.deviceOrientationOverride = WebInspector.settings.createSe
tting("deviceOrientationOverride", ""); |
912 this.settings.overrideCSSMedia = WebInspector.settings.createSetting("ov
errideCSSMedia", false); | 938 this.settings.overrideCSSMedia = WebInspector.settings.createSetting("ov
errideCSSMedia", false); |
913 this.settings.emulatedCSSMedia = WebInspector.settings.createSetting("em
ulatedCSSMedia", "print"); | 939 this.settings.emulatedCSSMedia = WebInspector.settings.createSetting("em
ulatedCSSMedia", "print"); |
914 this.settings.emulatedDevice = WebInspector.settings.createSetting("emul
atedDevice", "Google Nexus 5"); | |
915 | 940 |
916 this.settings.emulateNetworkConditions = WebInspector.settings.createSet
ting("emulateNetworkConditions", false); | 941 this.settings.emulateNetworkConditions = WebInspector.settings.createSet
ting("emulateNetworkConditions", false); |
917 this.settings.networkConditionsDomains = WebInspector.settings.createSet
ting("networkConditionsDomains", ""); | 942 this.settings.networkConditionsDomains = WebInspector.settings.createSet
ting("networkConditionsDomains", ""); |
918 this.settings.networkConditionsThroughput = WebInspector.settings.create
Setting("networkConditionsThroughput", 0); | 943 this.settings.networkConditionsThroughput = WebInspector.settings.create
Setting("networkConditionsThroughput", 0); |
919 | 944 |
920 this.maybeHasActiveOverridesChanged(); | 945 this.maybeHasActiveOverridesChanged(); |
921 | 946 |
922 if (this._applyInitialOverridesOnTargetAdded) { | 947 if (this._applyInitialOverridesOnTargetAdded) { |
923 delete this._applyInitialOverridesOnTargetAdded; | 948 delete this._applyInitialOverridesOnTargetAdded; |
924 this.applyInitialOverrides(); | 949 this.applyInitialOverrides(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 * | 990 * |
966 * For a description of the Android device scale adjustment algorithm, see: | 991 * For a description of the Android device scale adjustment algorithm, see: |
967 * chrome/browser/chrome_content_browser_client.cc, GetFontScaleMultipli
er(...) | 992 * chrome/browser/chrome_content_browser_client.cc, GetFontScaleMultipli
er(...) |
968 * | 993 * |
969 * @param {number} width | 994 * @param {number} width |
970 * @param {number} height | 995 * @param {number} height |
971 * @return {number} font scale factor. | 996 * @return {number} font scale factor. |
972 */ | 997 */ |
973 _fontScaleFactor: function(width, height) | 998 _fontScaleFactor: function(width, height) |
974 { | 999 { |
975 if (!this.settings.overrideDeviceResolution.get()) | 1000 if (!this.settings.emulateDevice.get()) |
976 return 1; | 1001 return 1; |
977 if (!width && !height) | 1002 if (!width && !height) |
978 return 1; | 1003 return 1; |
979 | 1004 |
980 var deviceScaleFactor = this.settings.deviceScaleFactor.get(); | 1005 var deviceScaleFactor = this.settings.deviceScaleFactor.get(); |
981 | 1006 |
982 var minWidth = Math.min(width, height) / deviceScaleFactor; | 1007 var minWidth = Math.min(width, height) / deviceScaleFactor; |
983 | 1008 |
984 var kMinFSM = 1.05; | 1009 var kMinFSM = 1.05; |
985 var kWidthForMinFSM = 320; | 1010 var kWidthForMinFSM = 320; |
(...skipping 14 matching lines...) Expand all Loading... |
1000 * @param {!Document} document | 1025 * @param {!Document} document |
1001 * @return {!Element} | 1026 * @return {!Element} |
1002 */ | 1027 */ |
1003 createDeviceSelect: function(document) | 1028 createDeviceSelect: function(document) |
1004 { | 1029 { |
1005 var deviceSelectElement = document.createElement("select"); | 1030 var deviceSelectElement = document.createElement("select"); |
1006 deviceSelectElement.disabled = WebInspector.overridesSupport.isInspectin
gDevice(); | 1031 deviceSelectElement.disabled = WebInspector.overridesSupport.isInspectin
gDevice(); |
1007 | 1032 |
1008 var devices = WebInspector.OverridesSupport._phones.concat(WebInspector.
OverridesSupport._tablets); | 1033 var devices = WebInspector.OverridesSupport._phones.concat(WebInspector.
OverridesSupport._tablets); |
1009 devices.sort(); | 1034 devices.sort(); |
| 1035 |
| 1036 var selectDevice = [WebInspector.UIString("<Select device>"), "", ""]; |
| 1037 devices = devices.concat([selectDevice]); |
1010 for (var i = 0; i < devices.length; ++i) { | 1038 for (var i = 0; i < devices.length; ++i) { |
1011 var device = devices[i]; | 1039 var device = devices[i]; |
1012 var option = new Option(device[0], device[0]); | 1040 var option = new Option(device[0], device[0]); |
1013 option.userAgent = device[1]; | 1041 option.userAgent = device[1]; |
1014 option.metrics = device[2]; | 1042 option.metrics = device[2]; |
1015 deviceSelectElement.add(option); | 1043 deviceSelectElement.add(option); |
1016 } | 1044 } |
1017 | 1045 |
1018 settingChanged(); | |
1019 WebInspector.overridesSupport.settings.emulatedDevice.addChangeListener(
settingChanged); | |
1020 deviceSelectElement.addEventListener("change", deviceSelected, false); | 1046 deviceSelectElement.addEventListener("change", deviceSelected, false); |
1021 | 1047 |
| 1048 var emulatedSettingChangedMuted = false; |
| 1049 WebInspector.overridesSupport.settings.deviceWidth.addChangeListener(emu
latedSettingChanged); |
| 1050 WebInspector.overridesSupport.settings.deviceHeight.addChangeListener(em
ulatedSettingChanged); |
| 1051 WebInspector.overridesSupport.settings.deviceScaleFactor.addChangeListen
er(emulatedSettingChanged); |
| 1052 WebInspector.overridesSupport.settings.deviceTextAutosizing.addChangeLis
tener(emulatedSettingChanged); |
| 1053 WebInspector.overridesSupport.settings.emulateViewport.addChangeListener
(emulatedSettingChanged); |
| 1054 WebInspector.overridesSupport.settings.deviceFitWindow.addChangeListener
(emulatedSettingChanged); |
| 1055 WebInspector.overridesSupport.settings.emulateTouchEvents.addChangeListe
ner(emulatedSettingChanged); |
| 1056 WebInspector.overridesSupport.settings.overrideUserAgent.addChangeListen
er(emulatedSettingChanged); |
| 1057 WebInspector.overridesSupport.settings.userAgent.addChangeListener(emula
tedSettingChanged); |
| 1058 emulatedSettingChanged(); |
| 1059 |
1022 function deviceSelected() | 1060 function deviceSelected() |
1023 { | 1061 { |
| 1062 if (deviceSelectElement.selectedIndex === devices.length - 1) |
| 1063 return; |
| 1064 |
1024 var option = deviceSelectElement.options[deviceSelectElement.selecte
dIndex]; | 1065 var option = deviceSelectElement.options[deviceSelectElement.selecte
dIndex]; |
1025 WebInspector.overridesSupport.settings.emulatedDevice.removeChangeLi
stener(settingChanged); | 1066 emulatedSettingChangedMuted = true; |
1026 WebInspector.overridesSupport.settings.emulatedDevice.set(option.val
ue); | 1067 WebInspector.overridesSupport.emulateDevice(option.metrics, option.u
serAgent); |
1027 WebInspector.overridesSupport.settings.emulatedDevice.addChangeListe
ner(settingChanged); | 1068 emulatedSettingChangedMuted = false; |
1028 } | 1069 } |
1029 | 1070 |
1030 function settingChanged() | 1071 function emulatedSettingChanged() |
1031 { | 1072 { |
1032 var selectionRestored = false; | 1073 if (emulatedSettingChangedMuted) |
| 1074 return; |
| 1075 |
| 1076 var index = devices.length - 1; |
1033 for (var i = 0; i < devices.length; ++i) { | 1077 for (var i = 0; i < devices.length; ++i) { |
1034 var device = devices[i]; | 1078 var option = deviceSelectElement.options[i]; |
1035 if (WebInspector.overridesSupport.settings.emulatedDevice.get()
=== device[0]) { | 1079 if (WebInspector.overridesSupport.isEmulatingDevice(option.metri
cs, option.userAgent)) { |
1036 deviceSelectElement.selectedIndex = i; | 1080 index = i; |
1037 selectionRestored = true; | |
1038 break; | 1081 break; |
1039 } | 1082 } |
1040 } | 1083 } |
1041 | 1084 deviceSelectElement.selectedIndex = index; |
1042 if (!selectionRestored) | |
1043 deviceSelectElement.selectedIndex = devices.length - 1; | |
1044 } | 1085 } |
1045 | 1086 |
1046 return deviceSelectElement; | 1087 return deviceSelectElement; |
1047 }, | 1088 }, |
1048 | 1089 |
1049 /** | 1090 /** |
1050 * @param {!Document} document | 1091 * @param {!Document} document |
1051 * @return {{select: !Element, input: !Element}} | 1092 * @return {{select: !Element, input: !Element}} |
1052 */ | 1093 */ |
1053 createUserAgentSelectAndInput: function(document) | 1094 createUserAgentSelectAndInput: function(document) |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1188 }, | 1229 }, |
1189 | 1230 |
1190 __proto__: WebInspector.Object.prototype | 1231 __proto__: WebInspector.Object.prototype |
1191 } | 1232 } |
1192 | 1233 |
1193 | 1234 |
1194 /** | 1235 /** |
1195 * @type {!WebInspector.OverridesSupport} | 1236 * @type {!WebInspector.OverridesSupport} |
1196 */ | 1237 */ |
1197 WebInspector.overridesSupport; | 1238 WebInspector.overridesSupport; |
OLD | NEW |