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

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

Issue 1969913002: [DevTools] Polish device mode UI, include outline into screenshot. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 4 years, 7 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeToolbar.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 { 129 {
130 var resetPageScaleFactor = this._type !== type || this._device !== devic e || this._mode !== mode; 130 var resetPageScaleFactor = this._type !== type || this._device !== devic e || this._mode !== mode;
131 this._type = type; 131 this._type = type;
132 132
133 if (type === WebInspector.DeviceModeModel.Type.Device) { 133 if (type === WebInspector.DeviceModeModel.Type.Device) {
134 console.assert(device && mode, "Must pass device and mode for device emulation"); 134 console.assert(device && mode, "Must pass device and mode for device emulation");
135 this._device = device; 135 this._device = device;
136 this._mode = mode; 136 this._mode = mode;
137 if (this._initialized) { 137 if (this._initialized) {
138 var orientation = device.orientationByName(mode.orientation); 138 var orientation = device.orientationByName(mode.orientation);
139 this._scaleSetting.set(this._calculateFitScale(orientation.width , orientation.height)); 139 this._scaleSetting.set(this._calculateFitScale(orientation.width , orientation.height, this._currentOutline()));
140 } 140 }
141 } else { 141 } else {
142 this._device = null; 142 this._device = null;
143 this._mode = null; 143 this._mode = null;
144 } 144 }
145 145
146 if (type !== WebInspector.DeviceModeModel.Type.None) 146 if (type !== WebInspector.DeviceModeModel.Type.None)
147 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action .DeviceModeEnabled); 147 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action .DeviceModeEnabled);
148 this._calculateAndEmulate(resetPageScaleFactor); 148 this._calculateAndEmulate(resetPageScaleFactor);
149 }, 149 },
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 screenImage: function() 228 screenImage: function()
229 { 229 {
230 return (this._device && this._mode) ? this._device.modeImage(this._mode) : ""; 230 return (this._device && this._mode) ? this._device.modeImage(this._mode) : "";
231 }, 231 },
232 232
233 /** 233 /**
234 * @return {string} 234 * @return {string}
235 */ 235 */
236 outlineImage: function() 236 outlineImage: function()
237 { 237 {
238 return (this._device && this._mode && Runtime.experiments.isEnabled("dev iceFrames")) ? 238 return (this._device && this._mode && Runtime.experiments.isEnabled("dev iceFrames") && this._deviceOutlineSetting.get()) ? this._device.outlineImage(thi s._mode) : "";
239 this._device.outlineImage(this._mode) : "";
240 }, 239 },
241 240
242 /** 241 /**
243 * @return {!WebInspector.Rect} 242 * @return {!WebInspector.Rect}
244 */ 243 */
245 outlineRect: function() 244 outlineRect: function()
246 { 245 {
247 return this._outlineRect; 246 return this._outlineRect;
248 }, 247 },
249 248
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 417
419 /** 418 /**
420 * @return {number} 419 * @return {number}
421 */ 420 */
422 _preferredScaledHeight: function() 421 _preferredScaledHeight: function()
423 { 422 {
424 return Math.floor(this._preferredSize.height / (this._scaleSetting.get() || 1)); 423 return Math.floor(this._preferredSize.height / (this._scaleSetting.get() || 1));
425 }, 424 },
426 425
427 /** 426 /**
427 * @return {!Insets}
428 */
429 _currentOutline: function()
430 {
431 var outline = new Insets(0, 0, 0, 0);
432 if (this._type !== WebInspector.DeviceModeModel.Type.Device)
433 return outline;
434 var orientation = this._device.orientationByName(this._mode.orientation) ;
435 if (Runtime.experiments.isEnabled("deviceFrames") && this._deviceOutline Setting.get())
436 outline = orientation.outlineInsets || outline;
437 return outline;
438 },
439
440 /**
428 * @param {boolean} resetPageScaleFactor 441 * @param {boolean} resetPageScaleFactor
429 */ 442 */
430 _calculateAndEmulate: function(resetPageScaleFactor) 443 _calculateAndEmulate: function(resetPageScaleFactor)
431 { 444 {
432 if (!this._target) 445 if (!this._target)
433 this._onTargetAvailable = this._calculateAndEmulate.bind(this, reset PageScaleFactor); 446 this._onTargetAvailable = this._calculateAndEmulate.bind(this, reset PageScaleFactor);
434 447
435 if (this._type === WebInspector.DeviceModeModel.Type.Device) { 448 if (this._type === WebInspector.DeviceModeModel.Type.Device) {
436 var orientation = this._device.orientationByName(this._mode.orientat ion); 449 var orientation = this._device.orientationByName(this._mode.orientat ion);
437 var outline = new Insets(0, 20, 0, 0); 450 var outline = this._currentOutline();
438 if (Runtime.experiments.isEnabled("deviceFrames") && this._deviceOut lineSetting.get()) 451 this._fitScale = this._calculateFitScale(orientation.width, orientat ion.height, outline);
439 outline = orientation.outlineInsets || outline;
440 this._fitScale = this._calculateFitScale(orientation.width, orientat ion.height);
441 if (this._device.mobile()) 452 if (this._device.mobile())
442 this._appliedUserAgentType = this._device.touch() ? WebInspector .DeviceModeModel.UA.Mobile : WebInspector.DeviceModeModel.UA.MobileNoTouch; 453 this._appliedUserAgentType = this._device.touch() ? WebInspector .DeviceModeModel.UA.Mobile : WebInspector.DeviceModeModel.UA.MobileNoTouch;
443 else 454 else
444 this._appliedUserAgentType = this._device.touch() ? WebInspector .DeviceModeModel.UA.DesktopTouch : WebInspector.DeviceModeModel.UA.Desktop; 455 this._appliedUserAgentType = this._device.touch() ? WebInspector .DeviceModeModel.UA.DesktopTouch : WebInspector.DeviceModeModel.UA.Desktop;
445 this._applyDeviceMetrics(new Size(orientation.width, orientation.hei ght), this._mode.insets, outline, this._scaleSetting.get(), this._device.deviceS caleFactor, this._device.mobile(), this._mode.orientation == WebInspector.Emulat edDevice.Horizontal ? "landscapePrimary" : "portraitPrimary", resetPageScaleFact or); 456 this._applyDeviceMetrics(new Size(orientation.width, orientation.hei ght), this._mode.insets, outline, this._scaleSetting.get(), this._device.deviceS caleFactor, this._device.mobile(), this._mode.orientation == WebInspector.Emulat edDevice.Horizontal ? "landscapePrimary" : "portraitPrimary", resetPageScaleFact or);
446 this._applyUserAgent(this._device.userAgent); 457 this._applyUserAgent(this._device.userAgent);
447 this._applyTouch(this._device.touch(), this._device.mobile()); 458 this._applyTouch(this._device.touch(), this._device.mobile());
448 } else if (this._type === WebInspector.DeviceModeModel.Type.None) { 459 } else if (this._type === WebInspector.DeviceModeModel.Type.None) {
449 this._fitScale = this._calculateFitScale(this._availableSize.width, this._availableSize.height); 460 this._fitScale = this._calculateFitScale(this._availableSize.width, this._availableSize.height);
450 this._appliedUserAgentType = WebInspector.DeviceModeModel.UA.Desktop ; 461 this._appliedUserAgentType = WebInspector.DeviceModeModel.UA.Desktop ;
451 this._applyDeviceMetrics(this._availableSize, new Insets(0, 0, 0, 0) , new Insets(0, 20, 0, 0), 1, 0, false, "", resetPageScaleFactor); 462 this._applyDeviceMetrics(this._availableSize, new Insets(0, 0, 0, 0) , new Insets(0, 0, 0, 0), 1, 0, false, "", resetPageScaleFactor);
452 this._applyUserAgent(""); 463 this._applyUserAgent("");
453 this._applyTouch(false, false); 464 this._applyTouch(false, false);
454 } else if (this._type === WebInspector.DeviceModeModel.Type.Responsive) { 465 } else if (this._type === WebInspector.DeviceModeModel.Type.Responsive) {
455 var screenWidth = this._widthSetting.get(); 466 var screenWidth = this._widthSetting.get();
456 if (!screenWidth || screenWidth > this._preferredScaledWidth()) 467 if (!screenWidth || screenWidth > this._preferredScaledWidth())
457 screenWidth = this._preferredScaledWidth(); 468 screenWidth = this._preferredScaledWidth();
458 var screenHeight = this._heightSetting.get(); 469 var screenHeight = this._heightSetting.get();
459 if (!screenHeight || screenHeight > this._preferredScaledHeight()) 470 if (!screenHeight || screenHeight > this._preferredScaledHeight())
460 screenHeight = this._preferredScaledHeight(); 471 screenHeight = this._preferredScaledHeight();
461 var mobile = this._uaSetting.get() === WebInspector.DeviceModeModel. UA.Mobile || this._uaSetting.get() === WebInspector.DeviceModeModel.UA.MobileNoT ouch; 472 var mobile = this._uaSetting.get() === WebInspector.DeviceModeModel. UA.Mobile || this._uaSetting.get() === WebInspector.DeviceModeModel.UA.MobileNoT ouch;
462 var defaultDeviceScaleFactor = mobile ? WebInspector.DeviceModeModel .defaultMobileScaleFactor : 0; 473 var defaultDeviceScaleFactor = mobile ? WebInspector.DeviceModeModel .defaultMobileScaleFactor : 0;
463 this._fitScale = this._calculateFitScale(this._widthSetting.get(), t his._heightSetting.get()); 474 this._fitScale = this._calculateFitScale(this._widthSetting.get(), t his._heightSetting.get());
464 this._appliedUserAgentType = this._uaSetting.get(); 475 this._appliedUserAgentType = this._uaSetting.get();
465 this._applyDeviceMetrics(new Size(screenWidth, screenHeight), new In sets(0, 0, 0, 0), new Insets(0, 20, 0, 0), this._scaleSetting.get(), this._devic eScaleFactorSetting.get() || defaultDeviceScaleFactor, mobile, screenHeight >= s creenWidth ? "portraitPrimary" : "landscapePrimary", resetPageScaleFactor); 476 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);
466 this._applyUserAgent(mobile ? WebInspector.DeviceModeModel._defaultM obileUserAgent : ""); 477 this._applyUserAgent(mobile ? WebInspector.DeviceModeModel._defaultM obileUserAgent : "");
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); 478 this._applyTouch(this._uaSetting.get() === WebInspector.DeviceModeMo del.UA.DesktopTouch || this._uaSetting.get() === WebInspector.DeviceModeModel.UA .Mobile, this._uaSetting.get() === WebInspector.DeviceModeModel.UA.Mobile);
468 } 479 }
469 if (this._target) 480 if (this._target)
470 this._target.renderingAgent().setShowViewportSizeOnResize(this._type === WebInspector.DeviceModeModel.Type.None); 481 this._target.renderingAgent().setShowViewportSizeOnResize(this._type === WebInspector.DeviceModeModel.Type.None);
471 this._updateCallback.call(null); 482 this._updateCallback.call(null);
472 }, 483 },
473 484
474 /** 485 /**
475 * @param {number} screenWidth 486 * @param {number} screenWidth
476 * @param {number} screenHeight 487 * @param {number} screenHeight
488 * @param {!Insets=} outline
477 * @return {number} 489 * @return {number}
478 */ 490 */
479 _calculateFitScale: function(screenWidth, screenHeight) 491 _calculateFitScale: function(screenWidth, screenHeight, outline)
480 { 492 {
481 var scale = Math.min(screenWidth ? this._preferredSize.width / screenWid th : 1, screenHeight ? this._preferredSize.height / screenHeight : 1); 493 var outlineWidth = outline ? outline.left + outline.right : 0;
494 var outlineHeight = outline ? outline.top + outline.bottom : 0;
495 var scale = Math.min(screenWidth ? this._preferredSize.width / (screenWi dth + outlineWidth) : 1, screenHeight ? this._preferredSize.height / (screenHeig ht + outlineHeight) : 1);
482 return Math.min(scale, 1); 496 return Math.min(scale, 1);
483 }, 497 },
484 498
485 /** 499 /**
486 * @param {number} width 500 * @param {number} width
487 * @param {number} height 501 * @param {number} height
488 */ 502 */
489 setSizeAndScaleToFit: function(width, height) 503 setSizeAndScaleToFit: function(width, height)
490 { 504 {
491 this._scaleSetting.set(this._calculateFitScale(width, height)); 505 this._scaleSetting.set(this._calculateFitScale(width, height));
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 602
589 /** 603 /**
590 * @param {boolean} touchEnabled 604 * @param {boolean} touchEnabled
591 * @param {boolean} mobile 605 * @param {boolean} mobile
592 */ 606 */
593 _applyTouch: function(touchEnabled, mobile) 607 _applyTouch: function(touchEnabled, mobile)
594 { 608 {
595 WebInspector.MultitargetTouchModel.instance().setTouchEnabled(touchEnabl ed, mobile); 609 WebInspector.MultitargetTouchModel.instance().setTouchEnabled(touchEnabl ed, mobile);
596 } 610 }
597 } 611 }
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeToolbar.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698