Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeToolbar.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeToolbar.js b/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeToolbar.js |
| index 9d190de2b0e491e57201ce2bc612d3e0e17849b7..c6f479e1239b63552b98445a0139978ad47b1f6b 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeToolbar.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeToolbar.js |
| @@ -27,6 +27,9 @@ WebInspector.DeviceModeToolbar = function(model, showMediaInspectorSetting, show |
| /** @type {!Map<!WebInspector.EmulatedDevice, !WebInspector.EmulatedDevice.Mode>} */ |
| this._lastMode = new Map(); |
| + /** @type {!Map<!WebInspector.EmulatedDevice, number>} */ |
| + this._lastScale = new Map(); |
| + |
| this._element = createElementWithClass("div", "device-mode-toolbar"); |
| var leftContainer = this._element.createChild("div", "device-mode-toolbar-spacer"); |
| @@ -196,28 +199,40 @@ WebInspector.DeviceModeToolbar.prototype = { |
| */ |
| _appendScaleMenuItems: function(contextMenu) |
| { |
| - var scaleSetting = this._model.scaleSetting(); |
| if (this._model.type() === WebInspector.DeviceModeModel.Type.Device) { |
| - contextMenu.appendItem(WebInspector.UIString("Fit to window (%.0f%%)", this._model.fitScale() * 100), scaleSetting.set.bind(scaleSetting, this._model.fitScale()), false); |
| + contextMenu.appendItem(WebInspector.UIString("Fit to window (%.0f%%)", this._model.fitScale() * 100), this._onScaleMenuChanged.bind(this, this._model.fitScale()), false); |
| contextMenu.appendSeparator(); |
| } |
| - appendScaleItem(WebInspector.UIString("50%"), 0.5); |
| - appendScaleItem(WebInspector.UIString("75%"), 0.75); |
| - appendScaleItem(WebInspector.UIString("100%"), 1); |
| - appendScaleItem(WebInspector.UIString("125%"), 1.25); |
| - appendScaleItem(WebInspector.UIString("150%"), 1.5); |
| + var boundAppendScaleItem = appendScaleItem.bind(this); |
| + boundAppendScaleItem(WebInspector.UIString("50%"), 0.5); |
| + boundAppendScaleItem(WebInspector.UIString("75%"), 0.75); |
| + boundAppendScaleItem(WebInspector.UIString("100%"), 1); |
| + boundAppendScaleItem(WebInspector.UIString("125%"), 1.25); |
| + boundAppendScaleItem(WebInspector.UIString("150%"), 1.5); |
| /** |
| * @param {string} title |
| * @param {number} value |
| + * @this {!WebInspector.DeviceModeToolbar} |
| */ |
| function appendScaleItem(title, value) |
| { |
| - contextMenu.appendCheckboxItem(title, scaleSetting.set.bind(scaleSetting, value), scaleSetting.get() === value, false); |
| + contextMenu.appendCheckboxItem(title, this._onScaleMenuChanged.bind(this, value), this._model.scaleSetting().get() === value, false); |
| } |
| }, |
| /** |
| + * @param {number} value |
| + */ |
| + _onScaleMenuChanged: function(value) |
| + { |
| + var device = this._model.device(); |
| + if (device) |
| + this._lastScale.set(device, value); |
| + this._model.scaleSetting().set(value); |
| + }, |
| + |
| + /** |
| * @param {!WebInspector.ContextMenu} contextMenu |
| */ |
| _appendDeviceScaleMenuItems: function(contextMenu) |
| @@ -321,7 +336,14 @@ WebInspector.DeviceModeToolbar.prototype = { |
| */ |
| _emulateDevice: function(device) |
| { |
| - this._model.emulate(WebInspector.DeviceModeModel.Type.Device, device, this._lastMode.get(device) || device.modes[0]); |
| + var lastDevice = this._model.device(); |
| + var lastOrientation = this._model.mode() ? this._model.mode().orientation : null; |
| + var newMode = this._lastMode.get(device) || device.modes[0]; |
| + if (device !== lastDevice && lastOrientation && newMode && lastOrientation !== newMode.orientation) { |
| + var matchingModes = device.modes.filter((mode) => mode.orientation === lastOrientation); |
|
dgozman
2016/10/21 20:32:56
I remember we agreed to revert this and leave as i
luoe
2016/10/22 01:58:02
Correct, this should now be reverted.
|
| + newMode = matchingModes[0] || newMode; |
| + } |
| + this._model.emulate(WebInspector.DeviceModeModel.Type.Device, device, newMode, this._lastScale.get(device)); |
| }, |
| _switchToResponsive: function() |