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 */ |
11 WebInspector.ResponsiveDesignView = function(inspectedPagePlaceholder) | 11 WebInspector.ResponsiveDesignView = function(inspectedPagePlaceholder) |
12 { | 12 { |
13 WebInspector.VBox.call(this); | 13 WebInspector.VBox.call(this); |
14 this.registerRequiredCSS("responsiveDesignView.css"); | 14 this.registerRequiredCSS("responsiveDesignView.css"); |
15 | 15 |
16 this._container = new WebInspector.View(); | 16 this._container = new WebInspector.View(); |
17 this._container.element.classList.add("responsive-design"); | 17 this._container.element.classList.add("responsive-design"); |
18 | 18 |
19 this._canvas = this._container.element.createChild("canvas", "fill"); | 19 this._canvas = this._container.element.createChild("canvas", "fill"); |
20 this._resetButton = this._container.element.createChild("div", "responsive-d
esign-reset-button"); | 20 this._resetButton = this._container.element.createChild("div", "responsive-d
esign-reset-button"); |
21 this._resetButton.addEventListener("click", this._reset.bind(this), false); | 21 this._resetButton.addEventListener("click", this._reset.bind(this), false); |
22 this._resetButton.title = WebInspector.UIString("Fit available space"); | 22 this._resetButton.title = WebInspector.UIString("Fit available space"); |
23 | 23 |
24 this._slidersContainer = this._container.element.createChild("div", "vbox re
sponsive-design-sliders-container"); | 24 this._slidersContainer = this._container.element.createChild("div", "vbox re
sponsive-design-sliders-container"); |
25 var hbox = this._slidersContainer.createChild("div", "hbox flex-auto"); | 25 var hbox = this._slidersContainer.createChild("div", "hbox flex-auto"); |
26 this._heightSliderContainer = this._slidersContainer.createChild("div", "hbo
x responsive-design-slider-height"); | 26 this._heightSliderContainer = this._slidersContainer.createChild("div", "hbo
x responsive-design-slider-height"); |
| 27 this._resolutionHeightLabel = this._heightSliderContainer.createChild("div",
"responsive-design-resolution-label responsive-design-resolution-height"); |
27 this._pageContainer = hbox.createChild("div", "vbox flex-auto"); | 28 this._pageContainer = hbox.createChild("div", "vbox flex-auto"); |
28 this._widthSliderContainer = hbox.createChild("div", "vbox responsive-design
-slider-width"); | 29 this._widthSliderContainer = hbox.createChild("div", "vbox responsive-design
-slider-width"); |
| 30 this._resolutionWidthLabel = this._widthSliderContainer.createChild("div", "
responsive-design-resolution-label responsive-design-resolution-width"); |
29 | 31 |
30 this._widthSlider = this._widthSliderContainer.createChild("div", "responsiv
e-design-slider-thumb"); | 32 this._widthSlider = this._widthSliderContainer.createChild("div", "responsiv
e-design-slider-thumb"); |
| 33 this._widthSlider.createChild("div", "responsive-design-thumb-handle"); |
31 this._createResizer(this._widthSlider, false); | 34 this._createResizer(this._widthSlider, false); |
32 this._widthZeroButton = this._widthSlider.createChild("div", "responsive-des
ign-zero-button"); | |
33 this._widthZeroButton.addEventListener("click", this._zeroButtonClicked.bind
(this, false)); | |
34 this._heightSlider = this._heightSliderContainer.createChild("div", "respons
ive-design-slider-thumb"); | 35 this._heightSlider = this._heightSliderContainer.createChild("div", "respons
ive-design-slider-thumb"); |
| 36 this._heightSlider.createChild("div", "responsive-design-thumb-handle"); |
35 this._createResizer(this._heightSlider, true); | 37 this._createResizer(this._heightSlider, true); |
36 this._heightZeroButton = this._heightSlider.createChild("div", "responsive-d
esign-zero-button"); | |
37 this._heightZeroButton.addEventListener("click", this._zeroButtonClicked.bin
d(this, true)); | |
38 | 38 |
39 this._inspectedPagePlaceholder = inspectedPagePlaceholder; | 39 this._inspectedPagePlaceholder = inspectedPagePlaceholder; |
40 inspectedPagePlaceholder.show(this.element); | 40 inspectedPagePlaceholder.show(this.element); |
41 | 41 |
42 this._enabled = false; | 42 this._enabled = false; |
43 | 43 |
44 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo
omChanged, this._onZoomChanged, this); | 44 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo
omChanged, this._onZoomChanged, this); |
45 WebInspector.dockController.addEventListener(WebInspector.DockController.Eve
nts.DockSideChanged, this._updateOverridesSupportOnDockSideChange, this); | 45 WebInspector.dockController.addEventListener(WebInspector.DockController.Eve
nts.DockSideChanged, this._updateOverridesSupportOnDockSideChange, this); |
46 this._updateOverridesSupportOnDockSideChange(); | 46 this._updateOverridesSupportOnDockSideChange(); |
47 }; | 47 }; |
(...skipping 21 matching lines...) Expand all Loading... |
69 this._enabled = true; | 69 this._enabled = true; |
70 this._inspectedPagePlaceholder.clearMinimumSizeAndMargins(); | 70 this._inspectedPagePlaceholder.clearMinimumSizeAndMargins(); |
71 this._inspectedPagePlaceholder.show(this._pageContainer); | 71 this._inspectedPagePlaceholder.show(this._pageContainer); |
72 this._container.show(this.element); | 72 this._container.show(this.element); |
73 delete this._ignoreResize; | 73 delete this._ignoreResize; |
74 } | 74 } |
75 | 75 |
76 this._scale = scale; | 76 this._scale = scale; |
77 this._dipWidth = dipWidth; | 77 this._dipWidth = dipWidth; |
78 this._dipHeight = dipHeight; | 78 this._dipHeight = dipHeight; |
| 79 this._resolutionWidthLabel.textContent = dipWidth + "px"; |
| 80 this._resolutionHeightLabel.textContent = dipHeight + "px"; |
79 this._updateUI(); | 81 this._updateUI(); |
80 }, | 82 }, |
81 | 83 |
82 /** | 84 /** |
83 * WebInspector.OverridesSupport.PageResizer override. | 85 * WebInspector.OverridesSupport.PageResizer override. |
84 */ | 86 */ |
85 disable: function() | 87 disable: function() |
86 { | 88 { |
87 if (!this._enabled) | 89 if (!this._enabled) |
88 return; | 90 return; |
89 | 91 |
90 this._ignoreResize = true; | 92 this._ignoreResize = true; |
91 this._enabled = false; | 93 this._enabled = false; |
92 this._scale = 0; | 94 this._scale = 0; |
93 this._inspectedPagePlaceholder.restoreMinimumSizeAndMargins(); | 95 this._inspectedPagePlaceholder.restoreMinimumSizeAndMargins(); |
94 this._container.detach(); | 96 this._container.detach(); |
95 this._inspectedPagePlaceholder.show(this.element); | 97 this._inspectedPagePlaceholder.show(this.element); |
96 delete this._ignoreResize; | 98 delete this._ignoreResize; |
97 }, | 99 }, |
98 | 100 |
99 /** | 101 /** |
100 * WebInspector.OverridesSupport.PageResizer override. | 102 * WebInspector.OverridesSupport.PageResizer override. |
101 * @return {!Size} | 103 * @return {!Size} |
102 */ | 104 */ |
103 availableDipSize: function() | 105 availableDipSize: function() |
104 { | 106 { |
105 if (typeof this._availableSize === "undefined") { | 107 if (typeof this._availableSize === "undefined") { |
106 var zoomFactor = WebInspector.zoomManager.zoomFactor(); | 108 var zoomFactor = WebInspector.zoomManager.zoomFactor(); |
107 var rect = this.element.getBoundingClientRect(); | 109 var rect = this.element.getBoundingClientRect(); |
108 this._availableSize = new Size(rect.width * zoomFactor - WebInspecto
r.ResponsiveDesignView.SliderWidth - WebInspector.ResponsiveDesignView.RulerWidt
h, | 110 this._availableSize = new Size(rect.width * zoomFactor - WebInspecto
r.ResponsiveDesignView.RulerWidth, |
109 rect.height * zoomFactor - WebInspect
or.ResponsiveDesignView.SliderWidth - WebInspector.ResponsiveDesignView.RulerWid
th); | 111 rect.height * zoomFactor - WebInspect
or.ResponsiveDesignView.RulerWidth); |
110 } | 112 } |
111 return this._availableSize; | 113 return this._availableSize; |
112 }, | 114 }, |
113 | 115 |
114 /** | 116 /** |
115 * @param {!Element} element | 117 * @param {!Element} element |
116 * @param {boolean} vertical | 118 * @param {boolean} vertical |
117 * @return {!WebInspector.ResizerWidget} | 119 * @return {!WebInspector.ResizerWidget} |
118 */ | 120 */ |
119 _createResizer: function(element, vertical) | 121 _createResizer: function(element, vertical) |
(...skipping 16 matching lines...) Expand all Loading... |
136 this._resizeStartSize = event.target.isVertical() ? (this._dipHeight ||
available.height) : (this._dipWidth || available.width); | 138 this._resizeStartSize = event.target.isVertical() ? (this._dipHeight ||
available.height) : (this._dipWidth || available.width); |
137 }, | 139 }, |
138 | 140 |
139 /** | 141 /** |
140 * @param {!WebInspector.Event} event | 142 * @param {!WebInspector.Event} event |
141 */ | 143 */ |
142 _onResizeUpdate: function(event) | 144 _onResizeUpdate: function(event) |
143 { | 145 { |
144 var cssOffset = event.data.currentPosition - event.data.startPosition; | 146 var cssOffset = event.data.currentPosition - event.data.startPosition; |
145 var dipOffset = cssOffset * WebInspector.zoomManager.zoomFactor(); | 147 var dipOffset = cssOffset * WebInspector.zoomManager.zoomFactor(); |
146 var newSize = this._resizeStartSize + dipOffset; | 148 var newSize = Math.max(this._resizeStartSize + dipOffset, 1); |
147 var requested = new Size(this._dipWidth, this._dipHeight); | 149 var requested = new Size(this._dipWidth, this._dipHeight); |
148 if (event.target.isVertical()) | 150 if (event.target.isVertical()) |
149 requested.height = Number.constrain(newSize, 1, this.availableDipSiz
e().height); | 151 requested.height = newSize; |
150 else | 152 else |
151 requested.width = Number.constrain(newSize, 1, this.availableDipSize
().width); | 153 requested.width = newSize; |
152 this.dispatchEventToListeners(WebInspector.OverridesSupport.PageResizer.
Events.ResizeRequested, requested); | 154 this.dispatchEventToListeners(WebInspector.OverridesSupport.PageResizer.
Events.ResizeRequested, requested); |
153 }, | 155 }, |
154 | 156 |
155 /** | 157 /** |
156 * @param {!WebInspector.Event} event | 158 * @param {!WebInspector.Event} event |
157 */ | 159 */ |
158 _onResizeEnd: function(event) | 160 _onResizeEnd: function(event) |
159 { | 161 { |
160 delete this._resizeStartSize; | 162 delete this._resizeStartSize; |
161 }, | 163 }, |
162 | 164 |
163 /** | 165 /** |
164 * @param {boolean} isHeight | |
165 */ | |
166 _zeroButtonClicked: function(isHeight) | |
167 { | |
168 var size = new Size(this._dipWidth, this._dipHeight); | |
169 var available = this.availableDipSize(); | |
170 if (isHeight) | |
171 size.height = this._dipHeight ? 0 : available.height; | |
172 else | |
173 size.width = this._dipWidth ? 0 : available.width; | |
174 this.dispatchEventToListeners(WebInspector.OverridesSupport.PageResizer.
Events.ResizeRequested, size); | |
175 }, | |
176 | |
177 /** | |
178 * Draws canvas of the specified css size in DevTools page space. | 166 * Draws canvas of the specified css size in DevTools page space. |
179 * Canvas contains grid and rulers. | 167 * Canvas contains grid and rulers. |
180 * @param {number} cssCanvasWidth | 168 * @param {number} cssCanvasWidth |
181 * @param {number} cssCanvasHeight | 169 * @param {number} cssCanvasHeight |
182 */ | 170 */ |
183 _drawCanvas: function(cssCanvasWidth, cssCanvasHeight) | 171 _drawCanvas: function(cssCanvasWidth, cssCanvasHeight) |
184 { | 172 { |
185 if (!this._enabled) | 173 if (!this._enabled) |
186 return; | 174 return; |
187 | 175 |
188 var canvas = this._canvas; | 176 var canvas = this._canvas; |
189 var context = canvas.getContext("2d"); | 177 var context = canvas.getContext("2d"); |
190 canvas.style.width = cssCanvasWidth + "px"; | 178 canvas.style.width = cssCanvasWidth + "px"; |
191 canvas.style.height = cssCanvasHeight + "px"; | 179 canvas.style.height = cssCanvasHeight + "px"; |
192 | 180 |
193 var zoomFactor = WebInspector.zoomManager.zoomFactor(); | 181 var zoomFactor = WebInspector.zoomManager.zoomFactor(); |
194 var dipCanvasWidth = cssCanvasWidth * zoomFactor; | 182 var dipCanvasWidth = cssCanvasWidth * zoomFactor; |
195 var dipCanvasHeight = cssCanvasHeight * zoomFactor; | 183 var dipCanvasHeight = cssCanvasHeight * zoomFactor; |
196 | 184 |
197 var deviceScaleFactor = window.devicePixelRatio; | 185 var deviceScaleFactor = window.devicePixelRatio; |
198 canvas.width = deviceScaleFactor * cssCanvasWidth; | 186 canvas.width = deviceScaleFactor * cssCanvasWidth; |
199 canvas.height = deviceScaleFactor * cssCanvasHeight; | 187 canvas.height = deviceScaleFactor * cssCanvasHeight; |
200 context.scale(canvas.width / dipCanvasWidth, canvas.height / dipCanvasHe
ight); | 188 context.scale(canvas.width / dipCanvasWidth, canvas.height / dipCanvasHe
ight); |
201 | 189 |
202 context.font = "10px " + WebInspector.monospaceFontFamily(); | 190 context.font = "11px " + WebInspector.fontFamily(); |
203 | 191 |
| 192 const rulerStep = 100; |
| 193 const rulerSubStep = 5; |
| 194 const gridStep = 50; |
204 const gridSubStep = 10; | 195 const gridSubStep = 10; |
205 const gridStep = 50; | 196 const rulerBackgroundColor = "rgb(64, 64, 64)"; |
206 const rulerBackgroundColor = "rgb(54, 54, 54)"; | |
207 const backgroundColor = "rgb(102, 102, 102)"; | 197 const backgroundColor = "rgb(102, 102, 102)"; |
208 const lightLineColor = "rgb(132, 132, 132)"; | 198 const lightLineColor = "rgb(132, 132, 132)"; |
209 const darkLineColor = "rgb(114, 114, 114)"; | 199 const darkLineColor = "rgb(114, 114, 114)"; |
210 const textColor = "rgb(180, 180, 180)"; | 200 const textColor = "rgb(220, 220, 220)"; |
211 | 201 |
212 var scale = this._scale || 1; | 202 var scale = this._scale || 1; |
213 var rulerWidth = WebInspector.ResponsiveDesignView.RulerWidth; | 203 var rulerWidth = WebInspector.ResponsiveDesignView.RulerWidth; |
214 var dipGridWidth = dipCanvasWidth / scale - rulerWidth; | 204 var dipGridWidth = dipCanvasWidth / scale - rulerWidth; |
215 var dipGridHeight = dipCanvasHeight / scale - rulerWidth; | 205 var dipGridHeight = dipCanvasHeight / scale - rulerWidth; |
216 rulerWidth /= scale; | 206 rulerWidth /= scale; |
217 context.scale(scale, scale); | 207 context.scale(scale, scale); |
218 context.translate(rulerWidth, rulerWidth); | 208 context.translate(rulerWidth, rulerWidth); |
219 | 209 |
220 context.fillStyle = rulerBackgroundColor; | 210 context.fillStyle = rulerBackgroundColor; |
221 context.fillRect(0, -rulerWidth, dipGridWidth, rulerWidth); | 211 context.fillRect(0, -rulerWidth, dipGridWidth, rulerWidth); |
222 context.fillRect(-rulerWidth, 0, rulerWidth, dipGridHeight); | 212 context.fillRect(-rulerWidth, 0, rulerWidth, dipGridHeight); |
223 | 213 |
224 context.fillStyle = backgroundColor; | 214 context.fillStyle = backgroundColor; |
225 context.fillRect(0, 0, dipGridWidth, dipGridHeight); | 215 context.fillRect(0, 0, dipGridWidth, dipGridHeight); |
226 | 216 |
227 context.translate(0.5, 0.5); | 217 context.translate(0.5, 0.5); |
| 218 context.strokeStyle = textColor; |
228 context.fillStyle = textColor; | 219 context.fillStyle = textColor; |
229 context.lineWidth = 1; | 220 context.lineWidth = 1; |
230 | 221 |
| 222 // Draw vertical ruler. |
| 223 for (var x = 0; x < dipGridWidth; x += rulerSubStep) { |
| 224 var color = darkLineColor; |
| 225 var y = -rulerWidth / 4; |
| 226 if (!(x % (rulerStep / 2))) |
| 227 y = -rulerWidth / 2; |
| 228 |
| 229 if (!(x % rulerStep)) { |
| 230 if (x) { |
| 231 context.save(); |
| 232 context.translate(x, 0); |
| 233 context.fillText(x, 2, -rulerWidth / 2); |
| 234 context.restore(); |
| 235 } |
| 236 y = -rulerWidth; |
| 237 } |
| 238 |
| 239 context.beginPath(); |
| 240 context.moveTo(x, y); |
| 241 context.lineTo(x, 0); |
| 242 context.stroke(); |
| 243 } |
| 244 |
| 245 // Draw horizontal ruler. |
| 246 for (var y = 0; y < dipGridHeight; y += rulerSubStep) { |
| 247 var color = darkLineColor; |
| 248 x = -rulerWidth / 4; |
| 249 if (!(y % (rulerStep / 2))) |
| 250 x = -rulerWidth / 2; |
| 251 |
| 252 if (!(y % rulerStep)) { |
| 253 if (y) { |
| 254 context.save(); |
| 255 context.translate(0, y); |
| 256 context.rotate(-Math.PI / 2); |
| 257 context.fillText(y, 2, -rulerWidth / 2); |
| 258 context.restore(); |
| 259 } |
| 260 x = -rulerWidth; |
| 261 } |
| 262 |
| 263 context.beginPath(); |
| 264 context.moveTo(x, y); |
| 265 context.lineTo(0, y); |
| 266 context.stroke(); |
| 267 } |
| 268 |
| 269 // Draw grid. |
| 270 drawGrid(darkLineColor, gridSubStep); |
| 271 drawGrid(lightLineColor, gridStep); |
| 272 |
| 273 /** |
| 274 * @param {string} color |
| 275 * @param {number} step |
| 276 */ |
| 277 function drawGrid(color, step) |
231 { | 278 { |
232 // Draw vertical lines. | 279 context.strokeStyle = color; |
233 for (var x = 0; x < dipGridWidth; x += gridSubStep) { | 280 for (var x = 0; x < dipGridWidth; x += step) { |
234 var color = darkLineColor; | |
235 var y = -rulerWidth / 6; | |
236 if (!(x % (2 * gridSubStep))) | |
237 y = -rulerWidth / 3; | |
238 if (!(x % gridStep)) { | |
239 if (x) { | |
240 context.save(); | |
241 context.translate(x, 0); | |
242 context.fillText(x, 2, -rulerWidth / 2); | |
243 context.restore(); | |
244 } | |
245 y = -rulerWidth; | |
246 color = lightLineColor; | |
247 } | |
248 context.strokeStyle = color; | |
249 | |
250 context.beginPath(); | 281 context.beginPath(); |
251 context.moveTo(x, y); | 282 context.moveTo(x, 0); |
252 context.lineTo(x, dipGridHeight); | 283 context.lineTo(x, dipGridHeight); |
253 context.stroke(); | 284 context.stroke(); |
254 } | 285 } |
255 } | 286 for (var y = 0; y < dipGridHeight; y += step) { |
256 | |
257 { | |
258 // Draw horizontal lines. | |
259 for (var y = 0; y < dipGridHeight; y += gridSubStep) { | |
260 var color = darkLineColor; | |
261 var x = -rulerWidth / 6; | |
262 if (!(y % (2 * gridSubStep))) | |
263 x = -rulerWidth / 3; | |
264 if (!(y % gridStep)) { | |
265 if (y) { | |
266 context.save(); | |
267 context.translate(0, y); | |
268 context.rotate(-Math.PI / 2); | |
269 context.fillText(y, 2, -rulerWidth / 2); | |
270 context.restore(); | |
271 } | |
272 x = -rulerWidth; | |
273 color = lightLineColor; | |
274 } | |
275 context.strokeStyle = color; | |
276 | |
277 context.beginPath(); | 287 context.beginPath(); |
278 context.moveTo(x, y); | 288 context.moveTo(0, y); |
279 context.lineTo(dipGridWidth, y); | 289 context.lineTo(dipGridWidth, y); |
280 context.stroke(); | 290 context.stroke(); |
281 } | 291 } |
282 context.restore(); | |
283 } | 292 } |
284 }, | 293 }, |
285 | 294 |
286 _updateUI: function() | 295 _updateUI: function() |
287 { | 296 { |
288 if (!this._enabled) | 297 if (!this._enabled) |
289 return; | 298 return; |
290 | 299 |
291 var zoomFactor = WebInspector.zoomManager.zoomFactor(); | 300 var zoomFactor = WebInspector.zoomManager.zoomFactor(); |
292 var rect = this._canvas.parentElement.getBoundingClientRect(); | 301 var rect = this._canvas.parentElement.getBoundingClientRect(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 _onZoomChanged: function() | 353 _onZoomChanged: function() |
345 { | 354 { |
346 this._updateUI(); | 355 this._updateUI(); |
347 }, | 356 }, |
348 | 357 |
349 /** | 358 /** |
350 * Resets emulated size to available space. | 359 * Resets emulated size to available space. |
351 */ | 360 */ |
352 _reset: function() | 361 _reset: function() |
353 { | 362 { |
354 this.dispatchEventToListeners(WebInspector.OverridesSupport.PageResizer.
Events.ResizeRequested, this.availableDipSize()); | 363 var availableDipSize = this.availableDipSize(); |
| 364 var size = new Size(availableDipSize.width - WebInspector.ResponsiveDesi
gnView.SliderWidth, |
| 365 availableDipSize.height - WebInspector.ResponsiveDes
ignView.SliderWidth); |
| 366 this.dispatchEventToListeners(WebInspector.OverridesSupport.PageResizer.
Events.ResizeRequested, size); |
355 }, | 367 }, |
356 | 368 |
357 __proto__: WebInspector.VBox.prototype | 369 __proto__: WebInspector.VBox.prototype |
358 }; | 370 }; |
OLD | NEW |