| Index: third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js
|
| diff --git a/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js b/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js
|
| index 5cc32caef64eb2ddd7a4bc2c59bb1acb8965b984..6373746f2dc3d6c79adb4e1f2a1143061125c199 100644
|
| --- a/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js
|
| +++ b/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
| /**
|
| - * @implements {SDK.TargetManager.Observer}
|
| + * @implements {SDK.SDKModelObserver<!SDK.EmulationModel>}
|
| * @unrestricted
|
| */
|
| Emulation.DeviceModeModel = class {
|
| @@ -58,11 +58,11 @@ Emulation.DeviceModeModel = class {
|
| /** @type {number} */
|
| this._fitScale = 1;
|
|
|
| - /** @type {?SDK.Target} */
|
| - this._target = null;
|
| + /** @type {?SDK.EmulationModel} */
|
| + this._emulationModel = null;
|
| /** @type {?function()} */
|
| - this._onTargetAvailable = null;
|
| - SDK.targetManager.observeTargets(this, SDK.Target.Capability.Browser);
|
| + this._onModelAvailable = null;
|
| + SDK.targetManager.observeModels(SDK.EmulationModel, this);
|
| }
|
|
|
| /**
|
| @@ -326,14 +326,14 @@ Emulation.DeviceModeModel = class {
|
|
|
| /**
|
| * @override
|
| - * @param {!SDK.Target} target
|
| - */
|
| - targetAdded(target) {
|
| - if (!this._target) {
|
| - this._target = target;
|
| - if (this._onTargetAvailable) {
|
| - var callback = this._onTargetAvailable;
|
| - this._onTargetAvailable = null;
|
| + * @param {!SDK.EmulationModel} emulationModel
|
| + */
|
| + modelAdded(emulationModel) {
|
| + if (!this._emulationModel && emulationModel.supportsDeviceEmulation()) {
|
| + this._emulationModel = emulationModel;
|
| + if (this._onModelAvailable) {
|
| + var callback = this._onModelAvailable;
|
| + this._onModelAvailable = null;
|
| callback();
|
| }
|
| }
|
| @@ -341,18 +341,18 @@ Emulation.DeviceModeModel = class {
|
|
|
| /**
|
| * @override
|
| - * @param {!SDK.Target} target
|
| + * @param {!SDK.EmulationModel} emulationModel
|
| */
|
| - targetRemoved(target) {
|
| - if (this._target === target)
|
| - this._target = null;
|
| + modelRemoved(emulationModel) {
|
| + if (this._emulationModel === emulationModel)
|
| + this._emulationModel = null;
|
| }
|
|
|
| /**
|
| - * @return {?SDK.Target}
|
| + * @return {?string}
|
| */
|
| - target() {
|
| - return this._target;
|
| + inspectedURL() {
|
| + return this._emulationModel ? this._emulationModel.target().inspectedURL() : null;
|
| }
|
|
|
| _scaleSettingChanged() {
|
| @@ -419,8 +419,8 @@ Emulation.DeviceModeModel = class {
|
| * @param {boolean} resetPageScaleFactor
|
| */
|
| _calculateAndEmulate(resetPageScaleFactor) {
|
| - if (!this._target)
|
| - this._onTargetAvailable = this._calculateAndEmulate.bind(this, resetPageScaleFactor);
|
| + if (!this._emulationModel)
|
| + this._onModelAvailable = this._calculateAndEmulate.bind(this, resetPageScaleFactor);
|
| var mobile = this._isMobile();
|
| if (this._type === Emulation.DeviceModeModel.Type.Device) {
|
| var orientation = this._device.orientationByName(this._mode.orientation);
|
| @@ -472,7 +472,7 @@ Emulation.DeviceModeModel = class {
|
| this._uaSetting.get() === Emulation.DeviceModeModel.UA.Mobile,
|
| this._uaSetting.get() === Emulation.DeviceModeModel.UA.Mobile);
|
| }
|
| - var overlayModel = this._target ? this._target.model(SDK.OverlayModel) : null;
|
| + var overlayModel = this._emulationModel ? this._emulationModel.overlayModel() : null;
|
| if (overlayModel)
|
| overlayModel.setShowViewportSizeOnResize(this._type === Emulation.DeviceModeModel.Type.None);
|
| this._updateCallback.call(null);
|
| @@ -590,18 +590,16 @@ Emulation.DeviceModeModel = class {
|
| * @return {!Promise.<?>}
|
| */
|
| function setDeviceMetricsOverride() {
|
| - if (!this._target)
|
| + if (!this._emulationModel)
|
| return Promise.resolve();
|
|
|
| var clear = !pageWidth && !pageHeight && !mobile && !deviceScaleFactor && scale === 1 && !screenOrientation;
|
| var allPromises = [];
|
| if (resetPageScaleFactor)
|
| - allPromises.push(this._target.emulationAgent().resetPageScaleFactor());
|
| - var setDevicePromise;
|
| - if (clear) {
|
| - setDevicePromise = this._target.emulationAgent().clearDeviceMetricsOverride();
|
| - } else {
|
| - var params = {
|
| + allPromises.push(this._emulationModel.resetPageScaleFactor());
|
| + var metrics = null;
|
| + if (!clear) {
|
| + metrics = {
|
| width: pageWidth,
|
| height: pageHeight,
|
| deviceScaleFactor: deviceScaleFactor,
|
| @@ -614,10 +612,9 @@ Emulation.DeviceModeModel = class {
|
| positionY: positionY
|
| };
|
| if (screenOrientation)
|
| - params.screenOrientation = {type: screenOrientation, angle: screenOrientationAngle};
|
| - setDevicePromise = this._target.emulationAgent().invoke_setDeviceMetricsOverride(params);
|
| + metrics.screenOrientation = {type: screenOrientation, angle: screenOrientationAngle};
|
| }
|
| - allPromises.push(setDevicePromise);
|
| + allPromises.push(this._emulationModel.emulateDevice(metrics));
|
| return Promise.all(allPromises);
|
| }
|
| }
|
| @@ -627,7 +624,7 @@ Emulation.DeviceModeModel = class {
|
| * @return {!Promise<?string>}
|
| */
|
| async captureScreenshot(fullSize) {
|
| - var screenCaptureModel = this._target ? this._target.model(SDK.ScreenCaptureModel) : null;
|
| + var screenCaptureModel = this._emulationModel ? this._emulationModel.target().model(SDK.ScreenCaptureModel) : null;
|
| if (!screenCaptureModel)
|
| return null;
|
|
|
| @@ -637,21 +634,20 @@ Emulation.DeviceModeModel = class {
|
|
|
| if (!this._emulatedPageSize)
|
| this._calculateAndEmulate(false);
|
| - var overlayModel = this._target ? this._target.model(SDK.OverlayModel) : null;
|
| + var overlayModel = this._emulationModel ? this._emulationModel.overlayModel() : null;
|
| if (overlayModel)
|
| overlayModel.setShowViewportSizeOnResize(false);
|
|
|
| var pageSize = fullSize ? new UI.Size(metrics.contentWidth, metrics.contentHeight) : this._emulatedPageSize;
|
| var promises = [];
|
| - promises.push(
|
| - this._target.emulationAgent().setVisibleSize(Math.floor(pageSize.width), Math.floor(pageSize.height)));
|
| + promises.push(this._emulationModel.setVisibleSize(Math.floor(pageSize.width), Math.floor(pageSize.height)));
|
| if (fullSize) {
|
| - promises.push(this._target.emulationAgent().forceViewport(0, 0, 1));
|
| + promises.push(this._emulationModel.forceViewport({x: 0, y: 0, scale: 1}));
|
| } else {
|
| - promises.push(this._target.emulationAgent().forceViewport(
|
| - Math.floor(metrics.viewportX), Math.floor(metrics.viewportY), metrics.viewportScale));
|
| + promises.push(this._emulationModel.forceViewport(
|
| + {x: Math.floor(metrics.viewportX), y: Math.floor(metrics.viewportY), scale: metrics.viewportScale}));
|
| }
|
| - promises.push(this._target.emulationAgent().invoke_setDeviceMetricsOverride({
|
| + promises.push(this._emulationModel.emulateDevice({
|
| width: 0,
|
| height: 0,
|
| deviceScaleFactor: this._appliedDeviceScaleFactor,
|
| @@ -662,10 +658,10 @@ Emulation.DeviceModeModel = class {
|
| await Promise.all(promises);
|
|
|
| var screenshot = await screenCaptureModel.captureScreenshot('png', 100);
|
| - this._target.emulationAgent().setVisibleSize(
|
| + this._emulationModel.setVisibleSize(
|
| Math.floor(this._emulatedPageSize.width * this._scale),
|
| Math.floor(this._emulatedPageSize.height * this._scale));
|
| - this._target.emulationAgent().resetViewport();
|
| + this._emulationModel.forceViewport(null);
|
| this._calculateAndEmulate(false);
|
| return screenshot;
|
| }
|
|
|