Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: Source/devtools/front_end/ResponsiveDesignView.js

Issue 298913004: [DevTools] Add Toolbox page to undocked DevTools frontend. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 27 matching lines...) Expand all
38 this._heightSlider = this._heightSliderContainer.createChild("div", "respons ive-design-slider-thumb"); 38 this._heightSlider = this._heightSliderContainer.createChild("div", "respons ive-design-slider-thumb");
39 this._heightSlider.createChild("div", "responsive-design-thumb-handle"); 39 this._heightSlider.createChild("div", "responsive-design-thumb-handle");
40 this._createResizer(this._heightSlider, true); 40 this._createResizer(this._heightSlider, true);
41 41
42 this._inspectedPagePlaceholder = inspectedPagePlaceholder; 42 this._inspectedPagePlaceholder = inspectedPagePlaceholder;
43 inspectedPagePlaceholder.show(this.element); 43 inspectedPagePlaceholder.show(this.element);
44 44
45 this._enabled = false; 45 this._enabled = false;
46 46
47 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo omChanged, this._onZoomChanged, this); 47 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo omChanged, this._onZoomChanged, this);
48 WebInspector.dockController.addEventListener(WebInspector.DockController.Eve nts.DockSideChanged, this._updateOverridesSupportOnDockSideChange, this);
49 WebInspector.settings.responsiveDesignMode.addChangeListener(this._responsiv eDesignModeChanged, this); 48 WebInspector.settings.responsiveDesignMode.addChangeListener(this._responsiv eDesignModeChanged, this);
50
51 WebInspector.overridesSupport.settings.emulateViewport.addChangeListener(thi s._maybeEnableResponsiveDesign, this); 49 WebInspector.overridesSupport.settings.emulateViewport.addChangeListener(thi s._maybeEnableResponsiveDesign, this);
52 WebInspector.overridesSupport.settings.emulateTouchEvents.addChangeListener( this._maybeEnableResponsiveDesign, this); 50 WebInspector.overridesSupport.settings.emulateTouchEvents.addChangeListener( this._maybeEnableResponsiveDesign, this);
53 WebInspector.overridesSupport.settings.overrideDeviceResolution.addChangeLis tener(this._maybeEnableResponsiveDesign, this); 51 WebInspector.overridesSupport.settings.overrideDeviceResolution.addChangeLis tener(this._maybeEnableResponsiveDesign, this);
54 52 this._responsiveDesignModeChanged();
55 this._updateOverridesSupportOnDockSideChange(); 53 this._overridesWarningUpdated();
56 }; 54 };
57 55
58 // Measured in DIP. 56 // Measured in DIP.
59 WebInspector.ResponsiveDesignView.SliderWidth = 19; 57 WebInspector.ResponsiveDesignView.SliderWidth = 19;
60 WebInspector.ResponsiveDesignView.RulerWidth = 20; 58 WebInspector.ResponsiveDesignView.RulerWidth = 20;
61 WebInspector.ResponsiveDesignView.ToolbarHeight = 23; 59 WebInspector.ResponsiveDesignView.ToolbarHeight = 23;
62 60
63 WebInspector.ResponsiveDesignView.prototype = { 61 WebInspector.ResponsiveDesignView.prototype = {
64 _maybeEnableResponsiveDesign: function() 62 _maybeEnableResponsiveDesign: function()
65 { 63 {
66 if (this._enabled) 64 if (this._enabled)
67 return; 65 return;
68 if (WebInspector.overridesSupport.settings.emulateViewport.get() || 66 if (WebInspector.overridesSupport.settings.emulateViewport.get() ||
69 WebInspector.overridesSupport.settings.emulateTouchEvents.get() || 67 WebInspector.overridesSupport.settings.emulateTouchEvents.get() ||
70 WebInspector.overridesSupport.settings.overrideDeviceResolution. get()) { 68 WebInspector.overridesSupport.settings.overrideDeviceResolution. get()) {
71 WebInspector.settings.responsiveDesignMode.set(true); 69 WebInspector.settings.responsiveDesignMode.set(true);
72 } 70 }
73 }, 71 },
74 72
75 _responsiveDesignModeChanged: function() 73 _invalidateCache: function()
76 { 74 {
77 delete this._cachedScale; 75 delete this._cachedScale;
78 delete this._cachedCssCanvasWidth; 76 delete this._cachedCssCanvasWidth;
79 delete this._cachedCssCanvasHeight; 77 delete this._cachedCssCanvasHeight;
80 delete this._cachedCssHeight; 78 delete this._cachedCssHeight;
81 delete this._cachedCssWidth; 79 delete this._cachedCssWidth;
82 delete this._cachedZoomFactor; 80 delete this._cachedZoomFactor;
83 delete this._availableSize; 81 delete this._availableSize;
82 },
84 83
85 var enabled = WebInspector.settings.responsiveDesignMode.get() && WebIns pector.dockController.dockSide() !== WebInspector.DockController.State.Undocked; 84 _responsiveDesignModeChanged: function()
85 {
86 var enabled = WebInspector.settings.responsiveDesignMode.get();
86 if (enabled && !this._enabled) { 87 if (enabled && !this._enabled) {
88 this._invalidateCache();
87 this._ignoreResize = true; 89 this._ignoreResize = true;
88 this._enabled = true; 90 this._enabled = true;
89 this._inspectedPagePlaceholder.clearMinimumSizeAndMargins(); 91 this._inspectedPagePlaceholder.clearMinimumSizeAndMargins();
90 this._inspectedPagePlaceholder.show(this._pageContainer); 92 this._inspectedPagePlaceholder.show(this._pageContainer);
91 this._responsiveDesignContainer.show(this.element); 93 this._responsiveDesignContainer.show(this.element);
92 WebInspector.overridesSupport.setPageResizer(this); 94 this.update(this._dipWidth, this._dipHeight, this._scale);
93 delete this._ignoreResize; 95 delete this._ignoreResize;
94 } 96 } else if (!enabled && this._enabled) {
95 97 this._invalidateCache();
96 if (!enabled && this._enabled) {
97 this._ignoreResize = true; 98 this._ignoreResize = true;
98 this._enabled = false; 99 this._enabled = false;
99 this._scale = 0; 100 this._scale = 0;
100 this._inspectedPagePlaceholder.restoreMinimumSizeAndMargins(); 101 this._inspectedPagePlaceholder.restoreMinimumSizeAndMargins();
101 this._responsiveDesignContainer.detach(); 102 this._responsiveDesignContainer.detach();
102 this._inspectedPagePlaceholder.show(this.element); 103 this._inspectedPagePlaceholder.show(this.element);
103 WebInspector.overridesSupport.setPageResizer(null);
104 delete this._ignoreResize; 104 delete this._ignoreResize;
105 } 105 }
106 }, 106 },
107 107
108 _updateOverridesSupportOnDockSideChange: function()
109 {
110 this._responsiveDesignModeChanged();
111 },
112
113 /** 108 /**
114 * WebInspector.OverridesSupport.PageResizer override. 109 * WebInspector.OverridesSupport.PageResizer override.
115 * @param {number} dipWidth 110 * @param {number} dipWidth
116 * @param {number} dipHeight 111 * @param {number} dipHeight
117 * @param {number} scale 112 * @param {number} scale
118 */ 113 */
119 update: function(dipWidth, dipHeight, scale) 114 update: function(dipWidth, dipHeight, scale)
120 { 115 {
121 if (!this._enabled)
122 return;
123
124 this._scale = scale; 116 this._scale = scale;
125 this._dipWidth = dipWidth; 117 this._dipWidth = dipWidth;
126 this._dipHeight = dipHeight; 118 this._dipHeight = dipHeight;
127 this._resolutionWidthLabel.textContent = dipWidth + "px"; 119 this._resolutionWidthLabel.textContent = dipWidth + "px";
128 this._resolutionHeightLabel.textContent = dipHeight + "px"; 120 this._resolutionHeightLabel.textContent = dipHeight + "px";
129 this._updateUI(); 121 this._updateUI();
130 }, 122 },
131 123
132 /** 124 /**
133 * WebInspector.OverridesSupport.PageResizer override. 125 * WebInspector.OverridesSupport.PageResizer override.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 * Draws canvas of the specified css size in DevTools page space. 189 * Draws canvas of the specified css size in DevTools page space.
198 * Canvas contains grid and rulers. 190 * Canvas contains grid and rulers.
199 * @param {number} cssCanvasWidth 191 * @param {number} cssCanvasWidth
200 * @param {number} cssCanvasHeight 192 * @param {number} cssCanvasHeight
201 */ 193 */
202 _drawCanvas: function(cssCanvasWidth, cssCanvasHeight) 194 _drawCanvas: function(cssCanvasWidth, cssCanvasHeight)
203 { 195 {
204 if (!this._enabled) 196 if (!this._enabled)
205 return; 197 return;
206 198
199 //console.error("_drawCanvas " + cssCanvasWidth + "x" + cssCanvasHeight + (new Error().stack));
apavlov 2014/06/04 09:04:24 please remove
dgozman 2014/06/04 11:16:18 Ops. Done.
200
207 var canvas = this._canvas; 201 var canvas = this._canvas;
208 var context = canvas.getContext("2d"); 202 var context = canvas.getContext("2d");
209 canvas.style.width = cssCanvasWidth + "px"; 203 canvas.style.width = cssCanvasWidth + "px";
210 canvas.style.height = cssCanvasHeight + "px"; 204 canvas.style.height = cssCanvasHeight + "px";
211 205
212 var zoomFactor = WebInspector.zoomManager.zoomFactor(); 206 var zoomFactor = WebInspector.zoomManager.zoomFactor();
213 var dipCanvasWidth = cssCanvasWidth * zoomFactor; 207 var dipCanvasWidth = cssCanvasWidth * zoomFactor;
214 var dipCanvasHeight = cssCanvasHeight * zoomFactor; 208 var dipCanvasHeight = cssCanvasHeight * zoomFactor;
215 209
216 var deviceScaleFactor = window.devicePixelRatio; 210 var deviceScaleFactor = window.devicePixelRatio;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 context.beginPath(); 312 context.beginPath();
319 context.moveTo(0, y); 313 context.moveTo(0, y);
320 context.lineTo(dipGridWidth, y); 314 context.lineTo(dipGridWidth, y);
321 context.stroke(); 315 context.stroke();
322 } 316 }
323 } 317 }
324 }, 318 },
325 319
326 _updateUI: function() 320 _updateUI: function()
327 { 321 {
328 if (!this._enabled) 322 if (!this._enabled || !this.isShowing())
apavlov 2014/06/04 09:04:24 Is (!this.isShowing()) by chance sufficient?
dgozman 2014/06/04 11:16:18 No, this view can be disabled but showing.
329 return; 323 return;
330 324
331 var zoomFactor = WebInspector.zoomManager.zoomFactor(); 325 var zoomFactor = WebInspector.zoomManager.zoomFactor();
332 var rect = this._canvas.parentElement.getBoundingClientRect(); 326 var rect = this._canvas.parentElement.getBoundingClientRect();
333 var availableDip = this.availableDipSize(); 327 var availableDip = this.availableDipSize();
334 var cssCanvasWidth = rect.width; 328 var cssCanvasWidth = rect.width;
335 var cssCanvasHeight = rect.height; 329 var cssCanvasHeight = rect.height;
336 330
337 this._widthSlider.classList.toggle("hidden", !!this._scale); 331 this._widthSlider.classList.toggle("hidden", !!this._scale);
338 this._heightSlider.classList.toggle("hidden", !!this._scale); 332 this._heightSlider.classList.toggle("hidden", !!this._scale);
(...skipping 28 matching lines...) Expand all
367 this._cachedCssCanvasHeight = cssCanvasHeight; 361 this._cachedCssCanvasHeight = cssCanvasHeight;
368 this._cachedCssHeight = cssHeight; 362 this._cachedCssHeight = cssHeight;
369 this._cachedCssWidth = cssWidth; 363 this._cachedCssWidth = cssWidth;
370 this._cachedZoomFactor = zoomFactor; 364 this._cachedZoomFactor = zoomFactor;
371 }, 365 },
372 366
373 onResize: function() 367 onResize: function()
374 { 368 {
375 if (!this._enabled || this._ignoreResize) 369 if (!this._enabled || this._ignoreResize)
376 return; 370 return;
371 var oldSize = this._availableSize;
377 delete this._availableSize; 372 delete this._availableSize;
378 this.dispatchEventToListeners(WebInspector.OverridesSupport.PageResizer. Events.AvailableSizeChanged); 373 if (!this.availableDipSize().isEqual(oldSize))
apavlov 2014/06/04 09:04:24 equals() for consistency (with Java)? :)
dgozman 2014/06/04 11:16:18 I have found approximately the same number of isEq
374 this.dispatchEventToListeners(WebInspector.OverridesSupport.PageResi zer.Events.AvailableSizeChanged);
379 this._updateUI(); 375 this._updateUI();
380 }, 376 },
381 377
382 _onZoomChanged: function() 378 _onZoomChanged: function()
383 { 379 {
384 this._updateUI(); 380 this._updateUI();
385 }, 381 },
386 382
387 _createToolbar: function() 383 _createToolbar: function()
388 { 384 {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 sectionElement.appendChild(WebInspector.SettingsUI.createSettingCheckbox (WebInspector.UIString("Viewport"), WebInspector.overridesSupport.settings.emula teViewport, true)); 451 sectionElement.appendChild(WebInspector.SettingsUI.createSettingCheckbox (WebInspector.UIString("Viewport"), WebInspector.overridesSupport.settings.emula teViewport, true));
456 }, 452 },
457 453
458 _overridesWarningUpdated: function() 454 _overridesWarningUpdated: function()
459 { 455 {
460 var message = WebInspector.overridesSupport.warningMessage(); 456 var message = WebInspector.overridesSupport.warningMessage();
461 if (this._warningMessage.textContent === message) 457 if (this._warningMessage.textContent === message)
462 return; 458 return;
463 this._warningMessage.classList.toggle("hidden", !message); 459 this._warningMessage.classList.toggle("hidden", !message);
464 this._warningMessage.textContent = message; 460 this._warningMessage.textContent = message;
465 this._responsiveDesignModeChanged(); 461 this._invalidateCache();
466 this.onResize(); 462 this.onResize();
467 }, 463 },
468 464
469 __proto__: WebInspector.VBox.prototype 465 __proto__: WebInspector.VBox.prototype
470 }; 466 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698