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

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

Issue 1650243004: [DevTools] Option to show device frames in emulation mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Disallow rulers and device frame to be show simultaneously Created 4 years, 8 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 27 matching lines...) Expand all
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
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 && Runtime.experiments.isEnabled("dev iceFrames")) ?
239 this._device.outlineImage(this._mode) : "";
240 },
241
242 /**
243 * @return {!WebInspector.Rect}
244 */
245 outlineRect: function()
246 {
247 return this._outlineRect;
248 },
249
250 /**
231 * @return {!WebInspector.Rect} 251 * @return {!WebInspector.Rect}
232 */ 252 */
233 screenRect: function() 253 screenRect: function()
234 { 254 {
235 return this._screenRect; 255 return this._screenRect;
236 }, 256 },
237 257
238 /** 258 /**
239 * @return {!WebInspector.Rect} 259 * @return {!WebInspector.Rect}
240 */ 260 */
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 }, 328 },
309 329
310 /** 330 /**
311 * @return {!WebInspector.Setting} 331 * @return {!WebInspector.Setting}
312 */ 332 */
313 deviceScaleFactorSetting: function() 333 deviceScaleFactorSetting: function()
314 { 334 {
315 return this._deviceScaleFactorSetting; 335 return this._deviceScaleFactorSetting;
316 }, 336 },
317 337
338 /**
339 * @return {!WebInspector.Setting}
340 */
341 deviceOutlineSetting: function()
342 {
343 return this._deviceOutlineSetting;
344 },
345
318 reset: function() 346 reset: function()
319 { 347 {
320 this._deviceScaleFactorSetting.set(0); 348 this._deviceScaleFactorSetting.set(0);
321 this._scaleSetting.set(1); 349 this._scaleSetting.set(1);
322 this.setWidth(400); 350 this.setWidth(400);
323 this.setHeight(0); 351 this.setHeight(0);
324 this._uaSetting.set(WebInspector.DeviceModeModel.UA.Mobile); 352 this._uaSetting.set(WebInspector.DeviceModeModel.UA.Mobile);
325 }, 353 },
326 354
327 /** 355 /**
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 _uaSettingChanged: function() 396 _uaSettingChanged: function()
369 { 397 {
370 this._calculateAndEmulate(true); 398 this._calculateAndEmulate(true);
371 }, 399 },
372 400
373 _deviceScaleFactorSettingChanged: function() 401 _deviceScaleFactorSettingChanged: function()
374 { 402 {
375 this._calculateAndEmulate(false); 403 this._calculateAndEmulate(false);
376 }, 404 },
377 405
406 _deviceOutlineSettingChanged: function()
407 {
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() && Runtime.experimen ts.isEnabled("deviceFrames"))? orientation.outlineInsets : new Insets(0,0,0,0);
404 this._fitScale = this._calculateFitScale(orientation.width, orientat ion.height); 438 this._fitScale = this._calculateFitScale(orientation.width, orientat ion.height);
405 if (this._device.mobile()) 439 if (this._device.mobile())
406 this._appliedUserAgentType = this._device.touch() ? WebInspector .DeviceModeModel.UA.Mobile : WebInspector.DeviceModeModel.UA.MobileNoTouch; 440 this._appliedUserAgentType = this._device.touch() ? WebInspector .DeviceModeModel.UA.Mobile : WebInspector.DeviceModeModel.UA.MobileNoTouch;
407 else 441 else
408 this._appliedUserAgentType = this._device.touch() ? WebInspector .DeviceModeModel.UA.DesktopTouch : WebInspector.DeviceModeModel.UA.Desktop; 442 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); 443 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);
410 this._applyUserAgent(this._device.userAgent); 444 this._applyUserAgent(this._device.userAgent);
411 this._applyTouch(this._device.touch(), this._device.mobile()); 445 this._applyTouch(this._device.touch(), this._device.mobile());
412 } else if (this._type === WebInspector.DeviceModeModel.Type.None) { 446 } else if (this._type === WebInspector.DeviceModeModel.Type.None) {
413 this._fitScale = this._calculateFitScale(this._availableSize.width, this._availableSize.height); 447 this._fitScale = this._calculateFitScale(this._availableSize.width, this._availableSize.height);
414 this._appliedUserAgentType = WebInspector.DeviceModeModel.UA.Desktop ; 448 this._appliedUserAgentType = WebInspector.DeviceModeModel.UA.Desktop ;
415 this._applyDeviceMetrics(this._availableSize, new Insets(0, 0, 0, 0) , 1, 0, false, "", resetPageScaleFactor); 449 this._applyDeviceMetrics(this._availableSize, new Insets(0, 0, 0, 0) , new Insets(0, 0, 0, 0), 1, 0, false, "", resetPageScaleFactor);
416 this._applyUserAgent(""); 450 this._applyUserAgent("");
417 this._applyTouch(false, false); 451 this._applyTouch(false, false);
418 } else if (this._type === WebInspector.DeviceModeModel.Type.Responsive) { 452 } else if (this._type === WebInspector.DeviceModeModel.Type.Responsive) {
419 var screenWidth = this._widthSetting.get(); 453 var screenWidth = this._widthSetting.get();
420 if (!screenWidth || screenWidth > this._preferredScaledWidth()) 454 if (!screenWidth || screenWidth > this._preferredScaledWidth())
421 screenWidth = this._preferredScaledWidth(); 455 screenWidth = this._preferredScaledWidth();
422 var screenHeight = this._heightSetting.get(); 456 var screenHeight = this._heightSetting.get();
423 if (!screenHeight || screenHeight > this._preferredScaledHeight()) 457 if (!screenHeight || screenHeight > this._preferredScaledHeight())
424 screenHeight = this._preferredScaledHeight(); 458 screenHeight = this._preferredScaledHeight();
425 var mobile = this._uaSetting.get() === WebInspector.DeviceModeModel. UA.Mobile || this._uaSetting.get() === WebInspector.DeviceModeModel.UA.MobileNoT ouch; 459 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; 460 var defaultDeviceScaleFactor = mobile ? WebInspector.DeviceModeModel .defaultMobileScaleFactor : 0;
427 this._fitScale = this._calculateFitScale(this._widthSetting.get(), t his._heightSetting.get()); 461 this._fitScale = this._calculateFitScale(this._widthSetting.get(), t his._heightSetting.get());
428 this._appliedUserAgentType = this._uaSetting.get(); 462 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); 463 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 : ""); 464 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); 465 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 } 466 }
433 if (this._target) 467 if (this._target)
434 this._target.renderingAgent().setShowViewportSizeOnResize(this._type === WebInspector.DeviceModeModel.Type.None); 468 this._target.renderingAgent().setShowViewportSizeOnResize(this._type === WebInspector.DeviceModeModel.Type.None);
435 this._updateCallback.call(null); 469 this._updateCallback.call(null);
436 }, 470 },
437 471
438 /** 472 /**
439 * @param {number} screenWidth 473 * @param {number} screenWidth
(...skipping 20 matching lines...) Expand all
460 * @param {string} userAgent 494 * @param {string} userAgent
461 */ 495 */
462 _applyUserAgent: function(userAgent) 496 _applyUserAgent: function(userAgent)
463 { 497 {
464 WebInspector.multitargetNetworkManager.setUserAgentOverride(userAgent); 498 WebInspector.multitargetNetworkManager.setUserAgentOverride(userAgent);
465 }, 499 },
466 500
467 /** 501 /**
468 * @param {!Size} screenSize 502 * @param {!Size} screenSize
469 * @param {!Insets} insets 503 * @param {!Insets} insets
504 * @param {!Insets|null} outline
470 * @param {number} scale 505 * @param {number} scale
471 * @param {number} deviceScaleFactor 506 * @param {number} deviceScaleFactor
472 * @param {boolean} mobile 507 * @param {boolean} mobile
473 * @param {string} screenOrientation 508 * @param {string} screenOrientation
474 * @param {boolean} resetPageScaleFactor 509 * @param {boolean} resetPageScaleFactor
475 */ 510 */
476 _applyDeviceMetrics: function(screenSize, insets, scale, deviceScaleFactor, mobile, screenOrientation, resetPageScaleFactor) 511 _applyDeviceMetrics: function(screenSize, insets, outline, scale, deviceScal eFactor, mobile, screenOrientation, resetPageScaleFactor)
477 { 512 {
478 screenSize.width = Math.max(1, Math.floor(screenSize.width)); 513 screenSize.width = Math.max(1, Math.floor(screenSize.width));
479 screenSize.height = Math.max(1, Math.floor(screenSize.height)); 514 screenSize.height = Math.max(1, Math.floor(screenSize.height));
480 515
481 var pageWidth = screenSize.width - insets.left - insets.right; 516 var pageWidth = screenSize.width - insets.left - insets.right;
482 var pageHeight = screenSize.height - insets.top - insets.bottom; 517 var pageHeight = screenSize.height - insets.top - insets.bottom;
518
483 var positionX = insets.left; 519 var positionX = insets.left;
484 var positionY = insets.top; 520 var positionY = insets.top;
485 var screenOrientationAngle = screenOrientation === "landscapePrimary" ? 90 : 0; 521 var screenOrientationAngle = screenOrientation === "landscapePrimary" ? 90 : 0;
486 522
487 this._appliedDeviceSize = screenSize; 523 this._appliedDeviceSize = screenSize;
488 this._appliedDeviceScaleFactor = deviceScaleFactor || window.devicePixel Ratio; 524 this._appliedDeviceScaleFactor = deviceScaleFactor || window.devicePixel Ratio;
489 this._screenRect = new WebInspector.Rect( 525 this._screenRect = new WebInspector.Rect(
490 Math.max(0, (this._availableSize.width - screenSize.width * scale) / 2), 526 Math.max(0, (this._availableSize.width - screenSize.width * scale) / 2),
491 0, 527 outline.top * scale,
492 screenSize.width * scale, 528 screenSize.width * scale,
493 screenSize.height * scale); 529 screenSize.height * scale);
530 this._outlineRect = new WebInspector.Rect(
531 Math.max(0, this._screenRect.left - outline.left * scale),
532 0,
533 (outline.left + screenSize.width + outline.right) * scale,
534 (outline.top + screenSize.height + outline.bottom) * scale);
494 this._visiblePageRect = new WebInspector.Rect( 535 this._visiblePageRect = new WebInspector.Rect(
495 positionX * scale, 536 positionX * scale,
496 positionY * scale, 537 positionY * scale,
497 Math.min(pageWidth * scale, this._availableSize.width - this._screen Rect.left - positionX * scale), 538 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)); 539 Math.min(pageHeight * scale, this._availableSize.height - this._scre enRect.top - positionY * scale));
499 this._scale = scale; 540 this._scale = scale;
500 541
501 if (scale === 1 && this._availableSize.width >= screenSize.width && this ._availableSize.height >= screenSize.height) { 542 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. 543 // When we have enough space, no page size override is required. Thi s will speed things up and remove lag.
503 pageWidth = 0; 544 pageWidth = 0;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 586
546 /** 587 /**
547 * @param {boolean} touchEnabled 588 * @param {boolean} touchEnabled
548 * @param {boolean} mobile 589 * @param {boolean} mobile
549 */ 590 */
550 _applyTouch: function(touchEnabled, mobile) 591 _applyTouch: function(touchEnabled, mobile)
551 { 592 {
552 WebInspector.MultitargetTouchModel.instance().setTouchEnabled(touchEnabl ed, mobile); 593 WebInspector.MultitargetTouchModel.instance().setTouchEnabled(touchEnabl ed, mobile);
553 } 594 }
554 } 595 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698