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 24 matching lines...) Expand all Loading... |
35 this._heightSlider.createChild("div", "responsive-design-thumb-handle"); | 35 this._heightSlider.createChild("div", "responsive-design-thumb-handle"); |
36 this._createResizer(this._heightSlider, true); | 36 this._createResizer(this._heightSlider, true); |
37 | 37 |
38 this._inspectedPagePlaceholder = inspectedPagePlaceholder; | 38 this._inspectedPagePlaceholder = inspectedPagePlaceholder; |
39 inspectedPagePlaceholder.show(this.element); | 39 inspectedPagePlaceholder.show(this.element); |
40 | 40 |
41 this._enabled = false; | 41 this._enabled = false; |
42 | 42 |
43 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo
omChanged, this._onZoomChanged, this); | 43 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo
omChanged, this._onZoomChanged, this); |
44 WebInspector.dockController.addEventListener(WebInspector.DockController.Eve
nts.DockSideChanged, this._updateOverridesSupportOnDockSideChange, this); | 44 WebInspector.dockController.addEventListener(WebInspector.DockController.Eve
nts.DockSideChanged, this._updateOverridesSupportOnDockSideChange, this); |
| 45 WebInspector.settings.responsiveDesignMode.addChangeListener(this._responsiv
eDesignModeChanged, this); |
45 this._updateOverridesSupportOnDockSideChange(); | 46 this._updateOverridesSupportOnDockSideChange(); |
46 }; | 47 }; |
47 | 48 |
48 // Measured in DIP. | 49 // Measured in DIP. |
49 WebInspector.ResponsiveDesignView.SliderWidth = 19; | 50 WebInspector.ResponsiveDesignView.SliderWidth = 19; |
50 WebInspector.ResponsiveDesignView.RulerWidth = 20; | 51 WebInspector.ResponsiveDesignView.RulerWidth = 20; |
51 WebInspector.ResponsiveDesignView.ToolbarHeight = 24; | 52 WebInspector.ResponsiveDesignView.ToolbarHeight = 24; |
52 | 53 |
53 WebInspector.ResponsiveDesignView.prototype = { | 54 WebInspector.ResponsiveDesignView.prototype = { |
| 55 _responsiveDesignModeChanged: function() |
| 56 { |
| 57 if (WebInspector.dockController.dockSide() === WebInspector.DockControll
er.State.Undocked) { |
| 58 WebInspector.overridesSupport.setPageResizer(null); |
| 59 return; |
| 60 } |
| 61 |
| 62 delete this._cachedScale; |
| 63 delete this._cachedCssCanvasWidth; |
| 64 delete this._cachedCssCanvasHeight; |
| 65 delete this._cachedCssHeight; |
| 66 delete this._cachedCssWidth; |
| 67 delete this._cachedZoomFactor; |
| 68 delete this._availableSize; |
| 69 |
| 70 var enabled = WebInspector.settings.responsiveDesignMode.get(); |
| 71 if (enabled && !this._enabled) { |
| 72 this._ignoreResize = true; |
| 73 this._enabled = true; |
| 74 this._inspectedPagePlaceholder.clearMinimumSizeAndMargins(); |
| 75 this._inspectedPagePlaceholder.show(this._pageContainer); |
| 76 this._responsiveDesignContainer.show(this.element); |
| 77 WebInspector.overridesSupport.setPageResizer(this); |
| 78 delete this._ignoreResize; |
| 79 } |
| 80 |
| 81 if (!enabled && this._enabled) { |
| 82 this._ignoreResize = true; |
| 83 this._enabled = false; |
| 84 this._scale = 0; |
| 85 this._inspectedPagePlaceholder.restoreMinimumSizeAndMargins(); |
| 86 this._responsiveDesignContainer.detach(); |
| 87 this._inspectedPagePlaceholder.show(this.element); |
| 88 WebInspector.overridesSupport.setPageResizer(null); |
| 89 delete this._ignoreResize; |
| 90 } |
| 91 }, |
| 92 |
54 _updateOverridesSupportOnDockSideChange: function() | 93 _updateOverridesSupportOnDockSideChange: function() |
55 { | 94 { |
56 WebInspector.overridesSupport.setPageResizer(WebInspector.dockController
.dockSide() !== WebInspector.DockController.State.Undocked ? this : null); | 95 this._responsiveDesignModeChanged(); |
57 }, | 96 }, |
58 | 97 |
59 /** | 98 /** |
60 * WebInspector.OverridesSupport.PageResizer override. | 99 * WebInspector.OverridesSupport.PageResizer override. |
61 * @param {number} dipWidth | 100 * @param {number} dipWidth |
62 * @param {number} dipHeight | 101 * @param {number} dipHeight |
63 * @param {number} scale | 102 * @param {number} scale |
64 */ | 103 */ |
65 enable: function(dipWidth, dipHeight, scale) | 104 update: function(dipWidth, dipHeight, scale) |
66 { | 105 { |
67 if (!this._enabled) { | 106 if (!this._enabled) |
68 this._ignoreResize = true; | 107 return; |
69 this._enabled = true; | |
70 this._inspectedPagePlaceholder.clearMinimumSizeAndMargins(); | |
71 this._inspectedPagePlaceholder.show(this._pageContainer); | |
72 this._responsiveDesignContainer.show(this.element); | |
73 delete this._ignoreResize; | |
74 } | |
75 | 108 |
76 this._scale = scale; | 109 this._scale = scale; |
77 this._dipWidth = dipWidth; | 110 this._dipWidth = dipWidth; |
78 this._dipHeight = dipHeight; | 111 this._dipHeight = dipHeight; |
79 this._resolutionWidthLabel.textContent = dipWidth + "px"; | 112 this._resolutionWidthLabel.textContent = dipWidth + "px"; |
80 this._resolutionHeightLabel.textContent = dipHeight + "px"; | 113 this._resolutionHeightLabel.textContent = dipHeight + "px"; |
81 this._updateUI(); | 114 this._updateUI(); |
82 }, | 115 }, |
83 | 116 |
84 /** | 117 /** |
85 * WebInspector.OverridesSupport.PageResizer override. | |
86 */ | |
87 disable: function() | |
88 { | |
89 if (!this._enabled) | |
90 return; | |
91 | |
92 this._ignoreResize = true; | |
93 this._enabled = false; | |
94 this._scale = 0; | |
95 this._inspectedPagePlaceholder.restoreMinimumSizeAndMargins(); | |
96 this._responsiveDesignContainer.detach(); | |
97 this._inspectedPagePlaceholder.show(this.element); | |
98 delete this._ignoreResize; | |
99 }, | |
100 | |
101 /** | |
102 * WebInspector.OverridesSupport.PageResizer override. | 118 * WebInspector.OverridesSupport.PageResizer override. |
103 * @return {!Size} | 119 * @return {!Size} |
104 */ | 120 */ |
105 availableDipSize: function() | 121 availableDipSize: function() |
106 { | 122 { |
107 if (typeof this._availableSize === "undefined") { | 123 if (typeof this._availableSize === "undefined") { |
108 var zoomFactor = WebInspector.zoomManager.zoomFactor(); | 124 var zoomFactor = WebInspector.zoomManager.zoomFactor(); |
109 var rect = this.element.getBoundingClientRect(); | 125 var rect = this.element.getBoundingClientRect(); |
110 this._availableSize = new Size(rect.width * zoomFactor - WebInspecto
r.ResponsiveDesignView.RulerWidth, | 126 this._availableSize = new Size(rect.width * zoomFactor - WebInspecto
r.ResponsiveDesignView.RulerWidth, |
111 rect.height * zoomFactor - WebInspect
or.ResponsiveDesignView.RulerWidth - WebInspector.ResponsiveDesignView.ToolbarHe
ight); | 127 rect.height * zoomFactor - WebInspect
or.ResponsiveDesignView.RulerWidth - WebInspector.ResponsiveDesignView.ToolbarHe
ight); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 | 366 |
351 _onZoomChanged: function() | 367 _onZoomChanged: function() |
352 { | 368 { |
353 this._updateUI(); | 369 this._updateUI(); |
354 }, | 370 }, |
355 | 371 |
356 _createToolbar: function() | 372 _createToolbar: function() |
357 { | 373 { |
358 this._toolbarElement = this._responsiveDesignContainer.element.createChi
ld("div", "responsive-design-toolbar"); | 374 this._toolbarElement = this._responsiveDesignContainer.element.createChi
ld("div", "responsive-design-toolbar"); |
359 | 375 |
360 const metricsSetting = WebInspector.overridesSupport.settings.deviceMetr
ics.get(); | 376 this._toolbarElement.appendChild(WebInspector.SettingsUI.createSettingCh
eckbox(WebInspector.UIString("Resolution"), WebInspector.overridesSupport.settin
gs.overrideDeviceResolution, true)); |
361 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(m
etricsSetting); | |
362 | 377 |
363 /** | 378 var fieldsetElement = WebInspector.SettingsUI.createSettingFieldset(WebI
nspector.overridesSupport.settings.overrideDeviceResolution); |
364 * @this {WebInspector.ResponsiveDesignView} | 379 this._toolbarElement.appendChild(fieldsetElement); |
365 */ | |
366 function swapDimensionsClicked() | |
367 { | |
368 var widthValue = this._widthOverrideElement.value; | |
369 this._widthOverrideElement.value = this._heightOverrideElement.value
; | |
370 this._heightOverrideElement.value = widthValue; | |
371 this._applyDeviceMetricsUserInput(); | |
372 } | |
373 | 380 |
374 this._toolbarElement.appendChild(document.createTextNode("Screen")).titl
e = WebInspector.UIString("Screen resolution"); | 381 fieldsetElement.appendChild(WebInspector.SettingsUI.createSettingInputFi
eld("", WebInspector.overridesSupport.settings.deviceWidth, true, 4, "3em", WebI
nspector.OverridesSupport.inputValidator, true)); |
375 this._widthOverrideElement = WebInspector.SettingsUI.createInput(this._t
oolbarElement, "responsive-design-override-width", String(metrics.width), this._
applyDeviceMetricsUserInput.bind(this), true, "3em"); | 382 fieldsetElement.appendChild(document.createTextNode(" \u00D7 ")); |
376 this._toolbarElement.appendChild(document.createTextNode(" \u00D7 ")); | 383 fieldsetElement.appendChild(WebInspector.SettingsUI.createSettingInputFi
eld("", WebInspector.overridesSupport.settings.deviceHeight, true, 4, "3em", Web
Inspector.OverridesSupport.inputValidator, true)); |
377 this._heightOverrideElement = WebInspector.SettingsUI.createInput(this._
toolbarElement, "responsive-design-override-height", String(metrics.height), thi
s._applyDeviceMetricsUserInput.bind(this), true, "3em"); | 384 |
378 this._swapDimensionsElement = this._toolbarElement.createChild("button",
"responsive-design-override-swap"); | 385 this._swapDimensionsElement = fieldsetElement.createChild("button", "res
ponsive-design-override-swap"); |
379 this._swapDimensionsElement.appendChild(document.createTextNode(" \u21C4
")); // RIGHTWARDS ARROW OVER LEFTWARDS ARROW. | 386 this._swapDimensionsElement.appendChild(document.createTextNode(" \u21C4
")); // RIGHTWARDS ARROW OVER LEFTWARDS ARROW. |
380 this._swapDimensionsElement.title = WebInspector.UIString("Swap dimensio
ns"); | 387 this._swapDimensionsElement.title = WebInspector.UIString("Swap dimensio
ns"); |
381 this._swapDimensionsElement.addEventListener("click", swapDimensionsClic
ked.bind(this), false); | 388 this._swapDimensionsElement.addEventListener("click", WebInspector.overr
idesSupport.swapDimensions.bind(WebInspector.overridesSupport), false); |
382 this._swapDimensionsElement.tabIndex = -1; | 389 this._swapDimensionsElement.tabIndex = -1; |
383 | 390 |
384 var span = this._toolbarElement.createChild("span"); | 391 fieldsetElement.appendChild(WebInspector.SettingsUI.createSettingInputFi
eld(WebInspector.UIString("Dpr"), WebInspector.overridesSupport.settings.deviceS
caleFactor, true, 2, "2em", WebInspector.OverridesSupport.inputValidator, true))
; |
385 span.textContent = WebInspector.UIString("Dpr"); | 392 this._toolbarElement.appendChild(WebInspector.SettingsUI.createSettingCh
eckbox(WebInspector.UIString("Viewport"), WebInspector.overridesSupport.settings
.emulateViewport, true)); |
386 span.title = WebInspector.UIString("Device pixel ratio"); | |
387 this._deviceScaleFactorOverrideElement = WebInspector.SettingsUI.createI
nput(this._toolbarElement, "responsive-design-device-scale", String(metrics.devi
ceScaleFactor), this._applyDeviceMetricsUserInput.bind(this), true, "2em"); | |
388 | |
389 var textAutosizingOverrideElement = WebInspector.SettingsUI.createNonPer
sistedCheckbox(WebInspector.UIString("Enable text autosizing "), this._applyDevi
ceMetricsUserInput.bind(this)); | |
390 textAutosizingOverrideElement.title = WebInspector.UIString("Text autosi
zing is the feature that boosts font sizes on mobile devices."); | |
391 this._textAutosizingOverrideCheckbox = textAutosizingOverrideElement.fir
stChild; | |
392 this._textAutosizingOverrideCheckbox.checked = metrics.textAutosizing; | |
393 | |
394 var checkbox = WebInspector.SettingsUI.createSettingCheckbox(WebInspecto
r.UIString("Viewport"), WebInspector.overridesSupport.settings.emulateViewport,
true); | |
395 this._toolbarElement.appendChild(checkbox); | |
396 | |
397 WebInspector.overridesSupport.settings.deviceMetrics.addChangeListener(t
his._updateDeviceMetricsElement, this); | |
398 }, | |
399 | |
400 _updateDeviceMetricsElement: function() | |
401 { | |
402 const metricsSetting = WebInspector.overridesSupport.settings.deviceMetr
ics.get(); | |
403 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(m
etricsSetting); | |
404 | |
405 if (this._widthOverrideElement.value != metrics.width) | |
406 this._widthOverrideElement.value = metrics.width; | |
407 if (this._heightOverrideElement.value != metrics.height) | |
408 this._heightOverrideElement.value = metrics.height; | |
409 if (this._deviceScaleFactorOverrideElement.value != metrics.deviceScaleF
actor) | |
410 this._deviceScaleFactorOverrideElement.value = metrics.deviceScaleFa
ctor; | |
411 if (this._textAutosizingOverrideCheckbox.checked !== metrics.textAutosiz
ing) | |
412 this._textAutosizingOverrideCheckbox.checked = metrics.textAutosizin
g; | |
413 }, | |
414 | |
415 _applyDeviceMetricsUserInput: function() | |
416 { | |
417 WebInspector.OverridesSupport.DeviceMetrics.applyOverrides(this._widthOv
errideElement, this._heightOverrideElement, this._deviceScaleFactorOverrideEleme
nt, this._textAutosizingOverrideCheckbox); | |
418 }, | 393 }, |
419 | 394 |
420 __proto__: WebInspector.VBox.prototype | 395 __proto__: WebInspector.VBox.prototype |
421 }; | 396 }; |
OLD | NEW |