OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 245 |
246 WebInspector.OverridesSupport.DeviceOrientation.clearDeviceOrientationOverride =
function() | 246 WebInspector.OverridesSupport.DeviceOrientation.clearDeviceOrientationOverride =
function() |
247 { | 247 { |
248 PageAgent.clearDeviceOrientationOverride(); | 248 PageAgent.clearDeviceOrientationOverride(); |
249 } | 249 } |
250 | 250 |
251 /** | 251 /** |
252 * @param {string} value | 252 * @param {string} value |
253 * @return {string} | 253 * @return {string} |
254 */ | 254 */ |
255 WebInspector.OverridesSupport.integerInputValidator = function(value) | 255 WebInspector.OverridesSupport.deviceSizeValidator = function(value) |
256 { | 256 { |
257 if (/^[\d]+$/.test(value) && value >= 0 && value <= 10000) | 257 if (!value || (/^[\d]+$/.test(value) && value >= 0 && value <= 10000)) |
258 return ""; | 258 return ""; |
259 return WebInspector.UIString("Value must be non-negative integer"); | 259 return WebInspector.UIString("Value must be non-negative integer"); |
260 } | 260 } |
261 | 261 |
262 /** | 262 /** |
263 * @param {string} value | 263 * @param {string} value |
264 * @return {string} | 264 * @return {string} |
265 */ | 265 */ |
266 WebInspector.OverridesSupport.doubleInputValidator = function(value) | 266 WebInspector.OverridesSupport.deviceScaleFactorValidator = function(value) |
267 { | 267 { |
268 if (/^[\d]+(\.\d+)?|\.\d+$/.test(value) && value >= 0 && value <= 10000) | 268 if (!value || (/^[\d]+(\.\d+)?|\.\d+$/.test(value) && value >= 0 && value <=
10000)) |
269 return ""; | 269 return ""; |
270 return WebInspector.UIString("Value must be non-negative float"); | 270 return WebInspector.UIString("Value must be non-negative float"); |
271 } | 271 } |
272 | 272 |
273 /** | 273 /** |
274 * @param {string} value | 274 * @param {string} value |
275 * @return {string} | 275 * @return {string} |
276 */ | 276 */ |
277 WebInspector.OverridesSupport.networkDomainsValidator = function(value) | 277 WebInspector.OverridesSupport.networkDomainsValidator = function(value) |
278 { | 278 { |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/27.0.1453.46 Safari/537.36", | 430 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/27.0.1453.46 Safari/537.36", |
431 "1280x800x1x0x0"], | 431 "1280x800x1x0x0"], |
432 ["Apple MacBook Pro Retina", | 432 ["Apple MacBook Pro Retina", |
433 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/27.0.1453.46 Safari/537.36", | 433 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/27.0.1453.46 Safari/537.36", |
434 "1440x900x2x0x0"], | 434 "1440x900x2x0x0"], |
435 ["Apple MacBook Air", | 435 ["Apple MacBook Air", |
436 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/27.0.1453.46 Safari/537.36", | 436 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/27.0.1453.46 Safari/537.36", |
437 "1366x768x1x0x0"], | 437 "1366x768x1x0x0"], |
438 ]; | 438 ]; |
439 | 439 |
440 WebInspector.OverridesSupport._userAgents = [ | 440 WebInspector.OverridesSupport._networkThroughputUnlimitedValue = -1; |
441 ["Android 4.0.2 \u2014 Galaxy Nexus", "Mozilla/5.0 (Linux; U; Android 4.0.2;
en-us; Galaxy Nexus Build/ICL53F) AppleWebKit/534.30 (KHTML, like Gecko) Versio
n/4.0 Mobile Safari/534.30"], | |
442 ["Android 2.3 \u2014 Nexus S", "Mozilla/5.0 (Linux; U; Android 2.3.6; en-us;
Nexus S Build/GRK39F) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile
Safari/533.1"], | |
443 ["BlackBerry \u2014 BB10", "Mozilla/5.0 (BB10; Touch) AppleWebKit/537.1+ (KH
TML, like Gecko) Version/10.0.0.1337 Mobile Safari/537.1+"], | |
444 ["BlackBerry \u2014 PlayBook 2.1", "Mozilla/5.0 (PlayBook; U; RIM Tablet OS
2.1.0; en-US) AppleWebKit/536.2+ (KHTML, like Gecko) Version/7.2.1.0 Safari/536.
2+"], | |
445 ["BlackBerry \u2014 9900", "Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en-
US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0.187 Mobile Safari/534.
11+"], | |
446 ["Chrome 31 \u2014 Mac", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) App
leWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36"], | |
447 ["Chrome 31 \u2014 Windows", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.3
6 (KHTML, like Gecko) Chrome/31.0.1650.16 Safari/537.36"], | |
448 ["Chrome \u2014 Android Tablet", "Mozilla/5.0 (Linux; Android 4.1.2; Nexus 7
Build/JZ054K) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safar
i/535.19"], | |
449 ["Chrome \u2014 Android Mobile", "Mozilla/5.0 (Linux; Android 4.0.4; Galaxy
Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133
Mobile Safari/535.19"], | |
450 ["Firefox 14 \u2014 Android Mobile", "Mozilla/5.0 (Android; Mobile; rv:14.0)
Gecko/14.0 Firefox/14.0"], | |
451 ["Firefox 14 \u2014 Android Tablet", "Mozilla/5.0 (Android; Tablet; rv:14.0)
Gecko/14.0 Firefox/14.0"], | |
452 ["Firefox 4 \u2014 Mac", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.
0.1) Gecko/20100101 Firefox/4.0.1"], | |
453 ["Firefox 4 \u2014 Windows", "Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/2
0100101 Firefox/4.0.1"], | |
454 ["Firefox 7 \u2014 Mac", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.
0.1) Gecko/20100101 Firefox/7.0.1"], | |
455 ["Firefox 7 \u2014 Windows", "Mozilla/5.0 (Windows NT 6.1; Intel Mac OS X 10
.6; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"], | |
456 ["Internet Explorer 10", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2
; Trident/6.0)"], | |
457 ["Internet Explorer 7", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"
], | |
458 ["Internet Explorer 8", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0;
Trident/4.0)"], | |
459 ["Internet Explorer 9", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1;
Trident/5.0)"], | |
460 ["iPad \u2014 iOS 7", "Mozilla/5.0 (iPad; CPU OS 7_0_2 like Mac OS X) AppleW
ebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A501 Safari/9537.53"], | |
461 ["iPad \u2014 iOS 6", "Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWeb
Kit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25"], | |
462 ["iPhone \u2014 iOS 7", "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0_2 like Mac O
S X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A4449d Safari
/9537.53"], | |
463 ["iPhone \u2014 iOS 6", "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS
X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/853
6.25"], | |
464 ["MeeGo \u2014 Nokia N9", "Mozilla/5.0 (MeeGo; NokiaN9) AppleWebKit/534.13 (
KHTML, like Gecko) NokiaBrowser/8.5.0 Mobile Safari/534.13"], | |
465 ["Opera 18 \u2014 Mac", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) Appl
eWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 OPR/18.0.12
84.68"], | |
466 ["Opera 18 \u2014 Windows", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 OPR/18.0.1284.68"], | |
467 ["Opera 12 \u2014 Mac", "Opera/9.80 (Macintosh; Intel Mac OS X 10.9.1) Prest
o/2.12.388 Version/12.16"], | |
468 ["Opera 12 \u2014 Windows", "Opera/9.80 (Windows NT 6.1) Presto/2.12.388 Ver
sion/12.16"], | |
469 ["Silk \u2014 Kindle Fire (Desktop view)", "Mozilla/5.0 (Linux; U; en-us; KF
THWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.13 Safari/535.19
Silk-Accelerated=true"], | |
470 ["Silk \u2014 Kindle Fire (Mobile view)", "Mozilla/5.0 (Linux; U; Android 4.
2.2; en-us; KFTHWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.13
Mobile Safari/535.19 Silk-Accelerated=true"], | |
471 ]; | |
472 | |
473 WebInspector.OverridesSupport._networkThroughputPresets = [ | 441 WebInspector.OverridesSupport._networkThroughputPresets = [ |
474 ["Offline", 0], | 442 ["Offline", 0], |
475 ["5 Kbps", 5 * 1024 / 8], | 443 ["5 Kbps", 5 * 1024 / 8], |
476 ["10 Kbps (GSM)", 10 * 1024 / 8], | 444 ["10 Kbps (GSM)", 10 * 1024 / 8], |
477 ["20 Kbps", 20 * 1024 / 8], | 445 ["20 Kbps", 20 * 1024 / 8], |
478 ["40 Kbps (GPRS)", 40 * 1024 / 8], | 446 ["40 Kbps (GPRS)", 40 * 1024 / 8], |
479 ["80 Kbps", 80 * 1024 / 8], | 447 ["80 Kbps", 80 * 1024 / 8], |
480 ["160 Kbps (EDGE)", 160 * 1024 / 8], | 448 ["160 Kbps (EDGE)", 160 * 1024 / 8], |
481 ["320 Kbps", 320 * 1024 / 8], | 449 ["320 Kbps", 320 * 1024 / 8], |
482 ["640 Kbps (3G)", 640 * 1024 / 8], | 450 ["640 Kbps (3G)", 640 * 1024 / 8], |
483 ["1 Mbps", 1024 * 1024 / 8], | 451 ["1 Mbps", 1024 * 1024 / 8], |
484 ["2 Mbps (802.11b)", 2048 * 1024 / 8] | 452 ["2 Mbps (802.11b)", 2048 * 1024 / 8], |
| 453 ["No throttling", WebInspector.OverridesSupport._networkThroughputUnlimitedV
alue] |
485 ]; | 454 ]; |
486 | 455 |
487 WebInspector.OverridesSupport.prototype = { | 456 WebInspector.OverridesSupport.prototype = { |
488 /** | 457 /** |
489 * @return {boolean} | 458 * @return {boolean} |
490 */ | 459 */ |
491 _responsiveDesignEnabledOrUnavailable: function() | 460 responsiveDesignAvailable: function() |
492 { | 461 { |
493 return !this._responsiveDesignAvailable || WebInspector.settings.respons
iveDesignEnabled.get(); | 462 return this._responsiveDesignAvailable; |
494 }, | 463 }, |
495 | 464 |
496 /** | 465 /** |
497 * @param {?WebInspector.OverridesSupport.PageResizer} pageResizer | 466 * @param {?WebInspector.OverridesSupport.PageResizer} pageResizer |
498 */ | 467 */ |
499 setPageResizer: function(pageResizer) | 468 setPageResizer: function(pageResizer) |
500 { | 469 { |
501 if (pageResizer === this._pageResizer) | 470 if (pageResizer === this._pageResizer) |
502 return; | 471 return; |
503 | 472 |
(...skipping 10 matching lines...) Expand all Loading... |
514 this._deviceMetricsChanged(); | 483 this._deviceMetricsChanged(); |
515 }, | 484 }, |
516 | 485 |
517 /** | 486 /** |
518 * @param {!WebInspector.OverridesSupport.Device} device | 487 * @param {!WebInspector.OverridesSupport.Device} device |
519 */ | 488 */ |
520 emulateDevice: function(device) | 489 emulateDevice: function(device) |
521 { | 490 { |
522 this._deviceMetricsChangedListenerMuted = true; | 491 this._deviceMetricsChangedListenerMuted = true; |
523 this._userAgentChangedListenerMuted = true; | 492 this._userAgentChangedListenerMuted = true; |
524 this.settings.deviceUserAgent.set(device.userAgent); | 493 this.settings.userAgent.set(device.userAgent); |
525 this.settings.deviceWidth.set(device.width); | 494 this.settings.deviceWidth.set(device.width); |
526 this.settings.deviceHeight.set(device.height); | 495 this.settings.deviceHeight.set(device.height); |
527 this.settings.deviceScaleFactor.set(device.deviceScaleFactor); | 496 this.settings.deviceScaleFactor.set(device.deviceScaleFactor); |
528 this.settings.deviceTextAutosizing.set(device.textAutosizing); | 497 this.settings.deviceTextAutosizing.set(device.textAutosizing); |
529 this.settings.deviceTouch.set(device.touch); | 498 this.settings.emulateTouch.set(device.touch); |
530 this.settings.emulateViewport.set(device.viewport); | 499 this.settings.emulateViewport.set(device.viewport); |
531 this.settings.emulateDevice.set(true); | |
532 delete this._deviceMetricsChangedListenerMuted; | 500 delete this._deviceMetricsChangedListenerMuted; |
533 delete this._userAgentChangedListenerMuted; | 501 delete this._userAgentChangedListenerMuted; |
534 | 502 |
535 if (this._initialized) { | 503 if (this._initialized) { |
536 this._deviceMetricsChanged(); | 504 this._deviceMetricsChanged(); |
537 this._userAgentChanged(); | 505 this._userAgentChanged(); |
538 } | 506 } |
539 }, | 507 }, |
540 | 508 |
541 reset: function() | 509 reset: function() |
542 { | 510 { |
543 this._deviceMetricsChangedListenerMuted = true; | 511 this._deviceMetricsChangedListenerMuted = true; |
544 this._userAgentChangedListenerMuted = true; | 512 this._userAgentChangedListenerMuted = true; |
545 this.settings.emulateDevice.set(false); | 513 this.settings.userAgent.set(""); |
546 this.settings.sensorsTouch.set(false); | 514 this.settings.deviceWidth.set(0); |
547 this.settings.overrideUserAgent.set(false); | 515 this.settings.deviceHeight.set(0); |
| 516 this.settings.deviceScaleFactor.set(0); |
| 517 this.settings.deviceTextAutosizing.set(false); |
| 518 this.settings.emulateTouch.set(false); |
| 519 this.settings.emulateViewport.set(false); |
548 this.settings.overrideDeviceOrientation.set(false); | 520 this.settings.overrideDeviceOrientation.set(false); |
549 this.settings.overrideGeolocation.set(false); | 521 this.settings.overrideGeolocation.set(false); |
550 this.settings.overrideCSSMedia.set(false); | 522 this.settings.overrideCSSMedia.set(false); |
| 523 this.settings.networkConditionsThroughput.set(WebInspector.OverridesSupp
ort._networkThroughputUnlimitedValue); |
551 delete this._deviceMetricsChangedListenerMuted; | 524 delete this._deviceMetricsChangedListenerMuted; |
552 delete this._userAgentChangedListenerMuted; | 525 delete this._userAgentChangedListenerMuted; |
553 | 526 |
554 if (this._initialized) { | 527 if (this._initialized) { |
555 this._deviceMetricsChanged(); | 528 this._deviceMetricsChanged(); |
556 this._userAgentChanged(); | 529 this._userAgentChanged(); |
557 } | 530 } |
558 }, | 531 }, |
559 | 532 |
560 /** | 533 /** |
561 * @param {!WebInspector.OverridesSupport.Device} device | 534 * @param {!WebInspector.OverridesSupport.Device} device |
562 * @return {boolean} | 535 * @return {boolean} |
563 */ | 536 */ |
564 isEmulatingDevice: function(device) | 537 isEmulatingDevice: function(device) |
565 { | 538 { |
566 return this.settings.deviceUserAgent.get() === device.userAgent | 539 return this.settings.userAgent.get() === device.userAgent |
567 && this.settings.deviceWidth.get() === device.width | 540 && this.settings.deviceWidth.get() === device.width |
568 && this.settings.deviceHeight.get() === device.height | 541 && this.settings.deviceHeight.get() === device.height |
569 && this.settings.deviceScaleFactor.get() === device.deviceScaleFacto
r | 542 && this.settings.deviceScaleFactor.get() === device.deviceScaleFacto
r |
570 && this.settings.deviceTextAutosizing.get() === device.textAutosizin
g | 543 && this.settings.deviceTextAutosizing.get() === device.textAutosizin
g |
571 && this.settings.deviceTouch.get() === device.touch | 544 && this.settings.emulateTouch.get() === device.touch |
572 && this.settings.emulateViewport.get() === device.viewport; | 545 && this.settings.emulateViewport.get() === device.viewport; |
573 }, | 546 }, |
574 | 547 |
575 applyInitialOverrides: function() | 548 applyInitialOverrides: function() |
576 { | 549 { |
577 if (!this._target) { | 550 if (!this._target) { |
578 this._applyInitialOverridesOnTargetAdded = true; | 551 this._applyInitialOverridesOnTargetAdded = true; |
579 return; | 552 return; |
580 } | 553 } |
581 | 554 |
582 this._initialized = true; | 555 this._initialized = true; |
583 | 556 |
584 this._addEmulateDeviceListener(this._userAgentChanged); | 557 this.settings.emulationEnabled.addChangeListener(this._userAgentChanged,
this); |
585 this.settings.deviceUserAgent.addChangeListener(this._userAgentChanged,
this); | |
586 this.settings.overrideUserAgent.addChangeListener(this._userAgentChanged
, this); | |
587 this.settings.userAgent.addChangeListener(this._userAgentChanged, this); | 558 this.settings.userAgent.addChangeListener(this._userAgentChanged, this); |
588 | 559 |
589 this._addEmulateDeviceListener(this._deviceMetricsChanged); | 560 this.settings.emulationEnabled.addChangeListener(this._deviceMetricsChan
ged, this); |
590 this.settings.deviceWidth.addChangeListener(this._deviceMetricsChanged,
this); | 561 this.settings.deviceWidth.addChangeListener(this._deviceMetricsChanged,
this); |
591 this.settings.deviceHeight.addChangeListener(this._deviceMetricsChanged,
this); | 562 this.settings.deviceHeight.addChangeListener(this._deviceMetricsChanged,
this); |
592 this.settings.deviceScaleFactor.addChangeListener(this._deviceMetricsCha
nged, this); | 563 this.settings.deviceScaleFactor.addChangeListener(this._deviceMetricsCha
nged, this); |
593 this.settings.deviceTextAutosizing.addChangeListener(this._deviceMetrics
Changed, this); | 564 this.settings.deviceTextAutosizing.addChangeListener(this._deviceMetrics
Changed, this); |
594 this.settings.emulateViewport.addChangeListener(this._deviceMetricsChang
ed, this); | 565 this.settings.emulateViewport.addChangeListener(this._deviceMetricsChang
ed, this); |
595 this.settings.deviceFitWindow.addChangeListener(this._deviceMetricsChang
ed, this); | 566 this.settings.deviceFitWindow.addChangeListener(this._deviceMetricsChang
ed, this); |
596 | 567 |
| 568 this.settings.emulationEnabled.addChangeListener(this._geolocationPositi
onChanged, this); |
597 this.settings.overrideGeolocation.addChangeListener(this._geolocationPos
itionChanged, this); | 569 this.settings.overrideGeolocation.addChangeListener(this._geolocationPos
itionChanged, this); |
598 this.settings.geolocationOverride.addChangeListener(this._geolocationPos
itionChanged, this); | 570 this.settings.geolocationOverride.addChangeListener(this._geolocationPos
itionChanged, this); |
599 WebInspector.settings.responsiveDesignEnabled.addChangeListener(this._ge
olocationPositionChanged, this); | |
600 | 571 |
| 572 this.settings.emulationEnabled.addChangeListener(this._deviceOrientation
Changed, this); |
601 this.settings.overrideDeviceOrientation.addChangeListener(this._deviceOr
ientationChanged, this); | 573 this.settings.overrideDeviceOrientation.addChangeListener(this._deviceOr
ientationChanged, this); |
602 this.settings.deviceOrientationOverride.addChangeListener(this._deviceOr
ientationChanged, this); | 574 this.settings.deviceOrientationOverride.addChangeListener(this._deviceOr
ientationChanged, this); |
603 WebInspector.settings.responsiveDesignEnabled.addChangeListener(this._de
viceOrientationChanged, this); | |
604 | 575 |
605 this._addEmulateDeviceListener(this._emulateTouchEventsChanged); | 576 this.settings.emulationEnabled.addChangeListener(this._emulateTouchEvent
sChanged, this); |
606 this.settings.deviceTouch.addChangeListener(this._emulateTouchEventsChan
ged, this); | 577 this.settings.emulateTouch.addChangeListener(this._emulateTouchEventsCha
nged, this); |
607 this.settings.sensorsTouch.addChangeListener(this._emulateTouchEventsCha
nged, this); | |
608 | 578 |
| 579 this.settings.emulationEnabled.addChangeListener(this._cssMediaChanged,
this); |
609 this.settings.overrideCSSMedia.addChangeListener(this._cssMediaChanged,
this); | 580 this.settings.overrideCSSMedia.addChangeListener(this._cssMediaChanged,
this); |
610 this.settings.emulatedCSSMedia.addChangeListener(this._cssMediaChanged,
this); | 581 this.settings.emulatedCSSMedia.addChangeListener(this._cssMediaChanged,
this); |
611 WebInspector.settings.responsiveDesignEnabled.addChangeListener(this._cs
sMediaChanged, this); | |
612 | 582 |
613 if (WebInspector.experimentsSettings.networkConditions.isEnabled()) { | 583 if (WebInspector.experimentsSettings.networkConditions.isEnabled()) { |
614 this.settings.emulateNetworkConditions.addChangeListener(this._netwo
rkConditionsChanged, this); | 584 this.settings.emulationEnabled.addChangeListener(this._networkCondit
ionsChanged, this); |
615 this.settings.networkConditionsDomains.addChangeListener(this._netwo
rkConditionsChanged, this); | 585 this.settings.networkConditionsDomains.addChangeListener(this._netwo
rkConditionsChanged, this); |
616 this.settings.networkConditionsThroughput.addChangeListener(this._ne
tworkConditionsChanged, this); | 586 this.settings.networkConditionsThroughput.addChangeListener(this._ne
tworkConditionsChanged, this); |
617 WebInspector.settings.responsiveDesignEnabled.addChangeListener(this
._networkConditionsChanged, this); | |
618 } | 587 } |
619 | 588 |
620 WebInspector.settings.showMetricsRulers.addChangeListener(this._showRule
rsChanged, this); | 589 WebInspector.settings.showMetricsRulers.addChangeListener(this._showRule
rsChanged, this); |
| 590 this._showRulersChanged(); |
| 591 |
| 592 if (!this.settings.emulationEnabled.get()) |
| 593 return; |
621 | 594 |
622 if (this.settings.overrideDeviceOrientation.get()) | 595 if (this.settings.overrideDeviceOrientation.get()) |
623 this._deviceOrientationChanged(); | 596 this._deviceOrientationChanged(); |
624 | 597 |
625 if (this.settings.overrideGeolocation.get()) | 598 if (this.settings.overrideGeolocation.get()) |
626 this._geolocationPositionChanged(); | 599 this._geolocationPositionChanged(); |
627 | 600 |
628 if (this.isTouchEmulationEnabled()) | 601 if (this.settings.emulateTouch.get()) |
629 this._emulateTouchEventsChanged(); | 602 this._emulateTouchEventsChanged(); |
630 | 603 |
631 if (this.settings.overrideCSSMedia.get()) | 604 if (this.settings.overrideCSSMedia.get()) |
632 this._cssMediaChanged(); | 605 this._cssMediaChanged(); |
633 | 606 |
634 if (this.settings.emulateDevice.get()) | 607 this._deviceMetricsChanged(); |
635 this._deviceMetricsChanged(); | |
636 | 608 |
637 if (this.userAgentOverride()) | 609 this._userAgentChanged(); |
638 this._userAgentChanged(); | |
639 | 610 |
640 if (WebInspector.experimentsSettings.networkConditions.isEnabled() && th
is.settings.emulateNetworkConditions.get()) | 611 if (WebInspector.experimentsSettings.networkConditions.isEnabled() && th
is.networkThroughputIsLimited()) |
641 this._networkConditionsChanged(); | 612 this._networkConditionsChanged(); |
642 | |
643 this._showRulersChanged(); | |
644 }, | |
645 | |
646 /** | |
647 * @param {function(this:WebInspector.OverridesSupport)} listener | |
648 */ | |
649 _addEmulateDeviceListener: function(listener) | |
650 { | |
651 this.settings.emulateDevice.addChangeListener(listener, this); | |
652 WebInspector.settings.responsiveDesignEnabled.addChangeListener(listener
, this); | |
653 }, | 613 }, |
654 | 614 |
655 _userAgentChanged: function() | 615 _userAgentChanged: function() |
656 { | 616 { |
657 if (this._userAgentChangedListenerMuted) | 617 if (this._userAgentChangedListenerMuted) |
658 return; | 618 return; |
659 var userAgent = this.userAgentOverride(); | 619 var userAgent = this.settings.emulationEnabled.get() ? this.settings.use
rAgent.get() : ""; |
660 NetworkAgent.setUserAgentOverride(userAgent); | 620 NetworkAgent.setUserAgentOverride(userAgent); |
661 if (this._userAgent !== userAgent) | 621 if (this._userAgent !== userAgent) |
662 this._updateUserAgentWarningMessage(WebInspector.UIString("You might
need to reload the page for proper user agent spoofing and viewport rendering."
)); | 622 this._updateUserAgentWarningMessage(WebInspector.UIString("You might
need to reload the page for proper user agent spoofing and viewport rendering."
)); |
663 this._userAgent = userAgent; | 623 this._userAgent = userAgent; |
664 this.maybeHasActiveOverridesChanged(); | 624 this.maybeHasActiveOverridesChanged(); |
665 }, | 625 }, |
666 | 626 |
667 _onPageResizerAvailableSizeChanged: function() | 627 _onPageResizerAvailableSizeChanged: function() |
668 { | 628 { |
669 if (this._initialized) | 629 if (this._initialized) |
(...skipping 13 matching lines...) Expand all Loading... |
683 this.settings.deviceHeight.set(height); | 643 this.settings.deviceHeight.set(height); |
684 } | 644 } |
685 }, | 645 }, |
686 | 646 |
687 _deviceMetricsChanged: function() | 647 _deviceMetricsChanged: function() |
688 { | 648 { |
689 this._showRulersChanged(); | 649 this._showRulersChanged(); |
690 | 650 |
691 if (this._deviceMetricsChangedListenerMuted) | 651 if (this._deviceMetricsChangedListenerMuted) |
692 return; | 652 return; |
693 var emulateDevice = this.settings.emulateDevice.get(); | 653 |
694 if (!this._responsiveDesignEnabledOrUnavailable() || !emulateDevice) { | 654 if (!this.settings.emulationEnabled.get()) { |
695 this._deviceMetricsThrottler.schedule(clearDeviceMetricsOverride.bin
d(this)); | 655 this._deviceMetricsThrottler.schedule(clearDeviceMetricsOverride.bin
d(this)); |
696 if (this._pageResizer && !emulateDevice) | 656 if (this._pageResizer) |
697 this._pageResizer.update(0, 0, 0); | 657 this._pageResizer.update(0, 0, 0); |
698 return; | 658 return; |
699 } | 659 } |
700 | 660 |
701 var dipWidth = emulateDevice ? this.settings.deviceWidth.get() : 0; | 661 var dipWidth = this.settings.deviceWidth.get(); |
702 var dipHeight = emulateDevice ? this.settings.deviceHeight.get() : 0; | 662 var dipHeight = this.settings.deviceHeight.get(); |
703 | 663 |
704 // Disable override without checks. | 664 // Disable override without checks. |
705 if (this.isInspectingDevice()) | 665 if (this.isInspectingDevice()) |
706 return; | 666 return; |
707 | 667 |
708 var overrideWidth = dipWidth; | 668 var overrideWidth = dipWidth; |
709 var overrideHeight = dipHeight; | 669 var overrideHeight = dipHeight; |
710 if (this._pageResizer) { | 670 if (this._pageResizer) { |
711 var available = this._pageResizer.availableDipSize(); | 671 var available = this._pageResizer.availableDipSize(); |
712 if (available.width >= dipWidth && available.height >= dipHeight) { | 672 if (available.width >= dipWidth && available.height >= dipHeight) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 */ | 710 */ |
751 function apiCallback(finishCallback, error) | 711 function apiCallback(finishCallback, error) |
752 { | 712 { |
753 if (error) { | 713 if (error) { |
754 this._updateDeviceMetricsWarningMessage(WebInspector.UIString("S
creen emulation is not available on this page.")); | 714 this._updateDeviceMetricsWarningMessage(WebInspector.UIString("S
creen emulation is not available on this page.")); |
755 this._deviceMetricsOverrideAppliedForTest(); | 715 this._deviceMetricsOverrideAppliedForTest(); |
756 finishCallback(); | 716 finishCallback(); |
757 return; | 717 return; |
758 } | 718 } |
759 | 719 |
760 var viewportEnabled = this.settings.emulateDevice.get() && this.sett
ings.emulateViewport.get(); | 720 var viewportEnabled = this.settings.emulationEnabled.get() && this.s
ettings.emulateViewport.get(); |
761 if (this._emulateViewportEnabled !== viewportEnabled) | 721 if (this._emulateViewportEnabled !== viewportEnabled) |
762 this._updateDeviceMetricsWarningMessage(WebInspector.UIString("Y
ou might need to reload the page for proper user agent spoofing and viewport ren
dering.")); | 722 this._updateDeviceMetricsWarningMessage(WebInspector.UIString("Y
ou might need to reload the page for proper user agent spoofing and viewport ren
dering.")); |
763 this._emulateViewportEnabled = viewportEnabled; | 723 this._emulateViewportEnabled = viewportEnabled; |
764 this._deviceMetricsOverrideAppliedForTest(); | 724 this._deviceMetricsOverrideAppliedForTest(); |
765 this.maybeHasActiveOverridesChanged(); | 725 this.maybeHasActiveOverridesChanged(); |
766 finishCallback(); | 726 finishCallback(); |
767 } | 727 } |
768 }, | 728 }, |
769 | 729 |
770 _deviceMetricsOverrideAppliedForTest: function() | 730 _deviceMetricsOverrideAppliedForTest: function() |
771 { | 731 { |
772 // Used for sniffing in tests. | 732 // Used for sniffing in tests. |
773 }, | 733 }, |
774 | 734 |
775 _geolocationPositionChanged: function() | 735 _geolocationPositionChanged: function() |
776 { | 736 { |
777 if (!this._responsiveDesignEnabledOrUnavailable() || !this.settings.over
rideGeolocation.get()) { | 737 if (!this.settings.emulationEnabled.get() || !this.settings.overrideGeol
ocation.get()) { |
778 GeolocationAgent.clearGeolocationOverride(); | 738 GeolocationAgent.clearGeolocationOverride(); |
779 return; | 739 return; |
780 } | 740 } |
781 var geolocation = WebInspector.OverridesSupport.GeolocationPosition.pars
eSetting(this.settings.geolocationOverride.get()); | 741 var geolocation = WebInspector.OverridesSupport.GeolocationPosition.pars
eSetting(this.settings.geolocationOverride.get()); |
782 if (geolocation.error) | 742 if (geolocation.error) |
783 GeolocationAgent.setGeolocationOverride(); | 743 GeolocationAgent.setGeolocationOverride(); |
784 else | 744 else |
785 GeolocationAgent.setGeolocationOverride(geolocation.latitude, geoloc
ation.longitude, 150); | 745 GeolocationAgent.setGeolocationOverride(geolocation.latitude, geoloc
ation.longitude, 150); |
786 this.maybeHasActiveOverridesChanged(); | 746 this.maybeHasActiveOverridesChanged(); |
787 }, | 747 }, |
788 | 748 |
789 _deviceOrientationChanged: function() | 749 _deviceOrientationChanged: function() |
790 { | 750 { |
791 if (!this._responsiveDesignEnabledOrUnavailable() || !this.settings.over
rideDeviceOrientation.get()) { | 751 if (!this.settings.emulationEnabled.get() || !this.settings.overrideDevi
ceOrientation.get()) { |
792 PageAgent.clearDeviceOrientationOverride(); | 752 PageAgent.clearDeviceOrientationOverride(); |
793 return; | 753 return; |
794 } | 754 } |
795 | 755 |
796 var deviceOrientation = WebInspector.OverridesSupport.DeviceOrientation.
parseSetting(this.settings.deviceOrientationOverride.get()); | 756 var deviceOrientation = WebInspector.OverridesSupport.DeviceOrientation.
parseSetting(this.settings.deviceOrientationOverride.get()); |
797 PageAgent.setDeviceOrientationOverride(deviceOrientation.alpha, deviceOr
ientation.beta, deviceOrientation.gamma); | 757 PageAgent.setDeviceOrientationOverride(deviceOrientation.alpha, deviceOr
ientation.beta, deviceOrientation.gamma); |
798 this.maybeHasActiveOverridesChanged(); | 758 this.maybeHasActiveOverridesChanged(); |
799 }, | 759 }, |
800 | 760 |
801 _emulateTouchEventsChanged: function() | 761 _emulateTouchEventsChanged: function() |
802 { | 762 { |
803 var emulateTouch = this.isTouchEmulationEnabled(); | 763 var emulateTouch = this.settings.emulationEnabled.get() && this.settings
.emulateTouch.get(); |
804 var targets = WebInspector.targetManager.targets(); | 764 var targets = WebInspector.targetManager.targets(); |
805 for (var i = 0; i < targets.length; ++i) | 765 for (var i = 0; i < targets.length; ++i) |
806 targets[i].domModel.emulateTouchEventObjects(emulateTouch); | 766 targets[i].domModel.emulateTouchEventObjects(emulateTouch); |
807 this.maybeHasActiveOverridesChanged(); | 767 this.maybeHasActiveOverridesChanged(); |
808 }, | 768 }, |
809 | 769 |
810 _cssMediaChanged: function() | 770 _cssMediaChanged: function() |
811 { | 771 { |
812 if (this.isInspectingDevice() && this.settings.overrideCSSMedia.get()) | 772 var enabled = !this.isInspectingDevice() && this.settings.emulationEnabl
ed.get() && this.settings.overrideCSSMedia.get(); |
813 return; | 773 PageAgent.setEmulatedMedia(enabled ? this.settings.emulatedCSSMedia.get(
) : ""); |
814 | |
815 PageAgent.setEmulatedMedia(this._responsiveDesignEnabledOrUnavailable()
&& this.settings.overrideCSSMedia.get() ? this.settings.emulatedCSSMedia.get() :
""); | |
816 var targets = WebInspector.targetManager.targets(); | 774 var targets = WebInspector.targetManager.targets(); |
817 for (var i = 0; i < targets.length; ++i) | 775 for (var i = 0; i < targets.length; ++i) |
818 targets[i].cssModel.mediaQueryResultChanged(); | 776 targets[i].cssModel.mediaQueryResultChanged(); |
819 this.maybeHasActiveOverridesChanged(); | 777 this.maybeHasActiveOverridesChanged(); |
820 }, | 778 }, |
821 | 779 |
822 _networkConditionsChanged: function() | 780 _networkConditionsChanged: function() |
823 { | 781 { |
824 if (!this._responsiveDesignEnabledOrUnavailable() || !this.settings.emul
ateNetworkConditions.get()) { | 782 if (!this.settings.emulationEnabled.get() || !this.networkThroughputIsLi
mited()) { |
825 NetworkAgent.emulateNetworkConditions([], 0, false, 0, 0, 0); | 783 NetworkAgent.emulateNetworkConditions([], 0, false, 0, 0, 0); |
826 } else { | 784 } else { |
827 var domainsString = this.settings.networkConditionsDomains.get().tri
m(); | 785 var domainsString = this.settings.networkConditionsDomains.get().tri
m(); |
828 var domains = domainsString ? domainsString.split(",").map(function
(s) { return s.trim(); }) : []; | 786 var domains = domainsString ? domainsString.split(",").map(function
(s) { return s.trim(); }) : []; |
829 var throughput = this.settings.networkConditionsThroughput.get(); | 787 var throughput = this.settings.networkConditionsThroughput.get(); |
830 var offline = !throughput; | 788 var offline = !throughput; |
831 NetworkAgent.emulateNetworkConditions(domains, throughput, offline,
0, throughput, throughput); | 789 NetworkAgent.emulateNetworkConditions(domains, throughput, offline,
0, throughput, throughput); |
832 } | 790 } |
833 this.maybeHasActiveOverridesChanged(); | 791 this.maybeHasActiveOverridesChanged(); |
834 }, | 792 }, |
835 | 793 |
836 /** | 794 /** |
837 * @return {boolean} | 795 * @return {boolean} |
838 */ | 796 */ |
839 showMetricsRulers: function() | 797 showMetricsRulers: function() |
840 { | 798 { |
841 var rulersInPageResizer = this._pageResizer && this.settings.emulateDevi
ce.get(); | 799 var rulersInPageResizer = this._pageResizer && this.settings.emulationEn
abled.get(); |
842 return WebInspector.settings.showMetricsRulers.get() && !rulersInPageRes
izer; | 800 return WebInspector.settings.showMetricsRulers.get() && !rulersInPageRes
izer; |
843 }, | 801 }, |
844 | 802 |
845 _showRulersChanged: function() | 803 _showRulersChanged: function() |
846 { | 804 { |
847 if (WebInspector.experimentsSettings.responsiveDesign.isEnabled()) | 805 if (WebInspector.experimentsSettings.responsiveDesign.isEnabled()) |
848 return; | 806 return; |
849 PageAgent.setShowViewportSizeOnResize(true, this.showMetricsRulers()); | 807 PageAgent.setShowViewportSizeOnResize(true, this.showMetricsRulers()); |
850 }, | 808 }, |
851 | 809 |
852 /** | 810 /** |
853 * @return {boolean} | 811 * @return {boolean} |
854 */ | 812 */ |
855 hasActiveOverrides: function() | 813 hasActiveOverrides: function() |
856 { | 814 { |
857 return this._hasActiveOverrides; | 815 return this._hasActiveOverrides; |
858 }, | 816 }, |
859 | 817 |
860 maybeHasActiveOverridesChanged: function() | 818 maybeHasActiveOverridesChanged: function() |
861 { | 819 { |
862 var hasActiveOverrides = | 820 var hasActiveOverrides = this.settings.emulationEnabled.get(); |
863 !!this.userAgentOverride() || | |
864 (this.settings.emulateDevice.get() && !this.isInspectingDevice()) || | |
865 this.settings.overrideGeolocation.get() || | |
866 this.settings.overrideDeviceOrientation.get() || | |
867 (WebInspector.experimentsSettings.networkConditions.isEnabled() && t
his.settings.emulateNetworkConditions.get()) || | |
868 this.isTouchEmulationEnabled() || | |
869 (this.settings.overrideCSSMedia.get() && !this.isInspectingDevice())
; | |
870 if (this._hasActiveOverrides !== hasActiveOverrides) { | 821 if (this._hasActiveOverrides !== hasActiveOverrides) { |
871 this._hasActiveOverrides = hasActiveOverrides; | 822 this._hasActiveOverrides = hasActiveOverrides; |
872 this.dispatchEventToListeners(WebInspector.OverridesSupport.Events.H
asActiveOverridesChanged); | 823 this.dispatchEventToListeners(WebInspector.OverridesSupport.Events.H
asActiveOverridesChanged); |
873 } | 824 } |
874 }, | 825 }, |
875 | 826 |
876 _onMainFrameNavigated: function() | 827 _onMainFrameNavigated: function() |
877 { | 828 { |
878 if (this._initialized) | 829 if (this._initialized) |
879 this._deviceMetricsChanged(); | 830 this._deviceMetricsChanged(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 * @param {!WebInspector.Target} target | 862 * @param {!WebInspector.Target} target |
912 */ | 863 */ |
913 targetAdded: function(target) | 864 targetAdded: function(target) |
914 { | 865 { |
915 // FIXME: adapt this to multiple targets. | 866 // FIXME: adapt this to multiple targets. |
916 if (this._target) | 867 if (this._target) |
917 return; | 868 return; |
918 this._target = target; | 869 this._target = target; |
919 | 870 |
920 this.settings = {}; | 871 this.settings = {}; |
921 this.settings.overrideUserAgent = WebInspector.settings.createSetting("o
verrideUserAgent", false); | 872 this.settings.emulationEnabled = WebInspector.settings.createSetting("em
ulationEnabled", false); |
| 873 |
922 this.settings.userAgent = WebInspector.settings.createSetting("userAgent
", ""); | 874 this.settings.userAgent = WebInspector.settings.createSetting("userAgent
", ""); |
923 | 875 |
924 this.settings.emulateDevice = WebInspector.settings.createSetting("emula
teDevice", false); | 876 this.settings.deviceWidth = WebInspector.settings.createSetting("deviceW
idth", 0); |
925 this.settings.deviceWidth = WebInspector.settings.createSetting("deviceW
idth", 800); | 877 this.settings.deviceHeight = WebInspector.settings.createSetting("device
Height", 0); |
926 this.settings.deviceHeight = WebInspector.settings.createSetting("device
Height", 600); | 878 this.settings.deviceScaleFactor = WebInspector.settings.createSetting("d
eviceScaleFactor", 0); |
927 this.settings.deviceScaleFactor = WebInspector.settings.createSetting("d
eviceScaleFactor", window.devicePixelRatio); | |
928 this.settings.deviceTextAutosizing = WebInspector.settings.createSetting
("deviceTextAutosizing", true); | 879 this.settings.deviceTextAutosizing = WebInspector.settings.createSetting
("deviceTextAutosizing", true); |
929 this.settings.deviceFitWindow = WebInspector.settings.createSetting("dev
iceFitWindow", true); | 880 this.settings.deviceFitWindow = WebInspector.settings.createSetting("dev
iceFitWindow", true); |
930 // FIXME: rename viewport to mobile everywhere in the code. | 881 // FIXME: rename viewport to mobile everywhere in the code. |
931 this.settings.emulateViewport = WebInspector.settings.createSetting("emu
lateViewport", false); | 882 this.settings.emulateViewport = WebInspector.settings.createSetting("emu
lateViewport", false); |
932 this.settings.deviceTouch = WebInspector.settings.createSetting("deviceT
ouch", false); | 883 |
933 this.settings.deviceUserAgent = WebInspector.settings.createSetting("dev
iceUserAgent", false); | 884 this.settings.emulateTouch = WebInspector.settings.createSetting("emulat
eTouch", false); |
934 | 885 |
935 this.settings.overrideGeolocation = WebInspector.settings.createSetting(
"overrideGeolocation", false); | 886 this.settings.overrideGeolocation = WebInspector.settings.createSetting(
"overrideGeolocation", false); |
936 this.settings.geolocationOverride = WebInspector.settings.createSetting(
"geolocationOverride", ""); | 887 this.settings.geolocationOverride = WebInspector.settings.createSetting(
"geolocationOverride", ""); |
| 888 |
937 this.settings.overrideDeviceOrientation = WebInspector.settings.createSe
tting("overrideDeviceOrientation", false); | 889 this.settings.overrideDeviceOrientation = WebInspector.settings.createSe
tting("overrideDeviceOrientation", false); |
938 this.settings.deviceOrientationOverride = WebInspector.settings.createSe
tting("deviceOrientationOverride", ""); | 890 this.settings.deviceOrientationOverride = WebInspector.settings.createSe
tting("deviceOrientationOverride", ""); |
| 891 |
939 this.settings.overrideCSSMedia = WebInspector.settings.createSetting("ov
errideCSSMedia", false); | 892 this.settings.overrideCSSMedia = WebInspector.settings.createSetting("ov
errideCSSMedia", false); |
940 this.settings.emulatedCSSMedia = WebInspector.settings.createSetting("em
ulatedCSSMedia", "print"); | 893 this.settings.emulatedCSSMedia = WebInspector.settings.createSetting("em
ulatedCSSMedia", "print"); |
941 this.settings.sensorsTouch = WebInspector.settings.createSetting("sensor
sTouch", false); | |
942 | 894 |
943 this.settings.emulateNetworkConditions = WebInspector.settings.createSet
ting("emulateNetworkConditions", false); | |
944 this.settings.networkConditionsDomains = WebInspector.settings.createSet
ting("networkConditionsDomains", ""); | 895 this.settings.networkConditionsDomains = WebInspector.settings.createSet
ting("networkConditionsDomains", ""); |
945 this.settings.networkConditionsThroughput = WebInspector.settings.create
Setting("networkConditionsThroughput", 0); | 896 this.settings.networkConditionsThroughput = WebInspector.settings.create
Setting("networkConditionsThroughput", WebInspector.OverridesSupport._networkThr
oughputUnlimitedValue); |
946 | 897 |
947 this.maybeHasActiveOverridesChanged(); | 898 this.maybeHasActiveOverridesChanged(); |
948 | 899 |
949 if (this._applyInitialOverridesOnTargetAdded) { | 900 if (this._applyInitialOverridesOnTargetAdded) { |
950 delete this._applyInitialOverridesOnTargetAdded; | 901 delete this._applyInitialOverridesOnTargetAdded; |
951 this.applyInitialOverrides(); | 902 this.applyInitialOverrides(); |
952 } | 903 } |
953 }, | 904 }, |
954 | 905 |
955 swapDimensions: function() | 906 swapDimensions: function() |
(...skipping 16 matching lines...) Expand all Loading... |
972 * @return {boolean} | 923 * @return {boolean} |
973 */ | 924 */ |
974 isInspectingDevice: function() | 925 isInspectingDevice: function() |
975 { | 926 { |
976 return !!this._target && this._target.isMobile(); | 927 return !!this._target && this._target.isMobile(); |
977 }, | 928 }, |
978 | 929 |
979 /** | 930 /** |
980 * @return {boolean} | 931 * @return {boolean} |
981 */ | 932 */ |
982 isEmulateDeviceEnabled: function() | |
983 { | |
984 return this.settings.emulateDevice.get() && this._responsiveDesignEnable
dOrUnavailable(); | |
985 }, | |
986 | |
987 /** | |
988 * @return {boolean} | |
989 */ | |
990 isTouchEmulationEnabled: function() | |
991 { | |
992 return !this.hasTouchInputs() && ((this.isEmulateDeviceEnabled() && this
.settings.deviceTouch.get()) || this.settings.sensorsTouch.get()); | |
993 }, | |
994 | |
995 /** | |
996 * @return {string} | |
997 */ | |
998 userAgentOverride: function() | |
999 { | |
1000 return this.isEmulateDeviceEnabled() ? this.settings.deviceUserAgent.get
() : (this.settings.overrideUserAgent.get() ? this.settings.userAgent.get() : ""
); | |
1001 }, | |
1002 | |
1003 /** | |
1004 * @return {boolean} | |
1005 */ | |
1006 hasTouchInputs: function() | 933 hasTouchInputs: function() |
1007 { | 934 { |
1008 return !!this._target && this._target.hasTouchInputs; | 935 return !!this._target && this._target.hasTouchInputs; |
1009 }, | 936 }, |
1010 | 937 |
1011 updateSensorsTouchToMatchDeviceTouch: function() | 938 /** |
| 939 * @return {boolean} |
| 940 */ |
| 941 networkThroughputIsLimited: function() |
1012 { | 942 { |
1013 var enabled = this.isEmulateDeviceEnabled() && this.settings.deviceTouch
.get(); | 943 return this.settings.networkConditionsThroughput.get() !== WebInspector.
OverridesSupport._networkThroughputUnlimitedValue; |
1014 if (this.settings.sensorsTouch.get() !== enabled) | |
1015 this.settings.sensorsTouch.set(enabled); | |
1016 }, | |
1017 | |
1018 updateUserAgentToMatchDeviceUserAgent: function() | |
1019 { | |
1020 var userAgent = this.settings.deviceUserAgent.get(); | |
1021 if (this.isEmulateDeviceEnabled() && userAgent && this.settings.userAgen
t.get() !== userAgent) | |
1022 this.settings.userAgent.set(userAgent); | |
1023 var enabled = this.isEmulateDeviceEnabled() && !!this.settings.deviceUse
rAgent.get(); | |
1024 if (this.settings.overrideUserAgent.get() !== enabled) | |
1025 this.settings.overrideUserAgent.set(enabled); | |
1026 }, | 944 }, |
1027 | 945 |
1028 /** | 946 /** |
1029 * Compute the font scale factor. | 947 * Compute the font scale factor. |
1030 * | 948 * |
1031 * Chromium on Android uses a device scale adjustment for fonts used in text
autosizing for | 949 * Chromium on Android uses a device scale adjustment for fonts used in text
autosizing for |
1032 * improved legibility. This function computes this adjusted value for text
autosizing. | 950 * improved legibility. This function computes this adjusted value for text
autosizing. |
1033 * | 951 * |
1034 * For a description of the Android device scale adjustment algorithm, see: | 952 * For a description of the Android device scale adjustment algorithm, see: |
1035 * chrome/browser/chrome_content_browser_client.cc, GetFontScaleMultipli
er(...) | 953 * chrome/browser/chrome_content_browser_client.cc, GetFontScaleMultipli
er(...) |
1036 * | 954 * |
1037 * @param {number} width | 955 * @param {number} width |
1038 * @param {number} height | 956 * @param {number} height |
1039 * @return {number} font scale factor. | 957 * @return {number} font scale factor. |
1040 */ | 958 */ |
1041 _fontScaleFactor: function(width, height) | 959 _fontScaleFactor: function(width, height) |
1042 { | 960 { |
1043 if (!this.settings.emulateDevice.get()) | 961 if (!this.settings.emulationEnabled.get()) |
1044 return 1; | 962 return 1; |
1045 if (!width && !height) | 963 var deviceScaleFactor = this.settings.deviceScaleFactor.get(); |
| 964 |
| 965 if (!width || !height || !deviceScaleFactor) |
1046 return 1; | 966 return 1; |
1047 | 967 |
1048 var deviceScaleFactor = this.settings.deviceScaleFactor.get(); | |
1049 | |
1050 var minWidth = Math.min(width, height) / deviceScaleFactor; | 968 var minWidth = Math.min(width, height) / deviceScaleFactor; |
1051 | 969 |
1052 var kMinFSM = 1.05; | 970 var kMinFSM = 1.05; |
1053 var kWidthForMinFSM = 320; | 971 var kWidthForMinFSM = 320; |
1054 var kMaxFSM = 1.3; | 972 var kMaxFSM = 1.3; |
1055 var kWidthForMaxFSM = 800; | 973 var kWidthForMaxFSM = 800; |
1056 | 974 |
1057 if (minWidth <= kWidthForMinFSM) | 975 if (minWidth <= kWidthForMinFSM) |
1058 return kMinFSM; | 976 return kMinFSM; |
1059 if (minWidth >= kWidthForMaxFSM) | 977 if (minWidth >= kWidthForMaxFSM) |
(...skipping 26 matching lines...) Expand all Loading... |
1086 } | 1004 } |
1087 | 1005 |
1088 deviceSelectElement.addEventListener("change", deviceSelected, false); | 1006 deviceSelectElement.addEventListener("change", deviceSelected, false); |
1089 | 1007 |
1090 var emulatedSettingChangedMuted = false; | 1008 var emulatedSettingChangedMuted = false; |
1091 WebInspector.overridesSupport.settings.deviceWidth.addChangeListener(emu
latedSettingChanged); | 1009 WebInspector.overridesSupport.settings.deviceWidth.addChangeListener(emu
latedSettingChanged); |
1092 WebInspector.overridesSupport.settings.deviceHeight.addChangeListener(em
ulatedSettingChanged); | 1010 WebInspector.overridesSupport.settings.deviceHeight.addChangeListener(em
ulatedSettingChanged); |
1093 WebInspector.overridesSupport.settings.deviceScaleFactor.addChangeListen
er(emulatedSettingChanged); | 1011 WebInspector.overridesSupport.settings.deviceScaleFactor.addChangeListen
er(emulatedSettingChanged); |
1094 WebInspector.overridesSupport.settings.deviceTextAutosizing.addChangeLis
tener(emulatedSettingChanged); | 1012 WebInspector.overridesSupport.settings.deviceTextAutosizing.addChangeLis
tener(emulatedSettingChanged); |
1095 WebInspector.overridesSupport.settings.emulateViewport.addChangeListener
(emulatedSettingChanged); | 1013 WebInspector.overridesSupport.settings.emulateViewport.addChangeListener
(emulatedSettingChanged); |
1096 WebInspector.overridesSupport.settings.deviceFitWindow.addChangeListener
(emulatedSettingChanged); | 1014 WebInspector.overridesSupport.settings.emulateTouch.addChangeListener(em
ulatedSettingChanged); |
1097 WebInspector.overridesSupport.settings.deviceTouch.addChangeListener(emu
latedSettingChanged); | 1015 WebInspector.overridesSupport.settings.userAgent.addChangeListener(emula
tedSettingChanged); |
1098 WebInspector.overridesSupport.settings.deviceUserAgent.addChangeListener
(emulatedSettingChanged); | |
1099 emulatedSettingChanged(); | 1016 emulatedSettingChanged(); |
1100 | 1017 |
1101 function deviceSelected() | 1018 function deviceSelected() |
1102 { | 1019 { |
1103 if (deviceSelectElement.selectedIndex === devices.length - 1) | 1020 if (deviceSelectElement.selectedIndex === devices.length - 1) |
1104 return; | 1021 return; |
1105 | 1022 |
1106 var option = deviceSelectElement.options[deviceSelectElement.selecte
dIndex]; | 1023 var option = deviceSelectElement.options[deviceSelectElement.selecte
dIndex]; |
1107 emulatedSettingChangedMuted = true; | 1024 emulatedSettingChangedMuted = true; |
1108 WebInspector.overridesSupport.emulateDevice(option.device); | 1025 WebInspector.overridesSupport.emulateDevice(option.device); |
(...skipping 19 matching lines...) Expand all Loading... |
1128 return deviceSelectElement; | 1045 return deviceSelectElement; |
1129 }, | 1046 }, |
1130 | 1047 |
1131 /** | 1048 /** |
1132 * @param {!Document} document | 1049 * @param {!Document} document |
1133 * @return {!Element} | 1050 * @return {!Element} |
1134 */ | 1051 */ |
1135 createNetworkThroughputSelect: function(document) | 1052 createNetworkThroughputSelect: function(document) |
1136 { | 1053 { |
1137 var throughputSetting = WebInspector.overridesSupport.settings.networkCo
nditionsThroughput; | 1054 var throughputSetting = WebInspector.overridesSupport.settings.networkCo
nditionsThroughput; |
1138 var emulateNetworkSetting = WebInspector.overridesSupport.settings.emula
teNetworkConditions; | |
1139 var throughputSelectElement = document.createElement("select"); | 1055 var throughputSelectElement = document.createElement("select"); |
1140 var presets = WebInspector.OverridesSupport._networkThroughputPresets; | 1056 var presets = WebInspector.OverridesSupport._networkThroughputPresets; |
1141 for (var i = 0; i < presets.length; ++i) | 1057 for (var i = 0; i < presets.length; ++i) |
1142 throughputSelectElement.add(new Option(presets[i][0], presets[i][1])
); | 1058 throughputSelectElement.add(new Option(presets[i][0], presets[i][1])
); |
1143 throughputSelectElement.selectedIndex = 0; | |
1144 | 1059 |
1145 settingChanged(); | 1060 settingChanged(); |
1146 throughputSetting.addChangeListener(settingChanged); | 1061 throughputSetting.addChangeListener(settingChanged); |
1147 throughputSelectElement.addEventListener("change", throughputSelected, f
alse); | 1062 throughputSelectElement.addEventListener("change", throughputSelected, f
alse); |
1148 | 1063 |
1149 function throughputSelected() | 1064 function throughputSelected() |
1150 { | 1065 { |
1151 var value = Number(throughputSelectElement.options[throughputSelectE
lement.selectedIndex].value); | 1066 var value = Number(throughputSelectElement.options[throughputSelectE
lement.selectedIndex].value); |
1152 throughputSetting.removeChangeListener(settingChanged); | 1067 throughputSetting.removeChangeListener(settingChanged); |
1153 throughputSetting.set(value); | 1068 throughputSetting.set(value); |
1154 throughputSetting.addChangeListener(settingChanged); | 1069 throughputSetting.addChangeListener(settingChanged); |
1155 emulateNetworkSetting.set(true); | |
1156 } | 1070 } |
1157 | 1071 |
1158 function settingChanged() | 1072 function settingChanged() |
1159 { | 1073 { |
1160 var value = String(throughputSetting.get()); | 1074 var value = String(throughputSetting.get()); |
1161 var options = throughputSelectElement.options; | 1075 var options = throughputSelectElement.options; |
1162 var selectionRestored = false; | 1076 var selectionRestored = false; |
1163 for (var i = 0; i < options.length; ++i) { | 1077 for (var i = 0; i < options.length; ++i) { |
1164 if (options[i].value === value) { | 1078 if (options[i].value === value) { |
1165 throughputSelectElement.selectedIndex = i; | 1079 throughputSelectElement.selectedIndex = i; |
1166 selectionRestored = true; | 1080 selectionRestored = true; |
1167 break; | 1081 break; |
1168 } | 1082 } |
1169 } | 1083 } |
1170 if (!selectionRestored) | 1084 if (!selectionRestored) |
1171 throughputSelectElement.selectedIndex = options.length - 1; | 1085 throughputSelectElement.selectedIndex = options.length - 1; |
1172 } | 1086 } |
1173 | 1087 |
1174 return throughputSelectElement; | 1088 return throughputSelectElement; |
1175 }, | 1089 }, |
1176 | 1090 |
1177 __proto__: WebInspector.Object.prototype | 1091 __proto__: WebInspector.Object.prototype |
1178 } | 1092 } |
1179 | 1093 |
1180 | 1094 |
1181 /** | 1095 /** |
1182 * @type {!WebInspector.OverridesSupport} | 1096 * @type {!WebInspector.OverridesSupport} |
1183 */ | 1097 */ |
1184 WebInspector.overridesSupport; | 1098 WebInspector.overridesSupport; |
OLD | NEW |