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 30 matching lines...) Expand all Loading... |
41 this._userAgent = ""; | 41 this._userAgent = ""; |
42 this._pageResizer = null; | 42 this._pageResizer = null; |
43 this._initialized = false; | 43 this._initialized = false; |
44 this._deviceMetricsThrottler = new WebInspector.Throttler(0); | 44 this._deviceMetricsThrottler = new WebInspector.Throttler(0); |
45 this._responsiveDesignAvailable = responsiveDesignAvailable; | 45 this._responsiveDesignAvailable = responsiveDesignAvailable; |
46 WebInspector.targetManager.observeTargets(this); | 46 WebInspector.targetManager.observeTargets(this); |
47 } | 47 } |
48 | 48 |
49 WebInspector.OverridesSupport.Events = { | 49 WebInspector.OverridesSupport.Events = { |
50 OverridesWarningUpdated: "OverridesWarningUpdated", | 50 OverridesWarningUpdated: "OverridesWarningUpdated", |
51 HasActiveOverridesChanged: "HasActiveOverridesChanged", | 51 EmulationStateChanged: "EmulationStateChanged" |
52 } | 52 } |
53 | 53 |
54 /** | 54 /** |
55 * @interface | 55 * @interface |
56 * @extends {WebInspector.EventTarget} | 56 * @extends {WebInspector.EventTarget} |
57 */ | 57 */ |
58 WebInspector.OverridesSupport.PageResizer = function() | 58 WebInspector.OverridesSupport.PageResizer = function() |
59 { | 59 { |
60 }; | 60 }; |
61 | 61 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 ["640 Kbps (3G)", 640 * 1024 / 8], | 431 ["640 Kbps (3G)", 640 * 1024 / 8], |
432 ["1 Mbps", 1024 * 1024 / 8], | 432 ["1 Mbps", 1024 * 1024 / 8], |
433 ["2 Mbps (802.11b)", 2048 * 1024 / 8], | 433 ["2 Mbps (802.11b)", 2048 * 1024 / 8], |
434 ["No throttling", WebInspector.OverridesSupport._networkThroughputUnlimitedV
alue] | 434 ["No throttling", WebInspector.OverridesSupport._networkThroughputUnlimitedV
alue] |
435 ]; | 435 ]; |
436 | 436 |
437 WebInspector.OverridesSupport.prototype = { | 437 WebInspector.OverridesSupport.prototype = { |
438 /** | 438 /** |
439 * @return {boolean} | 439 * @return {boolean} |
440 */ | 440 */ |
| 441 canEmulate: function() |
| 442 { |
| 443 return !!this._target && !this._target.isMobile(); |
| 444 }, |
| 445 |
| 446 /** |
| 447 * @return {boolean} |
| 448 */ |
| 449 emulationEnabled: function() |
| 450 { |
| 451 return this.canEmulate() && this.settings._emulationEnabled.get(); |
| 452 }, |
| 453 |
| 454 /** |
| 455 * @param {boolean} enabled |
| 456 */ |
| 457 setEmulationEnabled: function(enabled) |
| 458 { |
| 459 if (this.canEmulate()) { |
| 460 this.settings._emulationEnabled.set(enabled); |
| 461 this.dispatchEventToListeners(WebInspector.OverridesSupport.Events.E
mulationStateChanged); |
| 462 } |
| 463 }, |
| 464 |
| 465 /** |
| 466 * @return {boolean} |
| 467 */ |
441 responsiveDesignAvailable: function() | 468 responsiveDesignAvailable: function() |
442 { | 469 { |
443 return this._responsiveDesignAvailable; | 470 return this._responsiveDesignAvailable; |
444 }, | 471 }, |
445 | 472 |
446 /** | 473 /** |
447 * @param {?WebInspector.OverridesSupport.PageResizer} pageResizer | 474 * @param {?WebInspector.OverridesSupport.PageResizer} pageResizer |
448 */ | 475 */ |
449 setPageResizer: function(pageResizer) | 476 setPageResizer: function(pageResizer) |
450 { | 477 { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 | 555 |
529 applyInitialOverrides: function() | 556 applyInitialOverrides: function() |
530 { | 557 { |
531 if (!this._target) { | 558 if (!this._target) { |
532 this._applyInitialOverridesOnTargetAdded = true; | 559 this._applyInitialOverridesOnTargetAdded = true; |
533 return; | 560 return; |
534 } | 561 } |
535 | 562 |
536 this._initialized = true; | 563 this._initialized = true; |
537 | 564 |
538 this.settings.emulationEnabled.addChangeListener(this._userAgentChanged,
this); | 565 this.settings._emulationEnabled.addChangeListener(this._userAgentChanged
, this); |
539 this.settings.userAgent.addChangeListener(this._userAgentChanged, this); | 566 this.settings.userAgent.addChangeListener(this._userAgentChanged, this); |
540 | 567 |
541 this.settings.emulationEnabled.addChangeListener(this._deviceMetricsChan
ged, this); | 568 this.settings._emulationEnabled.addChangeListener(this._deviceMetricsCha
nged, this); |
542 this.settings.deviceWidth.addChangeListener(this._deviceMetricsChanged,
this); | 569 this.settings.deviceWidth.addChangeListener(this._deviceMetricsChanged,
this); |
543 this.settings.deviceHeight.addChangeListener(this._deviceMetricsChanged,
this); | 570 this.settings.deviceHeight.addChangeListener(this._deviceMetricsChanged,
this); |
544 this.settings.deviceScaleFactor.addChangeListener(this._deviceMetricsCha
nged, this); | 571 this.settings.deviceScaleFactor.addChangeListener(this._deviceMetricsCha
nged, this); |
545 this.settings.deviceTextAutosizing.addChangeListener(this._deviceMetrics
Changed, this); | 572 this.settings.deviceTextAutosizing.addChangeListener(this._deviceMetrics
Changed, this); |
546 this.settings.emulateViewport.addChangeListener(this._deviceMetricsChang
ed, this); | 573 this.settings.emulateViewport.addChangeListener(this._deviceMetricsChang
ed, this); |
547 this.settings.deviceFitWindow.addChangeListener(this._deviceMetricsChang
ed, this); | 574 this.settings.deviceFitWindow.addChangeListener(this._deviceMetricsChang
ed, this); |
548 | 575 |
549 this.settings.emulationEnabled.addChangeListener(this._geolocationPositi
onChanged, this); | 576 this.settings._emulationEnabled.addChangeListener(this._geolocationPosit
ionChanged, this); |
550 this.settings.overrideGeolocation.addChangeListener(this._geolocationPos
itionChanged, this); | 577 this.settings.overrideGeolocation.addChangeListener(this._geolocationPos
itionChanged, this); |
551 this.settings.geolocationOverride.addChangeListener(this._geolocationPos
itionChanged, this); | 578 this.settings.geolocationOverride.addChangeListener(this._geolocationPos
itionChanged, this); |
552 | 579 |
553 this.settings.emulationEnabled.addChangeListener(this._deviceOrientation
Changed, this); | 580 this.settings._emulationEnabled.addChangeListener(this._deviceOrientatio
nChanged, this); |
554 this.settings.overrideDeviceOrientation.addChangeListener(this._deviceOr
ientationChanged, this); | 581 this.settings.overrideDeviceOrientation.addChangeListener(this._deviceOr
ientationChanged, this); |
555 this.settings.deviceOrientationOverride.addChangeListener(this._deviceOr
ientationChanged, this); | 582 this.settings.deviceOrientationOverride.addChangeListener(this._deviceOr
ientationChanged, this); |
556 | 583 |
557 this.settings.emulationEnabled.addChangeListener(this._emulateTouchEvent
sChanged, this); | 584 this.settings._emulationEnabled.addChangeListener(this._emulateTouchEven
tsChanged, this); |
558 this.settings.emulateTouch.addChangeListener(this._emulateTouchEventsCha
nged, this); | 585 this.settings.emulateTouch.addChangeListener(this._emulateTouchEventsCha
nged, this); |
559 | 586 |
560 this.settings.emulationEnabled.addChangeListener(this._cssMediaChanged,
this); | 587 this.settings._emulationEnabled.addChangeListener(this._cssMediaChanged,
this); |
561 this.settings.overrideCSSMedia.addChangeListener(this._cssMediaChanged,
this); | 588 this.settings.overrideCSSMedia.addChangeListener(this._cssMediaChanged,
this); |
562 this.settings.emulatedCSSMedia.addChangeListener(this._cssMediaChanged,
this); | 589 this.settings.emulatedCSSMedia.addChangeListener(this._cssMediaChanged,
this); |
563 | 590 |
564 if (WebInspector.experimentsSettings.networkConditions.isEnabled()) { | 591 if (WebInspector.experimentsSettings.networkConditions.isEnabled()) { |
565 this.settings.emulationEnabled.addChangeListener(this._networkCondit
ionsChanged, this); | 592 this.settings._emulationEnabled.addChangeListener(this._networkCondi
tionsChanged, this); |
566 this.settings.networkConditionsThroughput.addChangeListener(this._ne
tworkConditionsChanged, this); | 593 this.settings.networkConditionsThroughput.addChangeListener(this._ne
tworkConditionsChanged, this); |
567 } | 594 } |
568 | 595 |
569 WebInspector.settings.showMetricsRulers.addChangeListener(this._showRule
rsChanged, this); | 596 WebInspector.settings.showMetricsRulers.addChangeListener(this._showRule
rsChanged, this); |
570 this._showRulersChanged(); | 597 this._showRulersChanged(); |
571 | 598 |
572 if (!this.settings.emulationEnabled.get()) | 599 if (!this.emulationEnabled()) |
573 return; | 600 return; |
574 | 601 |
575 if (this.settings.overrideDeviceOrientation.get()) | 602 if (this.settings.overrideDeviceOrientation.get()) |
576 this._deviceOrientationChanged(); | 603 this._deviceOrientationChanged(); |
577 | 604 |
578 if (this.settings.overrideGeolocation.get()) | 605 if (this.settings.overrideGeolocation.get()) |
579 this._geolocationPositionChanged(); | 606 this._geolocationPositionChanged(); |
580 | 607 |
581 if (this.settings.emulateTouch.get()) | 608 if (this.settings.emulateTouch.get()) |
582 this._emulateTouchEventsChanged(); | 609 this._emulateTouchEventsChanged(); |
583 | 610 |
584 if (this.settings.overrideCSSMedia.get()) | 611 if (this.settings.overrideCSSMedia.get()) |
585 this._cssMediaChanged(); | 612 this._cssMediaChanged(); |
586 | 613 |
587 this._deviceMetricsChanged(); | 614 this._deviceMetricsChanged(); |
588 | 615 |
589 this._userAgentChanged(); | 616 this._userAgentChanged(); |
590 | 617 |
591 if (WebInspector.experimentsSettings.networkConditions.isEnabled() && th
is.networkThroughputIsLimited()) | 618 if (WebInspector.experimentsSettings.networkConditions.isEnabled() && th
is.networkThroughputIsLimited()) |
592 this._networkConditionsChanged(); | 619 this._networkConditionsChanged(); |
593 }, | 620 }, |
594 | 621 |
595 _userAgentChanged: function() | 622 _userAgentChanged: function() |
596 { | 623 { |
597 if (this._userAgentChangedListenerMuted) | 624 if (this._userAgentChangedListenerMuted) |
598 return; | 625 return; |
599 var userAgent = this.settings.emulationEnabled.get() ? this.settings.use
rAgent.get() : ""; | 626 var userAgent = this.emulationEnabled() ? this.settings.userAgent.get()
: ""; |
600 NetworkAgent.setUserAgentOverride(userAgent); | 627 NetworkAgent.setUserAgentOverride(userAgent); |
601 if (this._userAgent !== userAgent) | 628 if (this._userAgent !== userAgent) |
602 this._updateUserAgentWarningMessage(WebInspector.UIString("You might
need to reload the page for proper user agent spoofing and viewport rendering."
)); | 629 this._updateUserAgentWarningMessage(WebInspector.UIString("You might
need to reload the page for proper user agent spoofing and viewport rendering."
)); |
603 this._userAgent = userAgent; | 630 this._userAgent = userAgent; |
604 this.maybeHasActiveOverridesChanged(); | |
605 }, | 631 }, |
606 | 632 |
607 _onPageResizerAvailableSizeChanged: function() | 633 _onPageResizerAvailableSizeChanged: function() |
608 { | 634 { |
609 if (this._initialized) | 635 if (this._initialized) |
610 this._deviceMetricsChanged(); | 636 this._deviceMetricsChanged(); |
611 }, | 637 }, |
612 | 638 |
613 _onPageResizerResizeRequested: function(event) | 639 _onPageResizerResizeRequested: function(event) |
614 { | 640 { |
615 if (typeof event.data.width !== "undefined") { | 641 if (typeof event.data.width !== "undefined") { |
616 var width = /** @type {number} */ (event.data.width); | 642 var width = /** @type {number} */ (event.data.width); |
617 if (width !== this.settings.deviceWidth.get()) | 643 if (width !== this.settings.deviceWidth.get()) |
618 this.settings.deviceWidth.set(width); | 644 this.settings.deviceWidth.set(width); |
619 } | 645 } |
620 if (typeof event.data.height !== "undefined") { | 646 if (typeof event.data.height !== "undefined") { |
621 var height = /** @type {number} */ (event.data.height); | 647 var height = /** @type {number} */ (event.data.height); |
622 if (height !== this.settings.deviceHeight.get()) | 648 if (height !== this.settings.deviceHeight.get()) |
623 this.settings.deviceHeight.set(height); | 649 this.settings.deviceHeight.set(height); |
624 } | 650 } |
625 }, | 651 }, |
626 | 652 |
627 _deviceMetricsChanged: function() | 653 _deviceMetricsChanged: function() |
628 { | 654 { |
629 this._showRulersChanged(); | 655 this._showRulersChanged(); |
630 | 656 |
631 if (this._deviceMetricsChangedListenerMuted) | 657 if (this._deviceMetricsChangedListenerMuted) |
632 return; | 658 return; |
633 | 659 |
634 if (!this.settings.emulationEnabled.get()) { | 660 if (!this.emulationEnabled()) { |
635 this._deviceMetricsThrottler.schedule(clearDeviceMetricsOverride.bin
d(this)); | 661 this._deviceMetricsThrottler.schedule(clearDeviceMetricsOverride.bin
d(this)); |
636 if (this._pageResizer) | 662 if (this._pageResizer) |
637 this._pageResizer.update(0, 0, 0); | 663 this._pageResizer.update(0, 0, 0); |
638 return; | 664 return; |
639 } | 665 } |
640 | 666 |
641 var dipWidth = this.settings.deviceWidth.get(); | 667 var dipWidth = this.settings.deviceWidth.get(); |
642 var dipHeight = this.settings.deviceHeight.get(); | 668 var dipHeight = this.settings.deviceHeight.get(); |
643 | 669 |
644 // Disable override without checks. | |
645 if (this.isInspectingDevice()) | |
646 return; | |
647 | |
648 var overrideWidth = dipWidth; | 670 var overrideWidth = dipWidth; |
649 var overrideHeight = dipHeight; | 671 var overrideHeight = dipHeight; |
650 if (this._pageResizer) { | 672 if (this._pageResizer) { |
651 var available = this._pageResizer.availableDipSize(); | 673 var available = this._pageResizer.availableDipSize(); |
652 if (available.width >= dipWidth && available.height >= dipHeight) { | 674 if (available.width >= dipWidth && available.height >= dipHeight) { |
653 this._pageResizer.update(dipWidth, dipHeight, 0); | 675 this._pageResizer.update(dipWidth, dipHeight, 0); |
654 // When we have enough space, no page size override is required.
This will speed things up and remove lag. | 676 // When we have enough space, no page size override is required.
This will speed things up and remove lag. |
655 overrideWidth = 0; | 677 overrideWidth = 0; |
656 overrideHeight = 0; | 678 overrideHeight = 0; |
657 } else { | 679 } else { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 */ | 712 */ |
691 function apiCallback(finishCallback, error) | 713 function apiCallback(finishCallback, error) |
692 { | 714 { |
693 if (error) { | 715 if (error) { |
694 this._updateDeviceMetricsWarningMessage(WebInspector.UIString("S
creen emulation is not available on this page.")); | 716 this._updateDeviceMetricsWarningMessage(WebInspector.UIString("S
creen emulation is not available on this page.")); |
695 this._deviceMetricsOverrideAppliedForTest(); | 717 this._deviceMetricsOverrideAppliedForTest(); |
696 finishCallback(); | 718 finishCallback(); |
697 return; | 719 return; |
698 } | 720 } |
699 | 721 |
700 var viewportEnabled = this.settings.emulationEnabled.get() && this.s
ettings.emulateViewport.get(); | 722 var viewportEnabled = this.emulationEnabled() && this.settings.emula
teViewport.get(); |
701 if (this._emulateViewportEnabled !== viewportEnabled) | 723 if (this._emulateViewportEnabled !== viewportEnabled) |
702 this._updateDeviceMetricsWarningMessage(WebInspector.UIString("Y
ou might need to reload the page for proper user agent spoofing and viewport ren
dering.")); | 724 this._updateDeviceMetricsWarningMessage(WebInspector.UIString("Y
ou might need to reload the page for proper user agent spoofing and viewport ren
dering.")); |
703 this._emulateViewportEnabled = viewportEnabled; | 725 this._emulateViewportEnabled = viewportEnabled; |
704 this._deviceMetricsOverrideAppliedForTest(); | 726 this._deviceMetricsOverrideAppliedForTest(); |
705 this.maybeHasActiveOverridesChanged(); | |
706 finishCallback(); | 727 finishCallback(); |
707 } | 728 } |
708 }, | 729 }, |
709 | 730 |
710 _deviceMetricsOverrideAppliedForTest: function() | 731 _deviceMetricsOverrideAppliedForTest: function() |
711 { | 732 { |
712 // Used for sniffing in tests. | 733 // Used for sniffing in tests. |
713 }, | 734 }, |
714 | 735 |
715 _geolocationPositionChanged: function() | 736 _geolocationPositionChanged: function() |
716 { | 737 { |
717 if (!this.settings.emulationEnabled.get() || !this.settings.overrideGeol
ocation.get()) { | 738 if (!this.emulationEnabled() || !this.settings.overrideGeolocation.get()
) { |
718 GeolocationAgent.clearGeolocationOverride(); | 739 GeolocationAgent.clearGeolocationOverride(); |
719 return; | 740 return; |
720 } | 741 } |
721 var geolocation = WebInspector.OverridesSupport.GeolocationPosition.pars
eSetting(this.settings.geolocationOverride.get()); | 742 var geolocation = WebInspector.OverridesSupport.GeolocationPosition.pars
eSetting(this.settings.geolocationOverride.get()); |
722 if (geolocation.error) | 743 if (geolocation.error) |
723 GeolocationAgent.setGeolocationOverride(); | 744 GeolocationAgent.setGeolocationOverride(); |
724 else | 745 else |
725 GeolocationAgent.setGeolocationOverride(geolocation.latitude, geoloc
ation.longitude, 150); | 746 GeolocationAgent.setGeolocationOverride(geolocation.latitude, geoloc
ation.longitude, 150); |
726 this.maybeHasActiveOverridesChanged(); | |
727 }, | 747 }, |
728 | 748 |
729 _deviceOrientationChanged: function() | 749 _deviceOrientationChanged: function() |
730 { | 750 { |
731 if (!this.settings.emulationEnabled.get() || !this.settings.overrideDevi
ceOrientation.get()) { | 751 if (!this.emulationEnabled() || !this.settings.overrideDeviceOrientation
.get()) { |
732 PageAgent.clearDeviceOrientationOverride(); | 752 PageAgent.clearDeviceOrientationOverride(); |
733 return; | 753 return; |
734 } | 754 } |
735 | 755 |
736 var deviceOrientation = WebInspector.OverridesSupport.DeviceOrientation.
parseSetting(this.settings.deviceOrientationOverride.get()); | 756 var deviceOrientation = WebInspector.OverridesSupport.DeviceOrientation.
parseSetting(this.settings.deviceOrientationOverride.get()); |
737 PageAgent.setDeviceOrientationOverride(deviceOrientation.alpha, deviceOr
ientation.beta, deviceOrientation.gamma); | 757 PageAgent.setDeviceOrientationOverride(deviceOrientation.alpha, deviceOr
ientation.beta, deviceOrientation.gamma); |
738 this.maybeHasActiveOverridesChanged(); | |
739 }, | 758 }, |
740 | 759 |
741 _emulateTouchEventsChanged: function() | 760 _emulateTouchEventsChanged: function() |
742 { | 761 { |
743 var emulateTouch = this.settings.emulationEnabled.get() && this.settings
.emulateTouch.get(); | 762 var emulateTouch = this.emulationEnabled() && this.settings.emulateTouch
.get(); |
744 var targets = WebInspector.targetManager.targets(); | 763 var targets = WebInspector.targetManager.targets(); |
745 for (var i = 0; i < targets.length; ++i) | 764 for (var i = 0; i < targets.length; ++i) |
746 targets[i].domModel.emulateTouchEventObjects(emulateTouch); | 765 targets[i].domModel.emulateTouchEventObjects(emulateTouch); |
747 this.maybeHasActiveOverridesChanged(); | |
748 }, | 766 }, |
749 | 767 |
750 _cssMediaChanged: function() | 768 _cssMediaChanged: function() |
751 { | 769 { |
752 var enabled = !this.isInspectingDevice() && this.settings.emulationEnabl
ed.get() && this.settings.overrideCSSMedia.get(); | 770 var enabled = this.emulationEnabled() && this.settings.overrideCSSMedia.
get(); |
753 PageAgent.setEmulatedMedia(enabled ? this.settings.emulatedCSSMedia.get(
) : ""); | 771 PageAgent.setEmulatedMedia(enabled ? this.settings.emulatedCSSMedia.get(
) : ""); |
754 var targets = WebInspector.targetManager.targets(); | 772 var targets = WebInspector.targetManager.targets(); |
755 for (var i = 0; i < targets.length; ++i) | 773 for (var i = 0; i < targets.length; ++i) |
756 targets[i].cssModel.mediaQueryResultChanged(); | 774 targets[i].cssModel.mediaQueryResultChanged(); |
757 this.maybeHasActiveOverridesChanged(); | |
758 }, | 775 }, |
759 | 776 |
760 _networkConditionsChanged: function() | 777 _networkConditionsChanged: function() |
761 { | 778 { |
762 if (!this.settings.emulationEnabled.get() || !this.networkThroughputIsLi
mited()) { | 779 if (!this.emulationEnabled() || !this.networkThroughputIsLimited()) { |
763 NetworkAgent.emulateNetworkConditions(false, 0, 0, 0); | 780 NetworkAgent.emulateNetworkConditions(false, 0, 0, 0); |
764 } else { | 781 } else { |
765 var throughput = this.settings.networkConditionsThroughput.get(); | 782 var throughput = this.settings.networkConditionsThroughput.get(); |
766 var offline = !throughput; | 783 var offline = !throughput; |
767 NetworkAgent.emulateNetworkConditions(offline, 0, throughput, throug
hput); | 784 NetworkAgent.emulateNetworkConditions(offline, 0, throughput, throug
hput); |
768 } | 785 } |
769 this.maybeHasActiveOverridesChanged(); | |
770 }, | 786 }, |
771 | 787 |
772 /** | 788 /** |
773 * @return {boolean} | 789 * @return {boolean} |
774 */ | 790 */ |
775 showMetricsRulers: function() | 791 showMetricsRulers: function() |
776 { | 792 { |
777 var rulersInPageResizer = this._pageResizer && this.settings.emulationEn
abled.get(); | 793 var rulersInPageResizer = this._pageResizer && this.emulationEnabled(); |
778 return WebInspector.settings.showMetricsRulers.get() && !rulersInPageRes
izer; | 794 return WebInspector.settings.showMetricsRulers.get() && !rulersInPageRes
izer; |
779 }, | 795 }, |
780 | 796 |
781 _showRulersChanged: function() | 797 _showRulersChanged: function() |
782 { | 798 { |
783 if (WebInspector.experimentsSettings.responsiveDesign.isEnabled()) | 799 if (WebInspector.experimentsSettings.responsiveDesign.isEnabled()) |
784 return; | 800 return; |
785 PageAgent.setShowViewportSizeOnResize(true, this.showMetricsRulers()); | 801 PageAgent.setShowViewportSizeOnResize(true, this.showMetricsRulers()); |
786 }, | 802 }, |
787 | 803 |
788 /** | |
789 * @return {boolean} | |
790 */ | |
791 hasActiveOverrides: function() | |
792 { | |
793 return this._hasActiveOverrides; | |
794 }, | |
795 | |
796 maybeHasActiveOverridesChanged: function() | |
797 { | |
798 var hasActiveOverrides = this.settings.emulationEnabled.get(); | |
799 if (this._hasActiveOverrides !== hasActiveOverrides) { | |
800 this._hasActiveOverrides = hasActiveOverrides; | |
801 this.dispatchEventToListeners(WebInspector.OverridesSupport.Events.H
asActiveOverridesChanged); | |
802 } | |
803 }, | |
804 | |
805 _onMainFrameNavigated: function() | 804 _onMainFrameNavigated: function() |
806 { | 805 { |
807 if (this._initialized) | 806 if (this._initialized) |
808 this._deviceMetricsChanged(); | 807 this._deviceMetricsChanged(); |
809 this._updateUserAgentWarningMessage(""); | 808 this._updateUserAgentWarningMessage(""); |
810 this._updateDeviceMetricsWarningMessage(""); | 809 this._updateDeviceMetricsWarningMessage(""); |
811 }, | 810 }, |
812 | 811 |
813 /** | 812 /** |
814 * @param {string} warningMessage | 813 * @param {string} warningMessage |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 * @param {!WebInspector.Target} target | 846 * @param {!WebInspector.Target} target |
848 */ | 847 */ |
849 targetAdded: function(target) | 848 targetAdded: function(target) |
850 { | 849 { |
851 // FIXME: adapt this to multiple targets. | 850 // FIXME: adapt this to multiple targets. |
852 if (this._target) | 851 if (this._target) |
853 return; | 852 return; |
854 this._target = target; | 853 this._target = target; |
855 | 854 |
856 this.settings = {}; | 855 this.settings = {}; |
857 this.settings.emulationEnabled = WebInspector.settings.createSetting("em
ulationEnabled", false); | 856 this.settings._emulationEnabled = WebInspector.settings.createSetting("e
mulationEnabled", false); |
858 | 857 |
859 this.settings.userAgent = WebInspector.settings.createSetting("userAgent
", ""); | 858 this.settings.userAgent = WebInspector.settings.createSetting("userAgent
", ""); |
860 | 859 |
861 this.settings.deviceWidth = WebInspector.settings.createSetting("deviceW
idth", 0); | 860 this.settings.deviceWidth = WebInspector.settings.createSetting("deviceW
idth", 0); |
862 this.settings.deviceHeight = WebInspector.settings.createSetting("device
Height", 0); | 861 this.settings.deviceHeight = WebInspector.settings.createSetting("device
Height", 0); |
863 this.settings.deviceScaleFactor = WebInspector.settings.createSetting("d
eviceScaleFactor", 0); | 862 this.settings.deviceScaleFactor = WebInspector.settings.createSetting("d
eviceScaleFactor", 0); |
864 this.settings.deviceTextAutosizing = WebInspector.settings.createSetting
("deviceTextAutosizing", true); | 863 this.settings.deviceTextAutosizing = WebInspector.settings.createSetting
("deviceTextAutosizing", true); |
865 this.settings.deviceFitWindow = WebInspector.settings.createSetting("dev
iceFitWindow", true); | 864 this.settings.deviceFitWindow = WebInspector.settings.createSetting("dev
iceFitWindow", true); |
866 // FIXME: rename viewport to mobile everywhere in the code. | 865 // FIXME: rename viewport to mobile everywhere in the code. |
867 this.settings.emulateViewport = WebInspector.settings.createSetting("emu
lateViewport", false); | 866 this.settings.emulateViewport = WebInspector.settings.createSetting("emu
lateViewport", false); |
868 | 867 |
869 this.settings.emulateTouch = WebInspector.settings.createSetting("emulat
eTouch", false); | 868 this.settings.emulateTouch = WebInspector.settings.createSetting("emulat
eTouch", false); |
870 | 869 |
871 this.settings.overrideGeolocation = WebInspector.settings.createSetting(
"overrideGeolocation", false); | 870 this.settings.overrideGeolocation = WebInspector.settings.createSetting(
"overrideGeolocation", false); |
872 this.settings.geolocationOverride = WebInspector.settings.createSetting(
"geolocationOverride", ""); | 871 this.settings.geolocationOverride = WebInspector.settings.createSetting(
"geolocationOverride", ""); |
873 | 872 |
874 this.settings.overrideDeviceOrientation = WebInspector.settings.createSe
tting("overrideDeviceOrientation", false); | 873 this.settings.overrideDeviceOrientation = WebInspector.settings.createSe
tting("overrideDeviceOrientation", false); |
875 this.settings.deviceOrientationOverride = WebInspector.settings.createSe
tting("deviceOrientationOverride", ""); | 874 this.settings.deviceOrientationOverride = WebInspector.settings.createSe
tting("deviceOrientationOverride", ""); |
876 | 875 |
877 this.settings.overrideCSSMedia = WebInspector.settings.createSetting("ov
errideCSSMedia", false); | 876 this.settings.overrideCSSMedia = WebInspector.settings.createSetting("ov
errideCSSMedia", false); |
878 this.settings.emulatedCSSMedia = WebInspector.settings.createSetting("em
ulatedCSSMedia", "print"); | 877 this.settings.emulatedCSSMedia = WebInspector.settings.createSetting("em
ulatedCSSMedia", "print"); |
879 | 878 |
880 this.settings.networkConditionsThroughput = WebInspector.settings.create
Setting("networkConditionsThroughput", WebInspector.OverridesSupport._networkThr
oughputUnlimitedValue); | 879 this.settings.networkConditionsThroughput = WebInspector.settings.create
Setting("networkConditionsThroughput", WebInspector.OverridesSupport._networkThr
oughputUnlimitedValue); |
881 | 880 |
882 this.maybeHasActiveOverridesChanged(); | |
883 | |
884 if (this._applyInitialOverridesOnTargetAdded) { | 881 if (this._applyInitialOverridesOnTargetAdded) { |
885 delete this._applyInitialOverridesOnTargetAdded; | 882 delete this._applyInitialOverridesOnTargetAdded; |
886 this.applyInitialOverrides(); | 883 this.applyInitialOverrides(); |
887 } | 884 } |
888 }, | 885 }, |
889 | 886 |
890 swapDimensions: function() | 887 swapDimensions: function() |
891 { | 888 { |
892 var width = WebInspector.overridesSupport.settings.deviceWidth.get(); | 889 var width = WebInspector.overridesSupport.settings.deviceWidth.get(); |
893 var height = WebInspector.overridesSupport.settings.deviceHeight.get(); | 890 var height = WebInspector.overridesSupport.settings.deviceHeight.get(); |
894 WebInspector.overridesSupport.settings.deviceWidth.set(height); | 891 WebInspector.overridesSupport.settings.deviceWidth.set(height); |
895 WebInspector.overridesSupport.settings.deviceHeight.set(width); | 892 WebInspector.overridesSupport.settings.deviceHeight.set(width); |
896 }, | 893 }, |
897 | 894 |
898 /** | 895 /** |
899 * @param {!WebInspector.Target} target | 896 * @param {!WebInspector.Target} target |
900 */ | 897 */ |
901 targetRemoved: function(target) | 898 targetRemoved: function(target) |
902 { | 899 { |
903 // FIXME: adapt this to multiple targets. | 900 // FIXME: adapt this to multiple targets. |
904 }, | 901 }, |
905 | 902 |
906 /** | 903 /** |
907 * @return {boolean} | 904 * @return {boolean} |
908 */ | 905 */ |
909 isInspectingDevice: function() | |
910 { | |
911 return !!this._target && this._target.isMobile(); | |
912 }, | |
913 | |
914 /** | |
915 * @return {boolean} | |
916 */ | |
917 hasTouchInputs: function() | 906 hasTouchInputs: function() |
918 { | 907 { |
919 return !!this._target && this._target.hasTouchInputs; | 908 return !!this._target && this._target.hasTouchInputs; |
920 }, | 909 }, |
921 | 910 |
922 /** | 911 /** |
923 * @return {boolean} | 912 * @return {boolean} |
924 */ | 913 */ |
925 networkThroughputIsLimited: function() | 914 networkThroughputIsLimited: function() |
926 { | 915 { |
927 return this.settings.networkConditionsThroughput.get() !== WebInspector.
OverridesSupport._networkThroughputUnlimitedValue; | 916 return this.settings.networkConditionsThroughput.get() !== WebInspector.
OverridesSupport._networkThroughputUnlimitedValue; |
928 }, | 917 }, |
929 | 918 |
930 /** | 919 /** |
931 * Compute the font scale factor. | 920 * Compute the font scale factor. |
932 * | 921 * |
933 * Chromium on Android uses a device scale adjustment for fonts used in text
autosizing for | 922 * Chromium on Android uses a device scale adjustment for fonts used in text
autosizing for |
934 * improved legibility. This function computes this adjusted value for text
autosizing. | 923 * improved legibility. This function computes this adjusted value for text
autosizing. |
935 * | 924 * |
936 * For a description of the Android device scale adjustment algorithm, see: | 925 * For a description of the Android device scale adjustment algorithm, see: |
937 * chrome/browser/chrome_content_browser_client.cc, GetFontScaleMultipli
er(...) | 926 * chrome/browser/chrome_content_browser_client.cc, GetFontScaleMultipli
er(...) |
938 * | 927 * |
939 * @param {number} width | 928 * @param {number} width |
940 * @param {number} height | 929 * @param {number} height |
941 * @return {number} font scale factor. | 930 * @return {number} font scale factor. |
942 */ | 931 */ |
943 _fontScaleFactor: function(width, height) | 932 _fontScaleFactor: function(width, height) |
944 { | 933 { |
945 if (!this.settings.emulationEnabled.get()) | 934 if (!this.emulationEnabled()) |
946 return 1; | 935 return 1; |
947 var deviceScaleFactor = this.settings.deviceScaleFactor.get(); | 936 var deviceScaleFactor = this.settings.deviceScaleFactor.get(); |
948 | 937 |
949 if (!width || !height || !deviceScaleFactor) | 938 if (!width || !height || !deviceScaleFactor) |
950 return 1; | 939 return 1; |
951 | 940 |
952 var minWidth = Math.min(width, height) / deviceScaleFactor; | 941 var minWidth = Math.min(width, height) / deviceScaleFactor; |
953 | 942 |
954 var kMinFSM = 1.05; | 943 var kMinFSM = 1.05; |
955 var kWidthForMinFSM = 320; | 944 var kWidthForMinFSM = 320; |
(...skipping 10 matching lines...) Expand all Loading... |
966 return ratio * (kMaxFSM - kMinFSM) + kMinFSM; | 955 return ratio * (kMaxFSM - kMinFSM) + kMinFSM; |
967 }, | 956 }, |
968 | 957 |
969 /** | 958 /** |
970 * @param {!Document} document | 959 * @param {!Document} document |
971 * @return {!Element} | 960 * @return {!Element} |
972 */ | 961 */ |
973 createDeviceSelect: function(document) | 962 createDeviceSelect: function(document) |
974 { | 963 { |
975 var deviceSelectElement = document.createElement("select"); | 964 var deviceSelectElement = document.createElement("select"); |
976 deviceSelectElement.disabled = WebInspector.overridesSupport.isInspectin
gDevice(); | |
977 | 965 |
978 var selectDeviceOption = new Option(WebInspector.UIString("<Select model
>"), WebInspector.UIString("<Select model>")); | 966 var selectDeviceOption = new Option(WebInspector.UIString("<Select model
>"), WebInspector.UIString("<Select model>")); |
979 selectDeviceOption.device = new WebInspector.OverridesSupport.Device("",
""); | 967 selectDeviceOption.device = new WebInspector.OverridesSupport.Device("",
""); |
980 deviceSelectElement.add(selectDeviceOption); | 968 deviceSelectElement.add(selectDeviceOption); |
981 | 969 |
982 addGroup(WebInspector.UIString("Devices"), WebInspector.OverridesSupport
._phones.concat(WebInspector.OverridesSupport._tablets)); | 970 addGroup(WebInspector.UIString("Devices"), WebInspector.OverridesSupport
._phones.concat(WebInspector.OverridesSupport._tablets)); |
983 addGroup(WebInspector.UIString("Notebooks"), WebInspector.OverridesSuppo
rt._notebooks); | 971 addGroup(WebInspector.UIString("Notebooks"), WebInspector.OverridesSuppo
rt._notebooks); |
984 | 972 |
985 /** | 973 /** |
986 * @param {string} name | 974 * @param {string} name |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1091 }, | 1079 }, |
1092 | 1080 |
1093 __proto__: WebInspector.Object.prototype | 1081 __proto__: WebInspector.Object.prototype |
1094 } | 1082 } |
1095 | 1083 |
1096 | 1084 |
1097 /** | 1085 /** |
1098 * @type {!WebInspector.OverridesSupport} | 1086 * @type {!WebInspector.OverridesSupport} |
1099 */ | 1087 */ |
1100 WebInspector.overridesSupport; | 1088 WebInspector.overridesSupport; |
OLD | NEW |