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