Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 /** | 4 /** |
| 5 * @implements {SDK.TargetManager.Observer} | 5 * @implements {SDK.TargetManager.Observer} |
| 6 * @unrestricted | 6 * @unrestricted |
| 7 */ | 7 */ |
| 8 Emulation.DeviceModeModel = class { | 8 Emulation.DeviceModeModel = class { |
| 9 /** | 9 /** |
| 10 * @param {function()} updateCallback | 10 * @param {function()} updateCallback |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 629 */ | 629 */ |
| 630 async captureScreenshot(fullSize) { | 630 async captureScreenshot(fullSize) { |
| 631 var screenCaptureModel = this._target ? this._target.model(SDK.ScreenCapture Model) : null; | 631 var screenCaptureModel = this._target ? this._target.model(SDK.ScreenCapture Model) : null; |
| 632 if (!screenCaptureModel) | 632 if (!screenCaptureModel) |
| 633 return null; | 633 return null; |
| 634 | 634 |
| 635 var metrics = await screenCaptureModel.fetchLayoutMetrics(); | 635 var metrics = await screenCaptureModel.fetchLayoutMetrics(); |
| 636 if (!metrics) | 636 if (!metrics) |
| 637 return null; | 637 return null; |
| 638 | 638 |
| 639 if (!this._emulatedPageSize) | |
| 640 this._calculateAndEmulate(false); | |
| 641 | |
| 639 var pageSize = fullSize ? new UI.Size(metrics.contentWidth, metrics.contentH eight) : this._emulatedPageSize; | 642 var pageSize = fullSize ? new UI.Size(metrics.contentWidth, metrics.contentH eight) : this._emulatedPageSize; |
| 640 var promises = []; | 643 var promises = []; |
| 641 promises.push( | 644 promises.push( |
| 642 this._target.emulationAgent().setVisibleSize(Math.floor(pageSize.width), Math.floor(pageSize.height))); | 645 this._target.emulationAgent().setVisibleSize(Math.floor(pageSize.width), Math.floor(pageSize.height))); |
| 643 if (fullSize) { | 646 if (fullSize) { |
| 644 promises.push(this._target.emulationAgent().forceViewport(0, 0, 1)); | 647 promises.push(this._target.emulationAgent().forceViewport(0, 0, 1)); |
| 645 } else { | 648 } else { |
| 646 promises.push(this._target.emulationAgent().forceViewport( | 649 promises.push(this._target.emulationAgent().forceViewport( |
| 647 Math.floor(metrics.viewportX), Math.floor(metrics.viewportY), metrics. viewportScale)); | 650 Math.floor(metrics.viewportX), Math.floor(metrics.viewportY), metrics. viewportScale)); |
| 648 } | 651 } |
| 649 promises.push(this._target.emulationAgent().invoke_setDeviceMetricsOverride( { | 652 promises.push(this._target.emulationAgent().invoke_setDeviceMetricsOverride( { |
| 650 width: 0, | 653 width: 0, |
| 651 height: 0, | 654 height: 0, |
| 652 deviceScaleFactor: this._appliedDeviceScaleFactor, | 655 deviceScaleFactor: this._appliedDeviceScaleFactor, |
| 653 mobile: this._isMobile(), | 656 mobile: this._isMobile(), |
| 654 fitWindow: false, | 657 fitWindow: false, |
| 655 scale: 1, | 658 scale: 1, |
| 656 })); | 659 })); |
| 657 await Promise.all(promises); | 660 await Promise.all(promises); |
| 658 | 661 |
| 659 var screenshot = await screenCaptureModel.captureScreenshot('png', 100); | 662 var screenshot = await screenCaptureModel.captureScreenshot('png', 100); |
| 663 this._calculateAndEmulate(false); | |
|
dgozman
2017/04/21 20:40:54
You can move this back now.
pfeldman
2017/04/21 20:51:35
Done.
| |
| 660 this._target.emulationAgent().setVisibleSize( | 664 this._target.emulationAgent().setVisibleSize( |
| 661 Math.floor(this._emulatedPageSize.width * this._scale), | 665 Math.floor(this._emulatedPageSize.width * this._scale), |
| 662 Math.floor(this._emulatedPageSize.height * this._scale)); | 666 Math.floor(this._emulatedPageSize.height * this._scale)); |
| 663 this._target.emulationAgent().resetViewport(); | 667 this._target.emulationAgent().resetViewport(); |
| 664 this._calculateAndEmulate(false); | |
| 665 return screenshot; | 668 return screenshot; |
| 666 } | 669 } |
| 667 | 670 |
| 668 _deviceMetricsOverrideAppliedForTest() { | 671 _deviceMetricsOverrideAppliedForTest() { |
| 669 // Used for sniffing in tests. | 672 // Used for sniffing in tests. |
| 670 } | 673 } |
| 671 | 674 |
| 672 /** | 675 /** |
| 673 * @param {boolean} touchEnabled | 676 * @param {boolean} touchEnabled |
| 674 * @param {boolean} mobile | 677 * @param {boolean} mobile |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 695 | 698 |
| 696 Emulation.DeviceModeModel.MinDeviceSize = 50; | 699 Emulation.DeviceModeModel.MinDeviceSize = 50; |
| 697 Emulation.DeviceModeModel.MaxDeviceSize = 9999; | 700 Emulation.DeviceModeModel.MaxDeviceSize = 9999; |
| 698 | 701 |
| 699 | 702 |
| 700 Emulation.DeviceModeModel._defaultMobileUserAgent = | 703 Emulation.DeviceModeModel._defaultMobileUserAgent = |
| 701 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 ( KHTML, like Gecko) Chrome/%s Mobile Safari/537.36'; | 704 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 ( KHTML, like Gecko) Chrome/%s Mobile Safari/537.36'; |
| 702 Emulation.DeviceModeModel._defaultMobileUserAgent = | 705 Emulation.DeviceModeModel._defaultMobileUserAgent = |
| 703 SDK.MultitargetNetworkManager.patchUserAgentWithChromeVersion(Emulation.Devi ceModeModel._defaultMobileUserAgent); | 706 SDK.MultitargetNetworkManager.patchUserAgentWithChromeVersion(Emulation.Devi ceModeModel._defaultMobileUserAgent); |
| 704 Emulation.DeviceModeModel.defaultMobileScaleFactor = 2; | 707 Emulation.DeviceModeModel.defaultMobileScaleFactor = 2; |
| OLD | NEW |