OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * @extends {WebInspector.VBox} | 7 * @extends {WebInspector.VBox} |
8 * @implements {WebInspector.OverridesSupport.PageResizer} | 8 * @implements {WebInspector.OverridesSupport.PageResizer} |
9 * @param {!WebInspector.InspectedPagePlaceholder} inspectedPagePlaceholder | 9 * @param {!WebInspector.InspectedPagePlaceholder} inspectedPagePlaceholder |
10 */ | 10 */ |
(...skipping 30 matching lines...) Expand all Loading... |
41 this._heightSlider.createChild("div", "responsive-design-thumb-handle"); | 41 this._heightSlider.createChild("div", "responsive-design-thumb-handle"); |
42 this._createResizer(this._heightSlider, true); | 42 this._createResizer(this._heightSlider, true); |
43 | 43 |
44 this._inspectedPagePlaceholder = inspectedPagePlaceholder; | 44 this._inspectedPagePlaceholder = inspectedPagePlaceholder; |
45 inspectedPagePlaceholder.show(this.element); | 45 inspectedPagePlaceholder.show(this.element); |
46 | 46 |
47 this._enabled = false; | 47 this._enabled = false; |
48 | 48 |
49 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo
omChanged, this._onZoomChanged, this); | 49 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo
omChanged, this._onZoomChanged, this); |
50 WebInspector.settings.responsiveDesign.enabled.addChangeListener(this._respo
nsiveDesignEnabledChanged, this); | 50 WebInspector.settings.responsiveDesign.enabled.addChangeListener(this._respo
nsiveDesignEnabledChanged, this); |
51 WebInspector.overridesSupport.settings.emulateViewport.addChangeListener(thi
s._maybeEnableResponsiveDesign, this); | |
52 WebInspector.overridesSupport.settings.emulateTouchEvents.addChangeListener(
this._maybeEnableResponsiveDesign, this); | |
53 WebInspector.overridesSupport.settings.overrideDeviceResolution.addChangeLis
tener(this._maybeEnableResponsiveDesign, this); | |
54 this._responsiveDesignEnabledChanged(); | 51 this._responsiveDesignEnabledChanged(); |
55 this._overridesWarningUpdated(); | 52 this._overridesWarningUpdated(); |
56 }; | 53 }; |
57 | 54 |
58 // Measured in DIP. | 55 // Measured in DIP. |
59 WebInspector.ResponsiveDesignView.SliderWidth = 19; | 56 WebInspector.ResponsiveDesignView.SliderWidth = 19; |
60 WebInspector.ResponsiveDesignView.RulerWidth = 20; | 57 WebInspector.ResponsiveDesignView.RulerWidth = 20; |
61 | 58 |
62 WebInspector.ResponsiveDesignView.prototype = { | 59 WebInspector.ResponsiveDesignView.prototype = { |
63 _maybeEnableResponsiveDesign: function() | |
64 { | |
65 if (this._enabled) | |
66 return; | |
67 if (WebInspector.overridesSupport.settings.emulateViewport.get() || | |
68 WebInspector.overridesSupport.settings.emulateTouchEvents.get()
|| | |
69 WebInspector.overridesSupport.settings.overrideDeviceResolution.
get()) { | |
70 WebInspector.settings.responsiveDesign.enabled.set(true); | |
71 } | |
72 }, | |
73 | |
74 _invalidateCache: function() | 60 _invalidateCache: function() |
75 { | 61 { |
76 delete this._cachedScale; | 62 delete this._cachedScale; |
77 delete this._cachedCssCanvasWidth; | 63 delete this._cachedCssCanvasWidth; |
78 delete this._cachedCssCanvasHeight; | 64 delete this._cachedCssCanvasHeight; |
79 delete this._cachedCssHeight; | 65 delete this._cachedCssHeight; |
80 delete this._cachedCssWidth; | 66 delete this._cachedCssWidth; |
81 delete this._cachedZoomFactor; | 67 delete this._cachedZoomFactor; |
82 delete this._availableSize; | 68 delete this._availableSize; |
83 }, | 69 }, |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 this._expandSection = document.createElementWithClass("div", "responsive
-design-section vbox"); | 382 this._expandSection = document.createElementWithClass("div", "responsive
-design-section vbox"); |
397 WebInspector.settings.responsiveDesign.toolbarExpanded = WebInspector.se
ttings.createSetting("responsiveDesign.toolbarExpanded", false); | 383 WebInspector.settings.responsiveDesign.toolbarExpanded = WebInspector.se
ttings.createSetting("responsiveDesign.toolbarExpanded", false); |
398 this._expandButton = this._expandSection.createChild("div", "responsive-
design-expand"); | 384 this._expandButton = this._expandSection.createChild("div", "responsive-
design-expand"); |
399 this._expandButton.createChild("div", "responsive-design-icon responsive
-design-icon-expand"); | 385 this._expandButton.createChild("div", "responsive-design-icon responsive
-design-icon-expand"); |
400 this._expandButton.createChild("span"); | 386 this._expandButton.createChild("span"); |
401 this._expandButton.addEventListener("click", this._toggleToolbarExpanded
.bind(this)); | 387 this._expandButton.addEventListener("click", this._toggleToolbarExpanded
.bind(this)); |
402 WebInspector.settings.responsiveDesign.toolbarExpanded.addChangeListener
(this._toolbarExpandedChanged, this); | 388 WebInspector.settings.responsiveDesign.toolbarExpanded.addChangeListener
(this._toolbarExpandedChanged, this); |
403 | 389 |
404 // Device | 390 // Device |
405 this._deviceSection = document.createElementWithClass("div", "responsive
-design-section"); | 391 this._deviceSection = document.createElementWithClass("div", "responsive
-design-section"); |
406 var deviceLabel = this._deviceSection.createChild("label"); | 392 this._deviceSection.appendChild(WebInspector.SettingsUI.createSettingChe
ckbox(WebInspector.UIString("Device"), WebInspector.overridesSupport.settings.em
ulateDevice, true)); |
407 var deviceCheckbox = deviceLabel.createChild("input"); | 393 this._deviceSection.appendChild(WebInspector.overridesSupport.createDevi
ceSelect(document)); |
408 deviceCheckbox.type = "checkbox"; | |
409 deviceLabel.createTextChild(WebInspector.UIString("Device")); | |
410 deviceLabel.title = WebInspector.UIString("Emulate device"); | |
411 deviceCheckbox.addEventListener("change", deviceChecked, false); | |
412 | |
413 function deviceChecked() | |
414 { | |
415 if (deviceCheckbox.checked) { | |
416 var option = deviceSelect.options[deviceSelect.selectedIndex]; | |
417 WebInspector.overridesSupport.emulateDevice(option.metrics, opti
on.userAgent); | |
418 } else { | |
419 WebInspector.overridesSupport.resetEmulatedDevice(); | |
420 } | |
421 } | |
422 | |
423 var deviceSelect = WebInspector.overridesSupport.createDeviceSelect(docu
ment); | |
424 this._deviceSection.appendChild(deviceSelect); | |
425 deviceSelect.addEventListener("change", emulateDevice, false); | |
426 | |
427 function emulateDevice() | |
428 { | |
429 var option = deviceSelect.options[deviceSelect.selectedIndex]; | |
430 WebInspector.overridesSupport.emulateDevice(option.metrics, option.u
serAgent); | |
431 } | |
432 | |
433 updateDeviceCheckboxStatus(); | |
434 | |
435 WebInspector.overridesSupport.settings.emulateViewport.addChangeListener
(updateDeviceCheckboxStatus); | |
436 WebInspector.overridesSupport.settings.emulateTouchEvents.addChangeListe
ner(updateDeviceCheckboxStatus); | |
437 WebInspector.overridesSupport.settings.overrideDeviceResolution.addChang
eListener(updateDeviceCheckboxStatus); | |
438 | |
439 function updateDeviceCheckboxStatus() | |
440 { | |
441 deviceCheckbox.checked = WebInspector.overridesSupport.settings.emul
ateViewport.get() && | |
442 WebInspector.overridesSupport.settings.emulateTouchEvents.get()
&& | |
443 WebInspector.overridesSupport.settings.overrideDeviceResolution.
get(); | |
444 } | |
445 | 394 |
446 // Screen | 395 // Screen |
447 this._screenSection = document.createElementWithClass("div", "responsive
-design-section"); | 396 this._screenSection = document.createElementWithClass("div", "responsive
-design-section responsive-design-screen-section"); |
448 this._screenSection.appendChild(WebInspector.SettingsUI.createSettingChe
ckbox("Screen", WebInspector.overridesSupport.settings.overrideDeviceResolution,
true)); | 397 var fieldsetElement = WebInspector.SettingsUI.createSettingFieldset(WebI
nspector.overridesSupport.settings.emulateDevice); |
449 | |
450 var fieldsetElement = WebInspector.SettingsUI.createSettingFieldset(WebI
nspector.overridesSupport.settings.overrideDeviceResolution); | |
451 this._screenSection.appendChild(fieldsetElement); | 398 this._screenSection.appendChild(fieldsetElement); |
452 fieldsetElement.createChild("div", "responsive-design-icon responsive-de
sign-icon-resolution").title = WebInspector.UIString("Screen resolution"); | 399 fieldsetElement.createChild("div", "responsive-design-icon responsive-de
sign-icon-resolution").title = WebInspector.UIString("Screen resolution"); |
453 | 400 |
454 fieldsetElement.appendChild(WebInspector.SettingsUI.createSettingInputFi
eld("", WebInspector.overridesSupport.settings.deviceWidth, true, 4, "3em", WebI
nspector.OverridesSupport.integerInputValidator, true)); | 401 fieldsetElement.appendChild(WebInspector.SettingsUI.createSettingInputFi
eld("", WebInspector.overridesSupport.settings.deviceWidth, true, 4, "3em", WebI
nspector.OverridesSupport.integerInputValidator, true)); |
455 fieldsetElement.appendChild(document.createTextNode(" \u00D7 ")); | 402 fieldsetElement.appendChild(document.createTextNode(" \u00D7 ")); |
456 fieldsetElement.appendChild(WebInspector.SettingsUI.createSettingInputFi
eld("", WebInspector.overridesSupport.settings.deviceHeight, true, 4, "3em", Web
Inspector.OverridesSupport.integerInputValidator, true)); | 403 fieldsetElement.appendChild(WebInspector.SettingsUI.createSettingInputFi
eld("", WebInspector.overridesSupport.settings.deviceHeight, true, 4, "3em", Web
Inspector.OverridesSupport.integerInputValidator, true)); |
457 | 404 |
458 this._swapDimensionsElement = fieldsetElement.createChild("button", "res
ponsive-design-icon responsive-design-icon-swap"); | 405 this._swapDimensionsElement = fieldsetElement.createChild("button", "res
ponsive-design-icon responsive-design-icon-swap"); |
459 this._swapDimensionsElement.title = WebInspector.UIString("Swap dimensio
ns"); | 406 this._swapDimensionsElement.title = WebInspector.UIString("Swap dimensio
ns"); |
460 this._swapDimensionsElement.addEventListener("click", WebInspector.overr
idesSupport.swapDimensions.bind(WebInspector.overridesSupport), false); | 407 this._swapDimensionsElement.addEventListener("click", WebInspector.overr
idesSupport.swapDimensions.bind(WebInspector.overridesSupport), false); |
461 | 408 |
462 fieldsetElement.createChild("div", "responsive-design-icon responsive-de
sign-icon-dpr").title = WebInspector.UIString("Device pixel ratio"); | 409 fieldsetElement.createChild("div", "responsive-design-icon responsive-de
sign-icon-dpr").title = WebInspector.UIString("Device pixel ratio"); |
463 fieldsetElement.appendChild(WebInspector.SettingsUI.createSettingInputFi
eld("", WebInspector.overridesSupport.settings.deviceScaleFactor, true, 4, "2.5e
m", WebInspector.OverridesSupport.doubleInputValidator, true)); | 410 fieldsetElement.appendChild(WebInspector.SettingsUI.createSettingInputFi
eld("", WebInspector.overridesSupport.settings.deviceScaleFactor, true, 4, "2.5e
m", WebInspector.OverridesSupport.doubleInputValidator, true)); |
464 | 411 |
465 // Touch and viewport | 412 // Touch and viewport. |
466 this._touchSection = document.createElementWithClass("div", "responsive-
design-section"); | 413 this._touchSection = document.createElementWithClass("div", "responsive-
design-section"); |
467 this._touchSection.appendChild(WebInspector.SettingsUI.createSettingChec
kbox(WebInspector.UIString("Touch"), WebInspector.overridesSupport.settings.emul
ateTouchEvents, true)); | 414 fieldsetElement = WebInspector.SettingsUI.createSettingFieldset(WebInspe
ctor.overridesSupport.settings.emulateDevice); |
468 this._touchSection.appendChild(WebInspector.SettingsUI.createSettingChec
kbox(WebInspector.UIString("Viewport"), WebInspector.overridesSupport.settings.e
mulateViewport, true)); | 415 fieldsetElement.appendChild(WebInspector.SettingsUI.createSettingCheckbo
x(WebInspector.UIString("Touch"), WebInspector.overridesSupport.settings.emulate
TouchEvents, true)); |
| 416 var viewportCheckbox = WebInspector.SettingsUI.createSettingCheckbox(Web
Inspector.UIString("Mobile"), WebInspector.overridesSupport.settings.emulateView
port, true); |
| 417 viewportCheckbox.title = WebInspector.UIString("Enable meta viewport, ov
erlay scrollbars and default 980px body width"); |
| 418 fieldsetElement.appendChild(viewportCheckbox); |
| 419 this._touchSection.appendChild(fieldsetElement); |
469 | 420 |
470 // Network. | 421 // Network. |
471 this._networkSection = document.createElementWithClass("div", "responsiv
e-design-section responsive-design-network"); | 422 this._networkSection = document.createElementWithClass("div", "responsiv
e-design-section responsive-design-network"); |
472 var networkCheckbox = WebInspector.SettingsUI.createSettingCheckbox(WebI
nspector.UIString("Network"), WebInspector.overridesSupport.settings.emulateNetw
orkConditions, true); | 423 var networkCheckbox = WebInspector.SettingsUI.createSettingCheckbox(WebI
nspector.UIString("Bandwidth"), WebInspector.overridesSupport.settings.emulateNe
tworkConditions, true); |
473 this._networkSection.appendChild(networkCheckbox); | 424 this._networkSection.appendChild(networkCheckbox); |
474 this._networkSection.appendChild(WebInspector.overridesSupport.createNet
workThroughputSelect(document)); | 425 this._networkSection.appendChild(WebInspector.overridesSupport.createNet
workThroughputSelect(document)); |
475 | 426 |
476 this._networkDomainsSection = document.createElementWithClass("div", "re
sponsive-design-section"); | 427 this._userAgentSection = document.createElementWithClass("div", "respons
ive-design-section responsive-design-user-agent-section"); |
477 fieldsetElement = WebInspector.SettingsUI.createSettingFieldset(WebInspe
ctor.overridesSupport.settings.emulateNetworkConditions); | 428 this._userAgentSection.appendChild(WebInspector.SettingsUI.createSetting
Label(WebInspector.UIString("User Agent:"), WebInspector.overridesSupport.settin
gs.userAgent, 25, "200px", WebInspector.overridesSupport.settings.overrideUserAg
ent, WebInspector.UIString("no override"))); |
478 var networkDomainsInput = WebInspector.SettingsUI.createSettingInputFiel
d("", WebInspector.overridesSupport.settings.networkConditionsDomains, false, 0,
"190px", WebInspector.OverridesSupport.networkDomainsValidator, false); | |
479 networkDomainsInput.querySelector("input").placeholder = WebInspector.UI
String("Leave empty to limit all domains"); | |
480 fieldsetElement.appendChild(networkDomainsInput); | |
481 this._networkDomainsSection.appendChild(fieldsetElement); | |
482 | 429 |
483 updateNetworkCheckboxTitle(); | 430 updateNetworkCheckboxTitle(); |
484 WebInspector.overridesSupport.settings.networkConditionsDomains.addChang
eListener(updateNetworkCheckboxTitle); | 431 WebInspector.overridesSupport.settings.networkConditionsDomains.addChang
eListener(updateNetworkCheckboxTitle); |
485 | 432 |
486 function updateNetworkCheckboxTitle() | 433 function updateNetworkCheckboxTitle() |
487 { | 434 { |
488 var domains = WebInspector.overridesSupport.settings.networkConditio
nsDomains.get(); | 435 var domains = WebInspector.overridesSupport.settings.networkConditio
nsDomains.get(); |
489 if (!domains.trim()) { | 436 if (!domains.trim()) { |
490 networkCheckbox.title = WebInspector.UIString("Limit for all dom
ains"); | 437 networkCheckbox.title = WebInspector.UIString("Limit for all dom
ains"); |
491 } else { | 438 } else { |
492 var trimmed = domains.split(",").map(function(s) { return s.trim
(); }).join(", "); | 439 var trimmed = domains.split(",").map(function(s) { return s.trim
(); }).join(", "); |
493 if (trimmed.length > 40) | 440 if (trimmed.length > 40) |
494 trimmed = trimmed.substring(0, 40) + "..."; | 441 trimmed = trimmed.substring(0, 40) + "..."; |
495 networkCheckbox.title = WebInspector.UIString("Limit for ") + tr
immed; | 442 networkCheckbox.title = WebInspector.UIString("Limit for ") + tr
immed; |
496 } | 443 } |
497 } | 444 } |
498 | 445 |
499 // User agent. | |
500 this._userAgentSection = document.createElementWithClass("div", "respons
ive-design-composite-section vbox solid"); | |
501 var userAgentRow = this._userAgentSection.createChild("div", "responsive
-design-composite-section hbox solid"); | |
502 userAgentRow.createChild("div", "responsive-design-section hbox").append
Child(WebInspector.SettingsUI.createSettingCheckbox("User Agent", WebInspector.o
verridesSupport.settings.overrideUserAgent, true)); | |
503 var userAgentSelectAndInput = WebInspector.overridesSupport.createUserAg
entSelectAndInput(document); | |
504 userAgentRow.createChild("div", "responsive-design-section hbox").append
Child(userAgentSelectAndInput.select); | |
505 this._userAgentSection.createChild("div", "responsive-design-section hbo
x").appendChild(userAgentSelectAndInput.input); | |
506 | |
507 this._toolbarExpandedChanged(); | 446 this._toolbarExpandedChanged(); |
508 }, | 447 }, |
509 | 448 |
510 _toggleToolbarExpanded: function() | 449 _toggleToolbarExpanded: function() |
511 { | 450 { |
512 WebInspector.settings.responsiveDesign.toolbarExpanded.set(!WebInspector
.settings.responsiveDesign.toolbarExpanded.get()); | 451 WebInspector.settings.responsiveDesign.toolbarExpanded.set(!WebInspector
.settings.responsiveDesign.toolbarExpanded.get()); |
513 }, | 452 }, |
514 | 453 |
515 _toolbarExpandedChanged: function() | 454 _toolbarExpandedChanged: function() |
516 { | 455 { |
517 var expanded = WebInspector.settings.responsiveDesign.toolbarExpanded.ge
t(); | 456 var expanded = WebInspector.settings.responsiveDesign.toolbarExpanded.ge
t(); |
518 this._expandButton.classList.toggle("expanded", expanded); | 457 this._expandButton.classList.toggle("expanded", expanded); |
519 this._expandButton.querySelector("span").textContent = WebInspector.UISt
ring(expanded ? "Collapse" : "Expand"); | 458 this._expandButton.querySelector("span").textContent = WebInspector.UISt
ring(expanded ? "Collapse" : "Expand"); |
520 | 459 |
521 if (expanded) { | 460 if (expanded) { |
522 this._expandedScreenTouchSection.setChildren([this._screenSection, t
his._touchSection]); | 461 this._expandedScreenTouchSection.setChildren([this._screenSection, t
his._touchSection]); |
523 this._expandedDeviceSection.setChildren([this._deviceSection, this._
expandedScreenTouchSection]); | 462 this._expandedDeviceSection.setChildren([this._deviceSection, this._
expandedScreenTouchSection]); |
524 this._expandedNetworkSection.setChildren([this._networkSection, this
._networkDomainsSection]); | 463 this._expandedNetworkSection.setChildren([this._networkSection, this
._userAgentSection]); |
525 this._toolbarSection.setChildren([this._expandSection, this._expande
dDeviceSection, this._userAgentSection, this._expandedNetworkSection]); | 464 this._toolbarSection.setChildren([this._expandSection, this._expande
dDeviceSection, this._expandedNetworkSection]); |
526 } else { | 465 } else { |
527 this._toolbarSection.setChildren([this._expandSection, this._deviceS
ection, this._screenSection, this._touchSection, this._networkSection]); | 466 this._toolbarSection.setChildren([this._expandSection, this._deviceS
ection, this._networkSection]); |
528 } | 467 } |
529 | 468 |
530 this.onResize(); | 469 this.onResize(); |
531 }, | 470 }, |
532 | 471 |
533 _overridesWarningUpdated: function() | 472 _overridesWarningUpdated: function() |
534 { | 473 { |
535 var message = WebInspector.overridesSupport.warningMessage(); | 474 var message = WebInspector.overridesSupport.warningMessage(); |
536 if (this._warningMessage.textContent === message) | 475 if (this._warningMessage.textContent === message) |
537 return; | 476 return; |
538 this._warningMessage.classList.toggle("hidden", !message); | 477 this._warningMessage.classList.toggle("hidden", !message); |
539 this._warningMessage.textContent = message; | 478 this._warningMessage.textContent = message; |
540 this._invalidateCache(); | 479 this._invalidateCache(); |
541 this.onResize(); | 480 this.onResize(); |
542 }, | 481 }, |
543 | 482 |
544 __proto__: WebInspector.VBox.prototype | 483 __proto__: WebInspector.VBox.prototype |
545 }; | 484 }; |
OLD | NEW |