| 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; | |
| 22 | 21 |
| 23 this._scaleSetting = WebInspector.settings.createSetting("emulation.deviceSc
ale", 1); | 22 this._scaleSetting = WebInspector.settings.createSetting("emulation.deviceSc
ale", 1); |
| 24 // We've used to allow zero before. | 23 // We've used to allow zero before. |
| 25 if (!this._scaleSetting.get()) | 24 if (!this._scaleSetting.get()) |
| 26 this._scaleSetting.set(1); | 25 this._scaleSetting.set(1); |
| 27 this._scaleSetting.addChangeListener(this._scaleSettingChanged, this); | 26 this._scaleSetting.addChangeListener(this._scaleSettingChanged, this); |
| 28 | 27 |
| 29 this._widthSetting = WebInspector.settings.createSetting("emulation.deviceWi
dth", 400); | 28 this._widthSetting = WebInspector.settings.createSetting("emulation.deviceWi
dth", 400); |
| 30 if (this._widthSetting.get() < WebInspector.DeviceModeModel.MinDeviceSize) | 29 if (this._widthSetting.get() < WebInspector.DeviceModeModel.MinDeviceSize) |
| 31 this._widthSetting.set(WebInspector.DeviceModeModel.MinDeviceSize); | 30 this._widthSetting.set(WebInspector.DeviceModeModel.MinDeviceSize); |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 276 |
| 278 /** | 277 /** |
| 279 * @return {boolean} | 278 * @return {boolean} |
| 280 */ | 279 */ |
| 281 isFullHeight: function() | 280 isFullHeight: function() |
| 282 { | 281 { |
| 283 return !this._heightSetting.get(); | 282 return !this._heightSetting.get(); |
| 284 }, | 283 }, |
| 285 | 284 |
| 286 /** | 285 /** |
| 287 * @return {number} | |
| 288 */ | |
| 289 appliedDeviceScaleFactor: function() | |
| 290 { | |
| 291 return this._appliedDeviceScaleFactor; | |
| 292 }, | |
| 293 | |
| 294 /** | |
| 295 * @return {!WebInspector.Setting} | 286 * @return {!WebInspector.Setting} |
| 296 */ | 287 */ |
| 297 scaleSetting: function() | 288 scaleSetting: function() |
| 298 { | 289 { |
| 299 return this._scaleSetting; | 290 return this._scaleSetting; |
| 300 }, | 291 }, |
| 301 | 292 |
| 302 /** | 293 /** |
| 303 * @return {!WebInspector.Setting} | 294 * @return {!WebInspector.Setting} |
| 304 */ | 295 */ |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 /** | 368 /** |
| 378 * @override | 369 * @override |
| 379 * @param {!WebInspector.Target} target | 370 * @param {!WebInspector.Target} target |
| 380 */ | 371 */ |
| 381 targetRemoved: function(target) | 372 targetRemoved: function(target) |
| 382 { | 373 { |
| 383 if (this._target === target) | 374 if (this._target === target) |
| 384 this._target = null; | 375 this._target = null; |
| 385 }, | 376 }, |
| 386 | 377 |
| 387 requestAppBanner: function() | |
| 388 { | |
| 389 this._target.pageAgent().requestAppBanner(); | |
| 390 }, | |
| 391 | |
| 392 _scaleSettingChanged: function() | 378 _scaleSettingChanged: function() |
| 393 { | 379 { |
| 394 this._calculateAndEmulate(true); | 380 this._calculateAndEmulate(true); |
| 395 }, | 381 }, |
| 396 | 382 |
| 397 _widthSettingChanged: function() | 383 _widthSettingChanged: function() |
| 398 { | 384 { |
| 399 this._calculateAndEmulate(false); | 385 this._calculateAndEmulate(false); |
| 400 }, | 386 }, |
| 401 | 387 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 Math.max(0, (this._availableSize.width - screenSize.width * scale) /
2), | 507 Math.max(0, (this._availableSize.width - screenSize.width * scale) /
2), |
| 522 0, | 508 0, |
| 523 screenSize.width * scale, | 509 screenSize.width * scale, |
| 524 screenSize.height * scale); | 510 screenSize.height * scale); |
| 525 this._visiblePageRect = new WebInspector.Rect( | 511 this._visiblePageRect = new WebInspector.Rect( |
| 526 positionX * scale, | 512 positionX * scale, |
| 527 positionY * scale, | 513 positionY * scale, |
| 528 Math.min(pageWidth * scale, this._availableSize.width - this._screen
Rect.left - positionX * scale), | 514 Math.min(pageWidth * scale, this._availableSize.width - this._screen
Rect.left - positionX * scale), |
| 529 Math.min(pageHeight * scale, this._availableSize.height - this._scre
enRect.top - positionY * scale)); | 515 Math.min(pageHeight * scale, this._availableSize.height - this._scre
enRect.top - positionY * scale)); |
| 530 this._scale = scale; | 516 this._scale = scale; |
| 531 this._appliedDeviceScaleFactor = deviceScaleFactor; | |
| 532 | 517 |
| 533 if (scale === 1 && this._availableSize.width >= screenSize.width && this
._availableSize.height >= screenSize.height) { | 518 if (scale === 1 && this._availableSize.width >= screenSize.width && this
._availableSize.height >= screenSize.height) { |
| 534 // When we have enough space, no page size override is required. Thi
s will speed things up and remove lag. | 519 // When we have enough space, no page size override is required. Thi
s will speed things up and remove lag. |
| 535 pageWidth = 0; | 520 pageWidth = 0; |
| 536 pageHeight = 0; | 521 pageHeight = 0; |
| 537 } | 522 } |
| 538 if (this._visiblePageRect.width === pageWidth * scale && this._visiblePa
geRect.height === pageHeight * scale) { | 523 if (this._visiblePageRect.width === pageWidth * scale && this._visiblePa
geRect.height === pageHeight * scale) { |
| 539 // When we only have to apply scale, do not resize the page. This wi
ll speed things up and remove lag. | 524 // When we only have to apply scale, do not resize the page. This wi
ll speed things up and remove lag. |
| 540 pageWidth = 0; | 525 pageWidth = 0; |
| 541 pageHeight = 0; | 526 pageHeight = 0; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 if (!this._target || orientation === this._screenOrientation) | 610 if (!this._target || orientation === this._screenOrientation) |
| 626 return; | 611 return; |
| 627 | 612 |
| 628 this._screenOrientation = orientation; | 613 this._screenOrientation = orientation; |
| 629 if (!this._screenOrientation) | 614 if (!this._screenOrientation) |
| 630 this._target.screenOrientationAgent().clearScreenOrientationOverride
(); | 615 this._target.screenOrientationAgent().clearScreenOrientationOverride
(); |
| 631 else | 616 else |
| 632 this._target.screenOrientationAgent().setScreenOrientationOverride(t
his._screenOrientation === "landscapePrimary" ? 90 : 0, /** @type {!ScreenOrient
ationAgent.OrientationType} */ (this._screenOrientation)); | 617 this._target.screenOrientationAgent().setScreenOrientationOverride(t
his._screenOrientation === "landscapePrimary" ? 90 : 0, /** @type {!ScreenOrient
ationAgent.OrientationType} */ (this._screenOrientation)); |
| 633 } | 618 } |
| 634 } | 619 } |
| OLD | NEW |