Chromium Code Reviews| 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 27 matching lines...) Expand all Loading... | |
| 38 this._heightSetting.set(WebInspector.DeviceModeModel.MinDeviceSize); | 38 this._heightSetting.set(WebInspector.DeviceModeModel.MinDeviceSize); |
| 39 if (this._heightSetting.get() > WebInspector.DeviceModeModel.MaxDeviceSize) | 39 if (this._heightSetting.get() > WebInspector.DeviceModeModel.MaxDeviceSize) |
| 40 this._heightSetting.set(WebInspector.DeviceModeModel.MaxDeviceSize); | 40 this._heightSetting.set(WebInspector.DeviceModeModel.MaxDeviceSize); |
| 41 this._heightSetting.addChangeListener(this._heightSettingChanged, this); | 41 this._heightSetting.addChangeListener(this._heightSettingChanged, this); |
| 42 | 42 |
| 43 this._uaSetting = WebInspector.settings.createSetting("emulation.deviceUA", WebInspector.DeviceModeModel.UA.Mobile); | 43 this._uaSetting = WebInspector.settings.createSetting("emulation.deviceUA", WebInspector.DeviceModeModel.UA.Mobile); |
| 44 this._uaSetting.addChangeListener(this._uaSettingChanged, this); | 44 this._uaSetting.addChangeListener(this._uaSettingChanged, this); |
| 45 this._deviceScaleFactorSetting = WebInspector.settings.createSetting("emulat ion.deviceScaleFactor", 0); | 45 this._deviceScaleFactorSetting = WebInspector.settings.createSetting("emulat ion.deviceScaleFactor", 0); |
| 46 this._deviceScaleFactorSetting.addChangeListener(this._deviceScaleFactorSett ingChanged, this); | 46 this._deviceScaleFactorSetting.addChangeListener(this._deviceScaleFactorSett ingChanged, this); |
| 47 | 47 |
| 48 this._deviceOutlineSetting = WebInspector.settings.createSetting("emulation. deviceOutline", true); | |
| 49 this._deviceOutlineSetting.addChangeListener(this._deviceOutlineSettingChang ed, this); | |
| 50 | |
| 48 /** @type {!WebInspector.DeviceModeModel.Type} */ | 51 /** @type {!WebInspector.DeviceModeModel.Type} */ |
| 49 this._type = WebInspector.DeviceModeModel.Type.None; | 52 this._type = WebInspector.DeviceModeModel.Type.None; |
| 50 /** @type {?WebInspector.EmulatedDevice} */ | 53 /** @type {?WebInspector.EmulatedDevice} */ |
| 51 this._device = null; | 54 this._device = null; |
| 52 /** @type {?WebInspector.EmulatedDevice.Mode} */ | 55 /** @type {?WebInspector.EmulatedDevice.Mode} */ |
| 53 this._mode = null; | 56 this._mode = null; |
| 54 /** @type {number} */ | 57 /** @type {number} */ |
| 55 this._fitScale = 1; | 58 this._fitScale = 1; |
| 56 | 59 |
| 57 /** @type {?WebInspector.Target} */ | 60 /** @type {?WebInspector.Target} */ |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 | 224 |
| 222 /** | 225 /** |
| 223 * @return {string} | 226 * @return {string} |
| 224 */ | 227 */ |
| 225 screenImage: function() | 228 screenImage: function() |
| 226 { | 229 { |
| 227 return (this._device && this._mode) ? this._device.modeImage(this._mode) : ""; | 230 return (this._device && this._mode) ? this._device.modeImage(this._mode) : ""; |
| 228 }, | 231 }, |
| 229 | 232 |
| 230 /** | 233 /** |
| 234 * @return {string} | |
| 235 */ | |
| 236 outlineImage: function() | |
| 237 { | |
| 238 return (this._device && this._mode) ? this._device.outlineImage(this._mo de) : ""; | |
| 239 }, | |
| 240 | |
| 241 /** | |
| 242 * @return {!WebInspector.Rect} | |
| 243 */ | |
| 244 outlineRect: function() | |
| 245 { | |
| 246 return this._outlineRect; | |
| 247 }, | |
| 248 | |
| 249 /** | |
| 231 * @return {!WebInspector.Rect} | 250 * @return {!WebInspector.Rect} |
| 232 */ | 251 */ |
| 233 screenRect: function() | 252 screenRect: function() |
| 234 { | 253 { |
| 235 return this._screenRect; | 254 return this._screenRect; |
| 236 }, | 255 }, |
| 237 | 256 |
| 238 /** | 257 /** |
| 239 * @return {!WebInspector.Rect} | 258 * @return {!WebInspector.Rect} |
| 240 */ | 259 */ |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 }, | 327 }, |
| 309 | 328 |
| 310 /** | 329 /** |
| 311 * @return {!WebInspector.Setting} | 330 * @return {!WebInspector.Setting} |
| 312 */ | 331 */ |
| 313 deviceScaleFactorSetting: function() | 332 deviceScaleFactorSetting: function() |
| 314 { | 333 { |
| 315 return this._deviceScaleFactorSetting; | 334 return this._deviceScaleFactorSetting; |
| 316 }, | 335 }, |
| 317 | 336 |
| 337 /** | |
| 338 * @return {!WebInspector.Setting} | |
| 339 */ | |
| 340 deviceOutlineSetting: function() | |
| 341 { | |
| 342 return this._deviceOutlineSetting; | |
| 343 }, | |
| 344 | |
| 318 reset: function() | 345 reset: function() |
| 319 { | 346 { |
| 320 this._deviceScaleFactorSetting.set(0); | 347 this._deviceScaleFactorSetting.set(0); |
| 321 this._scaleSetting.set(1); | 348 this._scaleSetting.set(1); |
| 322 this.setWidth(400); | 349 this.setWidth(400); |
| 323 this.setHeight(0); | 350 this.setHeight(0); |
| 324 this._uaSetting.set(WebInspector.DeviceModeModel.UA.Mobile); | 351 this._uaSetting.set(WebInspector.DeviceModeModel.UA.Mobile); |
| 325 }, | 352 }, |
| 326 | 353 |
| 327 /** | 354 /** |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 _uaSettingChanged: function() | 395 _uaSettingChanged: function() |
| 369 { | 396 { |
| 370 this._calculateAndEmulate(true); | 397 this._calculateAndEmulate(true); |
| 371 }, | 398 }, |
| 372 | 399 |
| 373 _deviceScaleFactorSettingChanged: function() | 400 _deviceScaleFactorSettingChanged: function() |
| 374 { | 401 { |
| 375 this._calculateAndEmulate(false); | 402 this._calculateAndEmulate(false); |
| 376 }, | 403 }, |
| 377 | 404 |
| 405 _deviceOutlineSettingChanged: function() | |
| 406 { | |
| 407 this._calculateAndEmulate(false); | |
| 408 }, | |
| 409 | |
| 378 /** | 410 /** |
| 379 * @return {number} | 411 * @return {number} |
| 380 */ | 412 */ |
| 381 _preferredScaledWidth: function() | 413 _preferredScaledWidth: function() |
| 382 { | 414 { |
| 383 return Math.floor(this._preferredSize.width / (this._scaleSetting.get() || 1)); | 415 return Math.floor(this._preferredSize.width / (this._scaleSetting.get() || 1)); |
| 384 }, | 416 }, |
| 385 | 417 |
| 386 /** | 418 /** |
| 387 * @return {number} | 419 * @return {number} |
| 388 */ | 420 */ |
| 389 _preferredScaledHeight: function() | 421 _preferredScaledHeight: function() |
| 390 { | 422 { |
| 391 return Math.floor(this._preferredSize.height / (this._scaleSetting.get() || 1)); | 423 return Math.floor(this._preferredSize.height / (this._scaleSetting.get() || 1)); |
| 392 }, | 424 }, |
| 393 | 425 |
| 394 /** | 426 /** |
| 395 * @param {boolean} resetPageScaleFactor | 427 * @param {boolean} resetPageScaleFactor |
| 396 */ | 428 */ |
| 397 _calculateAndEmulate: function(resetPageScaleFactor) | 429 _calculateAndEmulate: function(resetPageScaleFactor) |
| 398 { | 430 { |
| 399 if (!this._target) | 431 if (!this._target) |
| 400 this._onTargetAvailable = this._calculateAndEmulate.bind(this, reset PageScaleFactor); | 432 this._onTargetAvailable = this._calculateAndEmulate.bind(this, reset PageScaleFactor); |
| 401 | 433 |
| 402 if (this._type === WebInspector.DeviceModeModel.Type.Device) { | 434 if (this._type === WebInspector.DeviceModeModel.Type.Device) { |
| 403 var orientation = this._device.orientationByName(this._mode.orientat ion); | 435 var orientation = this._device.orientationByName(this._mode.orientat ion); |
| 436 var outline = this._deviceOutlineSetting.get() ? orientation.outline Insets : new Insets(0,0,0,0); | |
| 404 this._fitScale = this._calculateFitScale(orientation.width, orientat ion.height); | 437 this._fitScale = this._calculateFitScale(orientation.width, orientat ion.height); |
| 405 if (this._device.mobile()) | 438 if (this._device.mobile()) |
| 406 this._appliedUserAgentType = this._device.touch() ? WebInspector .DeviceModeModel.UA.Mobile : WebInspector.DeviceModeModel.UA.MobileNoTouch; | 439 this._appliedUserAgentType = this._device.touch() ? WebInspector .DeviceModeModel.UA.Mobile : WebInspector.DeviceModeModel.UA.MobileNoTouch; |
| 407 else | 440 else |
| 408 this._appliedUserAgentType = this._device.touch() ? WebInspector .DeviceModeModel.UA.DesktopTouch : WebInspector.DeviceModeModel.UA.Desktop; | 441 this._appliedUserAgentType = this._device.touch() ? WebInspector .DeviceModeModel.UA.DesktopTouch : WebInspector.DeviceModeModel.UA.Desktop; |
| 409 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); | 442 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(), this._mode.orientat ion == WebInspector.EmulatedDevice.Horizontal ? "landscapePrimary" : "portraitPr imary", resetPageScaleFactor); |
|
dgozman
2016/03/22 20:30:49
No need for "|| new Insets()" anymore.
mmccoy
2016/03/28 13:55:18
Done.
| |
| 410 this._applyUserAgent(this._device.userAgent); | 443 this._applyUserAgent(this._device.userAgent); |
| 411 this._applyTouch(this._device.touch(), this._device.mobile()); | 444 this._applyTouch(this._device.touch(), this._device.mobile()); |
| 412 } else if (this._type === WebInspector.DeviceModeModel.Type.None) { | 445 } else if (this._type === WebInspector.DeviceModeModel.Type.None) { |
| 413 this._fitScale = this._calculateFitScale(this._availableSize.width, this._availableSize.height); | 446 this._fitScale = this._calculateFitScale(this._availableSize.width, this._availableSize.height); |
| 414 this._appliedUserAgentType = WebInspector.DeviceModeModel.UA.Desktop ; | 447 this._appliedUserAgentType = WebInspector.DeviceModeModel.UA.Desktop ; |
| 415 this._applyDeviceMetrics(this._availableSize, new Insets(0, 0, 0, 0) , 1, 0, false, "", resetPageScaleFactor); | 448 this._applyDeviceMetrics(this._availableSize, new Insets(0, 0, 0, 0) , new Insets(0, 0, 0, 0), 1, 0, false, "", resetPageScaleFactor); |
| 416 this._applyUserAgent(""); | 449 this._applyUserAgent(""); |
| 417 this._applyTouch(false, false); | 450 this._applyTouch(false, false); |
| 418 } else if (this._type === WebInspector.DeviceModeModel.Type.Responsive) { | 451 } else if (this._type === WebInspector.DeviceModeModel.Type.Responsive) { |
| 419 var screenWidth = this._widthSetting.get(); | 452 var screenWidth = this._widthSetting.get(); |
| 420 if (!screenWidth || screenWidth > this._preferredScaledWidth()) | 453 if (!screenWidth || screenWidth > this._preferredScaledWidth()) |
| 421 screenWidth = this._preferredScaledWidth(); | 454 screenWidth = this._preferredScaledWidth(); |
| 422 var screenHeight = this._heightSetting.get(); | 455 var screenHeight = this._heightSetting.get(); |
| 423 if (!screenHeight || screenHeight > this._preferredScaledHeight()) | 456 if (!screenHeight || screenHeight > this._preferredScaledHeight()) |
| 424 screenHeight = this._preferredScaledHeight(); | 457 screenHeight = this._preferredScaledHeight(); |
| 425 var mobile = this._uaSetting.get() === WebInspector.DeviceModeModel. UA.Mobile || this._uaSetting.get() === WebInspector.DeviceModeModel.UA.MobileNoT ouch; | 458 var mobile = this._uaSetting.get() === WebInspector.DeviceModeModel. UA.Mobile || this._uaSetting.get() === WebInspector.DeviceModeModel.UA.MobileNoT ouch; |
| 426 var defaultDeviceScaleFactor = mobile ? WebInspector.DeviceModeModel .defaultMobileScaleFactor : 0; | 459 var defaultDeviceScaleFactor = mobile ? WebInspector.DeviceModeModel .defaultMobileScaleFactor : 0; |
| 427 this._fitScale = this._calculateFitScale(this._widthSetting.get(), t his._heightSetting.get()); | 460 this._fitScale = this._calculateFitScale(this._widthSetting.get(), t his._heightSetting.get()); |
| 428 this._appliedUserAgentType = this._uaSetting.get(); | 461 this._appliedUserAgentType = this._uaSetting.get(); |
| 429 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); | 462 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, screenHeight >= sc reenWidth ? "portraitPrimary" : "landscapePrimary", resetPageScaleFactor); |
| 430 this._applyUserAgent(mobile ? WebInspector.DeviceModeModel._defaultM obileUserAgent : ""); | 463 this._applyUserAgent(mobile ? WebInspector.DeviceModeModel._defaultM obileUserAgent : ""); |
| 431 this._applyTouch(this._uaSetting.get() === WebInspector.DeviceModeMo del.UA.DesktopTouch || this._uaSetting.get() === WebInspector.DeviceModeModel.UA .Mobile, this._uaSetting.get() === WebInspector.DeviceModeModel.UA.Mobile); | 464 this._applyTouch(this._uaSetting.get() === WebInspector.DeviceModeMo del.UA.DesktopTouch || this._uaSetting.get() === WebInspector.DeviceModeModel.UA .Mobile, this._uaSetting.get() === WebInspector.DeviceModeModel.UA.Mobile); |
| 432 } | 465 } |
| 433 if (this._target) | 466 if (this._target) |
| 434 this._target.renderingAgent().setShowViewportSizeOnResize(this._type === WebInspector.DeviceModeModel.Type.None); | 467 this._target.renderingAgent().setShowViewportSizeOnResize(this._type === WebInspector.DeviceModeModel.Type.None); |
| 435 this._updateCallback.call(null); | 468 this._updateCallback.call(null); |
| 436 }, | 469 }, |
| 437 | 470 |
| 438 /** | 471 /** |
| 439 * @param {number} screenWidth | 472 * @param {number} screenWidth |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 460 * @param {string} userAgent | 493 * @param {string} userAgent |
| 461 */ | 494 */ |
| 462 _applyUserAgent: function(userAgent) | 495 _applyUserAgent: function(userAgent) |
| 463 { | 496 { |
| 464 WebInspector.multitargetNetworkManager.setUserAgentOverride(userAgent); | 497 WebInspector.multitargetNetworkManager.setUserAgentOverride(userAgent); |
| 465 }, | 498 }, |
| 466 | 499 |
| 467 /** | 500 /** |
| 468 * @param {!Size} screenSize | 501 * @param {!Size} screenSize |
| 469 * @param {!Insets} insets | 502 * @param {!Insets} insets |
| 503 * @param {!Insets} outline | |
| 470 * @param {number} scale | 504 * @param {number} scale |
| 471 * @param {number} deviceScaleFactor | 505 * @param {number} deviceScaleFactor |
| 472 * @param {boolean} mobile | 506 * @param {boolean} mobile |
| 473 * @param {string} screenOrientation | 507 * @param {string} screenOrientation |
| 474 * @param {boolean} resetPageScaleFactor | 508 * @param {boolean} resetPageScaleFactor |
| 475 */ | 509 */ |
| 476 _applyDeviceMetrics: function(screenSize, insets, scale, deviceScaleFactor, mobile, screenOrientation, resetPageScaleFactor) | 510 _applyDeviceMetrics: function(screenSize, insets, outline, scale, deviceScal eFactor, mobile, screenOrientation, resetPageScaleFactor) |
| 477 { | 511 { |
| 478 screenSize.width = Math.max(1, Math.floor(screenSize.width)); | 512 screenSize.width = Math.max(1, Math.floor(screenSize.width)); |
| 479 screenSize.height = Math.max(1, Math.floor(screenSize.height)); | 513 screenSize.height = Math.max(1, Math.floor(screenSize.height)); |
| 480 | 514 |
| 481 var pageWidth = screenSize.width - insets.left - insets.right; | 515 var pageWidth = screenSize.width - insets.left - insets.right; |
| 482 var pageHeight = screenSize.height - insets.top - insets.bottom; | 516 var pageHeight = screenSize.height - insets.top - insets.bottom; |
| 517 | |
| 483 var positionX = insets.left; | 518 var positionX = insets.left; |
| 484 var positionY = insets.top; | 519 var positionY = insets.top; |
| 485 var screenOrientationAngle = screenOrientation === "landscapePrimary" ? 90 : 0; | 520 var screenOrientationAngle = screenOrientation === "landscapePrimary" ? 90 : 0; |
| 486 | 521 |
| 487 this._appliedDeviceSize = screenSize; | 522 this._appliedDeviceSize = screenSize; |
| 488 this._appliedDeviceScaleFactor = deviceScaleFactor || window.devicePixel Ratio; | 523 this._appliedDeviceScaleFactor = deviceScaleFactor || window.devicePixel Ratio; |
| 489 this._screenRect = new WebInspector.Rect( | 524 this._screenRect = new WebInspector.Rect( |
| 490 Math.max(0, (this._availableSize.width - screenSize.width * scale) / 2), | 525 Math.max(0, (this._availableSize.width - screenSize.width * scale) / 2), |
| 491 0, | 526 outline.top * scale, |
| 492 screenSize.width * scale, | 527 screenSize.width * scale, |
| 493 screenSize.height * scale); | 528 screenSize.height * scale); |
| 529 this._outlineRect = new WebInspector.Rect( | |
| 530 Math.max(0, this._screenRect.left - outline.left * scale), | |
| 531 0, | |
| 532 (outline.left + screenSize.width + outline.right) * scale, | |
| 533 (outline.top + screenSize.height + outline.bottom) * scale); | |
| 494 this._visiblePageRect = new WebInspector.Rect( | 534 this._visiblePageRect = new WebInspector.Rect( |
| 495 positionX * scale, | 535 positionX * scale, |
| 496 positionY * scale, | 536 positionY * scale, |
| 497 Math.min(pageWidth * scale, this._availableSize.width - this._screen Rect.left - positionX * scale), | 537 Math.min(pageWidth * scale, this._availableSize.width - this._screen Rect.left - positionX * scale), |
| 498 Math.min(pageHeight * scale, this._availableSize.height - this._scre enRect.top - positionY * scale)); | 538 Math.min(pageHeight * scale, this._availableSize.height - this._scre enRect.top - positionY * scale)); |
| 499 this._scale = scale; | 539 this._scale = scale; |
| 500 | 540 |
| 501 if (scale === 1 && this._availableSize.width >= screenSize.width && this ._availableSize.height >= screenSize.height) { | 541 if (scale === 1 && this._availableSize.width >= screenSize.width && this ._availableSize.height >= screenSize.height) { |
| 502 // When we have enough space, no page size override is required. Thi s will speed things up and remove lag. | 542 // When we have enough space, no page size override is required. Thi s will speed things up and remove lag. |
| 503 pageWidth = 0; | 543 pageWidth = 0; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 | 585 |
| 546 /** | 586 /** |
| 547 * @param {boolean} touchEnabled | 587 * @param {boolean} touchEnabled |
| 548 * @param {boolean} mobile | 588 * @param {boolean} mobile |
| 549 */ | 589 */ |
| 550 _applyTouch: function(touchEnabled, mobile) | 590 _applyTouch: function(touchEnabled, mobile) |
| 551 { | 591 { |
| 552 WebInspector.MultitargetTouchModel.instance().setTouchEnabled(touchEnabl ed, mobile); | 592 WebInspector.MultitargetTouchModel.instance().setTouchEnabled(touchEnabl ed, mobile); |
| 553 } | 593 } |
| 554 } | 594 } |
| OLD | NEW |