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

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: Changed DockSide events 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 context.beginPath(); 310 context.beginPath();
319 context.moveTo(0, y); 311 context.moveTo(0, y);
320 context.lineTo(dipGridWidth, y); 312 context.lineTo(dipGridWidth, y);
321 context.stroke(); 313 context.stroke();
322 } 314 }
323 } 315 }
324 }, 316 },
325 317
326 _updateUI: function() 318 _updateUI: function()
327 { 319 {
328 if (!this._enabled) 320 if (!this._enabled || !this.isShowing())
329 return; 321 return;
330 322
331 var zoomFactor = WebInspector.zoomManager.zoomFactor(); 323 var zoomFactor = WebInspector.zoomManager.zoomFactor();
332 var rect = this._canvas.parentElement.getBoundingClientRect(); 324 var rect = this._canvas.parentElement.getBoundingClientRect();
333 var availableDip = this.availableDipSize(); 325 var availableDip = this.availableDipSize();
334 var cssCanvasWidth = rect.width; 326 var cssCanvasWidth = rect.width;
335 var cssCanvasHeight = rect.height; 327 var cssCanvasHeight = rect.height;
336 328
337 this._widthSlider.classList.toggle("hidden", !!this._scale); 329 this._widthSlider.classList.toggle("hidden", !!this._scale);
338 this._heightSlider.classList.toggle("hidden", !!this._scale); 330 this._heightSlider.classList.toggle("hidden", !!this._scale);
(...skipping 28 matching lines...) Expand all
367 this._cachedCssCanvasHeight = cssCanvasHeight; 359 this._cachedCssCanvasHeight = cssCanvasHeight;
368 this._cachedCssHeight = cssHeight; 360 this._cachedCssHeight = cssHeight;
369 this._cachedCssWidth = cssWidth; 361 this._cachedCssWidth = cssWidth;
370 this._cachedZoomFactor = zoomFactor; 362 this._cachedZoomFactor = zoomFactor;
371 }, 363 },
372 364
373 onResize: function() 365 onResize: function()
374 { 366 {
375 if (!this._enabled || this._ignoreResize) 367 if (!this._enabled || this._ignoreResize)
376 return; 368 return;
369 var oldSize = this._availableSize;
377 delete this._availableSize; 370 delete this._availableSize;
378 this.dispatchEventToListeners(WebInspector.OverridesSupport.PageResizer. Events.AvailableSizeChanged); 371 if (!this.availableDipSize().isEqual(oldSize))
372 this.dispatchEventToListeners(WebInspector.OverridesSupport.PageResi zer.Events.AvailableSizeChanged);
379 this._updateUI(); 373 this._updateUI();
380 }, 374 },
381 375
382 _onZoomChanged: function() 376 _onZoomChanged: function()
383 { 377 {
384 this._updateUI(); 378 this._updateUI();
385 }, 379 },
386 380
387 _createToolbar: function() 381 _createToolbar: function()
388 { 382 {
(...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)); 449 sectionElement.appendChild(WebInspector.SettingsUI.createSettingCheckbox (WebInspector.UIString("Viewport"), WebInspector.overridesSupport.settings.emula teViewport, true));
456 }, 450 },
457 451
458 _overridesWarningUpdated: function() 452 _overridesWarningUpdated: function()
459 { 453 {
460 var message = WebInspector.overridesSupport.warningMessage(); 454 var message = WebInspector.overridesSupport.warningMessage();
461 if (this._warningMessage.textContent === message) 455 if (this._warningMessage.textContent === message)
462 return; 456 return;
463 this._warningMessage.classList.toggle("hidden", !message); 457 this._warningMessage.classList.toggle("hidden", !message);
464 this._warningMessage.textContent = message; 458 this._warningMessage.textContent = message;
465 this._responsiveDesignModeChanged(); 459 this._invalidateCache();
466 this.onResize(); 460 this.onResize();
467 }, 461 },
468 462
469 __proto__: WebInspector.VBox.prototype 463 __proto__: WebInspector.VBox.prototype
470 }; 464 };
OLDNEW
« no previous file with comments | « Source/devtools/front_end/InspectorFrontendHostStub.js ('k') | Source/devtools/front_end/common/Settings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698