OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 /** | 5 /** |
6 * @param {!WebInspector.DeviceModeModel} model | 6 * @param {!WebInspector.DeviceModeModel} model |
7 * @param {!WebInspector.Setting} showMediaInspectorSetting | 7 * @param {!WebInspector.Setting} showMediaInspectorSetting |
8 * @param {!WebInspector.Setting} showRulersSetting | 8 * @param {!WebInspector.Setting} showRulersSetting |
9 * @constructor | 9 * @constructor |
10 */ | 10 */ |
11 WebInspector.DeviceModeToolbar = function(model, showMediaInspectorSetting, show RulersSetting) | 11 WebInspector.DeviceModeToolbar = function(model, showMediaInspectorSetting, show RulersSetting) |
12 { | 12 { |
13 this._model = model; | 13 this._model = model; |
14 this._showMediaInspectorSetting = showMediaInspectorSetting; | 14 this._showMediaInspectorSetting = showMediaInspectorSetting; |
15 this._showRulersSetting = showRulersSetting; | 15 this._showRulersSetting = showRulersSetting; |
16 | 16 |
17 this._deviceOutlineSetting = this._model.deviceOutlineSetting(); | 17 this._deviceOutlineSetting = this._model.deviceOutlineSetting(); |
18 this._showDeviceScaleFactorSetting = WebInspector.settings.createSetting("em ulation.showDeviceScaleFactor", false); | 18 this._showDeviceScaleFactorSetting = WebInspector.settings.createSetting("em ulation.showDeviceScaleFactor", false); |
19 this._showDeviceScaleFactorSetting.addChangeListener(this._updateDeviceScale FactorVisibility, this); | 19 this._showDeviceScaleFactorSetting.addChangeListener(this._updateDeviceScale FactorVisibility, this); |
20 | 20 |
21 this._showUserAgentTypeSetting = WebInspector.settings.createSetting("emulat ion.showUserAgentType", false); | 21 this._showUserAgentTypeSetting = WebInspector.settings.createSetting("emulat ion.showUserAgentType", false); |
22 this._showUserAgentTypeSetting.addChangeListener(this._updateUserAgentTypeVi sibility, this); | 22 this._showUserAgentTypeSetting.addChangeListener(this._updateUserAgentTypeVi sibility, this); |
23 | 23 |
24 this._showNetworkConditionsSetting = WebInspector.settings.createSetting("em ulation.showNetworkConditions", false); | 24 this._showNetworkConditionsSetting = WebInspector.settings.createSetting("em ulation.showNetworkConditions", false); |
25 this._showNetworkConditionsSetting.addChangeListener(this._updateNetworkCond itionsVisibility, this); | 25 this._showNetworkConditionsSetting.addChangeListener(this._updateNetworkCond itionsVisibility, this); |
26 | 26 |
27 /** @type {!Map<!WebInspector.EmulatedDevice, !WebInspector.EmulatedDevice.M ode>} */ | 27 /** @type {!Map<!WebInspector.EmulatedDevice, !WebInspector.EmulatedDevice.M ode>} */ |
28 this._lastMode = new Map(); | 28 this._lastMode = new Map(); |
29 | 29 |
30 /** @type {!Map<!WebInspector.EmulatedDevice, number>} */ | |
31 this._lastScale = new Map(); | |
32 | |
30 this._element = createElementWithClass("div", "device-mode-toolbar"); | 33 this._element = createElementWithClass("div", "device-mode-toolbar"); |
31 | 34 |
32 var leftContainer = this._element.createChild("div", "device-mode-toolbar-sp acer"); | 35 var leftContainer = this._element.createChild("div", "device-mode-toolbar-sp acer"); |
33 leftContainer.createChild("div", "device-mode-toolbar-spacer"); | 36 leftContainer.createChild("div", "device-mode-toolbar-spacer"); |
34 var leftToolbar = new WebInspector.Toolbar("", leftContainer); | 37 var leftToolbar = new WebInspector.Toolbar("", leftContainer); |
35 leftToolbar.makeWrappable(); | 38 leftToolbar.makeWrappable(); |
36 this._fillLeftToolbar(leftToolbar); | 39 this._fillLeftToolbar(leftToolbar); |
37 | 40 |
38 var mainToolbar = new WebInspector.Toolbar("", this._element); | 41 var mainToolbar = new WebInspector.Toolbar("", this._element); |
39 mainToolbar.makeWrappable(); | 42 mainToolbar.makeWrappable(); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 | 192 |
190 toolbar.appendToolbarItem(this._wrapToolbarItem(createElementWithClass(" div", "device-mode-empty-toolbar-element"))); | 193 toolbar.appendToolbarItem(this._wrapToolbarItem(createElementWithClass(" div", "device-mode-empty-toolbar-element"))); |
191 }, | 194 }, |
192 | 195 |
193 | 196 |
194 /** | 197 /** |
195 * @param {!WebInspector.ContextMenu} contextMenu | 198 * @param {!WebInspector.ContextMenu} contextMenu |
196 */ | 199 */ |
197 _appendScaleMenuItems: function(contextMenu) | 200 _appendScaleMenuItems: function(contextMenu) |
198 { | 201 { |
199 var scaleSetting = this._model.scaleSetting(); | |
200 if (this._model.type() === WebInspector.DeviceModeModel.Type.Device) { | 202 if (this._model.type() === WebInspector.DeviceModeModel.Type.Device) { |
201 contextMenu.appendItem(WebInspector.UIString("Fit to window (%.0f%%) ", this._model.fitScale() * 100), scaleSetting.set.bind(scaleSetting, this._mode l.fitScale()), false); | 203 contextMenu.appendItem(WebInspector.UIString("Fit to window (%.0f%%) ", this._model.fitScale() * 100), this._onScaleMenuChanged.bind(this, this._mode l.fitScale()), false); |
202 contextMenu.appendSeparator(); | 204 contextMenu.appendSeparator(); |
203 } | 205 } |
204 appendScaleItem(WebInspector.UIString("50%"), 0.5); | 206 var boundAppendScaleItem = appendScaleItem.bind(this); |
205 appendScaleItem(WebInspector.UIString("75%"), 0.75); | 207 boundAppendScaleItem(WebInspector.UIString("50%"), 0.5); |
206 appendScaleItem(WebInspector.UIString("100%"), 1); | 208 boundAppendScaleItem(WebInspector.UIString("75%"), 0.75); |
207 appendScaleItem(WebInspector.UIString("125%"), 1.25); | 209 boundAppendScaleItem(WebInspector.UIString("100%"), 1); |
208 appendScaleItem(WebInspector.UIString("150%"), 1.5); | 210 boundAppendScaleItem(WebInspector.UIString("125%"), 1.25); |
211 boundAppendScaleItem(WebInspector.UIString("150%"), 1.5); | |
209 | 212 |
210 /** | 213 /** |
211 * @param {string} title | 214 * @param {string} title |
212 * @param {number} value | 215 * @param {number} value |
216 * @this {!WebInspector.DeviceModeToolbar} | |
213 */ | 217 */ |
214 function appendScaleItem(title, value) | 218 function appendScaleItem(title, value) |
215 { | 219 { |
216 contextMenu.appendCheckboxItem(title, scaleSetting.set.bind(scaleSet ting, value), scaleSetting.get() === value, false); | 220 contextMenu.appendCheckboxItem(title, this._onScaleMenuChanged.bind( this, value), this._model.scaleSetting().get() === value, false); |
217 } | 221 } |
218 }, | 222 }, |
219 | 223 |
220 /** | 224 /** |
225 * @param {number} value | |
226 */ | |
227 _onScaleMenuChanged: function(value) | |
228 { | |
229 var device = this._model.device(); | |
230 if (device) | |
231 this._lastScale.set(device, value); | |
232 this._model.scaleSetting().set(value); | |
233 }, | |
234 | |
235 /** | |
221 * @param {!WebInspector.ContextMenu} contextMenu | 236 * @param {!WebInspector.ContextMenu} contextMenu |
222 */ | 237 */ |
223 _appendDeviceScaleMenuItems: function(contextMenu) | 238 _appendDeviceScaleMenuItems: function(contextMenu) |
224 { | 239 { |
225 var deviceScaleFactorSetting = this._model.deviceScaleFactorSetting(); | 240 var deviceScaleFactorSetting = this._model.deviceScaleFactorSetting(); |
226 var defaultValue = this._model.uaSetting().get() === WebInspector.Device ModeModel.UA.Mobile || this._model.uaSetting().get() === WebInspector.DeviceMode Model.UA.MobileNoTouch ? WebInspector.DeviceModeModel.defaultMobileScaleFactor : window.devicePixelRatio; | 241 var defaultValue = this._model.uaSetting().get() === WebInspector.Device ModeModel.UA.Mobile || this._model.uaSetting().get() === WebInspector.DeviceMode Model.UA.MobileNoTouch ? WebInspector.DeviceModeModel.defaultMobileScaleFactor : window.devicePixelRatio; |
227 appendDeviceScaleFactorItem(WebInspector.UIString("Default: %.1f", defau ltValue), 0); | 242 appendDeviceScaleFactorItem(WebInspector.UIString("Default: %.1f", defau ltValue), 0); |
228 contextMenu.appendSeparator(); | 243 contextMenu.appendSeparator(); |
229 appendDeviceScaleFactorItem(WebInspector.UIString("1"), 1); | 244 appendDeviceScaleFactorItem(WebInspector.UIString("1"), 1); |
230 appendDeviceScaleFactorItem(WebInspector.UIString("2"), 2); | 245 appendDeviceScaleFactorItem(WebInspector.UIString("2"), 2); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 var shadowRoot = WebInspector.createShadowRootWithCoreStyles(container, "emulation/deviceModeToolbar.css"); | 329 var shadowRoot = WebInspector.createShadowRootWithCoreStyles(container, "emulation/deviceModeToolbar.css"); |
315 shadowRoot.appendChild(element); | 330 shadowRoot.appendChild(element); |
316 return new WebInspector.ToolbarItem(container); | 331 return new WebInspector.ToolbarItem(container); |
317 }, | 332 }, |
318 | 333 |
319 /** | 334 /** |
320 * @param {!WebInspector.EmulatedDevice} device | 335 * @param {!WebInspector.EmulatedDevice} device |
321 */ | 336 */ |
322 _emulateDevice: function(device) | 337 _emulateDevice: function(device) |
323 { | 338 { |
324 this._model.emulate(WebInspector.DeviceModeModel.Type.Device, device, th is._lastMode.get(device) || device.modes[0]); | 339 var lastDevice = this._model.device(); |
340 var lastOrientation = this._model.mode() ? this._model.mode().orientatio n : null; | |
341 var newMode = this._lastMode.get(device) || device.modes[0]; | |
342 if (device !== lastDevice && lastOrientation && newMode && lastOrientati on !== newMode.orientation) { | |
343 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.
| |
344 newMode = matchingModes[0] || newMode; | |
345 } | |
346 this._model.emulate(WebInspector.DeviceModeModel.Type.Device, device, ne wMode, this._lastScale.get(device)); | |
325 }, | 347 }, |
326 | 348 |
327 _switchToResponsive: function() | 349 _switchToResponsive: function() |
328 { | 350 { |
329 this._model.emulate(WebInspector.DeviceModeModel.Type.Responsive, null, null); | 351 this._model.emulate(WebInspector.DeviceModeModel.Type.Responsive, null, null); |
330 }, | 352 }, |
331 | 353 |
332 /** | 354 /** |
333 * @param {!Array<!WebInspector.EmulatedDevice>} devices | 355 * @param {!Array<!WebInspector.EmulatedDevice>} devices |
334 * @return {!Array<!WebInspector.EmulatedDevice>} | 356 * @return {!Array<!WebInspector.EmulatedDevice>} |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
565 this._emulateDevice(device); | 587 this._emulateDevice(device); |
566 return; | 588 return; |
567 } | 589 } |
568 } | 590 } |
569 } | 591 } |
570 } | 592 } |
571 | 593 |
572 this._model.emulate(WebInspector.DeviceModeModel.Type.Responsive, null, null); | 594 this._model.emulate(WebInspector.DeviceModeModel.Type.Responsive, null, null); |
573 } | 595 } |
574 } | 596 } |
OLD | NEW |