Chromium Code Reviews| 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) | |
|
dgozman
2014/05/28 15:26:41
setPageResizer(null) in case of undocked.
pfeldman
2014/05/28 15:40:00
Done.
| |
| 58 return; | |
| 59 | |
| 60 var enabled = WebInspector.settings.responsiveDesignMode.get(); | |
| 61 if (enabled && !this._enabled) { | |
| 62 this._ignoreResize = true; | |
| 63 this._enabled = true; | |
| 64 this._inspectedPagePlaceholder.clearMinimumSizeAndMargins(); | |
| 65 this._inspectedPagePlaceholder.show(this._pageContainer); | |
| 66 this._responsiveDesignContainer.show(this.element); | |
| 67 WebInspector.overridesSupport.setPageResizer(this); | |
| 68 delete this._ignoreResize; | |
| 69 } | |
| 70 | |
| 71 if (!enabled && this._enabled) { | |
| 72 this._ignoreResize = true; | |
| 73 this._enabled = false; | |
| 74 this._scale = 0; | |
| 75 this._inspectedPagePlaceholder.restoreMinimumSizeAndMargins(); | |
| 76 this._responsiveDesignContainer.detach(); | |
| 77 this._inspectedPagePlaceholder.show(this.element); | |
| 78 WebInspector.overridesSupport.setPageResizer(null); | |
| 79 delete this._ignoreResize; | |
| 80 } | |
| 81 }, | |
| 82 | |
| 54 _updateOverridesSupportOnDockSideChange: function() | 83 _updateOverridesSupportOnDockSideChange: function() |
| 55 { | 84 { |
| 56 WebInspector.overridesSupport.setPageResizer(WebInspector.dockController .dockSide() !== WebInspector.DockController.State.Undocked ? this : null); | 85 this._responsiveDesignModeChanged(); |
| 57 }, | 86 }, |
| 58 | 87 |
| 59 /** | 88 /** |
| 60 * WebInspector.OverridesSupport.PageResizer override. | 89 * WebInspector.OverridesSupport.PageResizer override. |
| 61 * @param {number} dipWidth | 90 * @param {number} dipWidth |
| 62 * @param {number} dipHeight | 91 * @param {number} dipHeight |
| 63 * @param {number} scale | 92 * @param {number} scale |
| 64 */ | 93 */ |
| 65 enable: function(dipWidth, dipHeight, scale) | 94 update: function(dipWidth, dipHeight, scale) |
| 66 { | 95 { |
| 67 if (!this._enabled) { | 96 if (!this._enabled) |
| 68 this._ignoreResize = true; | 97 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 | 98 |
| 76 this._scale = scale; | 99 this._scale = scale; |
| 77 this._dipWidth = dipWidth; | 100 this._dipWidth = dipWidth; |
| 78 this._dipHeight = dipHeight; | 101 this._dipHeight = dipHeight; |
| 79 this._resolutionWidthLabel.textContent = dipWidth + "px"; | 102 this._resolutionWidthLabel.textContent = dipWidth + "px"; |
| 80 this._resolutionHeightLabel.textContent = dipHeight + "px"; | 103 this._resolutionHeightLabel.textContent = dipHeight + "px"; |
| 81 this._updateUI(); | 104 this._updateUI(); |
| 82 }, | 105 }, |
| 83 | 106 |
| 84 /** | 107 /** |
| 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. | 108 * WebInspector.OverridesSupport.PageResizer override. |
| 103 * @return {!Size} | 109 * @return {!Size} |
| 104 */ | 110 */ |
| 105 availableDipSize: function() | 111 availableDipSize: function() |
| 106 { | 112 { |
| 107 if (typeof this._availableSize === "undefined") { | 113 if (typeof this._availableSize === "undefined") { |
| 108 var zoomFactor = WebInspector.zoomManager.zoomFactor(); | 114 var zoomFactor = WebInspector.zoomManager.zoomFactor(); |
| 109 var rect = this.element.getBoundingClientRect(); | 115 var rect = this.element.getBoundingClientRect(); |
| 110 this._availableSize = new Size(rect.width * zoomFactor - WebInspecto r.ResponsiveDesignView.RulerWidth, | 116 this._availableSize = new Size(rect.width * zoomFactor - WebInspecto r.ResponsiveDesignView.RulerWidth, |
| 111 rect.height * zoomFactor - WebInspect or.ResponsiveDesignView.RulerWidth - WebInspector.ResponsiveDesignView.ToolbarHe ight); | 117 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 | 356 |
| 351 _onZoomChanged: function() | 357 _onZoomChanged: function() |
| 352 { | 358 { |
| 353 this._updateUI(); | 359 this._updateUI(); |
| 354 }, | 360 }, |
| 355 | 361 |
| 356 _createToolbar: function() | 362 _createToolbar: function() |
| 357 { | 363 { |
| 358 this._toolbarElement = this._responsiveDesignContainer.element.createChi ld("div", "responsive-design-toolbar"); | 364 this._toolbarElement = this._responsiveDesignContainer.element.createChi ld("div", "responsive-design-toolbar"); |
| 359 | 365 |
| 360 const metricsSetting = WebInspector.overridesSupport.settings.deviceMetr ics.get(); | 366 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 | 367 |
| 363 /** | 368 var fieldsetElement = WebInspector.SettingsUI.createSettingFieldset(WebI nspector.overridesSupport.settings.overrideDeviceResolution); |
| 364 * @this {WebInspector.ResponsiveDesignView} | 369 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 | 370 |
| 374 this._toolbarElement.appendChild(document.createTextNode("Screen")).titl e = WebInspector.UIString("Screen resolution"); | 371 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"); | 372 fieldsetElement.appendChild(document.createTextNode(" \u00D7 ")); |
| 376 this._toolbarElement.appendChild(document.createTextNode(" \u00D7 ")); | 373 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"); | 374 |
| 378 this._swapDimensionsElement = this._toolbarElement.createChild("button", "responsive-design-override-swap"); | 375 this._swapDimensionsElement = fieldsetElement.createChild("button", "res ponsive-design-override-swap"); |
| 379 this._swapDimensionsElement.appendChild(document.createTextNode(" \u21C4 ")); // RIGHTWARDS ARROW OVER LEFTWARDS ARROW. | 376 this._swapDimensionsElement.appendChild(document.createTextNode(" \u21C4 ")); // RIGHTWARDS ARROW OVER LEFTWARDS ARROW. |
| 380 this._swapDimensionsElement.title = WebInspector.UIString("Swap dimensio ns"); | 377 this._swapDimensionsElement.title = WebInspector.UIString("Swap dimensio ns"); |
| 381 this._swapDimensionsElement.addEventListener("click", swapDimensionsClic ked.bind(this), false); | 378 this._swapDimensionsElement.addEventListener("click", WebInspector.overr idesSupport.swapDimensions.bind(WebInspector.overridesSupport), false); |
| 382 this._swapDimensionsElement.tabIndex = -1; | 379 this._swapDimensionsElement.tabIndex = -1; |
| 383 | 380 |
| 384 var span = this._toolbarElement.createChild("span"); | 381 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"); | 382 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 }, | 383 }, |
| 419 | 384 |
| 420 __proto__: WebInspector.VBox.prototype | 385 __proto__: WebInspector.VBox.prototype |
| 421 }; | 386 }; |
| OLD | NEW |