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

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

Issue 2020083004: [DevTools] Try to adjust device mode scale to avoid rounding errors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed nits Created 4 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 f8c11cf83dfbca385ed3641cb231fee657839740..2e5c1b53c2f6df0987cfcfd1023cc2f1f084e168 100644
--- a/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js
+++ b/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js
@@ -136,7 +136,7 @@ WebInspector.DeviceModeModel.prototype = {
this._mode = mode;
if (this._initialized) {
var orientation = device.orientationByName(mode.orientation);
- this._scaleSetting.set(this._calculateFitScale(orientation.width, orientation.height, this._currentOutline()));
+ this._scaleSetting.set(this._calculateFitScale(orientation.width, orientation.height, this._currentOutline(), this._currentInsets()));
}
} else {
this._device = null;
@@ -438,6 +438,16 @@ WebInspector.DeviceModeModel.prototype = {
},
/**
+ * @return {!Insets}
+ */
+ _currentInsets: function()
+ {
+ if (this._type !== WebInspector.DeviceModeModel.Type.Device)
+ return new Insets(0, 0, 0, 0);
+ return this._mode.insets;
+ },
+
+ /**
* @param {boolean} resetPageScaleFactor
*/
_calculateAndEmulate: function(resetPageScaleFactor)
@@ -448,12 +458,13 @@ WebInspector.DeviceModeModel.prototype = {
if (this._type === WebInspector.DeviceModeModel.Type.Device) {
var orientation = this._device.orientationByName(this._mode.orientation);
var outline = this._currentOutline();
- this._fitScale = this._calculateFitScale(orientation.width, orientation.height, outline);
+ var insets = this._currentInsets();
+ this._fitScale = this._calculateFitScale(orientation.width, orientation.height, outline, insets);
if (this._device.mobile())
this._appliedUserAgentType = this._device.touch() ? WebInspector.DeviceModeModel.UA.Mobile : WebInspector.DeviceModeModel.UA.MobileNoTouch;
else
this._appliedUserAgentType = this._device.touch() ? WebInspector.DeviceModeModel.UA.DesktopTouch : WebInspector.DeviceModeModel.UA.Desktop;
- this._applyDeviceMetrics(new Size(orientation.width, orientation.height), this._mode.insets, outline, this._scaleSetting.get(), this._device.deviceScaleFactor, this._device.mobile(), this._mode.orientation === WebInspector.EmulatedDevice.Horizontal ? "landscapePrimary" : "portraitPrimary", resetPageScaleFactor);
+ this._applyDeviceMetrics(new Size(orientation.width, orientation.height), insets, outline, this._scaleSetting.get(), this._device.deviceScaleFactor, this._device.mobile(), this._mode.orientation === WebInspector.EmulatedDevice.Horizontal ? "landscapePrimary" : "portraitPrimary", resetPageScaleFactor);
this._applyUserAgent(this._device.userAgent);
this._applyTouch(this._device.touch(), this._device.mobile());
} else if (this._type === WebInspector.DeviceModeModel.Type.None) {
@@ -486,14 +497,30 @@ WebInspector.DeviceModeModel.prototype = {
* @param {number} screenWidth
* @param {number} screenHeight
* @param {!Insets=} outline
+ * @param {!Insets=} insets
* @return {number}
*/
- _calculateFitScale: function(screenWidth, screenHeight, outline)
+ _calculateFitScale: function(screenWidth, screenHeight, outline, insets)
{
var outlineWidth = outline ? outline.left + outline.right : 0;
var outlineHeight = outline ? outline.top + outline.bottom : 0;
+ var insetsWidth = insets ? insets.left + insets.right : 0;
+ var insetsHeight = insets ? insets.top + insets.bottom : 0;
var scale = Math.min(screenWidth ? this._preferredSize.width / (screenWidth + outlineWidth) : 1, screenHeight ? this._preferredSize.height / (screenHeight + outlineHeight) : 1);
- return Math.min(scale, 1);
+ scale = Math.min(Math.ceil(scale * 100), 100);
+
+ var sharpScale = scale;
+ while (sharpScale > scale * 0.7) {
+ var sharp = true;
+ if (screenWidth)
+ sharp = sharp && Number.isInteger((screenWidth - insetsWidth) * sharpScale / 100);
+ if (screenHeight)
+ sharp = sharp && Number.isInteger((screenHeight - insetsHeight) * sharpScale / 100);
+ if (sharp)
+ return sharpScale / 100;
+ sharpScale -= 1;
+ }
+ return scale / 100;
},
/**
@@ -560,7 +587,7 @@ WebInspector.DeviceModeModel.prototype = {
pageWidth = 0;
pageHeight = 0;
}
- if (this._visiblePageRect.width === pageWidth * scale && this._visiblePageRect.height === pageHeight * scale) {
+ if (this._visiblePageRect.width === pageWidth * scale && this._visiblePageRect.height === pageHeight * scale && Number.isInteger(pageWidth * scale) && Number.isInteger(pageHeight * scale)) {
// When we only have to apply scale, do not resize the page. This will speed things up and remove lag.
pageWidth = 0;
pageHeight = 0;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698