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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 /** @type {!WebInspector.DeviceModeModel.Type} */ | 48 /** @type {!WebInspector.DeviceModeModel.Type} */ |
49 this._type = WebInspector.DeviceModeModel.Type.None; | 49 this._type = WebInspector.DeviceModeModel.Type.None; |
50 /** @type {?WebInspector.EmulatedDevice} */ | 50 /** @type {?WebInspector.EmulatedDevice} */ |
51 this._device = null; | 51 this._device = null; |
52 /** @type {?WebInspector.EmulatedDevice.Mode} */ | 52 /** @type {?WebInspector.EmulatedDevice.Mode} */ |
53 this._mode = null; | 53 this._mode = null; |
54 /** @type {boolean} */ | 54 /** @type {boolean} */ |
55 this._touchEnabled = false; | 55 this._touchEnabled = false; |
56 /** @type {string} */ | 56 /** @type {string} */ |
57 this._touchConfiguration = ""; | 57 this._touchConfiguration = ""; |
| 58 /** @type {string} */ |
| 59 this._screenOrientation = ""; |
58 /** @type {number} */ | 60 /** @type {number} */ |
59 this._fitScale = 1; | 61 this._fitScale = 1; |
60 | 62 |
61 /** @type {?WebInspector.Target} */ | 63 /** @type {?WebInspector.Target} */ |
62 this._target = null; | 64 this._target = null; |
63 /** @type {?function()} */ | 65 /** @type {?function()} */ |
64 this._onTargetAvailable = null; | 66 this._onTargetAvailable = null; |
65 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Type.Pag
e); | 67 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Type.Pag
e); |
66 } | 68 } |
67 | 69 |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 if (!this._target) | 415 if (!this._target) |
414 this._onTargetAvailable = this._calculateAndEmulate.bind(this, reset
PageScaleFactor); | 416 this._onTargetAvailable = this._calculateAndEmulate.bind(this, reset
PageScaleFactor); |
415 | 417 |
416 if (this._type === WebInspector.DeviceModeModel.Type.Device) { | 418 if (this._type === WebInspector.DeviceModeModel.Type.Device) { |
417 var orientation = this._device.orientationByName(this._mode.orientat
ion); | 419 var orientation = this._device.orientationByName(this._mode.orientat
ion); |
418 this._fitScale = this._calculateFitScale(orientation.width, orientat
ion.height); | 420 this._fitScale = this._calculateFitScale(orientation.width, orientat
ion.height); |
419 if (this._device.mobile()) | 421 if (this._device.mobile()) |
420 this._appliedUserAgentType = this._device.touch() ? WebInspector
.DeviceModeModel.UA.Mobile : WebInspector.DeviceModeModel.UA.MobileNoTouch; | 422 this._appliedUserAgentType = this._device.touch() ? WebInspector
.DeviceModeModel.UA.Mobile : WebInspector.DeviceModeModel.UA.MobileNoTouch; |
421 else | 423 else |
422 this._appliedUserAgentType = this._device.touch() ? WebInspector
.DeviceModeModel.UA.DesktopTouch : WebInspector.DeviceModeModel.UA.Desktop; | 424 this._appliedUserAgentType = this._device.touch() ? WebInspector
.DeviceModeModel.UA.DesktopTouch : WebInspector.DeviceModeModel.UA.Desktop; |
423 this._applyDeviceMetrics(new Size(orientation.width, orientation.hei
ght), this._mode.insets, this._scaleSetting.get(), this._device.deviceScaleFacto
r, this._device.mobile(), this._mode.orientation == WebInspector.EmulatedDevice.
Horizontal ? "landscapePrimary" : "portraitPrimary", resetPageScaleFactor); | 425 this._applyDeviceMetrics(new Size(orientation.width, orientation.hei
ght), this._mode.insets, this._scaleSetting.get(), this._device.deviceScaleFacto
r, this._device.mobile(), resetPageScaleFactor); |
424 this._applyUserAgent(this._device.userAgent); | 426 this._applyUserAgent(this._device.userAgent); |
| 427 this._applyScreenOrientation(this._mode.orientation == WebInspector.
EmulatedDevice.Horizontal ? "landscapePrimary" : "portraitPrimary"); |
425 } else if (this._type === WebInspector.DeviceModeModel.Type.None) { | 428 } else if (this._type === WebInspector.DeviceModeModel.Type.None) { |
426 this._fitScale = this._calculateFitScale(this._availableSize.width,
this._availableSize.height); | 429 this._fitScale = this._calculateFitScale(this._availableSize.width,
this._availableSize.height); |
427 this._appliedUserAgentType = WebInspector.DeviceModeModel.UA.Desktop
; | 430 this._appliedUserAgentType = WebInspector.DeviceModeModel.UA.Desktop
; |
428 this._applyDeviceMetrics(this._availableSize, new Insets(0, 0, 0, 0)
, 1, 0, false, "", resetPageScaleFactor); | 431 this._applyDeviceMetrics(this._availableSize, new Insets(0, 0, 0, 0)
, 1, 0, false, resetPageScaleFactor); |
429 this._applyUserAgent(""); | 432 this._applyUserAgent(""); |
| 433 this._applyScreenOrientation(""); |
430 } else if (this._type === WebInspector.DeviceModeModel.Type.Responsive)
{ | 434 } else if (this._type === WebInspector.DeviceModeModel.Type.Responsive)
{ |
431 var screenWidth = this._widthSetting.get(); | 435 var screenWidth = this._widthSetting.get(); |
432 if (!screenWidth || screenWidth > this._preferredScaledWidth()) | 436 if (!screenWidth || screenWidth > this._preferredScaledWidth()) |
433 screenWidth = this._preferredScaledWidth(); | 437 screenWidth = this._preferredScaledWidth(); |
434 var screenHeight = this._heightSetting.get(); | 438 var screenHeight = this._heightSetting.get(); |
435 if (!screenHeight || screenHeight > this._preferredScaledHeight()) | 439 if (!screenHeight || screenHeight > this._preferredScaledHeight()) |
436 screenHeight = this._preferredScaledHeight(); | 440 screenHeight = this._preferredScaledHeight(); |
437 var mobile = this._uaSetting.get() === WebInspector.DeviceModeModel.
UA.Mobile || this._uaSetting.get() === WebInspector.DeviceModeModel.UA.MobileNoT
ouch; | 441 var mobile = this._uaSetting.get() === WebInspector.DeviceModeModel.
UA.Mobile || this._uaSetting.get() === WebInspector.DeviceModeModel.UA.MobileNoT
ouch; |
438 var defaultDeviceScaleFactor = mobile ? WebInspector.DeviceModeModel
.defaultMobileScaleFactor : 0; | 442 var defaultDeviceScaleFactor = mobile ? WebInspector.DeviceModeModel
.defaultMobileScaleFactor : 0; |
439 this._fitScale = this._calculateFitScale(this._widthSetting.get(), t
his._heightSetting.get()); | 443 this._fitScale = this._calculateFitScale(this._widthSetting.get(), t
his._heightSetting.get()); |
440 this._appliedUserAgentType = this._uaSetting.get(); | 444 this._appliedUserAgentType = this._uaSetting.get(); |
441 this._applyDeviceMetrics(new Size(screenWidth, screenHeight), new In
sets(0, 0, 0, 0), this._scaleSetting.get(), this._deviceScaleFactorSetting.get()
|| defaultDeviceScaleFactor, mobile, screenHeight >= screenWidth ? "portraitPri
mary" : "landscapePrimary", resetPageScaleFactor); | 445 this._applyDeviceMetrics(new Size(screenWidth, screenHeight), new In
sets(0, 0, 0, 0), this._scaleSetting.get(), this._deviceScaleFactorSetting.get()
|| defaultDeviceScaleFactor, mobile, resetPageScaleFactor); |
442 this._applyUserAgent(mobile ? WebInspector.DeviceModeModel._defaultM
obileUserAgent : ""); | 446 this._applyUserAgent(mobile ? WebInspector.DeviceModeModel._defaultM
obileUserAgent : ""); |
| 447 this._applyScreenOrientation(screenHeight >= screenWidth ? "portrait
Primary" : "landscapePrimary"); |
443 } | 448 } |
444 this._reapplyTouch(); | 449 this._reapplyTouch(); |
445 this._updateCallback.call(null); | 450 this._updateCallback.call(null); |
446 }, | 451 }, |
447 | 452 |
448 /** | 453 /** |
449 * @param {number} screenWidth | 454 * @param {number} screenWidth |
450 * @param {number} screenHeight | 455 * @param {number} screenHeight |
451 * @return {number} | 456 * @return {number} |
452 */ | 457 */ |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 { | 495 { |
491 WebInspector.multitargetNetworkManager.setUserAgentOverride(userAgent); | 496 WebInspector.multitargetNetworkManager.setUserAgentOverride(userAgent); |
492 }, | 497 }, |
493 | 498 |
494 /** | 499 /** |
495 * @param {!Size} screenSize | 500 * @param {!Size} screenSize |
496 * @param {!Insets} insets | 501 * @param {!Insets} insets |
497 * @param {number} scale | 502 * @param {number} scale |
498 * @param {number} deviceScaleFactor | 503 * @param {number} deviceScaleFactor |
499 * @param {boolean} mobile | 504 * @param {boolean} mobile |
500 * @param {string} screenOrientation | |
501 * @param {boolean} resetPageScaleFactor | 505 * @param {boolean} resetPageScaleFactor |
502 */ | 506 */ |
503 _applyDeviceMetrics: function(screenSize, insets, scale, deviceScaleFactor,
mobile, screenOrientation, resetPageScaleFactor) | 507 _applyDeviceMetrics: function(screenSize, insets, scale, deviceScaleFactor,
mobile, resetPageScaleFactor) |
504 { | 508 { |
505 screenSize.width = Math.max(1, Math.floor(screenSize.width)); | 509 screenSize.width = Math.max(1, Math.floor(screenSize.width)); |
506 screenSize.height = Math.max(1, Math.floor(screenSize.height)); | 510 screenSize.height = Math.max(1, Math.floor(screenSize.height)); |
507 | 511 |
508 var pageWidth = screenSize.width - insets.left - insets.right; | 512 var pageWidth = screenSize.width - insets.left - insets.right; |
509 var pageHeight = screenSize.height - insets.top - insets.bottom; | 513 var pageHeight = screenSize.height - insets.top - insets.bottom; |
510 var positionX = insets.left; | 514 var positionX = insets.left; |
511 var positionY = insets.top; | 515 var positionY = insets.top; |
512 var screenOrientationAngle = screenOrientation === "landscapePrimary" ?
90 : 0; | |
513 | 516 |
514 this._appliedDeviceSize = screenSize; | 517 this._appliedDeviceSize = screenSize; |
515 this._appliedDeviceScaleFactor = deviceScaleFactor || window.devicePixel
Ratio; | 518 this._appliedDeviceScaleFactor = deviceScaleFactor || window.devicePixel
Ratio; |
516 this._screenRect = new WebInspector.Rect( | 519 this._screenRect = new WebInspector.Rect( |
517 Math.max(0, (this._availableSize.width - screenSize.width * scale) /
2), | 520 Math.max(0, (this._availableSize.width - screenSize.width * scale) /
2), |
518 0, | 521 0, |
519 screenSize.width * scale, | 522 screenSize.width * scale, |
520 screenSize.height * scale); | 523 screenSize.height * scale); |
521 this._visiblePageRect = new WebInspector.Rect( | 524 this._visiblePageRect = new WebInspector.Rect( |
522 positionX * scale, | 525 positionX * scale, |
(...skipping 17 matching lines...) Expand all Loading... |
540 | 543 |
541 /** | 544 /** |
542 * @this {WebInspector.DeviceModeModel} | 545 * @this {WebInspector.DeviceModeModel} |
543 * @return {!Promise.<?>} | 546 * @return {!Promise.<?>} |
544 */ | 547 */ |
545 function setDeviceMetricsOverride() | 548 function setDeviceMetricsOverride() |
546 { | 549 { |
547 if (!this._target) | 550 if (!this._target) |
548 return Promise.resolve(); | 551 return Promise.resolve(); |
549 | 552 |
550 var clear = !pageWidth && !pageHeight && !mobile && !deviceScaleFact
or && scale === 1 && !screenOrientation; | 553 var clear = !pageWidth && !pageHeight && !mobile && !deviceScaleFact
or && scale === 1; |
551 var allPromises = []; | 554 var allPromises = []; |
552 if (resetPageScaleFactor) | 555 if (resetPageScaleFactor) |
553 allPromises.push(this._target.emulationAgent().resetPageScaleFac
tor()); | 556 allPromises.push(this._target.emulationAgent().resetPageScaleFac
tor()); |
554 var setDevicePromise; | 557 var setDevicePromise = clear ? |
555 if (clear) { | 558 this._target.emulationAgent().clearDeviceMetricsOverride(this._d
eviceMetricsOverrideAppliedForTest.bind(this)) : |
556 setDevicePromise = this._target.emulationAgent().clearDeviceMetr
icsOverride(this._deviceMetricsOverrideAppliedForTest.bind(this)); | 559 this._target.emulationAgent().setDeviceMetricsOverride(pageWidth
, pageHeight, deviceScaleFactor, mobile, false, scale, 0, 0, screenSize.width, s
creenSize.height, positionX, positionY, this._deviceMetricsOverrideAppliedForTes
t.bind(this)); |
557 } else { | |
558 var params = {width: pageWidth, height: pageHeight, deviceScaleF
actor: deviceScaleFactor, mobile: mobile, fitWindow: false, scale: scale, screen
Width: screenSize.width, screenHeight: screenSize.height, positionX: positionX,
positionY: positionY}; | |
559 if (screenOrientation) | |
560 params.screenOrientation = {type: screenOrientation, angle:
screenOrientationAngle}; | |
561 setDevicePromise = this._target.emulationAgent().invoke_setDevic
eMetricsOverride(params, this._deviceMetricsOverrideAppliedForTest.bind(this)); | |
562 } | |
563 allPromises.push(setDevicePromise); | 560 allPromises.push(setDevicePromise); |
564 return Promise.all(allPromises); | 561 return Promise.all(allPromises); |
565 } | 562 } |
566 }, | 563 }, |
567 | 564 |
568 _deviceMetricsOverrideAppliedForTest: function() | 565 _deviceMetricsOverrideAppliedForTest: function() |
569 { | 566 { |
570 // Used for sniffing in tests. | 567 // Used for sniffing in tests. |
571 }, | 568 }, |
572 | 569 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 { | 607 { |
611 if (error) | 608 if (error) |
612 delete target[symbol]; | 609 delete target[symbol]; |
613 else | 610 else |
614 target[symbol] = scriptId; | 611 target[symbol] = scriptId; |
615 } | 612 } |
616 | 613 |
617 target.emulationAgent().setTouchEmulationEnabled(touchEnabled, configura
tion); | 614 target.emulationAgent().setTouchEmulationEnabled(touchEnabled, configura
tion); |
618 this._touchEnabled = touchEnabled; | 615 this._touchEnabled = touchEnabled; |
619 this._touchConfiguration = configuration; | 616 this._touchConfiguration = configuration; |
| 617 }, |
| 618 |
| 619 /** |
| 620 * @param {string} orientation |
| 621 */ |
| 622 _applyScreenOrientation: function(orientation) |
| 623 { |
| 624 if (!this._target || orientation === this._screenOrientation) |
| 625 return; |
| 626 |
| 627 this._screenOrientation = orientation; |
| 628 if (!this._screenOrientation) |
| 629 this._target.screenOrientationAgent().clearScreenOrientationOverride
(); |
| 630 else |
| 631 this._target.screenOrientationAgent().setScreenOrientationOverride(t
his._screenOrientation === "landscapePrimary" ? 90 : 0, /** @type {!ScreenOrient
ationAgent.OrientationType} */ (this._screenOrientation)); |
620 } | 632 } |
621 } | 633 } |
OLD | NEW |