| 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) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 this._heightSetting.set(WebInspector.DeviceModeModel.MinDeviceSize); | 37 this._heightSetting.set(WebInspector.DeviceModeModel.MinDeviceSize); |
| 38 if (this._heightSetting.get() > WebInspector.DeviceModeModel.MaxDeviceSize) | 38 if (this._heightSetting.get() > WebInspector.DeviceModeModel.MaxDeviceSize) |
| 39 this._heightSetting.set(WebInspector.DeviceModeModel.MaxDeviceSize); | 39 this._heightSetting.set(WebInspector.DeviceModeModel.MaxDeviceSize); |
| 40 this._heightSetting.addChangeListener(this._heightSettingChanged, this); | 40 this._heightSetting.addChangeListener(this._heightSettingChanged, this); |
| 41 | 41 |
| 42 this._uaSetting = WebInspector.settings.createSetting("emulation.deviceUA",
WebInspector.DeviceModeModel.UA.Mobile); | 42 this._uaSetting = WebInspector.settings.createSetting("emulation.deviceUA",
WebInspector.DeviceModeModel.UA.Mobile); |
| 43 this._uaSetting.addChangeListener(this._uaSettingChanged, this); | 43 this._uaSetting.addChangeListener(this._uaSettingChanged, this); |
| 44 this._deviceScaleFactorSetting = WebInspector.settings.createSetting("emulat
ion.deviceScaleFactor", 0); | 44 this._deviceScaleFactorSetting = WebInspector.settings.createSetting("emulat
ion.deviceScaleFactor", 0); |
| 45 this._deviceScaleFactorSetting.addChangeListener(this._deviceScaleFactorSett
ingChanged, this); | 45 this._deviceScaleFactorSetting.addChangeListener(this._deviceScaleFactorSett
ingChanged, this); |
| 46 | 46 |
| 47 this._deviceOutlineSetting = WebInspector.settings.createSetting("emulation.
deviceOutline", true); |
| 48 this._deviceOutlineSetting.addChangeListener(this._deviceOutlineSettingChang
ed, this); |
| 49 |
| 47 /** @type {!WebInspector.DeviceModeModel.Type} */ | 50 /** @type {!WebInspector.DeviceModeModel.Type} */ |
| 48 this._type = WebInspector.DeviceModeModel.Type.None; | 51 this._type = WebInspector.DeviceModeModel.Type.None; |
| 49 /** @type {?WebInspector.EmulatedDevice} */ | 52 /** @type {?WebInspector.EmulatedDevice} */ |
| 50 this._device = null; | 53 this._device = null; |
| 51 /** @type {?WebInspector.EmulatedDevice.Mode} */ | 54 /** @type {?WebInspector.EmulatedDevice.Mode} */ |
| 52 this._mode = null; | 55 this._mode = null; |
| 53 /** @type {boolean} */ | 56 /** @type {boolean} */ |
| 54 this._touchEnabled = false; | 57 this._touchEnabled = false; |
| 55 /** @type {string} */ | 58 /** @type {string} */ |
| 56 this._touchConfiguration = ""; | 59 this._touchConfiguration = ""; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 229 |
| 227 /** | 230 /** |
| 228 * @return {string} | 231 * @return {string} |
| 229 */ | 232 */ |
| 230 screenImage: function() | 233 screenImage: function() |
| 231 { | 234 { |
| 232 return (this._device && this._mode) ? this._device.modeImage(this._mode)
: ""; | 235 return (this._device && this._mode) ? this._device.modeImage(this._mode)
: ""; |
| 233 }, | 236 }, |
| 234 | 237 |
| 235 /** | 238 /** |
| 239 * @return {string} |
| 240 */ |
| 241 outlineImage: function() |
| 242 { |
| 243 return this._deviceOutlineSetting.get() && this._device && this._device.
outlineImage(this._mode.orientation) || ""; |
| 244 }, |
| 245 |
| 246 /** |
| 247 * @return {!WebInspector.Rect} |
| 248 */ |
| 249 outlineRect: function() |
| 250 { |
| 251 return this._outlineRect; |
| 252 }, |
| 253 |
| 254 /** |
| 236 * @return {!WebInspector.Rect} | 255 * @return {!WebInspector.Rect} |
| 237 */ | 256 */ |
| 238 screenRect: function() | 257 screenRect: function() |
| 239 { | 258 { |
| 240 return this._screenRect; | 259 return this._screenRect; |
| 241 }, | 260 }, |
| 242 | 261 |
| 243 /** | 262 /** |
| 244 * @return {!WebInspector.Rect} | 263 * @return {!WebInspector.Rect} |
| 245 */ | 264 */ |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 317 |
| 299 /** | 318 /** |
| 300 * @return {!WebInspector.Setting} | 319 * @return {!WebInspector.Setting} |
| 301 */ | 320 */ |
| 302 deviceScaleFactorSetting: function() | 321 deviceScaleFactorSetting: function() |
| 303 { | 322 { |
| 304 return this._deviceScaleFactorSetting; | 323 return this._deviceScaleFactorSetting; |
| 305 }, | 324 }, |
| 306 | 325 |
| 307 /** | 326 /** |
| 327 * @return {!WebInspector.Setting} |
| 328 */ |
| 329 deviceOutlineSetting: function() |
| 330 { |
| 331 return this._deviceOutlineSetting; |
| 332 }, |
| 333 |
| 334 /** |
| 308 * @return {number} | 335 * @return {number} |
| 309 */ | 336 */ |
| 310 defaultDeviceScaleFactor: function() | 337 defaultDeviceScaleFactor: function() |
| 311 { | 338 { |
| 312 if (this._type === WebInspector.DeviceModeModel.Type.Responsive) | 339 if (this._type === WebInspector.DeviceModeModel.Type.Responsive) |
| 313 return this._uaSetting.get() === WebInspector.DeviceModeModel.UA.Mob
ile ? WebInspector.DeviceModeModel._defaultMobileScaleFactor : this._currentDevi
ceScaleFactor; | 340 return this._uaSetting.get() === WebInspector.DeviceModeModel.UA.Mob
ile ? WebInspector.DeviceModeModel._defaultMobileScaleFactor : this._currentDevi
ceScaleFactor; |
| 314 else if (this._type === WebInspector.DeviceModeModel.Type.Device) | 341 else if (this._type === WebInspector.DeviceModeModel.Type.Device) |
| 315 return this._device.deviceScaleFactor; | 342 return this._device.deviceScaleFactor; |
| 316 else | 343 else |
| 317 return this._currentDeviceScaleFactor; | 344 return this._currentDeviceScaleFactor; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 _uaSettingChanged: function() | 418 _uaSettingChanged: function() |
| 392 { | 419 { |
| 393 this._calculateAndEmulate(true); | 420 this._calculateAndEmulate(true); |
| 394 }, | 421 }, |
| 395 | 422 |
| 396 _deviceScaleFactorSettingChanged: function() | 423 _deviceScaleFactorSettingChanged: function() |
| 397 { | 424 { |
| 398 this._calculateAndEmulate(false); | 425 this._calculateAndEmulate(false); |
| 399 }, | 426 }, |
| 400 | 427 |
| 428 _deviceOutlineSettingChanged: function() |
| 429 { |
| 430 this._calculateAndEmulate(false); |
| 431 }, |
| 432 |
| 401 /** | 433 /** |
| 402 * @return {number} | 434 * @return {number} |
| 403 */ | 435 */ |
| 404 _preferredScaledWidth: function() | 436 _preferredScaledWidth: function() |
| 405 { | 437 { |
| 406 return Math.floor(this._preferredSize.width / (this._scaleSetting.get()
|| 1)); | 438 return Math.floor(this._preferredSize.width / (this._scaleSetting.get()
|| 1)); |
| 407 }, | 439 }, |
| 408 | 440 |
| 409 /** | 441 /** |
| 410 * @return {number} | 442 * @return {number} |
| 411 */ | 443 */ |
| 412 _preferredScaledHeight: function() | 444 _preferredScaledHeight: function() |
| 413 { | 445 { |
| 414 return Math.floor(this._preferredSize.height / (this._scaleSetting.get()
|| 1)); | 446 return Math.floor(this._preferredSize.height / (this._scaleSetting.get()
|| 1)); |
| 415 }, | 447 }, |
| 416 | 448 |
| 417 /** | 449 /** |
| 418 * @param {boolean} resetPageScaleFactor | 450 * @param {boolean} resetPageScaleFactor |
| 419 */ | 451 */ |
| 420 _calculateAndEmulate: function(resetPageScaleFactor) | 452 _calculateAndEmulate: function(resetPageScaleFactor) |
| 421 { | 453 { |
| 422 if (!this._target) | 454 if (!this._target) |
| 423 this._onTargetAvailable = this._calculateAndEmulate.bind(this, reset
PageScaleFactor); | 455 this._onTargetAvailable = this._calculateAndEmulate.bind(this, reset
PageScaleFactor); |
| 424 | 456 |
| 425 if (this._type === WebInspector.DeviceModeModel.Type.Device) { | 457 if (this._type === WebInspector.DeviceModeModel.Type.Device) { |
| 426 var orientation = this._device.orientationByName(this._mode.orientat
ion); | 458 var orientation = this._device.orientationByName(this._mode.orientat
ion); |
| 427 this._fitScale = this._calculateFitScale(orientation.width, orientat
ion.height); | 459 var outline = this._deviceOutlineSetting.get() ? orientation.outline
Insets : null; |
| 428 this._applyDeviceMetrics(new Size(orientation.width, orientation.hei
ght), this._mode.insets, this._scaleSetting.get(), this._device.deviceScaleFacto
r, this._device.mobile(), resetPageScaleFactor); | 460 var width = outline ? outline.left + orientation.width + outline.rig
ht : orientation.width; |
| 461 var height = outline ? outline.top + orientation.height + outline.bo
ttom : orientation.height; |
| 462 this._fitScale = this._calculateFitScale(width, height); |
| 463 this._applyDeviceMetrics(new Size(orientation.width, orientation.hei
ght), this._mode.insets, outline || new Insets(0, 0, 0, 0), this._scaleSetting.g
et(), this._device.deviceScaleFactor, this._device.mobile(), resetPageScaleFacto
r); |
| 429 this._applyUserAgent(this._device.userAgent); | 464 this._applyUserAgent(this._device.userAgent); |
| 430 this._applyTouch(this._device.touch(), this._device.mobile()); | 465 this._applyTouch(this._device.touch(), this._device.mobile()); |
| 431 this._applyScreenOrientation(this._mode.orientation == WebInspector.
EmulatedDevice.Horizontal ? "landscapePrimary" : "portraitPrimary"); | 466 this._applyScreenOrientation(this._mode.orientation == WebInspector.
EmulatedDevice.Horizontal ? "landscapePrimary" : "portraitPrimary"); |
| 432 } else if (this._type === WebInspector.DeviceModeModel.Type.None) { | 467 } else if (this._type === WebInspector.DeviceModeModel.Type.None) { |
| 433 this._fitScale = this._calculateFitScale(this._availableSize.width,
this._availableSize.height); | 468 this._fitScale = this._calculateFitScale(this._availableSize.width,
this._availableSize.height); |
| 434 this._applyDeviceMetrics(this._availableSize, new Insets(0, 0, 0, 0)
, 1, 0, false, resetPageScaleFactor); | 469 this._applyDeviceMetrics(this._availableSize, new Insets(0, 0, 0, 0)
, new Insets(0, 0, 0, 0), 1, 0, false, resetPageScaleFactor); |
| 435 this._applyUserAgent(""); | 470 this._applyUserAgent(""); |
| 436 this._applyTouch(false, false); | 471 this._applyTouch(false, false); |
| 437 this._applyScreenOrientation(""); | 472 this._applyScreenOrientation(""); |
| 438 } else if (this._type === WebInspector.DeviceModeModel.Type.Responsive)
{ | 473 } else if (this._type === WebInspector.DeviceModeModel.Type.Responsive)
{ |
| 439 var screenWidth = this._widthSetting.get(); | 474 var screenWidth = this._widthSetting.get(); |
| 440 if (!screenWidth || screenWidth > this._preferredScaledWidth()) | 475 if (!screenWidth || screenWidth > this._preferredScaledWidth()) |
| 441 screenWidth = this._preferredScaledWidth(); | 476 screenWidth = this._preferredScaledWidth(); |
| 442 var screenHeight = this._heightSetting.get(); | 477 var screenHeight = this._heightSetting.get(); |
| 443 if (!screenHeight || screenHeight > this._preferredScaledHeight()) | 478 if (!screenHeight || screenHeight > this._preferredScaledHeight()) |
| 444 screenHeight = this._preferredScaledHeight(); | 479 screenHeight = this._preferredScaledHeight(); |
| 445 var mobile = this._uaSetting.get() === WebInspector.DeviceModeModel.
UA.Mobile; | 480 var mobile = this._uaSetting.get() === WebInspector.DeviceModeModel.
UA.Mobile; |
| 446 var defaultDeviceScaleFactor = mobile ? WebInspector.DeviceModeModel
._defaultMobileScaleFactor : 0; | 481 var defaultDeviceScaleFactor = mobile ? WebInspector.DeviceModeModel
._defaultMobileScaleFactor : 0; |
| 447 this._fitScale = this._calculateFitScale(this._widthSetting.get(), t
his._heightSetting.get()); | 482 this._fitScale = this._calculateFitScale(this._widthSetting.get(), t
his._heightSetting.get()); |
| 448 this._applyDeviceMetrics(new Size(screenWidth, screenHeight), new In
sets(0, 0, 0, 0), this._scaleSetting.get(), this._deviceScaleFactorSetting.get()
|| defaultDeviceScaleFactor, mobile, resetPageScaleFactor); | 483 this._applyDeviceMetrics(new Size(screenWidth, screenHeight), new In
sets(0, 0, 0, 0), new Insets(0, 0, 0, 0), this._scaleSetting.get(), this._device
ScaleFactorSetting.get() || defaultDeviceScaleFactor, mobile, resetPageScaleFact
or); |
| 449 this._applyUserAgent(mobile ? WebInspector.DeviceModeModel._defaultM
obileUserAgent : ""); | 484 this._applyUserAgent(mobile ? WebInspector.DeviceModeModel._defaultM
obileUserAgent : ""); |
| 450 this._applyTouch(this._uaSetting.get() !== WebInspector.DeviceModeMo
del.UA.Desktop, mobile); | 485 this._applyTouch(this._uaSetting.get() !== WebInspector.DeviceModeMo
del.UA.Desktop, mobile); |
| 451 this._applyScreenOrientation(screenHeight >= screenWidth ? "portrait
Primary" : "landscapePrimary"); | 486 this._applyScreenOrientation(screenHeight >= screenWidth ? "portrait
Primary" : "landscapePrimary"); |
| 452 } | 487 } |
| 453 this._updateCallback.call(null); | 488 this._updateCallback.call(null); |
| 454 }, | 489 }, |
| 455 | 490 |
| 456 /** | 491 /** |
| 457 * @param {number} screenWidth | 492 * @param {number} screenWidth |
| 458 * @param {number} screenHeight | 493 * @param {number} screenHeight |
| (...skipping 19 matching lines...) Expand all Loading... |
| 478 * @param {string} userAgent | 513 * @param {string} userAgent |
| 479 */ | 514 */ |
| 480 _applyUserAgent: function(userAgent) | 515 _applyUserAgent: function(userAgent) |
| 481 { | 516 { |
| 482 WebInspector.multitargetNetworkManager.setUserAgentOverride(userAgent); | 517 WebInspector.multitargetNetworkManager.setUserAgentOverride(userAgent); |
| 483 }, | 518 }, |
| 484 | 519 |
| 485 /** | 520 /** |
| 486 * @param {!Size} screenSize | 521 * @param {!Size} screenSize |
| 487 * @param {!Insets} insets | 522 * @param {!Insets} insets |
| 523 * @param {!Insets} outline |
| 488 * @param {number} scale | 524 * @param {number} scale |
| 489 * @param {number} deviceScaleFactor | 525 * @param {number} deviceScaleFactor |
| 490 * @param {boolean} mobile | 526 * @param {boolean} mobile |
| 491 * @param {boolean} resetPageScaleFactor | 527 * @param {boolean} resetPageScaleFactor |
| 492 */ | 528 */ |
| 493 _applyDeviceMetrics: function(screenSize, insets, scale, deviceScaleFactor,
mobile, resetPageScaleFactor) | 529 _applyDeviceMetrics: function(screenSize, insets, outline, scale, deviceScal
eFactor, mobile, resetPageScaleFactor) |
| 494 { | 530 { |
| 495 screenSize.width = Math.max(1, Math.floor(screenSize.width)); | 531 screenSize.width = Math.max(1, Math.floor(screenSize.width)); |
| 496 screenSize.height = Math.max(1, Math.floor(screenSize.height)); | 532 screenSize.height = Math.max(1, Math.floor(screenSize.height)); |
| 497 | 533 |
| 498 var pageWidth = screenSize.width - insets.left - insets.right; | 534 var pageWidth = screenSize.width - insets.left - insets.right; |
| 499 var pageHeight = screenSize.height - insets.top - insets.bottom; | 535 var pageHeight = screenSize.height - insets.top - insets.bottom; |
| 500 var positionX = insets.left; | 536 var positionX = insets.left; |
| 501 var positionY = insets.top; | 537 var positionY = insets.top; |
| 502 | 538 |
| 503 this._appliedDeviceSize = screenSize; | 539 this._appliedDeviceSize = screenSize; |
| 504 this._screenRect = new WebInspector.Rect( | 540 this._screenRect = new WebInspector.Rect( |
| 505 Math.max(0, (this._availableSize.width - screenSize.width * scale) /
2), | 541 Math.max(0, (this._availableSize.width - screenSize.width * scale) /
2), |
| 506 0, | 542 outline.top * scale, |
| 507 screenSize.width * scale, | 543 screenSize.width * scale, |
| 508 screenSize.height * scale); | 544 screenSize.height * scale); |
| 545 this._outlineRect = new WebInspector.Rect( |
| 546 this._screenRect.left - outline.left * scale, |
| 547 0, |
| 548 (outline.left + screenSize.width + outline.right) * scale, |
| 549 (outline.top + screenSize.height + outline.bottom) * scale); |
| 509 this._visiblePageRect = new WebInspector.Rect( | 550 this._visiblePageRect = new WebInspector.Rect( |
| 510 positionX * scale, | 551 positionX * scale, |
| 511 positionY * scale, | 552 positionY * scale, |
| 512 Math.min(pageWidth * scale, this._availableSize.width - this._screen
Rect.left - positionX * scale), | 553 Math.min(pageWidth * scale, this._availableSize.width - this._screen
Rect.left - positionX * scale), |
| 513 Math.min(pageHeight * scale, this._availableSize.height - this._scre
enRect.top - positionY * scale)); | 554 Math.min(pageHeight * scale, this._availableSize.height - this._scre
enRect.top - positionY * scale)); |
| 514 this._scale = scale; | 555 this._scale = scale; |
| 515 | 556 |
| 516 if (scale === 1 && this._availableSize.width >= screenSize.width && this
._availableSize.height >= screenSize.height) { | 557 if (scale === 1 && this._availableSize.width >= screenSize.width && this
._availableSize.height >= screenSize.height) { |
| 517 // When we have enough space, no page size override is required. Thi
s will speed things up and remove lag. | 558 // When we have enough space, no page size override is required. Thi
s will speed things up and remove lag. |
| 518 pageWidth = 0; | 559 pageWidth = 0; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 if (!this._target || orientation === this._screenOrientation) | 650 if (!this._target || orientation === this._screenOrientation) |
| 610 return; | 651 return; |
| 611 | 652 |
| 612 this._screenOrientation = orientation; | 653 this._screenOrientation = orientation; |
| 613 if (!this._screenOrientation) | 654 if (!this._screenOrientation) |
| 614 this._target.screenOrientationAgent().clearScreenOrientationOverride
(); | 655 this._target.screenOrientationAgent().clearScreenOrientationOverride
(); |
| 615 else | 656 else |
| 616 this._target.screenOrientationAgent().setScreenOrientationOverride(t
his._screenOrientation === "landscapePrimary" ? 90 : 0, /** @type {!ScreenOrient
ationAgent.OrientationType} */ (this._screenOrientation)); | 657 this._target.screenOrientationAgent().setScreenOrientationOverride(t
his._screenOrientation === "landscapePrimary" ? 90 : 0, /** @type {!ScreenOrient
ationAgent.OrientationType} */ (this._screenOrientation)); |
| 617 } | 658 } |
| 618 } | 659 } |
| OLD | NEW |