Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Unified Diff: third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js

Issue 2612913002: DevTools: Add feature to capture full-height screenshots (Closed)
Patch Set: More readable Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 bd206f7f032ed68b044970f5fef781ff119ad854..459d4656dccfbe8693b6a5d15c8675bfa02acad9 100644
--- a/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js
+++ b/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js
@@ -273,6 +273,23 @@ Emulation.DeviceModeModel = class {
}
/**
+ * @return {boolean}
+ */
+ _isMobile() {
+ switch (this._type) {
+ case Emulation.DeviceModeModel.Type.Device:
+ return this._device.mobile();
+
+ case Emulation.DeviceModeModel.Type.None:
+ return false;
+
+ case Emulation.DeviceModeModel.Type.Responsive:
+ return this._uaSetting.get() === Emulation.DeviceModeModel.UA.Mobile ||
+ this._uaSetting.get() === Emulation.DeviceModeModel.UA.MobileNoTouch;
+ }
+ }
+
+ /**
* @return {!Common.Setting}
*/
scaleSetting() {
@@ -398,13 +415,13 @@ Emulation.DeviceModeModel = class {
_calculateAndEmulate(resetPageScaleFactor) {
if (!this._target)
this._onTargetAvailable = this._calculateAndEmulate.bind(this, resetPageScaleFactor);
-
+ var mobile = this._isMobile();
if (this._type === Emulation.DeviceModeModel.Type.Device) {
var orientation = this._device.orientationByName(this._mode.orientation);
var outline = this._currentOutline();
var insets = this._currentInsets();
this._fitScale = this._calculateFitScale(orientation.width, orientation.height, outline, insets);
- if (this._device.mobile()) {
+ if (mobile) {
this._appliedUserAgentType =
this._device.touch() ? Emulation.DeviceModeModel.UA.Mobile : Emulation.DeviceModeModel.UA.MobileNoTouch;
} else {
@@ -413,16 +430,16 @@ Emulation.DeviceModeModel = class {
}
this._applyDeviceMetrics(
new UI.Size(orientation.width, orientation.height), insets, outline, this._scaleSetting.get(),
- this._device.deviceScaleFactor, this._device.mobile(),
+ this._device.deviceScaleFactor, mobile,
this._mode.orientation === Emulation.EmulatedDevice.Horizontal ? 'landscapePrimary' : 'portraitPrimary',
resetPageScaleFactor);
this._applyUserAgent(this._device.userAgent);
- this._applyTouch(this._device.touch(), this._device.mobile());
+ this._applyTouch(this._device.touch(), mobile);
} else if (this._type === Emulation.DeviceModeModel.Type.None) {
this._fitScale = this._calculateFitScale(this._availableSize.width, this._availableSize.height);
this._appliedUserAgentType = Emulation.DeviceModeModel.UA.Desktop;
this._applyDeviceMetrics(
- this._availableSize, new UI.Insets(0, 0, 0, 0), new UI.Insets(0, 0, 0, 0), 1, 0, false, '',
+ this._availableSize, new UI.Insets(0, 0, 0, 0), new UI.Insets(0, 0, 0, 0), 1, 0, mobile, '',
resetPageScaleFactor);
this._applyUserAgent('');
this._applyTouch(false, false);
@@ -433,8 +450,6 @@ Emulation.DeviceModeModel = class {
var screenHeight = this._heightSetting.get();
if (!screenHeight || screenHeight > this._preferredScaledHeight())
screenHeight = this._preferredScaledHeight();
- var mobile = this._uaSetting.get() === Emulation.DeviceModeModel.UA.Mobile ||
- this._uaSetting.get() === Emulation.DeviceModeModel.UA.MobileNoTouch;
var defaultDeviceScaleFactor = mobile ? Emulation.DeviceModeModel.defaultMobileScaleFactor : 0;
this._fitScale = this._calculateFitScale(this._widthSetting.get(), this._heightSetting.get());
this._appliedUserAgentType = this._uaSetting.get();
@@ -524,6 +539,7 @@ Emulation.DeviceModeModel = class {
var pageWidth = screenSize.width - insets.left - insets.right;
var pageHeight = screenSize.height - insets.top - insets.bottom;
+ this._emulatedPageSize = new UI.Size(Math.floor(pageWidth * scale), Math.floor(pageHeight * scale));
var positionX = insets.left;
var positionY = insets.top;
@@ -597,6 +613,42 @@ Emulation.DeviceModeModel = class {
}
}
+ /**
+ * @param {function(?Protocol.Error, string) callback
+ */
+ captureFullHeightScreenshot(callback) {
+ this._target.pageAgent().getLayoutMetrics((err, layoutViewport, visualViewport, contentSize) => {
+ var promises = [];
+ var scaledPageSize =
+ new UI.Rect(0, 0, contentSize.width, contentSize.height).scale(visualViewport.scale * this._scale);
+ var params = {
+ width: 0,
+ height: 0,
+ deviceScaleFactor: this._appliedDeviceScaleFactor,
+ mobile: this._isMobile(),
+ fitWindow: false,
+ scale: this._scale,
+ };
+ promises.push(this._target.emulationAgent().forceViewport(0, 0, visualViewport.scale));
dgozman 2017/01/19 23:40:42 I tried this out: with 150% scale in dropdown and
+ promises.push(this._target.emulationAgent().invoke_setDeviceMetricsOverride(params));
+ promises.push(this._target.emulationAgent().setVisibleSize(scaledPageSize.width, scaledPageSize.height));
dgozman 2017/01/19 23:40:42 You have to Math.floor() these to send integers.
+ Promise.all(promises).then(() => {
+ this._target.pageAgent().captureScreenshot(screenshotCaptured.bind(this));
+ });
+
+ /**
+ * @param {?Protocol.Error} error
+ * @param {string} content
+ * @this {Emulation.DeviceModeModel}
+ */
+ function screenshotCaptured(error, content) {
+ this._target.emulationAgent().setVisibleSize(this._emulatedPageSize.width, this._emulatedPageSize.height);
+ this._target.emulationAgent().resetViewport();
+ callback(error, content);
+ }
+ });
+ }
+
_deviceMetricsOverrideAppliedForTest() {
// Used for sniffing in tests.
}

Powered by Google App Engine
This is Rietveld 408576698