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 | |
|
dgozman
2016/03/21 21:08:38
nit: extra blank line
mmccoy
2016/03/21 22:03:05
Done.
| |
| 408 this._calculateAndEmulate(false); | |
| 409 }, | |
| 410 | |
| 378 /** | 411 /** |
| 379 * @return {number} | 412 * @return {number} |
| 380 */ | 413 */ |
| 381 _preferredScaledWidth: function() | 414 _preferredScaledWidth: function() |
| 382 { | 415 { |
| 383 return Math.floor(this._preferredSize.width / (this._scaleSetting.get() || 1)); | 416 return Math.floor(this._preferredSize.width / (this._scaleSetting.get() || 1)); |
| 384 }, | 417 }, |
| 385 | 418 |
| 386 /** | 419 /** |
| 387 * @return {number} | 420 * @return {number} |
| 388 */ | 421 */ |
| 389 _preferredScaledHeight: function() | 422 _preferredScaledHeight: function() |
| 390 { | 423 { |
| 391 return Math.floor(this._preferredSize.height / (this._scaleSetting.get() || 1)); | 424 return Math.floor(this._preferredSize.height / (this._scaleSetting.get() || 1)); |
| 392 }, | 425 }, |
| 393 | 426 |
| 394 /** | 427 /** |
| 395 * @param {boolean} resetPageScaleFactor | 428 * @param {boolean} resetPageScaleFactor |
| 396 */ | 429 */ |
| 397 _calculateAndEmulate: function(resetPageScaleFactor) | 430 _calculateAndEmulate: function(resetPageScaleFactor) |
| 398 { | 431 { |
| 399 if (!this._target) | 432 if (!this._target) |
| 400 this._onTargetAvailable = this._calculateAndEmulate.bind(this, reset PageScaleFactor); | 433 this._onTargetAvailable = this._calculateAndEmulate.bind(this, reset PageScaleFactor); |
| 401 | 434 |
| 402 if (this._type === WebInspector.DeviceModeModel.Type.Device) { | 435 if (this._type === WebInspector.DeviceModeModel.Type.Device) { |
| 403 var orientation = this._device.orientationByName(this._mode.orientat ion); | 436 var orientation = this._device.orientationByName(this._mode.orientat ion); |
| 437 var outline = this._deviceOutlineSetting.get() ? orientation.outline Insets : null; | |
|
dgozman
2016/03/21 21:08:38
Use new Insets(0, 0, 0, 0) instead of null.
mmccoy
2016/03/21 22:03:05
Done.
| |
| 438 var width = outline ? outline.left + orientation.width + outline.rig ht : orientation.width; | |
|
dgozman
2016/03/21 21:08:38
You don't really use |width| and |height| variable
| |
| 439 var height = outline ? outline.top + orientation.height + outline.bo ttom : orientation.height; | |
| 404 this._fitScale = this._calculateFitScale(orientation.width, orientat ion.height); | 440 this._fitScale = this._calculateFitScale(orientation.width, orientat ion.height); |
| 405 if (this._device.mobile()) | 441 if (this._device.mobile()) |
| 406 this._appliedUserAgentType = this._device.touch() ? WebInspector .DeviceModeModel.UA.Mobile : WebInspector.DeviceModeModel.UA.MobileNoTouch; | 442 this._appliedUserAgentType = this._device.touch() ? WebInspector .DeviceModeModel.UA.Mobile : WebInspector.DeviceModeModel.UA.MobileNoTouch; |
| 407 else | 443 else |
| 408 this._appliedUserAgentType = this._device.touch() ? WebInspector .DeviceModeModel.UA.DesktopTouch : WebInspector.DeviceModeModel.UA.Desktop; | 444 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); | 445 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); |
| 410 this._applyUserAgent(this._device.userAgent); | 446 this._applyUserAgent(this._device.userAgent); |
| 411 this._applyTouch(this._device.touch(), this._device.mobile()); | 447 this._applyTouch(this._device.touch(), this._device.mobile()); |
| 412 } else if (this._type === WebInspector.DeviceModeModel.Type.None) { | 448 } else if (this._type === WebInspector.DeviceModeModel.Type.None) { |
| 413 this._fitScale = this._calculateFitScale(this._availableSize.width, this._availableSize.height); | 449 this._fitScale = this._calculateFitScale(this._availableSize.width, this._availableSize.height); |
| 414 this._appliedUserAgentType = WebInspector.DeviceModeModel.UA.Desktop ; | 450 this._appliedUserAgentType = WebInspector.DeviceModeModel.UA.Desktop ; |
| 415 this._applyDeviceMetrics(this._availableSize, new Insets(0, 0, 0, 0) , 1, 0, false, "", resetPageScaleFactor); | 451 this._applyDeviceMetrics(this._availableSize, new Insets(0, 0, 0, 0) , new Insets(0, 0, 0, 0), 1, 0, false, "", resetPageScaleFactor); |
| 416 this._applyUserAgent(""); | 452 this._applyUserAgent(""); |
| 417 this._applyTouch(false, false); | 453 this._applyTouch(false, false); |
| 418 } else if (this._type === WebInspector.DeviceModeModel.Type.Responsive) { | 454 } else if (this._type === WebInspector.DeviceModeModel.Type.Responsive) { |
| 419 var screenWidth = this._widthSetting.get(); | 455 var screenWidth = this._widthSetting.get(); |
| 420 if (!screenWidth || screenWidth > this._preferredScaledWidth()) | 456 if (!screenWidth || screenWidth > this._preferredScaledWidth()) |
| 421 screenWidth = this._preferredScaledWidth(); | 457 screenWidth = this._preferredScaledWidth(); |
| 422 var screenHeight = this._heightSetting.get(); | 458 var screenHeight = this._heightSetting.get(); |
| 423 if (!screenHeight || screenHeight > this._preferredScaledHeight()) | 459 if (!screenHeight || screenHeight > this._preferredScaledHeight()) |
| 424 screenHeight = this._preferredScaledHeight(); | 460 screenHeight = this._preferredScaledHeight(); |
| 425 var mobile = this._uaSetting.get() === WebInspector.DeviceModeModel. UA.Mobile || this._uaSetting.get() === WebInspector.DeviceModeModel.UA.MobileNoT ouch; | 461 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; | 462 var defaultDeviceScaleFactor = mobile ? WebInspector.DeviceModeModel .defaultMobileScaleFactor : 0; |
| 427 this._fitScale = this._calculateFitScale(this._widthSetting.get(), t his._heightSetting.get()); | 463 this._fitScale = this._calculateFitScale(this._widthSetting.get(), t his._heightSetting.get()); |
| 428 this._appliedUserAgentType = this._uaSetting.get(); | 464 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); | 465 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 : ""); | 466 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); | 467 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 } | 468 } |
| 433 if (this._target) | 469 if (this._target) |
| 434 this._target.renderingAgent().setShowViewportSizeOnResize(this._type === WebInspector.DeviceModeModel.Type.None); | 470 this._target.renderingAgent().setShowViewportSizeOnResize(this._type === WebInspector.DeviceModeModel.Type.None); |
| 435 this._updateCallback.call(null); | 471 this._updateCallback.call(null); |
| 436 }, | 472 }, |
| 437 | 473 |
| 438 /** | 474 /** |
| 439 * @param {number} screenWidth | 475 * @param {number} screenWidth |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 460 * @param {string} userAgent | 496 * @param {string} userAgent |
| 461 */ | 497 */ |
| 462 _applyUserAgent: function(userAgent) | 498 _applyUserAgent: function(userAgent) |
| 463 { | 499 { |
| 464 WebInspector.multitargetNetworkManager.setUserAgentOverride(userAgent); | 500 WebInspector.multitargetNetworkManager.setUserAgentOverride(userAgent); |
| 465 }, | 501 }, |
| 466 | 502 |
| 467 /** | 503 /** |
| 468 * @param {!Size} screenSize | 504 * @param {!Size} screenSize |
| 469 * @param {!Insets} insets | 505 * @param {!Insets} insets |
| 506 * @param {!Insets} outline | |
| 470 * @param {number} scale | 507 * @param {number} scale |
| 471 * @param {number} deviceScaleFactor | 508 * @param {number} deviceScaleFactor |
| 472 * @param {boolean} mobile | 509 * @param {boolean} mobile |
| 473 * @param {string} screenOrientation | 510 * @param {string} screenOrientation |
| 474 * @param {boolean} resetPageScaleFactor | 511 * @param {boolean} resetPageScaleFactor |
| 475 */ | 512 */ |
| 476 _applyDeviceMetrics: function(screenSize, insets, scale, deviceScaleFactor, mobile, screenOrientation, resetPageScaleFactor) | 513 _applyDeviceMetrics: function(screenSize, insets, outline, scale, deviceScal eFactor, mobile, screenOrientation, resetPageScaleFactor) |
| 477 { | 514 { |
| 478 screenSize.width = Math.max(1, Math.floor(screenSize.width)); | 515 screenSize.width = Math.max(1, Math.floor(screenSize.width)); |
| 479 screenSize.height = Math.max(1, Math.floor(screenSize.height)); | 516 screenSize.height = Math.max(1, Math.floor(screenSize.height)); |
| 480 | 517 |
| 481 var pageWidth = screenSize.width - insets.left - insets.right; | 518 var pageWidth = screenSize.width - insets.left - insets.right; |
| 482 var pageHeight = screenSize.height - insets.top - insets.bottom; | 519 var pageHeight = screenSize.height - insets.top - insets.bottom; |
| 520 | |
| 483 var positionX = insets.left; | 521 var positionX = insets.left; |
| 484 var positionY = insets.top; | 522 var positionY = insets.top; |
| 485 var screenOrientationAngle = screenOrientation === "landscapePrimary" ? 90 : 0; | 523 var screenOrientationAngle = screenOrientation === "landscapePrimary" ? 90 : 0; |
| 486 | 524 |
| 487 this._appliedDeviceSize = screenSize; | 525 this._appliedDeviceSize = screenSize; |
| 488 this._appliedDeviceScaleFactor = deviceScaleFactor || window.devicePixel Ratio; | 526 this._appliedDeviceScaleFactor = deviceScaleFactor || window.devicePixel Ratio; |
| 489 this._screenRect = new WebInspector.Rect( | 527 this._screenRect = new WebInspector.Rect( |
| 490 Math.max(0, (this._availableSize.width - screenSize.width * scale) / 2), | 528 Math.max(0, (this._availableSize.width - screenSize.width * scale) / 2), |
| 491 0, | 529 outline.top * scale, |
| 492 screenSize.width * scale, | 530 screenSize.width * scale, |
| 493 screenSize.height * scale); | 531 screenSize.height * scale); |
| 532 this._outlineRect = new WebInspector.Rect( | |
| 533 this._screenRect.left - outline.left * scale, | |
|
dgozman
2016/03/21 21:08:38
Math.max(0, .....)
mmccoy
2016/03/21 22:03:05
Done.
| |
| 534 0, | |
| 535 (outline.left + screenSize.width + outline.right) * scale, | |
| 536 (outline.top + screenSize.height + outline.bottom) * scale); | |
| 494 this._visiblePageRect = new WebInspector.Rect( | 537 this._visiblePageRect = new WebInspector.Rect( |
| 495 positionX * scale, | 538 positionX * scale, |
| 496 positionY * scale, | 539 positionY * scale, |
| 497 Math.min(pageWidth * scale, this._availableSize.width - this._screen Rect.left - positionX * scale), | 540 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)); | 541 Math.min(pageHeight * scale, this._availableSize.height - this._scre enRect.top - positionY * scale)); |
| 499 this._scale = scale; | 542 this._scale = scale; |
| 500 | 543 |
| 501 if (scale === 1 && this._availableSize.width >= screenSize.width && this ._availableSize.height >= screenSize.height) { | 544 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. | 545 // When we have enough space, no page size override is required. Thi s will speed things up and remove lag. |
| 503 pageWidth = 0; | 546 pageWidth = 0; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 | 588 |
| 546 /** | 589 /** |
| 547 * @param {boolean} touchEnabled | 590 * @param {boolean} touchEnabled |
| 548 * @param {boolean} mobile | 591 * @param {boolean} mobile |
| 549 */ | 592 */ |
| 550 _applyTouch: function(touchEnabled, mobile) | 593 _applyTouch: function(touchEnabled, mobile) |
| 551 { | 594 { |
| 552 WebInspector.MultitargetTouchModel.instance().setTouchEnabled(touchEnabl ed, mobile); | 595 WebInspector.MultitargetTouchModel.instance().setTouchEnabled(touchEnabl ed, mobile); |
| 553 } | 596 } |
| 554 } | 597 } |
| OLD | NEW |