| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * @unrestricted | 5 * @unrestricted |
| 6 */ | 6 */ |
| 7 WebInspector.EmulatedDevice = class { | 7 Emulation.EmulatedDevice = class { |
| 8 constructor() { | 8 constructor() { |
| 9 /** @type {string} */ | 9 /** @type {string} */ |
| 10 this.title = ''; | 10 this.title = ''; |
| 11 /** @type {string} */ | 11 /** @type {string} */ |
| 12 this.type = WebInspector.EmulatedDevice.Type.Unknown; | 12 this.type = Emulation.EmulatedDevice.Type.Unknown; |
| 13 /** @type {!WebInspector.EmulatedDevice.Orientation} */ | 13 /** @type {!Emulation.EmulatedDevice.Orientation} */ |
| 14 this.vertical = {width: 0, height: 0, outlineInsets: null, outlineImage: nul
l}; | 14 this.vertical = {width: 0, height: 0, outlineInsets: null, outlineImage: nul
l}; |
| 15 /** @type {!WebInspector.EmulatedDevice.Orientation} */ | 15 /** @type {!Emulation.EmulatedDevice.Orientation} */ |
| 16 this.horizontal = {width: 0, height: 0, outlineInsets: null, outlineImage: n
ull}; | 16 this.horizontal = {width: 0, height: 0, outlineInsets: null, outlineImage: n
ull}; |
| 17 /** @type {number} */ | 17 /** @type {number} */ |
| 18 this.deviceScaleFactor = 1; | 18 this.deviceScaleFactor = 1; |
| 19 /** @type {!Array.<string>} */ | 19 /** @type {!Array.<string>} */ |
| 20 this.capabilities = [WebInspector.EmulatedDevice.Capability.Touch, WebInspec
tor.EmulatedDevice.Capability.Mobile]; | 20 this.capabilities = [Emulation.EmulatedDevice.Capability.Touch, Emulation.Em
ulatedDevice.Capability.Mobile]; |
| 21 /** @type {string} */ | 21 /** @type {string} */ |
| 22 this.userAgent = ''; | 22 this.userAgent = ''; |
| 23 /** @type {!Array.<!WebInspector.EmulatedDevice.Mode>} */ | 23 /** @type {!Array.<!Emulation.EmulatedDevice.Mode>} */ |
| 24 this.modes = []; | 24 this.modes = []; |
| 25 | 25 |
| 26 /** @type {string} */ | 26 /** @type {string} */ |
| 27 this._show = WebInspector.EmulatedDevice._Show.Default; | 27 this._show = Emulation.EmulatedDevice._Show.Default; |
| 28 /** @type {boolean} */ | 28 /** @type {boolean} */ |
| 29 this._showByDefault = true; | 29 this._showByDefault = true; |
| 30 | 30 |
| 31 /** @type {?Runtime.Extension} */ | 31 /** @type {?Runtime.Extension} */ |
| 32 this._extension = null; | 32 this._extension = null; |
| 33 } | 33 } |
| 34 | 34 |
| 35 /** | 35 /** |
| 36 * @param {*} json | 36 * @param {*} json |
| 37 * @return {?WebInspector.EmulatedDevice} | 37 * @return {?Emulation.EmulatedDevice} |
| 38 */ | 38 */ |
| 39 static fromJSONV1(json) { | 39 static fromJSONV1(json) { |
| 40 try { | 40 try { |
| 41 /** | 41 /** |
| 42 * @param {*} object | 42 * @param {*} object |
| 43 * @param {string} key | 43 * @param {string} key |
| 44 * @param {string} type | 44 * @param {string} type |
| 45 * @param {*=} defaultValue | 45 * @param {*=} defaultValue |
| 46 * @return {*} | 46 * @return {*} |
| 47 */ | 47 */ |
| (...skipping 26 matching lines...) Expand all Loading... |
| 74 * @return {!Insets} | 74 * @return {!Insets} |
| 75 */ | 75 */ |
| 76 function parseInsets(json) { | 76 function parseInsets(json) { |
| 77 return new Insets( | 77 return new Insets( |
| 78 parseIntValue(json, 'left'), parseIntValue(json, 'top'), parseIntVal
ue(json, 'right'), | 78 parseIntValue(json, 'left'), parseIntValue(json, 'top'), parseIntVal
ue(json, 'right'), |
| 79 parseIntValue(json, 'bottom')); | 79 parseIntValue(json, 'bottom')); |
| 80 } | 80 } |
| 81 | 81 |
| 82 /** | 82 /** |
| 83 * @param {*} json | 83 * @param {*} json |
| 84 * @return {!WebInspector.EmulatedDevice.Orientation} | 84 * @return {!Emulation.EmulatedDevice.Orientation} |
| 85 */ | 85 */ |
| 86 function parseOrientation(json) { | 86 function parseOrientation(json) { |
| 87 var result = {}; | 87 var result = {}; |
| 88 | 88 |
| 89 result.width = parseIntValue(json, 'width'); | 89 result.width = parseIntValue(json, 'width'); |
| 90 if (result.width < 0 || result.width > WebInspector.DeviceModeModel.MaxD
eviceSize || | 90 if (result.width < 0 || result.width > Emulation.DeviceModeModel.MaxDevi
ceSize || |
| 91 result.width < WebInspector.DeviceModeModel.MinDeviceSize) | 91 result.width < Emulation.DeviceModeModel.MinDeviceSize) |
| 92 throw new Error('Emulated device has wrong width: ' + result.width); | 92 throw new Error('Emulated device has wrong width: ' + result.width); |
| 93 | 93 |
| 94 result.height = parseIntValue(json, 'height'); | 94 result.height = parseIntValue(json, 'height'); |
| 95 if (result.height < 0 || result.height > WebInspector.DeviceModeModel.Ma
xDeviceSize || | 95 if (result.height < 0 || result.height > Emulation.DeviceModeModel.MaxDe
viceSize || |
| 96 result.height < WebInspector.DeviceModeModel.MinDeviceSize) | 96 result.height < Emulation.DeviceModeModel.MinDeviceSize) |
| 97 throw new Error('Emulated device has wrong height: ' + result.height); | 97 throw new Error('Emulated device has wrong height: ' + result.height); |
| 98 | 98 |
| 99 var outlineInsets = parseValue(json['outline'], 'insets', 'object', null
); | 99 var outlineInsets = parseValue(json['outline'], 'insets', 'object', null
); |
| 100 if (outlineInsets) { | 100 if (outlineInsets) { |
| 101 result.outlineInsets = parseInsets(outlineInsets); | 101 result.outlineInsets = parseInsets(outlineInsets); |
| 102 if (result.outlineInsets.left < 0 || result.outlineInsets.top < 0) | 102 if (result.outlineInsets.left < 0 || result.outlineInsets.top < 0) |
| 103 throw new Error('Emulated device has wrong outline insets'); | 103 throw new Error('Emulated device has wrong outline insets'); |
| 104 result.outlineImage = /** @type {string} */ (parseValue(json['outline'
], 'image', 'string')); | 104 result.outlineImage = /** @type {string} */ (parseValue(json['outline'
], 'image', 'string')); |
| 105 } | 105 } |
| 106 return /** @type {!WebInspector.EmulatedDevice.Orientation} */ (result); | 106 return /** @type {!Emulation.EmulatedDevice.Orientation} */ (result); |
| 107 } | 107 } |
| 108 | 108 |
| 109 var result = new WebInspector.EmulatedDevice(); | 109 var result = new Emulation.EmulatedDevice(); |
| 110 result.title = /** @type {string} */ (parseValue(json, 'title', 'string'))
; | 110 result.title = /** @type {string} */ (parseValue(json, 'title', 'string'))
; |
| 111 result.type = /** @type {string} */ (parseValue(json, 'type', 'string')); | 111 result.type = /** @type {string} */ (parseValue(json, 'type', 'string')); |
| 112 var rawUserAgent = /** @type {string} */ (parseValue(json, 'user-agent', '
string')); | 112 var rawUserAgent = /** @type {string} */ (parseValue(json, 'user-agent', '
string')); |
| 113 result.userAgent = WebInspector.MultitargetNetworkManager.patchUserAgentWi
thChromeVersion(rawUserAgent); | 113 result.userAgent = SDK.MultitargetNetworkManager.patchUserAgentWithChromeV
ersion(rawUserAgent); |
| 114 | 114 |
| 115 var capabilities = parseValue(json, 'capabilities', 'object', []); | 115 var capabilities = parseValue(json, 'capabilities', 'object', []); |
| 116 if (!Array.isArray(capabilities)) | 116 if (!Array.isArray(capabilities)) |
| 117 throw new Error('Emulated device capabilities must be an array'); | 117 throw new Error('Emulated device capabilities must be an array'); |
| 118 result.capabilities = []; | 118 result.capabilities = []; |
| 119 for (var i = 0; i < capabilities.length; ++i) { | 119 for (var i = 0; i < capabilities.length; ++i) { |
| 120 if (typeof capabilities[i] !== 'string') | 120 if (typeof capabilities[i] !== 'string') |
| 121 throw new Error('Emulated device capability must be a string'); | 121 throw new Error('Emulated device capability must be a string'); |
| 122 result.capabilities.push(capabilities[i]); | 122 result.capabilities.push(capabilities[i]); |
| 123 } | 123 } |
| 124 | 124 |
| 125 result.deviceScaleFactor = /** @type {number} */ (parseValue(json['screen'
], 'device-pixel-ratio', 'number')); | 125 result.deviceScaleFactor = /** @type {number} */ (parseValue(json['screen'
], 'device-pixel-ratio', 'number')); |
| 126 if (result.deviceScaleFactor < 0 || result.deviceScaleFactor > 100) | 126 if (result.deviceScaleFactor < 0 || result.deviceScaleFactor > 100) |
| 127 throw new Error('Emulated device has wrong deviceScaleFactor: ' + result
.deviceScaleFactor); | 127 throw new Error('Emulated device has wrong deviceScaleFactor: ' + result
.deviceScaleFactor); |
| 128 | 128 |
| 129 result.vertical = parseOrientation(parseValue(json['screen'], 'vertical',
'object')); | 129 result.vertical = parseOrientation(parseValue(json['screen'], 'vertical',
'object')); |
| 130 result.horizontal = parseOrientation(parseValue(json['screen'], 'horizonta
l', 'object')); | 130 result.horizontal = parseOrientation(parseValue(json['screen'], 'horizonta
l', 'object')); |
| 131 | 131 |
| 132 var modes = parseValue(json, 'modes', 'object', []); | 132 var modes = parseValue(json, 'modes', 'object', []); |
| 133 if (!Array.isArray(modes)) | 133 if (!Array.isArray(modes)) |
| 134 throw new Error('Emulated device modes must be an array'); | 134 throw new Error('Emulated device modes must be an array'); |
| 135 result.modes = []; | 135 result.modes = []; |
| 136 for (var i = 0; i < modes.length; ++i) { | 136 for (var i = 0; i < modes.length; ++i) { |
| 137 var mode = {}; | 137 var mode = {}; |
| 138 mode.title = /** @type {string} */ (parseValue(modes[i], 'title', 'strin
g')); | 138 mode.title = /** @type {string} */ (parseValue(modes[i], 'title', 'strin
g')); |
| 139 mode.orientation = /** @type {string} */ (parseValue(modes[i], 'orientat
ion', 'string')); | 139 mode.orientation = /** @type {string} */ (parseValue(modes[i], 'orientat
ion', 'string')); |
| 140 if (mode.orientation !== WebInspector.EmulatedDevice.Vertical && | 140 if (mode.orientation !== Emulation.EmulatedDevice.Vertical && |
| 141 mode.orientation !== WebInspector.EmulatedDevice.Horizontal) | 141 mode.orientation !== Emulation.EmulatedDevice.Horizontal) |
| 142 throw new Error('Emulated device mode has wrong orientation \'' + mode
.orientation + '\''); | 142 throw new Error('Emulated device mode has wrong orientation \'' + mode
.orientation + '\''); |
| 143 var orientation = result.orientationByName(mode.orientation); | 143 var orientation = result.orientationByName(mode.orientation); |
| 144 mode.insets = parseInsets(parseValue(modes[i], 'insets', 'object')); | 144 mode.insets = parseInsets(parseValue(modes[i], 'insets', 'object')); |
| 145 if (mode.insets.top < 0 || mode.insets.left < 0 || mode.insets.right < 0
|| mode.insets.bottom < 0 || | 145 if (mode.insets.top < 0 || mode.insets.left < 0 || mode.insets.right < 0
|| mode.insets.bottom < 0 || |
| 146 mode.insets.top + mode.insets.bottom > orientation.height || | 146 mode.insets.top + mode.insets.bottom > orientation.height || |
| 147 mode.insets.left + mode.insets.right > orientation.width) { | 147 mode.insets.left + mode.insets.right > orientation.width) { |
| 148 throw new Error('Emulated device mode \'' + mode.title + '\'has wrong
mode insets'); | 148 throw new Error('Emulated device mode \'' + mode.title + '\'has wrong
mode insets'); |
| 149 } | 149 } |
| 150 mode.image = /** @type {string} */ (parseValue(modes[i], 'image', 'strin
g', null)); | 150 mode.image = /** @type {string} */ (parseValue(modes[i], 'image', 'strin
g', null)); |
| 151 result.modes.push(mode); | 151 result.modes.push(mode); |
| 152 } | 152 } |
| 153 | 153 |
| 154 result._showByDefault = /** @type {boolean} */ (parseValue(json, 'show-by-
default', 'boolean', undefined)); | 154 result._showByDefault = /** @type {boolean} */ (parseValue(json, 'show-by-
default', 'boolean', undefined)); |
| 155 result._show = | 155 result._show = |
| 156 /** @type {string} */ (parseValue(json, 'show', 'string', WebInspector
.EmulatedDevice._Show.Default)); | 156 /** @type {string} */ (parseValue(json, 'show', 'string', Emulation.Em
ulatedDevice._Show.Default)); |
| 157 | 157 |
| 158 return result; | 158 return result; |
| 159 } catch (e) { | 159 } catch (e) { |
| 160 return null; | 160 return null; |
| 161 } | 161 } |
| 162 } | 162 } |
| 163 | 163 |
| 164 /** | 164 /** |
| 165 * @param {!WebInspector.EmulatedDevice} device1 | 165 * @param {!Emulation.EmulatedDevice} device1 |
| 166 * @param {!WebInspector.EmulatedDevice} device2 | 166 * @param {!Emulation.EmulatedDevice} device2 |
| 167 * @return {number} | 167 * @return {number} |
| 168 */ | 168 */ |
| 169 static deviceComparator(device1, device2) { | 169 static deviceComparator(device1, device2) { |
| 170 var order1 = (device1._extension && device1._extension.descriptor()['order']
) || -1; | 170 var order1 = (device1._extension && device1._extension.descriptor()['order']
) || -1; |
| 171 var order2 = (device2._extension && device2._extension.descriptor()['order']
) || -1; | 171 var order2 = (device2._extension && device2._extension.descriptor()['order']
) || -1; |
| 172 if (order1 > order2) | 172 if (order1 > order2) |
| 173 return 1; | 173 return 1; |
| 174 if (order2 > order1) | 174 if (order2 > order1) |
| 175 return -1; | 175 return -1; |
| 176 return device1.title < device2.title ? -1 : (device1.title > device2.title ?
1 : 0); | 176 return device1.title < device2.title ? -1 : (device1.title > device2.title ?
1 : 0); |
| 177 } | 177 } |
| 178 | 178 |
| 179 /** | 179 /** |
| 180 * @return {?Runtime.Extension} | 180 * @return {?Runtime.Extension} |
| 181 */ | 181 */ |
| 182 extension() { | 182 extension() { |
| 183 return this._extension; | 183 return this._extension; |
| 184 } | 184 } |
| 185 | 185 |
| 186 /** | 186 /** |
| 187 * @param {?Runtime.Extension} extension | 187 * @param {?Runtime.Extension} extension |
| 188 */ | 188 */ |
| 189 setExtension(extension) { | 189 setExtension(extension) { |
| 190 this._extension = extension; | 190 this._extension = extension; |
| 191 } | 191 } |
| 192 | 192 |
| 193 /** | 193 /** |
| 194 * @param {string} orientation | 194 * @param {string} orientation |
| 195 * @return {!Array.<!WebInspector.EmulatedDevice.Mode>} | 195 * @return {!Array.<!Emulation.EmulatedDevice.Mode>} |
| 196 */ | 196 */ |
| 197 modesForOrientation(orientation) { | 197 modesForOrientation(orientation) { |
| 198 var result = []; | 198 var result = []; |
| 199 for (var index = 0; index < this.modes.length; index++) { | 199 for (var index = 0; index < this.modes.length; index++) { |
| 200 if (this.modes[index].orientation === orientation) | 200 if (this.modes[index].orientation === orientation) |
| 201 result.push(this.modes[index]); | 201 result.push(this.modes[index]); |
| 202 } | 202 } |
| 203 return result; | 203 return result; |
| 204 } | 204 } |
| 205 | 205 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 233 json['modes'].push(mode); | 233 json['modes'].push(mode); |
| 234 } | 234 } |
| 235 | 235 |
| 236 json['show-by-default'] = this._showByDefault; | 236 json['show-by-default'] = this._showByDefault; |
| 237 json['show'] = this._show; | 237 json['show'] = this._show; |
| 238 | 238 |
| 239 return json; | 239 return json; |
| 240 } | 240 } |
| 241 | 241 |
| 242 /** | 242 /** |
| 243 * @param {!WebInspector.EmulatedDevice.Orientation} orientation | 243 * @param {!Emulation.EmulatedDevice.Orientation} orientation |
| 244 * @return {*} | 244 * @return {*} |
| 245 */ | 245 */ |
| 246 _orientationToJSON(orientation) { | 246 _orientationToJSON(orientation) { |
| 247 var json = {}; | 247 var json = {}; |
| 248 json['width'] = orientation.width; | 248 json['width'] = orientation.width; |
| 249 json['height'] = orientation.height; | 249 json['height'] = orientation.height; |
| 250 if (orientation.outlineInsets) { | 250 if (orientation.outlineInsets) { |
| 251 json['outline'] = {}; | 251 json['outline'] = {}; |
| 252 json['outline']['insets'] = {}; | 252 json['outline']['insets'] = {}; |
| 253 json['outline']['insets']['left'] = orientation.outlineInsets.left; | 253 json['outline']['insets']['left'] = orientation.outlineInsets.left; |
| 254 json['outline']['insets']['top'] = orientation.outlineInsets.top; | 254 json['outline']['insets']['top'] = orientation.outlineInsets.top; |
| 255 json['outline']['insets']['right'] = orientation.outlineInsets.right; | 255 json['outline']['insets']['right'] = orientation.outlineInsets.right; |
| 256 json['outline']['insets']['bottom'] = orientation.outlineInsets.bottom; | 256 json['outline']['insets']['bottom'] = orientation.outlineInsets.bottom; |
| 257 json['outline']['image'] = orientation.outlineImage; | 257 json['outline']['image'] = orientation.outlineImage; |
| 258 } | 258 } |
| 259 return json; | 259 return json; |
| 260 } | 260 } |
| 261 | 261 |
| 262 /** | 262 /** |
| 263 * @param {!WebInspector.EmulatedDevice.Mode} mode | 263 * @param {!Emulation.EmulatedDevice.Mode} mode |
| 264 * @return {string} | 264 * @return {string} |
| 265 */ | 265 */ |
| 266 modeImage(mode) { | 266 modeImage(mode) { |
| 267 if (!mode.image) | 267 if (!mode.image) |
| 268 return ''; | 268 return ''; |
| 269 if (!this._extension) | 269 if (!this._extension) |
| 270 return mode.image; | 270 return mode.image; |
| 271 return this._extension.module().substituteURL(mode.image); | 271 return this._extension.module().substituteURL(mode.image); |
| 272 } | 272 } |
| 273 | 273 |
| 274 /** | 274 /** |
| 275 * @param {!WebInspector.EmulatedDevice.Mode} mode | 275 * @param {!Emulation.EmulatedDevice.Mode} mode |
| 276 * @return {string} | 276 * @return {string} |
| 277 */ | 277 */ |
| 278 outlineImage(mode) { | 278 outlineImage(mode) { |
| 279 var orientation = this.orientationByName(mode.orientation); | 279 var orientation = this.orientationByName(mode.orientation); |
| 280 if (!orientation.outlineImage) | 280 if (!orientation.outlineImage) |
| 281 return ''; | 281 return ''; |
| 282 if (!this._extension) | 282 if (!this._extension) |
| 283 return orientation.outlineImage; | 283 return orientation.outlineImage; |
| 284 return this._extension.module().substituteURL(orientation.outlineImage); | 284 return this._extension.module().substituteURL(orientation.outlineImage); |
| 285 } | 285 } |
| 286 | 286 |
| 287 /** | 287 /** |
| 288 * @param {string} name | 288 * @param {string} name |
| 289 * @return {!WebInspector.EmulatedDevice.Orientation} | 289 * @return {!Emulation.EmulatedDevice.Orientation} |
| 290 */ | 290 */ |
| 291 orientationByName(name) { | 291 orientationByName(name) { |
| 292 return name === WebInspector.EmulatedDevice.Vertical ? this.vertical : this.
horizontal; | 292 return name === Emulation.EmulatedDevice.Vertical ? this.vertical : this.hor
izontal; |
| 293 } | 293 } |
| 294 | 294 |
| 295 /** | 295 /** |
| 296 * @return {boolean} | 296 * @return {boolean} |
| 297 */ | 297 */ |
| 298 show() { | 298 show() { |
| 299 if (this._show === WebInspector.EmulatedDevice._Show.Default) | 299 if (this._show === Emulation.EmulatedDevice._Show.Default) |
| 300 return this._showByDefault; | 300 return this._showByDefault; |
| 301 return this._show === WebInspector.EmulatedDevice._Show.Always; | 301 return this._show === Emulation.EmulatedDevice._Show.Always; |
| 302 } | 302 } |
| 303 | 303 |
| 304 /** | 304 /** |
| 305 * @param {boolean} show | 305 * @param {boolean} show |
| 306 */ | 306 */ |
| 307 setShow(show) { | 307 setShow(show) { |
| 308 this._show = show ? WebInspector.EmulatedDevice._Show.Always : WebInspector.
EmulatedDevice._Show.Never; | 308 this._show = show ? Emulation.EmulatedDevice._Show.Always : Emulation.Emulat
edDevice._Show.Never; |
| 309 } | 309 } |
| 310 | 310 |
| 311 /** | 311 /** |
| 312 * @param {!WebInspector.EmulatedDevice} other | 312 * @param {!Emulation.EmulatedDevice} other |
| 313 */ | 313 */ |
| 314 copyShowFrom(other) { | 314 copyShowFrom(other) { |
| 315 this._show = other._show; | 315 this._show = other._show; |
| 316 } | 316 } |
| 317 | 317 |
| 318 /** | 318 /** |
| 319 * @return {boolean} | 319 * @return {boolean} |
| 320 */ | 320 */ |
| 321 touch() { | 321 touch() { |
| 322 return this.capabilities.indexOf(WebInspector.EmulatedDevice.Capability.Touc
h) !== -1; | 322 return this.capabilities.indexOf(Emulation.EmulatedDevice.Capability.Touch)
!== -1; |
| 323 } | 323 } |
| 324 | 324 |
| 325 /** | 325 /** |
| 326 * @return {boolean} | 326 * @return {boolean} |
| 327 */ | 327 */ |
| 328 mobile() { | 328 mobile() { |
| 329 return this.capabilities.indexOf(WebInspector.EmulatedDevice.Capability.Mobi
le) !== -1; | 329 return this.capabilities.indexOf(Emulation.EmulatedDevice.Capability.Mobile)
!== -1; |
| 330 } | 330 } |
| 331 }; | 331 }; |
| 332 | 332 |
| 333 /** @typedef {!{title: string, orientation: string, insets: !Insets, image: ?str
ing}} */ | 333 /** @typedef {!{title: string, orientation: string, insets: !Insets, image: ?str
ing}} */ |
| 334 WebInspector.EmulatedDevice.Mode; | 334 Emulation.EmulatedDevice.Mode; |
| 335 | 335 |
| 336 /** @typedef {!{width: number, height: number, outlineInsets: ?Insets, outlineIm
age: ?string}} */ | 336 /** @typedef {!{width: number, height: number, outlineInsets: ?Insets, outlineIm
age: ?string}} */ |
| 337 WebInspector.EmulatedDevice.Orientation; | 337 Emulation.EmulatedDevice.Orientation; |
| 338 | 338 |
| 339 WebInspector.EmulatedDevice.Horizontal = 'horizontal'; | 339 Emulation.EmulatedDevice.Horizontal = 'horizontal'; |
| 340 WebInspector.EmulatedDevice.Vertical = 'vertical'; | 340 Emulation.EmulatedDevice.Vertical = 'vertical'; |
| 341 | 341 |
| 342 WebInspector.EmulatedDevice.Type = { | 342 Emulation.EmulatedDevice.Type = { |
| 343 Phone: 'phone', | 343 Phone: 'phone', |
| 344 Tablet: 'tablet', | 344 Tablet: 'tablet', |
| 345 Notebook: 'notebook', | 345 Notebook: 'notebook', |
| 346 Desktop: 'desktop', | 346 Desktop: 'desktop', |
| 347 Unknown: 'unknown' | 347 Unknown: 'unknown' |
| 348 }; | 348 }; |
| 349 | 349 |
| 350 WebInspector.EmulatedDevice.Capability = { | 350 Emulation.EmulatedDevice.Capability = { |
| 351 Touch: 'touch', | 351 Touch: 'touch', |
| 352 Mobile: 'mobile' | 352 Mobile: 'mobile' |
| 353 }; | 353 }; |
| 354 | 354 |
| 355 WebInspector.EmulatedDevice._Show = { | 355 Emulation.EmulatedDevice._Show = { |
| 356 Always: 'Always', | 356 Always: 'Always', |
| 357 Default: 'Default', | 357 Default: 'Default', |
| 358 Never: 'Never' | 358 Never: 'Never' |
| 359 }; | 359 }; |
| 360 | 360 |
| 361 | 361 |
| 362 /** | 362 /** |
| 363 * @unrestricted | 363 * @unrestricted |
| 364 */ | 364 */ |
| 365 WebInspector.EmulatedDevicesList = class extends WebInspector.Object { | 365 Emulation.EmulatedDevicesList = class extends Common.Object { |
| 366 constructor() { | 366 constructor() { |
| 367 super(); | 367 super(); |
| 368 | 368 |
| 369 /** @type {!WebInspector.Setting} */ | 369 /** @type {!Common.Setting} */ |
| 370 this._standardSetting = WebInspector.settings.createSetting('standardEmulate
dDeviceList', []); | 370 this._standardSetting = Common.settings.createSetting('standardEmulatedDevic
eList', []); |
| 371 /** @type {!Array.<!WebInspector.EmulatedDevice>} */ | 371 /** @type {!Array.<!Emulation.EmulatedDevice>} */ |
| 372 this._standard = []; | 372 this._standard = []; |
| 373 this._listFromJSONV1(this._standardSetting.get(), this._standard); | 373 this._listFromJSONV1(this._standardSetting.get(), this._standard); |
| 374 this._updateStandardDevices(); | 374 this._updateStandardDevices(); |
| 375 | 375 |
| 376 /** @type {!WebInspector.Setting} */ | 376 /** @type {!Common.Setting} */ |
| 377 this._customSetting = WebInspector.settings.createSetting('customEmulatedDev
iceList', []); | 377 this._customSetting = Common.settings.createSetting('customEmulatedDeviceLis
t', []); |
| 378 /** @type {!Array.<!WebInspector.EmulatedDevice>} */ | 378 /** @type {!Array.<!Emulation.EmulatedDevice>} */ |
| 379 this._custom = []; | 379 this._custom = []; |
| 380 if (!this._listFromJSONV1(this._customSetting.get(), this._custom)) | 380 if (!this._listFromJSONV1(this._customSetting.get(), this._custom)) |
| 381 this.saveCustomDevices(); | 381 this.saveCustomDevices(); |
| 382 } | 382 } |
| 383 | 383 |
| 384 /** | 384 /** |
| 385 * @return {!WebInspector.EmulatedDevicesList} | 385 * @return {!Emulation.EmulatedDevicesList} |
| 386 */ | 386 */ |
| 387 static instance() { | 387 static instance() { |
| 388 if (!WebInspector.EmulatedDevicesList._instance) | 388 if (!Emulation.EmulatedDevicesList._instance) |
| 389 WebInspector.EmulatedDevicesList._instance = new WebInspector.EmulatedDevi
cesList(); | 389 Emulation.EmulatedDevicesList._instance = new Emulation.EmulatedDevicesLis
t(); |
| 390 return /** @type {!WebInspector.EmulatedDevicesList} */ (WebInspector.Emulat
edDevicesList._instance); | 390 return /** @type {!Emulation.EmulatedDevicesList} */ (Emulation.EmulatedDevi
cesList._instance); |
| 391 } | 391 } |
| 392 | 392 |
| 393 _updateStandardDevices() { | 393 _updateStandardDevices() { |
| 394 var devices = []; | 394 var devices = []; |
| 395 var extensions = self.runtime.extensions('emulated-device'); | 395 var extensions = self.runtime.extensions('emulated-device'); |
| 396 for (var i = 0; i < extensions.length; ++i) { | 396 for (var i = 0; i < extensions.length; ++i) { |
| 397 var device = WebInspector.EmulatedDevice.fromJSONV1(extensions[i].descript
or()['device']); | 397 var device = Emulation.EmulatedDevice.fromJSONV1(extensions[i].descriptor(
)['device']); |
| 398 device.setExtension(extensions[i]); | 398 device.setExtension(extensions[i]); |
| 399 devices.push(device); | 399 devices.push(device); |
| 400 } | 400 } |
| 401 this._copyShowValues(this._standard, devices); | 401 this._copyShowValues(this._standard, devices); |
| 402 this._standard = devices; | 402 this._standard = devices; |
| 403 this.saveStandardDevices(); | 403 this.saveStandardDevices(); |
| 404 } | 404 } |
| 405 | 405 |
| 406 /** | 406 /** |
| 407 * @param {!Array.<*>} jsonArray | 407 * @param {!Array.<*>} jsonArray |
| 408 * @param {!Array.<!WebInspector.EmulatedDevice>} result | 408 * @param {!Array.<!Emulation.EmulatedDevice>} result |
| 409 * @return {boolean} | 409 * @return {boolean} |
| 410 */ | 410 */ |
| 411 _listFromJSONV1(jsonArray, result) { | 411 _listFromJSONV1(jsonArray, result) { |
| 412 if (!Array.isArray(jsonArray)) | 412 if (!Array.isArray(jsonArray)) |
| 413 return false; | 413 return false; |
| 414 var success = true; | 414 var success = true; |
| 415 for (var i = 0; i < jsonArray.length; ++i) { | 415 for (var i = 0; i < jsonArray.length; ++i) { |
| 416 var device = WebInspector.EmulatedDevice.fromJSONV1(jsonArray[i]); | 416 var device = Emulation.EmulatedDevice.fromJSONV1(jsonArray[i]); |
| 417 if (device) { | 417 if (device) { |
| 418 result.push(device); | 418 result.push(device); |
| 419 if (!device.modes.length) { | 419 if (!device.modes.length) { |
| 420 device.modes.push({ | 420 device.modes.push({ |
| 421 title: '', | 421 title: '', |
| 422 orientation: WebInspector.EmulatedDevice.Horizontal, | 422 orientation: Emulation.EmulatedDevice.Horizontal, |
| 423 insets: new Insets(0, 0, 0, 0), | 423 insets: new Insets(0, 0, 0, 0), |
| 424 image: null | 424 image: null |
| 425 }); | 425 }); |
| 426 device.modes.push({ | 426 device.modes.push({ |
| 427 title: '', | 427 title: '', |
| 428 orientation: WebInspector.EmulatedDevice.Vertical, | 428 orientation: Emulation.EmulatedDevice.Vertical, |
| 429 insets: new Insets(0, 0, 0, 0), | 429 insets: new Insets(0, 0, 0, 0), |
| 430 image: null | 430 image: null |
| 431 }); | 431 }); |
| 432 } | 432 } |
| 433 } else { | 433 } else { |
| 434 success = false; | 434 success = false; |
| 435 } | 435 } |
| 436 } | 436 } |
| 437 return success; | 437 return success; |
| 438 } | 438 } |
| 439 | 439 |
| 440 /** | 440 /** |
| 441 * @return {!Array.<!WebInspector.EmulatedDevice>} | 441 * @return {!Array.<!Emulation.EmulatedDevice>} |
| 442 */ | 442 */ |
| 443 standard() { | 443 standard() { |
| 444 return this._standard; | 444 return this._standard; |
| 445 } | 445 } |
| 446 | 446 |
| 447 /** | 447 /** |
| 448 * @return {!Array.<!WebInspector.EmulatedDevice>} | 448 * @return {!Array.<!Emulation.EmulatedDevice>} |
| 449 */ | 449 */ |
| 450 custom() { | 450 custom() { |
| 451 return this._custom; | 451 return this._custom; |
| 452 } | 452 } |
| 453 | 453 |
| 454 revealCustomSetting() { | 454 revealCustomSetting() { |
| 455 WebInspector.Revealer.reveal(this._customSetting); | 455 Common.Revealer.reveal(this._customSetting); |
| 456 } | 456 } |
| 457 | 457 |
| 458 /** | 458 /** |
| 459 * @param {!WebInspector.EmulatedDevice} device | 459 * @param {!Emulation.EmulatedDevice} device |
| 460 */ | 460 */ |
| 461 addCustomDevice(device) { | 461 addCustomDevice(device) { |
| 462 this._custom.push(device); | 462 this._custom.push(device); |
| 463 this.saveCustomDevices(); | 463 this.saveCustomDevices(); |
| 464 } | 464 } |
| 465 | 465 |
| 466 /** | 466 /** |
| 467 * @param {!WebInspector.EmulatedDevice} device | 467 * @param {!Emulation.EmulatedDevice} device |
| 468 */ | 468 */ |
| 469 removeCustomDevice(device) { | 469 removeCustomDevice(device) { |
| 470 this._custom.remove(device); | 470 this._custom.remove(device); |
| 471 this.saveCustomDevices(); | 471 this.saveCustomDevices(); |
| 472 } | 472 } |
| 473 | 473 |
| 474 saveCustomDevices() { | 474 saveCustomDevices() { |
| 475 var json = this._custom.map(/** @param {!WebInspector.EmulatedDevice} device
*/ function(device) { | 475 var json = this._custom.map(/** @param {!Emulation.EmulatedDevice} device */
function(device) { |
| 476 return device._toJSON(); | 476 return device._toJSON(); |
| 477 }); | 477 }); |
| 478 this._customSetting.set(json); | 478 this._customSetting.set(json); |
| 479 this.dispatchEventToListeners(WebInspector.EmulatedDevicesList.Events.Custom
DevicesUpdated); | 479 this.dispatchEventToListeners(Emulation.EmulatedDevicesList.Events.CustomDev
icesUpdated); |
| 480 } | 480 } |
| 481 | 481 |
| 482 saveStandardDevices() { | 482 saveStandardDevices() { |
| 483 var json = this._standard.map(/** @param {!WebInspector.EmulatedDevice} devi
ce */ function(device) { | 483 var json = this._standard.map(/** @param {!Emulation.EmulatedDevice} device
*/ function(device) { |
| 484 return device._toJSON(); | 484 return device._toJSON(); |
| 485 }); | 485 }); |
| 486 this._standardSetting.set(json); | 486 this._standardSetting.set(json); |
| 487 this.dispatchEventToListeners(WebInspector.EmulatedDevicesList.Events.Standa
rdDevicesUpdated); | 487 this.dispatchEventToListeners(Emulation.EmulatedDevicesList.Events.StandardD
evicesUpdated); |
| 488 } | 488 } |
| 489 | 489 |
| 490 /** | 490 /** |
| 491 * @param {!Array.<!WebInspector.EmulatedDevice>} from | 491 * @param {!Array.<!Emulation.EmulatedDevice>} from |
| 492 * @param {!Array.<!WebInspector.EmulatedDevice>} to | 492 * @param {!Array.<!Emulation.EmulatedDevice>} to |
| 493 */ | 493 */ |
| 494 _copyShowValues(from, to) { | 494 _copyShowValues(from, to) { |
| 495 var deviceById = new Map(); | 495 var deviceById = new Map(); |
| 496 for (var i = 0; i < from.length; ++i) | 496 for (var i = 0; i < from.length; ++i) |
| 497 deviceById.set(from[i].title, from[i]); | 497 deviceById.set(from[i].title, from[i]); |
| 498 | 498 |
| 499 for (var i = 0; i < to.length; ++i) { | 499 for (var i = 0; i < to.length; ++i) { |
| 500 var title = to[i].title; | 500 var title = to[i].title; |
| 501 if (deviceById.has(title)) | 501 if (deviceById.has(title)) |
| 502 to[i].copyShowFrom(/** @type {!WebInspector.EmulatedDevice} */ (deviceBy
Id.get(title))); | 502 to[i].copyShowFrom(/** @type {!Emulation.EmulatedDevice} */ (deviceById.
get(title))); |
| 503 } | 503 } |
| 504 } | 504 } |
| 505 }; | 505 }; |
| 506 | 506 |
| 507 /** @enum {symbol} */ | 507 /** @enum {symbol} */ |
| 508 WebInspector.EmulatedDevicesList.Events = { | 508 Emulation.EmulatedDevicesList.Events = { |
| 509 CustomDevicesUpdated: Symbol('CustomDevicesUpdated'), | 509 CustomDevicesUpdated: Symbol('CustomDevicesUpdated'), |
| 510 StandardDevicesUpdated: Symbol('StandardDevicesUpdated') | 510 StandardDevicesUpdated: Symbol('StandardDevicesUpdated') |
| 511 }; | 511 }; |
| 512 | 512 |
| 513 /** @type {?WebInspector.EmulatedDevicesList} */ | 513 /** @type {?Emulation.EmulatedDevicesList} */ |
| 514 WebInspector.EmulatedDevicesList._instance; | 514 Emulation.EmulatedDevicesList._instance; |
| OLD | NEW |