| 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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 return; | 484 return; |
| 485 var userAgent = this.settings.overrideUserAgent.get() ? this.settings.us
erAgent.get() : ""; | 485 var userAgent = this.settings.overrideUserAgent.get() ? this.settings.us
erAgent.get() : ""; |
| 486 NetworkAgent.setUserAgentOverride(userAgent); | 486 NetworkAgent.setUserAgentOverride(userAgent); |
| 487 this._updateUserAgentWarningMessage(this._userAgent !== userAgent ? WebI
nspector.UIString("You might need to reload the page for proper user agent spoof
ing and viewport rendering.") : ""); | 487 this._updateUserAgentWarningMessage(this._userAgent !== userAgent ? WebI
nspector.UIString("You might need to reload the page for proper user agent spoof
ing and viewport rendering.") : ""); |
| 488 this._userAgent = userAgent; | 488 this._userAgent = userAgent; |
| 489 this.maybeHasActiveOverridesChanged(); | 489 this.maybeHasActiveOverridesChanged(); |
| 490 }, | 490 }, |
| 491 | 491 |
| 492 _onPageResizerAvailableSizeChanged: function() | 492 _onPageResizerAvailableSizeChanged: function() |
| 493 { | 493 { |
| 494 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(t
his.settings.deviceMetrics.get()); |
| 495 if (!metrics.isValid()) |
| 496 return; |
| 497 |
| 498 var available = this._pageResizer.availableDipSize(); |
| 499 if (available.width > metrics.width && available.height > metrics.height
) |
| 500 return; |
| 501 |
| 494 this._deviceMetricsChanged(); | 502 this._deviceMetricsChanged(); |
| 495 }, | 503 }, |
| 496 | 504 |
| 497 _onPageResizerResizeRequested: function(event) | 505 _onPageResizerResizeRequested: function(event) |
| 498 { | 506 { |
| 499 if (!this.settings.overrideDeviceMetrics.get()) | 507 if (!this.settings.overrideDeviceMetrics.get()) |
| 500 return; | 508 return; |
| 501 | 509 |
| 502 var size = /** @type {!Size} */ (event.data); | 510 var size = /** @type {!Size} */ (event.data); |
| 503 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(t
his.settings.deviceMetrics.get()); | 511 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(t
his.settings.deviceMetrics.get()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 var overrideWidth = dipWidth; | 551 var overrideWidth = dipWidth; |
| 544 var overrideHeight = dipHeight; | 552 var overrideHeight = dipHeight; |
| 545 if (this._pageResizer) { | 553 if (this._pageResizer) { |
| 546 var available = this._pageResizer.availableDipSize(); | 554 var available = this._pageResizer.availableDipSize(); |
| 547 if (available.width >= dipWidth && available.height >= dipHeight) { | 555 if (available.width >= dipWidth && available.height >= dipHeight) { |
| 548 this._pageResizer.enable(dipWidth, dipHeight, 0); | 556 this._pageResizer.enable(dipWidth, dipHeight, 0); |
| 549 // When we have enough space, no page size override is required.
This will speed things up and remove lag. | 557 // When we have enough space, no page size override is required.
This will speed things up and remove lag. |
| 550 overrideWidth = 0; | 558 overrideWidth = 0; |
| 551 overrideHeight = 0; | 559 overrideHeight = 0; |
| 552 } else { | 560 } else { |
| 553 var widthScale = dipWidth ? dipWidth / Math.max(available.width,
1) : 1; | 561 this._pageResizer.enable(Math.min(dipWidth, available.width), Ma
th.min(dipHeight, available.height), 0); |
| 554 var heightScale = dipHeight ? dipHeight / Math.max(available.hei
ght, 1) : 1; | |
| 555 var scale = 1 / Math.max(widthScale, heightScale); | |
| 556 this._pageResizer.enable(dipWidth ? Math.max(Math.floor(dipWidth
* scale), 1) : 0, dipHeight ? Math.max(Math.floor(dipHeight * scale), 1) : 0, s
cale); | |
| 557 if (!dipWidth) | |
| 558 overrideWidth = Math.round(available.width / scale); | |
| 559 if (!dipHeight) | |
| 560 overrideHeight = Math.round(available.height / scale); | |
| 561 } | 562 } |
| 562 } | 563 } |
| 563 PageAgent.setDeviceMetricsOverride( | 564 |
| 564 overrideWidth, overrideHeight, metrics.deviceScaleFactor, | 565 // Do not emulate resolution more often than 10Hz. |
| 565 this.settings.emulateViewport.get(), this._pageResizer ? true : this
.settings.deviceFitWindow.get(), | 566 this._setDeviceMetricsTimers = (this._setDeviceMetricsTimers || 0) + 1; |
| 566 metrics.textAutosizing, metrics.fontScaleFactor(), | 567 if (overrideWidth || overrideHeight) |
| 567 apiCallback.bind(this)); | 568 setTimeout(setDeviceMetricsOverride.bind(this), 100); |
| 569 else |
| 570 setDeviceMetricsOverride.call(this); |
| 571 |
| 572 /** |
| 573 * @this {WebInspector.OverridesSupport} |
| 574 */ |
| 575 function setDeviceMetricsOverride() |
| 576 { |
| 577 // Drop heavy intermediate commands. |
| 578 this._setDeviceMetricsTimers--; |
| 579 var isExpensive = overrideWidth || overrideHeight; |
| 580 if (isExpensive && this._setDeviceMetricsTimers) { |
| 581 var commandThreshold = 100; |
| 582 var time = window.performance.now(); |
| 583 if (time - this._lastExpensivePageAgentCommandTime < commandThre
shold) |
| 584 return; |
| 585 this._lastExpensivePageAgentCommandTime = time; |
| 586 } |
| 587 |
| 588 PageAgent.setDeviceMetricsOverride( |
| 589 overrideWidth, overrideHeight, metrics.deviceScaleFactor, |
| 590 this.settings.emulateViewport.get(), this._pageResizer ? false :
this.settings.deviceFitWindow.get(), |
| 591 metrics.textAutosizing, metrics.fontScaleFactor(), |
| 592 apiCallback.bind(this)); |
| 593 } |
| 568 | 594 |
| 569 this.maybeHasActiveOverridesChanged(); | 595 this.maybeHasActiveOverridesChanged(); |
| 570 | 596 |
| 571 /** | 597 /** |
| 572 * @param {?Protocol.Error} error | 598 * @param {?Protocol.Error} error |
| 573 * @this {WebInspector.OverridesSupport} | 599 * @this {WebInspector.OverridesSupport} |
| 574 */ | 600 */ |
| 575 function apiCallback(error) | 601 function apiCallback(error) |
| 576 { | 602 { |
| 577 if (error) { | 603 if (error) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 * @return {boolean} | 675 * @return {boolean} |
| 650 */ | 676 */ |
| 651 showMetricsRulers: function() | 677 showMetricsRulers: function() |
| 652 { | 678 { |
| 653 var rulersInPageResizer = this._pageResizer && this.settings.overrideDev
iceMetrics.get(); | 679 var rulersInPageResizer = this._pageResizer && this.settings.overrideDev
iceMetrics.get(); |
| 654 return WebInspector.settings.showMetricsRulers.get() && !rulersInPageRes
izer; | 680 return WebInspector.settings.showMetricsRulers.get() && !rulersInPageRes
izer; |
| 655 }, | 681 }, |
| 656 | 682 |
| 657 _showRulersChanged: function() | 683 _showRulersChanged: function() |
| 658 { | 684 { |
| 685 if (WebInspector.experimentsSettings.responsiveDesign.isEnabled()) |
| 686 return; |
| 659 PageAgent.setShowViewportSizeOnResize(true, this.showMetricsRulers()); | 687 PageAgent.setShowViewportSizeOnResize(true, this.showMetricsRulers()); |
| 660 }, | 688 }, |
| 661 | 689 |
| 662 /** | 690 /** |
| 663 * @return {boolean} | 691 * @return {boolean} |
| 664 */ | 692 */ |
| 665 hasActiveOverrides: function() | 693 hasActiveOverrides: function() |
| 666 { | 694 { |
| 667 return this._hasActiveOverrides; | 695 return this._hasActiveOverrides; |
| 668 }, | 696 }, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 }, | 821 }, |
| 794 | 822 |
| 795 __proto__: WebInspector.Object.prototype | 823 __proto__: WebInspector.Object.prototype |
| 796 } | 824 } |
| 797 | 825 |
| 798 | 826 |
| 799 /** | 827 /** |
| 800 * @type {!WebInspector.OverridesSupport} | 828 * @type {!WebInspector.OverridesSupport} |
| 801 */ | 829 */ |
| 802 WebInspector.overridesSupport; | 830 WebInspector.overridesSupport; |
| OLD | NEW |