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.View} innerView |
10 */ | 10 */ |
11 WebInspector.ResponsiveDesignView = function(inspectedPagePlaceholder) | 11 WebInspector.ResponsiveDesignView = function(innerView) |
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._pageContainer = hbox.createChild("div", "vbox flex-auto"); | 27 this._pageContainer = hbox.createChild("div", "vbox flex-auto"); |
28 this._widthSliderContainer = hbox.createChild("div", "vbox responsive-design
-slider-width"); | 28 this._widthSliderContainer = hbox.createChild("div", "vbox responsive-design
-slider-width"); |
29 | 29 |
30 this._widthSlider = this._widthSliderContainer.createChild("div", "responsiv
e-design-slider-thumb"); | 30 this._widthSlider = this._widthSliderContainer.createChild("div", "responsiv
e-design-slider-thumb"); |
31 this._createResizer(this._widthSlider, false); | 31 this._createResizer(this._widthSlider, false); |
32 this._widthZeroButton = this._widthSlider.createChild("div", "responsive-des
ign-zero-button"); | 32 this._widthZeroButton = this._widthSlider.createChild("div", "responsive-des
ign-zero-button"); |
33 this._widthZeroButton.addEventListener("click", this._zeroButtonClicked.bind
(this, false)); | 33 this._widthZeroButton.addEventListener("click", this._zeroButtonClicked.bind
(this, false)); |
34 this._heightSlider = this._heightSliderContainer.createChild("div", "respons
ive-design-slider-thumb"); | 34 this._heightSlider = this._heightSliderContainer.createChild("div", "respons
ive-design-slider-thumb"); |
35 this._createResizer(this._heightSlider, true); | 35 this._createResizer(this._heightSlider, true); |
36 this._heightZeroButton = this._heightSlider.createChild("div", "responsive-d
esign-zero-button"); | 36 this._heightZeroButton = this._heightSlider.createChild("div", "responsive-d
esign-zero-button"); |
37 this._heightZeroButton.addEventListener("click", this._zeroButtonClicked.bin
d(this, true)); | 37 this._heightZeroButton.addEventListener("click", this._zeroButtonClicked.bin
d(this, true)); |
38 | 38 |
39 this._inspectedPagePlaceholder = inspectedPagePlaceholder; | 39 this._innerView = innerView; |
40 inspectedPagePlaceholder.show(this.element); | 40 this._innerView.show(this.element); |
41 | 41 |
42 this._enabled = false; | 42 this._enabled = false; |
43 | |
44 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo
omChanged, this._onZoomChanged, this); | |
45 WebInspector.dockController.addEventListener(WebInspector.DockController.Eve
nts.DockSideChanged, this._updateOverridesSupportOnDockSideChange, this); | |
46 this._updateOverridesSupportOnDockSideChange(); | |
47 }; | 43 }; |
48 | 44 |
49 // Measured in DIP. | 45 // Measured in DIP. |
50 WebInspector.ResponsiveDesignView.SliderWidth = 19; | 46 WebInspector.ResponsiveDesignView.SliderWidth = 19; |
51 WebInspector.ResponsiveDesignView.RulerWidth = 23; | 47 WebInspector.ResponsiveDesignView.RulerWidth = 23; |
52 | 48 |
| 49 WebInspector.ResponsiveDesignView.Events = { |
| 50 Toggled: "Toggled", |
| 51 ResizeRequested: "ResizeRequested", |
| 52 AvailableSizeChanged: "AvailableSizeChanged" |
| 53 }; |
| 54 |
53 WebInspector.ResponsiveDesignView.prototype = { | 55 WebInspector.ResponsiveDesignView.prototype = { |
54 _updateOverridesSupportOnDockSideChange: function() | |
55 { | |
56 WebInspector.overridesSupport.setPageResizer(WebInspector.dockController
.dockSide() !== WebInspector.DockController.State.Undocked ? this : null); | |
57 }, | |
58 | |
59 /** | 56 /** |
60 * WebInspector.OverridesSupport.PageResizer override. | 57 * WebInspector.OverridesSupport.PageResizer override. |
61 * @param {number} dipWidth | 58 * @param {number} dipWidth |
62 * @param {number} dipHeight | 59 * @param {number} dipHeight |
63 * @param {number} scale | 60 * @param {number} scale |
64 */ | 61 */ |
65 enable: function(dipWidth, dipHeight, scale) | 62 enable: function(dipWidth, dipHeight, scale) |
66 { | 63 { |
67 if (!this._enabled) { | 64 if (!this._enabled) { |
| 65 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.E
vents.ZoomChanged, this._updateUI, this); |
68 this._ignoreResize = true; | 66 this._ignoreResize = true; |
69 this._enabled = true; | 67 this._enabled = true; |
70 this._inspectedPagePlaceholder.clearMinimumSizeAndMargins(); | 68 this.dispatchEventToListeners(WebInspector.ResponsiveDesignView.Even
ts.Toggled, true); |
71 this._inspectedPagePlaceholder.show(this._pageContainer); | 69 this._innerView.show(this._pageContainer); |
72 this._container.show(this.element); | 70 this._container.show(this.element); |
73 delete this._ignoreResize; | 71 delete this._ignoreResize; |
74 } | 72 } |
75 | 73 |
76 this._scale = scale; | 74 this._scale = scale; |
77 this._dipWidth = dipWidth; | 75 this._dipWidth = dipWidth; |
78 this._dipHeight = dipHeight; | 76 this._dipHeight = dipHeight; |
79 this._updateUI(); | 77 this._updateUI(); |
80 }, | 78 }, |
81 | 79 |
82 /** | 80 /** |
83 * WebInspector.OverridesSupport.PageResizer override. | 81 * WebInspector.OverridesSupport.PageResizer override. |
84 */ | 82 */ |
85 disable: function() | 83 disable: function() |
86 { | 84 { |
87 if (!this._enabled) | 85 if (!this._enabled) |
88 return; | 86 return; |
89 | 87 |
| 88 WebInspector.zoomManager.removeEventListener(WebInspector.ZoomManager.Ev
ents.ZoomChanged, this._updateUI, this); |
90 this._ignoreResize = true; | 89 this._ignoreResize = true; |
91 this._enabled = false; | 90 this._enabled = false; |
92 this._scale = 0; | 91 this._scale = 0; |
93 this._inspectedPagePlaceholder.restoreMinimumSizeAndMargins(); | 92 this.dispatchEventToListeners(WebInspector.ResponsiveDesignView.Events.T
oggled, false); |
| 93 //this._inspectedPagePlaceholder.restoreMinimumSizeAndMargins(); |
94 this._container.detach(); | 94 this._container.detach(); |
95 this._inspectedPagePlaceholder.show(this.element); | 95 this._innerView.show(this.element); |
96 delete this._ignoreResize; | 96 delete this._ignoreResize; |
97 }, | 97 }, |
98 | 98 |
99 /** | 99 /** |
100 * WebInspector.OverridesSupport.PageResizer override. | 100 * WebInspector.OverridesSupport.PageResizer override. |
101 * @return {!Size} | 101 * @return {!Size} |
102 */ | 102 */ |
103 availableDipSize: function() | 103 availableDipSize: function() |
104 { | 104 { |
105 if (typeof this._availableSize === "undefined") { | 105 if (typeof this._availableSize === "undefined") { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 _onResizeUpdate: function(event) | 142 _onResizeUpdate: function(event) |
143 { | 143 { |
144 var cssOffset = event.data.currentPosition - event.data.startPosition; | 144 var cssOffset = event.data.currentPosition - event.data.startPosition; |
145 var dipOffset = cssOffset * WebInspector.zoomManager.zoomFactor(); | 145 var dipOffset = cssOffset * WebInspector.zoomManager.zoomFactor(); |
146 var newSize = this._resizeStartSize + dipOffset; | 146 var newSize = this._resizeStartSize + dipOffset; |
147 var requested = new Size(this._dipWidth, this._dipHeight); | 147 var requested = new Size(this._dipWidth, this._dipHeight); |
148 if (event.target.isVertical()) | 148 if (event.target.isVertical()) |
149 requested.height = Number.constrain(newSize, 1, this.availableDipSiz
e().height); | 149 requested.height = Number.constrain(newSize, 1, this.availableDipSiz
e().height); |
150 else | 150 else |
151 requested.width = Number.constrain(newSize, 1, this.availableDipSize
().width); | 151 requested.width = Number.constrain(newSize, 1, this.availableDipSize
().width); |
152 this.dispatchEventToListeners(WebInspector.OverridesSupport.PageResizer.
Events.ResizeRequested, requested); | 152 this.dispatchEventToListeners(WebInspector.ResponsiveDesignView.Events.R
esizeRequested, requested); |
153 }, | 153 }, |
154 | 154 |
155 /** | 155 /** |
156 * @param {!WebInspector.Event} event | 156 * @param {!WebInspector.Event} event |
157 */ | 157 */ |
158 _onResizeEnd: function(event) | 158 _onResizeEnd: function(event) |
159 { | 159 { |
160 delete this._resizeStartSize; | 160 delete this._resizeStartSize; |
161 }, | 161 }, |
162 | 162 |
163 /** | 163 /** |
164 * @param {boolean} isHeight | 164 * @param {boolean} isHeight |
165 */ | 165 */ |
166 _zeroButtonClicked: function(isHeight) | 166 _zeroButtonClicked: function(isHeight) |
167 { | 167 { |
168 var size = new Size(this._dipWidth, this._dipHeight); | 168 var size = new Size(this._dipWidth, this._dipHeight); |
169 var available = this.availableDipSize(); | 169 var available = this.availableDipSize(); |
170 if (isHeight) | 170 if (isHeight) |
171 size.height = this._dipHeight ? 0 : available.height; | 171 size.height = this._dipHeight ? 0 : available.height; |
172 else | 172 else |
173 size.width = this._dipWidth ? 0 : available.width; | 173 size.width = this._dipWidth ? 0 : available.width; |
174 this.dispatchEventToListeners(WebInspector.OverridesSupport.PageResizer.
Events.ResizeRequested, size); | 174 this.dispatchEventToListeners(WebInspector.ResponsiveDesignView.Events.R
esizeRequested, size); |
175 }, | 175 }, |
176 | 176 |
177 /** | 177 /** |
178 * Draws canvas of the specified css size in DevTools page space. | 178 * Draws canvas of the specified css size in DevTools page space. |
179 * Canvas contains grid and rulers. | 179 * Canvas contains grid and rulers. |
180 * @param {number} cssCanvasWidth | 180 * @param {number} cssCanvasWidth |
181 * @param {number} cssCanvasHeight | 181 * @param {number} cssCanvasHeight |
182 */ | 182 */ |
183 _drawCanvas: function(cssCanvasWidth, cssCanvasHeight) | 183 _drawCanvas: function(cssCanvasWidth, cssCanvasHeight) |
184 { | 184 { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 this._heightSliderContainer.style.marginBottom = "-" + cssSliderWidt
h; | 311 this._heightSliderContainer.style.marginBottom = "-" + cssSliderWidt
h; |
312 this._widthSliderContainer.style.flexBasis = cssSliderWidth; | 312 this._widthSliderContainer.style.flexBasis = cssSliderWidth; |
313 this._widthSliderContainer.style.marginRight = "-" + cssSliderWidth; | 313 this._widthSliderContainer.style.marginRight = "-" + cssSliderWidth; |
314 } | 314 } |
315 | 315 |
316 var cssWidth = this._dipWidth ? (this._dipWidth / zoomFactor + "px") : (
availableDip.width / zoomFactor + "px"); | 316 var cssWidth = this._dipWidth ? (this._dipWidth / zoomFactor + "px") : (
availableDip.width / zoomFactor + "px"); |
317 var cssHeight = this._dipHeight ? (this._dipHeight / zoomFactor + "px")
: (availableDip.height / zoomFactor + "px"); | 317 var cssHeight = this._dipHeight ? (this._dipHeight / zoomFactor + "px")
: (availableDip.height / zoomFactor + "px"); |
318 if (this._cachedCssWidth !== cssWidth || this._cachedCssHeight !== cssHe
ight) { | 318 if (this._cachedCssWidth !== cssWidth || this._cachedCssHeight !== cssHe
ight) { |
319 this._slidersContainer.style.width = cssWidth; | 319 this._slidersContainer.style.width = cssWidth; |
320 this._slidersContainer.style.height = cssHeight; | 320 this._slidersContainer.style.height = cssHeight; |
321 this._inspectedPagePlaceholder.onResize(); | 321 this._innerView.onResize(); |
322 } | 322 } |
323 | 323 |
324 if (this._cachedScale !== this._scale || this._cachedCssCanvasWidth !==
cssCanvasWidth || this._cachedCssCanvasHeight !== cssCanvasHeight || this._cache
dZoomFactor !== zoomFactor) | 324 if (this._cachedScale !== this._scale || this._cachedCssCanvasWidth !==
cssCanvasWidth || this._cachedCssCanvasHeight !== cssCanvasHeight || this._cache
dZoomFactor !== zoomFactor) |
325 this._drawCanvas(cssCanvasWidth, cssCanvasHeight); | 325 this._drawCanvas(cssCanvasWidth, cssCanvasHeight); |
326 | 326 |
327 this._cachedScale = this._scale; | 327 this._cachedScale = this._scale; |
328 this._cachedCssCanvasWidth = cssCanvasWidth; | 328 this._cachedCssCanvasWidth = cssCanvasWidth; |
329 this._cachedCssCanvasHeight = cssCanvasHeight; | 329 this._cachedCssCanvasHeight = cssCanvasHeight; |
330 this._cachedCssHeight = cssHeight; | 330 this._cachedCssHeight = cssHeight; |
331 this._cachedCssWidth = cssWidth; | 331 this._cachedCssWidth = cssWidth; |
332 this._cachedZoomFactor = zoomFactor; | 332 this._cachedZoomFactor = zoomFactor; |
333 }, | 333 }, |
334 | 334 |
335 onResize: function() | 335 onResize: function() |
336 { | 336 { |
337 if (!this._enabled || this._ignoreResize) | 337 if (!this._enabled || this._ignoreResize) |
338 return; | 338 return; |
| 339 var oldSize = this._availableSize; |
339 delete this._availableSize; | 340 delete this._availableSize; |
340 this.dispatchEventToListeners(WebInspector.OverridesSupport.PageResizer.
Events.AvailableSizeChanged); | 341 if (!this.availableDipSize().isEqual(oldSize)) |
| 342 this.dispatchEventToListeners(WebInspector.ResponsiveDesignView.Even
ts.AvailableSizeChanged); |
341 this._updateUI(); | 343 this._updateUI(); |
342 }, | 344 }, |
343 | 345 |
344 _onZoomChanged: function() | |
345 { | |
346 this._updateUI(); | |
347 }, | |
348 | |
349 /** | 346 /** |
350 * Resets emulated size to available space. | 347 * Resets emulated size to available space. |
351 */ | 348 */ |
352 _reset: function() | 349 _reset: function() |
353 { | 350 { |
354 this.dispatchEventToListeners(WebInspector.OverridesSupport.PageResizer.
Events.ResizeRequested, this.availableDipSize()); | 351 this.dispatchEventToListeners(WebInspector.ResponsiveDesignView.Events.R
esizeRequested, this.availableDipSize()); |
355 }, | 352 }, |
356 | 353 |
357 __proto__: WebInspector.VBox.prototype | 354 __proto__: WebInspector.VBox.prototype |
358 }; | 355 }; |
OLD | NEW |