Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js

Issue 1722643003: Reland of [DevTools] Move screen orientation override to RenderWidgetScreenMetricsEmulator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 = "";
60 /** @type {number} */ 58 /** @type {number} */
61 this._fitScale = 1; 59 this._fitScale = 1;
62 60
63 /** @type {?WebInspector.Target} */ 61 /** @type {?WebInspector.Target} */
64 this._target = null; 62 this._target = null;
65 /** @type {?function()} */ 63 /** @type {?function()} */
66 this._onTargetAvailable = null; 64 this._onTargetAvailable = null;
67 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Type.Pag e); 65 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Type.Pag e);
68 } 66 }
69 67
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 if (!this._target) 413 if (!this._target)
416 this._onTargetAvailable = this._calculateAndEmulate.bind(this, reset PageScaleFactor); 414 this._onTargetAvailable = this._calculateAndEmulate.bind(this, reset PageScaleFactor);
417 415
418 if (this._type === WebInspector.DeviceModeModel.Type.Device) { 416 if (this._type === WebInspector.DeviceModeModel.Type.Device) {
419 var orientation = this._device.orientationByName(this._mode.orientat ion); 417 var orientation = this._device.orientationByName(this._mode.orientat ion);
420 this._fitScale = this._calculateFitScale(orientation.width, orientat ion.height); 418 this._fitScale = this._calculateFitScale(orientation.width, orientat ion.height);
421 if (this._device.mobile()) 419 if (this._device.mobile())
422 this._appliedUserAgentType = this._device.touch() ? WebInspector .DeviceModeModel.UA.Mobile : WebInspector.DeviceModeModel.UA.MobileNoTouch; 420 this._appliedUserAgentType = this._device.touch() ? WebInspector .DeviceModeModel.UA.Mobile : WebInspector.DeviceModeModel.UA.MobileNoTouch;
423 else 421 else
424 this._appliedUserAgentType = this._device.touch() ? WebInspector .DeviceModeModel.UA.DesktopTouch : WebInspector.DeviceModeModel.UA.Desktop; 422 this._appliedUserAgentType = this._device.touch() ? WebInspector .DeviceModeModel.UA.DesktopTouch : WebInspector.DeviceModeModel.UA.Desktop;
425 this._applyDeviceMetrics(new Size(orientation.width, orientation.hei ght), this._mode.insets, this._scaleSetting.get(), this._device.deviceScaleFacto r, this._device.mobile(), resetPageScaleFactor); 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);
426 this._applyUserAgent(this._device.userAgent); 424 this._applyUserAgent(this._device.userAgent);
427 this._applyScreenOrientation(this._mode.orientation == WebInspector. EmulatedDevice.Horizontal ? "landscapePrimary" : "portraitPrimary");
428 } else if (this._type === WebInspector.DeviceModeModel.Type.None) { 425 } else if (this._type === WebInspector.DeviceModeModel.Type.None) {
429 this._fitScale = this._calculateFitScale(this._availableSize.width, this._availableSize.height); 426 this._fitScale = this._calculateFitScale(this._availableSize.width, this._availableSize.height);
430 this._appliedUserAgentType = WebInspector.DeviceModeModel.UA.Desktop ; 427 this._appliedUserAgentType = WebInspector.DeviceModeModel.UA.Desktop ;
431 this._applyDeviceMetrics(this._availableSize, new Insets(0, 0, 0, 0) , 1, 0, false, resetPageScaleFactor); 428 this._applyDeviceMetrics(this._availableSize, new Insets(0, 0, 0, 0) , 1, 0, false, "", resetPageScaleFactor);
432 this._applyUserAgent(""); 429 this._applyUserAgent("");
433 this._applyScreenOrientation("");
434 } else if (this._type === WebInspector.DeviceModeModel.Type.Responsive) { 430 } else if (this._type === WebInspector.DeviceModeModel.Type.Responsive) {
435 var screenWidth = this._widthSetting.get(); 431 var screenWidth = this._widthSetting.get();
436 if (!screenWidth || screenWidth > this._preferredScaledWidth()) 432 if (!screenWidth || screenWidth > this._preferredScaledWidth())
437 screenWidth = this._preferredScaledWidth(); 433 screenWidth = this._preferredScaledWidth();
438 var screenHeight = this._heightSetting.get(); 434 var screenHeight = this._heightSetting.get();
439 if (!screenHeight || screenHeight > this._preferredScaledHeight()) 435 if (!screenHeight || screenHeight > this._preferredScaledHeight())
440 screenHeight = this._preferredScaledHeight(); 436 screenHeight = this._preferredScaledHeight();
441 var mobile = this._uaSetting.get() === WebInspector.DeviceModeModel. UA.Mobile || this._uaSetting.get() === WebInspector.DeviceModeModel.UA.MobileNoT ouch; 437 var mobile = this._uaSetting.get() === WebInspector.DeviceModeModel. UA.Mobile || this._uaSetting.get() === WebInspector.DeviceModeModel.UA.MobileNoT ouch;
442 var defaultDeviceScaleFactor = mobile ? WebInspector.DeviceModeModel .defaultMobileScaleFactor : 0; 438 var defaultDeviceScaleFactor = mobile ? WebInspector.DeviceModeModel .defaultMobileScaleFactor : 0;
443 this._fitScale = this._calculateFitScale(this._widthSetting.get(), t his._heightSetting.get()); 439 this._fitScale = this._calculateFitScale(this._widthSetting.get(), t his._heightSetting.get());
444 this._appliedUserAgentType = this._uaSetting.get(); 440 this._appliedUserAgentType = this._uaSetting.get();
445 this._applyDeviceMetrics(new Size(screenWidth, screenHeight), new In sets(0, 0, 0, 0), this._scaleSetting.get(), this._deviceScaleFactorSetting.get() || defaultDeviceScaleFactor, mobile, resetPageScaleFactor); 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);
446 this._applyUserAgent(mobile ? WebInspector.DeviceModeModel._defaultM obileUserAgent : ""); 442 this._applyUserAgent(mobile ? WebInspector.DeviceModeModel._defaultM obileUserAgent : "");
447 this._applyScreenOrientation(screenHeight >= screenWidth ? "portrait Primary" : "landscapePrimary");
448 } 443 }
449 this._reapplyTouch(); 444 this._reapplyTouch();
450 this._updateCallback.call(null); 445 this._updateCallback.call(null);
451 }, 446 },
452 447
453 /** 448 /**
454 * @param {number} screenWidth 449 * @param {number} screenWidth
455 * @param {number} screenHeight 450 * @param {number} screenHeight
456 * @return {number} 451 * @return {number}
457 */ 452 */
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 { 490 {
496 WebInspector.multitargetNetworkManager.setUserAgentOverride(userAgent); 491 WebInspector.multitargetNetworkManager.setUserAgentOverride(userAgent);
497 }, 492 },
498 493
499 /** 494 /**
500 * @param {!Size} screenSize 495 * @param {!Size} screenSize
501 * @param {!Insets} insets 496 * @param {!Insets} insets
502 * @param {number} scale 497 * @param {number} scale
503 * @param {number} deviceScaleFactor 498 * @param {number} deviceScaleFactor
504 * @param {boolean} mobile 499 * @param {boolean} mobile
500 * @param {string} screenOrientation
505 * @param {boolean} resetPageScaleFactor 501 * @param {boolean} resetPageScaleFactor
506 */ 502 */
507 _applyDeviceMetrics: function(screenSize, insets, scale, deviceScaleFactor, mobile, resetPageScaleFactor) 503 _applyDeviceMetrics: function(screenSize, insets, scale, deviceScaleFactor, mobile, screenOrientation, resetPageScaleFactor)
508 { 504 {
509 screenSize.width = Math.max(1, Math.floor(screenSize.width)); 505 screenSize.width = Math.max(1, Math.floor(screenSize.width));
510 screenSize.height = Math.max(1, Math.floor(screenSize.height)); 506 screenSize.height = Math.max(1, Math.floor(screenSize.height));
511 507
512 var pageWidth = screenSize.width - insets.left - insets.right; 508 var pageWidth = screenSize.width - insets.left - insets.right;
513 var pageHeight = screenSize.height - insets.top - insets.bottom; 509 var pageHeight = screenSize.height - insets.top - insets.bottom;
514 var positionX = insets.left; 510 var positionX = insets.left;
515 var positionY = insets.top; 511 var positionY = insets.top;
512 var screenOrientationAngle = screenOrientation === "landscapePrimary" ? 90 : 0;
516 513
517 this._appliedDeviceSize = screenSize; 514 this._appliedDeviceSize = screenSize;
518 this._appliedDeviceScaleFactor = deviceScaleFactor || window.devicePixel Ratio; 515 this._appliedDeviceScaleFactor = deviceScaleFactor || window.devicePixel Ratio;
519 this._screenRect = new WebInspector.Rect( 516 this._screenRect = new WebInspector.Rect(
520 Math.max(0, (this._availableSize.width - screenSize.width * scale) / 2), 517 Math.max(0, (this._availableSize.width - screenSize.width * scale) / 2),
521 0, 518 0,
522 screenSize.width * scale, 519 screenSize.width * scale,
523 screenSize.height * scale); 520 screenSize.height * scale);
524 this._visiblePageRect = new WebInspector.Rect( 521 this._visiblePageRect = new WebInspector.Rect(
525 positionX * scale, 522 positionX * scale,
(...skipping 17 matching lines...) Expand all
543 540
544 /** 541 /**
545 * @this {WebInspector.DeviceModeModel} 542 * @this {WebInspector.DeviceModeModel}
546 * @return {!Promise.<?>} 543 * @return {!Promise.<?>}
547 */ 544 */
548 function setDeviceMetricsOverride() 545 function setDeviceMetricsOverride()
549 { 546 {
550 if (!this._target) 547 if (!this._target)
551 return Promise.resolve(); 548 return Promise.resolve();
552 549
553 var clear = !pageWidth && !pageHeight && !mobile && !deviceScaleFact or && scale === 1; 550 var clear = !pageWidth && !pageHeight && !mobile && !deviceScaleFact or && scale === 1 && !screenOrientation;
554 var allPromises = []; 551 var allPromises = [];
555 if (resetPageScaleFactor) 552 if (resetPageScaleFactor)
556 allPromises.push(this._target.emulationAgent().resetPageScaleFac tor()); 553 allPromises.push(this._target.emulationAgent().resetPageScaleFac tor());
557 var setDevicePromise = clear ? 554 var setDevicePromise;
558 this._target.emulationAgent().clearDeviceMetricsOverride(this._d eviceMetricsOverrideAppliedForTest.bind(this)) : 555 if (clear) {
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)); 556 setDevicePromise = this._target.emulationAgent().clearDeviceMetr icsOverride(this._deviceMetricsOverrideAppliedForTest.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 }
560 allPromises.push(setDevicePromise); 563 allPromises.push(setDevicePromise);
561 return Promise.all(allPromises); 564 return Promise.all(allPromises);
562 } 565 }
563 }, 566 },
564 567
565 _deviceMetricsOverrideAppliedForTest: function() 568 _deviceMetricsOverrideAppliedForTest: function()
566 { 569 {
567 // Used for sniffing in tests. 570 // Used for sniffing in tests.
568 }, 571 },
569 572
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 { 610 {
608 if (error) 611 if (error)
609 delete target[symbol]; 612 delete target[symbol];
610 else 613 else
611 target[symbol] = scriptId; 614 target[symbol] = scriptId;
612 } 615 }
613 616
614 target.emulationAgent().setTouchEmulationEnabled(touchEnabled, configura tion); 617 target.emulationAgent().setTouchEmulationEnabled(touchEnabled, configura tion);
615 this._touchEnabled = touchEnabled; 618 this._touchEnabled = touchEnabled;
616 this._touchConfiguration = configuration; 619 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));
632 } 620 }
633 } 621 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698