| 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 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 scale, | 541 scale, |
| 542 deviceScaleFactor, | 542 deviceScaleFactor, |
| 543 mobile, | 543 mobile, |
| 544 screenOrientation, | 544 screenOrientation, |
| 545 resetPageScaleFactor) { | 545 resetPageScaleFactor) { |
| 546 screenSize.width = Math.max(1, Math.floor(screenSize.width)); | 546 screenSize.width = Math.max(1, Math.floor(screenSize.width)); |
| 547 screenSize.height = Math.max(1, Math.floor(screenSize.height)); | 547 screenSize.height = Math.max(1, Math.floor(screenSize.height)); |
| 548 | 548 |
| 549 var pageWidth = screenSize.width - insets.left - insets.right; | 549 var pageWidth = screenSize.width - insets.left - insets.right; |
| 550 var pageHeight = screenSize.height - insets.top - insets.bottom; | 550 var pageHeight = screenSize.height - insets.top - insets.bottom; |
| 551 this._emulatedPageSize = new UI.Size(Math.floor(pageWidth * scale), Math.flo
or(pageHeight * scale)); | 551 this._emulatedPageSize = new UI.Size(pageWidth, pageHeight); |
| 552 | 552 |
| 553 var positionX = insets.left; | 553 var positionX = insets.left; |
| 554 var positionY = insets.top; | 554 var positionY = insets.top; |
| 555 var screenOrientationAngle = | 555 var screenOrientationAngle = |
| 556 screenOrientation === Protocol.Emulation.ScreenOrientationType.Landscape
Primary ? 90 : 0; | 556 screenOrientation === Protocol.Emulation.ScreenOrientationType.Landscape
Primary ? 90 : 0; |
| 557 | 557 |
| 558 this._appliedDeviceSize = screenSize; | 558 this._appliedDeviceSize = screenSize; |
| 559 this._appliedDeviceScaleFactor = deviceScaleFactor || window.devicePixelRati
o; | 559 this._appliedDeviceScaleFactor = deviceScaleFactor || window.devicePixelRati
o; |
| 560 this._screenRect = new UI.Rect( | 560 this._screenRect = new UI.Rect( |
| 561 Math.max(0, (this._availableSize.width - screenSize.width * scale) / 2),
outline.top * scale, | 561 Math.max(0, (this._availableSize.width - screenSize.width * scale) / 2),
outline.top * scale, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 params.screenOrientation = {type: screenOrientation, angle: screenOrie
ntationAngle}; | 617 params.screenOrientation = {type: screenOrientation, angle: screenOrie
ntationAngle}; |
| 618 setDevicePromise = this._target.emulationAgent().invoke_setDeviceMetrics
Override( | 618 setDevicePromise = this._target.emulationAgent().invoke_setDeviceMetrics
Override( |
| 619 params, this._deviceMetricsOverrideAppliedForTest.bind(this)); | 619 params, this._deviceMetricsOverrideAppliedForTest.bind(this)); |
| 620 } | 620 } |
| 621 allPromises.push(setDevicePromise); | 621 allPromises.push(setDevicePromise); |
| 622 return Promise.all(allPromises); | 622 return Promise.all(allPromises); |
| 623 } | 623 } |
| 624 } | 624 } |
| 625 | 625 |
| 626 /** | 626 /** |
| 627 * @param {function(?string)} callback | 627 * @param {boolean} fullSize |
| 628 * @return {!Promise<?string>} |
| 628 */ | 629 */ |
| 629 captureFullSizeScreenshot(callback) { | 630 async captureScreenshot(fullSize) { |
| 630 var screenCaptureModel = this._target ? this._target.model(SDK.ScreenCapture
Model) : null; | 631 var screenCaptureModel = this._target ? this._target.model(SDK.ScreenCapture
Model) : null; |
| 631 if (!screenCaptureModel) { | 632 if (!screenCaptureModel) |
| 632 callback(null); | 633 return null; |
| 633 return; | 634 |
| 635 var metrics = await screenCaptureModel.fetchLayoutMetrics(); |
| 636 if (!metrics) |
| 637 return null; |
| 638 |
| 639 var pageSize = fullSize ? new UI.Size(metrics.contentWidth, metrics.contentH
eight) : this._emulatedPageSize; |
| 640 var promises = []; |
| 641 promises.push( |
| 642 this._target.emulationAgent().setVisibleSize(Math.floor(pageSize.width),
Math.floor(pageSize.height))); |
| 643 if (fullSize) { |
| 644 promises.push(this._target.emulationAgent().forceViewport(0, 0, 1)); |
| 645 } else { |
| 646 promises.push(this._target.emulationAgent().forceViewport( |
| 647 Math.floor(metrics.viewportX), Math.floor(metrics.viewportY), metrics.
viewportScale)); |
| 634 } | 648 } |
| 649 promises.push(this._target.emulationAgent().invoke_setDeviceMetricsOverride(
{ |
| 650 width: 0, |
| 651 height: 0, |
| 652 deviceScaleFactor: this._appliedDeviceScaleFactor, |
| 653 mobile: this._isMobile(), |
| 654 fitWindow: false, |
| 655 scale: 1, |
| 656 })); |
| 657 await Promise.all(promises); |
| 635 | 658 |
| 636 screenCaptureModel.fetchContentSize().then(contentSize => { | 659 var screenshot = await screenCaptureModel.captureScreenshot('png', 100); |
| 637 if (!contentSize) { | 660 this._target.emulationAgent().setVisibleSize( |
| 638 callback(null); | 661 Math.floor(this._emulatedPageSize.width * this._scale), |
| 639 return; | 662 Math.floor(this._emulatedPageSize.height * this._scale)); |
| 640 } | 663 this._target.emulationAgent().resetViewport(); |
| 641 | 664 this._calculateAndEmulate(false); |
| 642 var scaledPageSize = new UI.Rect(0, 0, contentSize.width, contentSize.heig
ht).scale(this._scale); | 665 return screenshot; |
| 643 var promises = []; | |
| 644 promises.push(this._target.emulationAgent().forceViewport(0, 0, 1)); | |
| 645 promises.push(this._target.emulationAgent().invoke_setDeviceMetricsOverrid
e({ | |
| 646 width: 0, | |
| 647 height: 0, | |
| 648 deviceScaleFactor: this._appliedDeviceScaleFactor, | |
| 649 mobile: this._isMobile(), | |
| 650 fitWindow: false, | |
| 651 scale: this._scale, | |
| 652 })); | |
| 653 promises.push(this._target.emulationAgent().setVisibleSize( | |
| 654 Math.floor(scaledPageSize.width), Math.floor(scaledPageSize.height))); | |
| 655 Promise.all(promises).then(() => screenCaptureModel.captureScreenshot('png
', 100)).then(content => { | |
| 656 this._target.emulationAgent().setVisibleSize(this._emulatedPageSize.widt
h, this._emulatedPageSize.height); | |
| 657 this._target.emulationAgent().resetViewport(); | |
| 658 callback(content); | |
| 659 }); | |
| 660 }); | |
| 661 } | 666 } |
| 662 | 667 |
| 663 _deviceMetricsOverrideAppliedForTest() { | 668 _deviceMetricsOverrideAppliedForTest() { |
| 664 // Used for sniffing in tests. | 669 // Used for sniffing in tests. |
| 665 } | 670 } |
| 666 | 671 |
| 667 /** | 672 /** |
| 668 * @param {boolean} touchEnabled | 673 * @param {boolean} touchEnabled |
| 669 * @param {boolean} mobile | 674 * @param {boolean} mobile |
| 670 */ | 675 */ |
| (...skipping 19 matching lines...) Expand all Loading... |
| 690 | 695 |
| 691 Emulation.DeviceModeModel.MinDeviceSize = 50; | 696 Emulation.DeviceModeModel.MinDeviceSize = 50; |
| 692 Emulation.DeviceModeModel.MaxDeviceSize = 9999; | 697 Emulation.DeviceModeModel.MaxDeviceSize = 9999; |
| 693 | 698 |
| 694 | 699 |
| 695 Emulation.DeviceModeModel._defaultMobileUserAgent = | 700 Emulation.DeviceModeModel._defaultMobileUserAgent = |
| 696 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (
KHTML, like Gecko) Chrome/%s Mobile Safari/537.36'; | 701 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (
KHTML, like Gecko) Chrome/%s Mobile Safari/537.36'; |
| 697 Emulation.DeviceModeModel._defaultMobileUserAgent = | 702 Emulation.DeviceModeModel._defaultMobileUserAgent = |
| 698 SDK.MultitargetNetworkManager.patchUserAgentWithChromeVersion(Emulation.Devi
ceModeModel._defaultMobileUserAgent); | 703 SDK.MultitargetNetworkManager.patchUserAgentWithChromeVersion(Emulation.Devi
ceModeModel._defaultMobileUserAgent); |
| 699 Emulation.DeviceModeModel.defaultMobileScaleFactor = 2; | 704 Emulation.DeviceModeModel.defaultMobileScaleFactor = 2; |
| OLD | NEW |