| 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 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 */ | 7 */ |
| 8 WebInspector.EmulatedDevice = function() | 8 WebInspector.EmulatedDevice = function() |
| 9 { | 9 { |
| 10 /** @type {string} */ | 10 /** @type {string} */ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 /** @type {string} */ | 27 /** @type {string} */ |
| 28 this._show = WebInspector.EmulatedDevice._Show.Default; | 28 this._show = WebInspector.EmulatedDevice._Show.Default; |
| 29 /** @type {boolean} */ | 29 /** @type {boolean} */ |
| 30 this._showByDefault = true; | 30 this._showByDefault = true; |
| 31 | 31 |
| 32 /** @type {?Runtime.Extension} */ | 32 /** @type {?Runtime.Extension} */ |
| 33 this._extension = null; | 33 this._extension = null; |
| 34 } | 34 } |
| 35 | 35 |
| 36 /** @typedef {!{title: string, orientation: string, pageRect: !WebInspector.Geom
etry.Rect, images: !WebInspector.EmulatedDevice.Images}} */ | 36 /** @typedef {!{title: string, orientation: string, pageRect: !WebInspector.Geom
etry.Rect, images: ?WebInspector.EmulatedDevice.Images}} */ |
| 37 WebInspector.EmulatedDevice.Mode; | 37 WebInspector.EmulatedDevice.Mode; |
| 38 | 38 |
| 39 /** @typedef {!{width: number, height: number, outlineInsets: ?WebInspector.Geom
etry.Insets, outlineImages: ?WebInspector.EmulatedDevice.Images}} */ | 39 /** @typedef {!{width: number, height: number, outlineInsets: ?WebInspector.Geom
etry.Insets, outlineImages: ?WebInspector.EmulatedDevice.Images}} */ |
| 40 WebInspector.EmulatedDevice.Orientation; | 40 WebInspector.EmulatedDevice.Orientation; |
| 41 | 41 |
| 42 WebInspector.EmulatedDevice.Horizontal = "horizontal"; | 42 WebInspector.EmulatedDevice.Horizontal = "horizontal"; |
| 43 WebInspector.EmulatedDevice.Vertical = "vertical"; | 43 WebInspector.EmulatedDevice.Vertical = "vertical"; |
| 44 | 44 |
| 45 WebInspector.EmulatedDevice.Type = { | 45 WebInspector.EmulatedDevice.Type = { |
| 46 Phone: "phone", | 46 Phone: "phone", |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 mode.title = /** @type {string} */ (parseValue(modes[i], "title", "s
tring")); | 205 mode.title = /** @type {string} */ (parseValue(modes[i], "title", "s
tring")); |
| 206 mode.orientation = /** @type {string} */ (parseValue(modes[i], "orie
ntation", "string")); | 206 mode.orientation = /** @type {string} */ (parseValue(modes[i], "orie
ntation", "string")); |
| 207 if (mode.orientation !== WebInspector.EmulatedDevice.Vertical && mod
e.orientation !== WebInspector.EmulatedDevice.Horizontal) | 207 if (mode.orientation !== WebInspector.EmulatedDevice.Vertical && mod
e.orientation !== WebInspector.EmulatedDevice.Horizontal) |
| 208 throw new Error("Emulated device mode has wrong orientation '" +
mode.orientation + "'"); | 208 throw new Error("Emulated device mode has wrong orientation '" +
mode.orientation + "'"); |
| 209 var orientation = result.orientationByName(mode.orientation); | 209 var orientation = result.orientationByName(mode.orientation); |
| 210 mode.pageRect = parseIntRect(parseValue(modes[i], "page-rect", "obje
ct")); | 210 mode.pageRect = parseIntRect(parseValue(modes[i], "page-rect", "obje
ct")); |
| 211 if (mode.pageRect.top < 0 || mode.pageRect.left < 0 || mode.pageRect
.width < 0 || mode.pageRect.height < 0 || | 211 if (mode.pageRect.top < 0 || mode.pageRect.left < 0 || mode.pageRect
.width < 0 || mode.pageRect.height < 0 || |
| 212 mode.pageRect.top + mode.pageRect.height > orientation.height ||
mode.pageRect.left + mode.pageRect.width > orientation.width) { | 212 mode.pageRect.top + mode.pageRect.height > orientation.height ||
mode.pageRect.left + mode.pageRect.width > orientation.width) { |
| 213 throw new Error("Emulated device mode '" + mode.title + "'has wr
ong page rect"); | 213 throw new Error("Emulated device mode '" + mode.title + "'has wr
ong page rect"); |
| 214 } | 214 } |
| 215 mode.images = parseImages(parseValue(modes[i], "images", "object")); | 215 if (modes[i].hasOwnProperty("images")) |
| 216 mode.images = parseImages(parseValue(modes[i], "images", "object
")); |
| 216 result.modes.push(mode); | 217 result.modes.push(mode); |
| 217 } | 218 } |
| 218 | 219 |
| 219 result._showByDefault = /** @type {boolean} */ (parseValue(json, "show-b
y-default", "boolean", true)); | 220 result._showByDefault = /** @type {boolean} */ (parseValue(json, "show-b
y-default", "boolean", true)); |
| 220 result._show = /** @type {string} */ (parseValue(json, "show", "string",
WebInspector.EmulatedDevice._Show.Default)); | 221 result._show = /** @type {string} */ (parseValue(json, "show", "string",
WebInspector.EmulatedDevice._Show.Default)); |
| 221 | 222 |
| 223 result.createImplicitModes(); |
| 222 return result; | 224 return result; |
| 223 } catch (e) { | 225 } catch (e) { |
| 224 WebInspector.console.error("Failed to update emulated device list. " + S
tring(e)); | 226 WebInspector.console.error("Failed to update emulated device list. " + S
tring(e)); |
| 225 return null; | 227 return null; |
| 226 } | 228 } |
| 227 } | 229 } |
| 228 | 230 |
| 229 /** | 231 /** |
| 230 * @param {!WebInspector.OverridesSupport.Device} device | 232 * @param {!WebInspector.OverridesSupport.Device} device |
| 231 * @param {string} title | 233 * @param {string} title |
| 232 * @param {string=} type | 234 * @param {string=} type |
| 233 * @return {!WebInspector.EmulatedDevice} | 235 * @return {!WebInspector.EmulatedDevice} |
| 234 */ | 236 */ |
| 235 WebInspector.EmulatedDevice.fromOverridesDevice = function(device, title, type) | 237 WebInspector.EmulatedDevice.fromOverridesDevice = function(device, title, type) |
| 236 { | 238 { |
| 237 var result = new WebInspector.EmulatedDevice(); | 239 var result = new WebInspector.EmulatedDevice(); |
| 238 result.title = title; | 240 result.title = title; |
| 239 result.type = type || WebInspector.EmulatedDevice.Type.Unknown; | 241 result.type = type || WebInspector.EmulatedDevice.Type.Unknown; |
| 240 result.vertical.width = device.width; | 242 result.vertical.width = device.width; |
| 241 result.vertical.height = device.height; | 243 result.vertical.height = device.height; |
| 242 result.horizontal.width = device.height; | 244 result.horizontal.width = device.height; |
| 243 result.horizontal.height = device.width; | 245 result.horizontal.height = device.width; |
| 244 result.deviceScaleFactor = device.deviceScaleFactor; | 246 result.deviceScaleFactor = device.deviceScaleFactor; |
| 245 result.userAgent = device.userAgent; | 247 result.userAgent = device.userAgent; |
| 246 result.capabilities = []; | 248 result.capabilities = []; |
| 247 if (device.touch) | 249 if (device.touch) |
| 248 result.capabilities.push(WebInspector.EmulatedDevice.Capability.Touch); | 250 result.capabilities.push(WebInspector.EmulatedDevice.Capability.Touch); |
| 249 if (device.mobile) | 251 if (device.mobile) |
| 250 result.capabilities.push(WebInspector.EmulatedDevice.Capability.Mobile); | 252 result.capabilities.push(WebInspector.EmulatedDevice.Capability.Mobile); |
| 253 result.createImplicitModes(); |
| 251 return result; | 254 return result; |
| 252 } | 255 } |
| 253 | 256 |
| 254 /** | 257 /** |
| 255 * @param {!WebInspector.EmulatedDevice} device1 | 258 * @param {!WebInspector.EmulatedDevice} device1 |
| 256 * @param {!WebInspector.EmulatedDevice} device2 | 259 * @param {!WebInspector.EmulatedDevice} device2 |
| 257 * @return {number} | 260 * @return {number} |
| 258 */ | 261 */ |
| 259 WebInspector.EmulatedDevice.compareByTitle = function(device1, device2) | 262 WebInspector.EmulatedDevice.compareByTitle = function(device1, device2) |
| 260 { | 263 { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 271 }, | 274 }, |
| 272 | 275 |
| 273 /** | 276 /** |
| 274 * @param {?Runtime.Extension} extension | 277 * @param {?Runtime.Extension} extension |
| 275 */ | 278 */ |
| 276 setExtension: function(extension) | 279 setExtension: function(extension) |
| 277 { | 280 { |
| 278 this._extension = extension; | 281 this._extension = extension; |
| 279 }, | 282 }, |
| 280 | 283 |
| 284 createImplicitModes: function() |
| 285 { |
| 286 // TODO(dgozman): this whole method should be removed once we have modes
for all devices. |
| 287 if (this.modes.length) |
| 288 return; |
| 289 this.modes.push({title: "", orientation: WebInspector.EmulatedDevice.Hor
izontal, pageRect: {top: 0, left: 0, width: this.horizontal.width, height: this.
horizontal.height}, images: null}); |
| 290 if (this.type === WebInspector.EmulatedDevice.Type.Phone || this.type ==
= WebInspector.EmulatedDevice.Type.Tablet || this.type === WebInspector.Emulated
Device.Type.Unknown) |
| 291 this.modes.push({title: "", orientation: WebInspector.EmulatedDevice
.Vertical, pageRect: {top: 0, left: 0, width: this.vertical.width, height: this.
vertical.height}, images: null}); |
| 292 }, |
| 293 |
| 294 /** |
| 295 * @param {string} orientation |
| 296 * @return {!Array.<!WebInspector.EmulatedDevice.Mode>} |
| 297 */ |
| 298 modesForOrientation: function(orientation) |
| 299 { |
| 300 var result = []; |
| 301 for (var index = 0; index < this.modes.length; index++) { |
| 302 if (this.modes[index].orientation === orientation) |
| 303 result.push(this.modes[index]); |
| 304 } |
| 305 return result; |
| 306 }, |
| 307 |
| 281 /** | 308 /** |
| 282 * @return {*} | 309 * @return {*} |
| 283 */ | 310 */ |
| 284 _toJSON: function() | 311 _toJSON: function() |
| 285 { | 312 { |
| 286 var json = {}; | 313 var json = {}; |
| 287 json["title"] = this.title; | 314 json["title"] = this.title; |
| 288 json["type"] = this.type; | 315 json["type"] = this.type; |
| 289 json["user-agent"] = this.userAgent; | 316 json["user-agent"] = this.userAgent; |
| 290 json["capabilities"] = this.capabilities; | 317 json["capabilities"] = this.capabilities; |
| 291 | 318 |
| 292 json["screen"] = {}; | 319 json["screen"] = {}; |
| 293 json["screen"]["device-pixel-ratio"] = this.deviceScaleFactor; | 320 json["screen"]["device-pixel-ratio"] = this.deviceScaleFactor; |
| 294 json["screen"]["vertical"] = this._orientationToJSON(this.vertical); | 321 json["screen"]["vertical"] = this._orientationToJSON(this.vertical); |
| 295 json["screen"]["horizontal"] = this._orientationToJSON(this.horizontal); | 322 json["screen"]["horizontal"] = this._orientationToJSON(this.horizontal); |
| 296 | 323 |
| 297 json["modes"] = []; | 324 json["modes"] = []; |
| 298 for (var i = 0; i < this.modes.length; ++i) { | 325 for (var i = 0; i < this.modes.length; ++i) { |
| 299 var mode = {}; | 326 var mode = {}; |
| 300 mode["title"] = this.modes[i].title; | 327 mode["title"] = this.modes[i].title; |
| 301 mode["orientation"] = this.modes[i].orientation; | 328 mode["orientation"] = this.modes[i].orientation; |
| 302 mode["page-rect"] = this.modes[i].pageRect; | 329 mode["page-rect"] = this.modes[i].pageRect; |
| 303 mode["images"] = this.modes[i].images._toJSON(); | 330 if (this.modes[i].images) |
| 331 mode["images"] = this.modes[i].images._toJSON(); |
| 304 json["modes"].push(mode); | 332 json["modes"].push(mode); |
| 305 } | 333 } |
| 306 | 334 |
| 307 json["show-by-default"] = this._showByDefault; | 335 json["show-by-default"] = this._showByDefault; |
| 308 json["show"] = this._show; | 336 json["show"] = this._show; |
| 309 | 337 |
| 310 return json; | 338 return json; |
| 311 }, | 339 }, |
| 312 | 340 |
| 313 /** | 341 /** |
| 314 * @param {!WebInspector.EmulatedDevice.Orientation} orientation | 342 * @param {!WebInspector.EmulatedDevice.Orientation} orientation |
| 315 * @return {*} | 343 * @return {*} |
| 316 */ | 344 */ |
| 317 _orientationToJSON: function(orientation) | 345 _orientationToJSON: function(orientation) |
| 318 { | 346 { |
| 319 var json = {}; | 347 var json = {}; |
| 320 json["width"] = orientation.width; | 348 json["width"] = orientation.width; |
| 321 json["height"] = orientation.height; | 349 json["height"] = orientation.height; |
| 322 if (orientation.outlineInsets) { | 350 if (orientation.outlineInsets) { |
| 323 json["outline"] = {}; | 351 json["outline"] = {}; |
| 324 json["outline"]["insets"] = orientation.outlineInsets; | 352 json["outline"]["insets"] = orientation.outlineInsets; |
| 325 json["outline"]["images"] = orientation.outlineImages._toJSON(); | 353 json["outline"]["images"] = orientation.outlineImages._toJSON(); |
| 326 } | 354 } |
| 327 return json; | 355 return json; |
| 328 }, | 356 }, |
| 329 | 357 |
| 330 /** | 358 /** |
| 359 * @param {!WebInspector.EmulatedDevice.Mode} mode |
| 331 * @return {!WebInspector.OverridesSupport.Device} | 360 * @return {!WebInspector.OverridesSupport.Device} |
| 332 */ | 361 */ |
| 333 toOverridesDevice: function() | 362 modeToOverridesDevice: function(mode) |
| 334 { | 363 { |
| 335 var result = {}; | 364 var result = {}; |
| 336 result.width = this.vertical.width; | 365 result.width = mode.pageRect.width; |
| 337 result.height = this.vertical.height; | 366 result.height = mode.pageRect.height; |
| 338 result.deviceScaleFactor = this.deviceScaleFactor; | 367 result.deviceScaleFactor = this.deviceScaleFactor; |
| 339 result.userAgent = this.userAgent; | 368 result.userAgent = this.userAgent; |
| 340 result.touch = this.touch(); | 369 result.touch = this.touch(); |
| 341 result.mobile = this.mobile(); | 370 result.mobile = this.mobile(); |
| 342 return result; | 371 return result; |
| 343 }, | 372 }, |
| 344 | 373 |
| 345 /** | 374 /** |
| 346 * @param {string} name | 375 * @param {string} name |
| 347 * @return {!WebInspector.EmulatedDevice.Orientation} | 376 * @return {!WebInspector.EmulatedDevice.Orientation} |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 if (deviceById.has(title)) | 581 if (deviceById.has(title)) |
| 553 to[i].copyShowFrom(/** @type {!WebInspector.EmulatedDevice} */ (
deviceById.get(title))); | 582 to[i].copyShowFrom(/** @type {!WebInspector.EmulatedDevice} */ (
deviceById.get(title))); |
| 554 } | 583 } |
| 555 }, | 584 }, |
| 556 | 585 |
| 557 __proto__: WebInspector.Object.prototype | 586 __proto__: WebInspector.Object.prototype |
| 558 } | 587 } |
| 559 | 588 |
| 560 /** @type {!WebInspector.EmulatedDevicesList} */ | 589 /** @type {!WebInspector.EmulatedDevicesList} */ |
| 561 WebInspector.emulatedDevicesList; | 590 WebInspector.emulatedDevicesList; |
| OLD | NEW |