| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 * @constructor | 6 * @constructor |
| 7 * @param {function()} updateCallback | 7 * @param {function()} updateCallback |
| 8 * @implements {WebInspector.TargetManager.Observer} | 8 * @implements {WebInspector.TargetManager.Observer} |
| 9 */ | 9 */ |
| 10 WebInspector.DeviceModeModel = function(updateCallback) | 10 WebInspector.DeviceModeModel = function(updateCallback) |
| 11 { | 11 { |
| 12 this._updateCallback = updateCallback; | 12 this._updateCallback = updateCallback; |
| 13 this._screenRect = new WebInspector.Rect(0, 0, 1, 1); | 13 this._screenRect = new WebInspector.Rect(0, 0, 1, 1); |
| 14 this._visiblePageRect = new WebInspector.Rect(0, 0, 1, 1); | 14 this._visiblePageRect = new WebInspector.Rect(0, 0, 1, 1); |
| 15 this._availableSize = new Size(1, 1); | 15 this._availableSize = new Size(1, 1); |
| 16 this._preferredSize = new Size(1, 1); | 16 this._preferredSize = new Size(1, 1); |
| 17 this._initialized = false; | 17 this._initialized = false; |
| 18 this._deviceMetricsThrottler = new WebInspector.Throttler(0); | 18 this._deviceMetricsThrottler = new WebInspector.Throttler(0); |
| 19 this._appliedDeviceSize = new Size(1, 1); | 19 this._appliedDeviceSize = new Size(1, 1); |
| 20 this._currentDeviceScaleFactor = window.devicePixelRatio; | 20 this._currentDeviceScaleFactor = window.devicePixelRatio; |
| 21 this._appliedDeviceScaleFactor = 0; | 21 this._appliedDeviceScaleFactor = 0; |
| 22 | 22 |
| 23 this._scaleSetting = WebInspector.settings.createSetting("emulation.deviceSc
ale", 1); | 23 this._scaleSetting = WebInspector.settings.createSetting("emulation.deviceSc
ale", 1); |
| 24 this._scaleSetting.addChangeListener(this._scaleSettingChanged, this); | |
| 25 // We've used to allow zero before. | 24 // We've used to allow zero before. |
| 26 if (!this._scaleSetting.get()) | 25 if (!this._scaleSetting.get()) |
| 27 this._scaleSetting.set(1); | 26 this._scaleSetting.set(1); |
| 27 this._scaleSetting.addChangeListener(this._scaleSettingChanged, this); |
| 28 |
| 28 this._widthSetting = WebInspector.settings.createSetting("emulation.deviceWi
dth", 400); | 29 this._widthSetting = WebInspector.settings.createSetting("emulation.deviceWi
dth", 400); |
| 30 if (this._widthSetting.get() < WebInspector.DeviceModeModel.MinDeviceSize) |
| 31 this._widthSetting.set(WebInspector.DeviceModeModel.MinDeviceSize); |
| 32 if (this._widthSetting.get() > WebInspector.DeviceModeModel.MaxDeviceSize) |
| 33 this._widthSetting.set(WebInspector.DeviceModeModel.MaxDeviceSize); |
| 29 this._widthSetting.addChangeListener(this._widthSettingChanged, this); | 34 this._widthSetting.addChangeListener(this._widthSettingChanged, this); |
| 35 |
| 30 this._heightSetting = WebInspector.settings.createSetting("emulation.deviceH
eight", 0); | 36 this._heightSetting = WebInspector.settings.createSetting("emulation.deviceH
eight", 0); |
| 37 if (this._heightSetting.get() && this._heightSetting.get() < WebInspector.De
viceModeModel.MinDeviceSize) |
| 38 this._heightSetting.set(WebInspector.DeviceModeModel.MinDeviceSize); |
| 39 if (this._heightSetting.get() > WebInspector.DeviceModeModel.MaxDeviceSize) |
| 40 this._heightSetting.set(WebInspector.DeviceModeModel.MaxDeviceSize); |
| 31 this._heightSetting.addChangeListener(this._heightSettingChanged, this); | 41 this._heightSetting.addChangeListener(this._heightSettingChanged, this); |
| 42 |
| 32 this._uaSetting = WebInspector.settings.createSetting("emulation.deviceUA",
WebInspector.DeviceModeModel.UA.Mobile); | 43 this._uaSetting = WebInspector.settings.createSetting("emulation.deviceUA",
WebInspector.DeviceModeModel.UA.Mobile); |
| 33 this._uaSetting.addChangeListener(this._uaSettingChanged, this); | 44 this._uaSetting.addChangeListener(this._uaSettingChanged, this); |
| 34 this._deviceScaleFactorSetting = WebInspector.settings.createSetting("emulat
ion.deviceScaleFactor", 0); | 45 this._deviceScaleFactorSetting = WebInspector.settings.createSetting("emulat
ion.deviceScaleFactor", 0); |
| 35 this._deviceScaleFactorSetting.addChangeListener(this._deviceScaleFactorSett
ingChanged, this); | 46 this._deviceScaleFactorSetting.addChangeListener(this._deviceScaleFactorSett
ingChanged, this); |
| 36 | 47 |
| 37 /** @type {!WebInspector.DeviceModeModel.Type} */ | 48 /** @type {!WebInspector.DeviceModeModel.Type} */ |
| 38 this._type = WebInspector.DeviceModeModel.Type.None; | 49 this._type = WebInspector.DeviceModeModel.Type.None; |
| 39 /** @type {?WebInspector.EmulatedDevice} */ | 50 /** @type {?WebInspector.EmulatedDevice} */ |
| 40 this._device = null; | 51 this._device = null; |
| 41 /** @type {?WebInspector.EmulatedDevice.Mode} */ | 52 /** @type {?WebInspector.EmulatedDevice.Mode} */ |
| (...skipping 21 matching lines...) Expand all Loading... |
| 63 Device: "Device" | 74 Device: "Device" |
| 64 } | 75 } |
| 65 | 76 |
| 66 /** @enum {string} */ | 77 /** @enum {string} */ |
| 67 WebInspector.DeviceModeModel.UA = { | 78 WebInspector.DeviceModeModel.UA = { |
| 68 Mobile: "Mobile", | 79 Mobile: "Mobile", |
| 69 Desktop: "Desktop", | 80 Desktop: "Desktop", |
| 70 DesktopTouch: "DesktopTouch" | 81 DesktopTouch: "DesktopTouch" |
| 71 } | 82 } |
| 72 | 83 |
| 84 WebInspector.DeviceModeModel.MinDeviceSize = 50; |
| 73 WebInspector.DeviceModeModel.MaxDeviceSize = 9999; | 85 WebInspector.DeviceModeModel.MaxDeviceSize = 9999; |
| 74 | 86 |
| 75 /** | 87 /** |
| 76 * @param {string} value | 88 * @param {string} value |
| 77 * @return {string} | 89 * @return {string} |
| 78 */ | 90 */ |
| 79 WebInspector.DeviceModeModel.deviceSizeValidator = function(value) | 91 WebInspector.DeviceModeModel.deviceSizeValidator = function(value) |
| 80 { | 92 { |
| 81 if (/^[\d]+$/.test(value) && value > 0 && value <= WebInspector.DeviceModeMo
del.MaxDeviceSize) | 93 if (/^[\d]+$/.test(value) && value >= WebInspector.DeviceModeModel.MinDevice
Size && value <= WebInspector.DeviceModeModel.MaxDeviceSize) |
| 82 return ""; | 94 return ""; |
| 83 return WebInspector.UIString("Value must be positive integer"); | 95 return WebInspector.UIString("Value must be positive integer"); |
| 84 } | 96 } |
| 85 | 97 |
| 86 WebInspector.DeviceModeModel._touchEventsScriptIdSymbol = Symbol("DeviceModeMode
l.touchEventsScriptIdSymbol"); | 98 WebInspector.DeviceModeModel._touchEventsScriptIdSymbol = Symbol("DeviceModeMode
l.touchEventsScriptIdSymbol"); |
| 87 WebInspector.DeviceModeModel._defaultMobileUserAgent = "Mozilla/5.0 (Linux; Andr
oid 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.
0.2490.76 Mobile Safari/537.36"; | 99 WebInspector.DeviceModeModel._defaultMobileUserAgent = "Mozilla/5.0 (Linux; Andr
oid 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.
0.2490.76 Mobile Safari/537.36"; |
| 88 WebInspector.DeviceModeModel._defaultMobileScaleFactor = 2; | 100 WebInspector.DeviceModeModel._defaultMobileScaleFactor = 2; |
| 89 | 101 |
| 90 WebInspector.DeviceModeModel.prototype = { | 102 WebInspector.DeviceModeModel.prototype = { |
| 91 /** | 103 /** |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 if (!this._target || orientation === this._screenOrientation) | 609 if (!this._target || orientation === this._screenOrientation) |
| 598 return; | 610 return; |
| 599 | 611 |
| 600 this._screenOrientation = orientation; | 612 this._screenOrientation = orientation; |
| 601 if (!this._screenOrientation) | 613 if (!this._screenOrientation) |
| 602 this._target.screenOrientationAgent().clearScreenOrientationOverride
(); | 614 this._target.screenOrientationAgent().clearScreenOrientationOverride
(); |
| 603 else | 615 else |
| 604 this._target.screenOrientationAgent().setScreenOrientationOverride(t
his._screenOrientation === "landscapePrimary" ? 90 : 0, /** @type {!ScreenOrient
ationAgent.OrientationType} */ (this._screenOrientation)); | 616 this._target.screenOrientationAgent().setScreenOrientationOverride(t
his._screenOrientation === "landscapePrimary" ? 90 : 0, /** @type {!ScreenOrient
ationAgent.OrientationType} */ (this._screenOrientation)); |
| 605 } | 617 } |
| 606 } | 618 } |
| OLD | NEW |