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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeView.js

Issue 1650243004: [DevTools] Option to show device frames in emulation mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Positioning and context menu fixes, addressing review comments Created 4 years, 10 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 */ 8 */
9 WebInspector.DeviceModeView = function() 9 WebInspector.DeviceModeView = function()
10 { 10 {
11 WebInspector.VBox.call(this, true); 11 WebInspector.VBox.call(this, true);
12 this.setMinimumSize(150, 150); 12 this.setMinimumSize(150, 150);
13 this.element.classList.add("device-mode-view"); 13 this.element.classList.add("device-mode-view");
14 this.registerRequiredCSS("emulation/deviceModeView.css"); 14 this.registerRequiredCSS("emulation/deviceModeView.css");
15 WebInspector.Tooltip.addNativeOverrideContainer(this.contentElement); 15 WebInspector.Tooltip.addNativeOverrideContainer(this.contentElement);
16 16
17 this._model = new WebInspector.DeviceModeModel(this._updateUI.bind(this)); 17 this._model = new WebInspector.DeviceModeModel(this._updateUI.bind(this));
18 this._mediaInspector = new WebInspector.MediaQueryInspector(() => this._mode l.appliedDeviceSize().width, this._model.setWidth.bind(this._model)); 18 this._mediaInspector = new WebInspector.MediaQueryInspector(() => this._mode l.appliedDeviceSize().width, this._model.setWidth.bind(this._model));
19 // TODO(dgozman): remove CountUpdated event. 19 // TODO(dgozman): remove CountUpdated event.
20 this._showMediaInspectorSetting = WebInspector.settings.createSetting("showM ediaQueryInspector", false); 20 this._showMediaInspectorSetting = WebInspector.settings.createSetting("showM ediaQueryInspector", false);
21 this._showMediaInspectorSetting.addChangeListener(this._updateUI, this); 21 this._showMediaInspectorSetting.addChangeListener(this._updateUI, this);
22 this._showRulersSetting = WebInspector.settings.createSetting("emulation.sho wRulers", false); 22 this._showRulersSetting = WebInspector.settings.createSetting("emulation.sho wRulers", false);
23 this._showRulersSetting.addChangeListener(this._updateUI, this); 23 this._showRulersSetting.addChangeListener(this._updateUI, this);
24 this._showOutlineSetting = WebInspector.settings.createSetting("emulation.sh owOutline", false);
25 this._showOutlineSetting.addChangeListener(this._updateUI, this);
24 26
25 this._topRuler = new WebInspector.DeviceModeView.Ruler(true, this._model.set WidthAndScaleToFit.bind(this._model)); 27 this._topRuler = new WebInspector.DeviceModeView.Ruler(true, this._model.set WidthAndScaleToFit.bind(this._model));
26 this._topRuler.element.classList.add("device-mode-ruler-top"); 28 this._topRuler.element.classList.add("device-mode-ruler-top");
27 this._leftRuler = new WebInspector.DeviceModeView.Ruler(false, this._model.s etHeightAndScaleToFit.bind(this._model)); 29 this._leftRuler = new WebInspector.DeviceModeView.Ruler(false, this._model.s etHeightAndScaleToFit.bind(this._model));
28 this._leftRuler.element.classList.add("device-mode-ruler-left"); 30 this._leftRuler.element.classList.add("device-mode-ruler-left");
29 this._createUI(); 31 this._createUI();
30 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo omChanged, this._zoomChanged, this); 32 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo omChanged, this._zoomChanged, this);
31 }; 33 };
32 34
33 WebInspector.DeviceModeView.prototype = { 35 WebInspector.DeviceModeView.prototype = {
34 _createUI: function() 36 _createUI: function()
35 { 37 {
36 this._toolbar = new WebInspector.DeviceModeToolbar(this._model, this._sh owMediaInspectorSetting, this._showRulersSetting); 38 this._toolbar = new WebInspector.DeviceModeToolbar(this._model, this._sh owMediaInspectorSetting, this._showRulersSetting, this._showOutlineSetting);
37 this.contentElement.appendChild(this._toolbar.element()); 39 this.contentElement.appendChild(this._toolbar.element());
38 40
39 this._contentClip = this.contentElement.createChild("div", "device-mode- content-clip vbox"); 41 this._contentClip = this.contentElement.createChild("div", "device-mode- content-clip vbox");
40 this._responsivePresetsContainer = this._contentClip.createChild("div", "device-mode-presets-container"); 42 this._responsivePresetsContainer = this._contentClip.createChild("div", "device-mode-presets-container");
41 this._populatePresetsContainer(); 43 this._populatePresetsContainer();
42 this._mediaInspectorContainer = this._contentClip.createChild("div", "de vice-mode-media-container"); 44 this._mediaInspectorContainer = this._contentClip.createChild("div", "de vice-mode-media-container");
43 this._contentArea = this._contentClip.createChild("div", "device-mode-co ntent-area"); 45 this._contentArea = this._contentClip.createChild("div", "device-mode-co ntent-area");
44 46
47 this._outlineArea = this._contentArea.createChild("div", "device-mode-ou tline-area");
48 this._outlineImage = this._outlineArea.createChild("img", "device-mode-o utline-image hidden");
49 this._outlineImage.addEventListener("load", this._onOutlineImageLoaded.b ind(this, true), false);
50 this._outlineImage.addEventListener("error", this._onOutlineImageLoaded. bind(this, false), false);
51
45 this._screenArea = this._contentArea.createChild("div", "device-mode-scr een-area"); 52 this._screenArea = this._contentArea.createChild("div", "device-mode-scr een-area");
46 this._screenImage = this._screenArea.createChild("img", "device-mode-scr een-image hidden"); 53 this._screenImage = this._screenArea.createChild("img", "device-mode-scr een-image hidden");
47 this._screenImage.addEventListener("load", this._onScreenImageLoaded.bin d(this, true), false); 54 this._screenImage.addEventListener("load", this._onScreenImageLoaded.bin d(this, true), false);
48 this._screenImage.addEventListener("error", this._onScreenImageLoaded.bi nd(this, false), false); 55 this._screenImage.addEventListener("error", this._onScreenImageLoaded.bi nd(this, false), false);
49 56
50 this._bottomRightResizerElement = this._screenArea.createChild("div", "d evice-mode-resizer device-mode-bottom-right-resizer"); 57 this._bottomRightResizerElement = this._screenArea.createChild("div", "d evice-mode-resizer device-mode-bottom-right-resizer");
51 this._bottomRightResizerElement.createChild("div", ""); 58 this._bottomRightResizerElement.createChild("div", "");
52 this._createResizer(this._bottomRightResizerElement, 2, 1); 59 this._createResizer(this._bottomRightResizerElement, 2, 1);
53 60
54 this._bottomLeftResizerElement = this._screenArea.createChild("div", "de vice-mode-resizer device-mode-bottom-left-resizer"); 61 this._bottomLeftResizerElement = this._screenArea.createChild("div", "de vice-mode-resizer device-mode-bottom-left-resizer");
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 }, 195 },
189 196
190 _updateUI: function() 197 _updateUI: function()
191 { 198 {
192 if (!this.isShowing()) 199 if (!this.isShowing())
193 return; 200 return;
194 201
195 var zoomFactor = WebInspector.zoomManager.zoomFactor(); 202 var zoomFactor = WebInspector.zoomManager.zoomFactor();
196 var callDoResize = false; 203 var callDoResize = false;
197 var showRulers = this._showRulersSetting.get() && this._model.type() !== WebInspector.DeviceModeModel.Type.None; 204 var showRulers = this._showRulersSetting.get() && this._model.type() !== WebInspector.DeviceModeModel.Type.None;
205 var showOutline = this._showOutlineSetting.get() && this._model.type() ! == WebInspector.DeviceModeModel.Type.None;
dgozman 2016/02/09 21:15:10 type === Device, as you don't have an outline for
mmccoy 2016/02/10 20:06:34 Done.
198 var contentAreaResized = false; 206 var contentAreaResized = false;
199 var updateRulers = false; 207 var updateRulers = false;
200 208
201 var cssScreenRect = this._model.screenRect().scale(1 / zoomFactor); 209 var cssScreenRect = this._model.screenRect().scale(1 / zoomFactor);
202 if (!cssScreenRect.isEqual(this._cachedCssScreenRect)) { 210 if (!cssScreenRect.isEqual(this._cachedCssScreenRect)) {
203 this._screenArea.style.left = cssScreenRect.left + "px"; 211 this._screenArea.style.left = cssScreenRect.left + "px";
204 this._screenArea.style.top = cssScreenRect.top + "px"; 212 this._screenArea.style.top = cssScreenRect.top + "px";
205 this._screenArea.style.width = cssScreenRect.width + "px"; 213 this._screenArea.style.width = cssScreenRect.width + "px";
206 this._screenArea.style.height = cssScreenRect.height + "px"; 214 this._screenArea.style.height = cssScreenRect.height + "px";
207 this._leftRuler.element.style.left = cssScreenRect.left + "px"; 215 this._leftRuler.element.style.left = cssScreenRect.left + "px";
216 var outlineImageDimensions = this._model.outlineDimensions();
dgozman 2016/02/09 21:15:10 I believe you don't need this.
mmccoy 2016/02/10 20:06:34 Ah yes, removed throughout.
217 var outlineInsets = this._model.outlineInsets();
218 if (outlineInsets) {
219 this._outlineArea.style.left = (cssScreenRect.left - outlineInse ts.left) + "px";
220 this._outlineArea.style.top = (cssScreenRect.top - outlineInsets .top) + "px";
221 this._outlineArea.style.width = outlineImageDimensions.width + " px";
dgozman 2016/02/09 21:15:10 What about |style.right = outlineInsets.right + "p
mmccoy 2016/02/10 20:06:34 Hrm, can you elaborate a little. outlineArea shou
222 this._outlineArea.style.height = outlineImageDimensions.height + "px";
223 }
208 updateRulers = true; 224 updateRulers = true;
209 callDoResize = true; 225 callDoResize = true;
210 this._cachedCssScreenRect = cssScreenRect; 226 this._cachedCssScreenRect = cssScreenRect;
211 } 227 }
212 228
213 var cssVisiblePageRect = this._model.visiblePageRect().scale(1 / zoomFac tor); 229 var cssVisiblePageRect = this._model.visiblePageRect().scale(1 / zoomFac tor);
214 if (!cssVisiblePageRect.isEqual(this._cachedCssVisiblePageRect)) { 230 if (!cssVisiblePageRect.isEqual(this._cachedCssVisiblePageRect)) {
215 this._pageArea.style.left = cssVisiblePageRect.left + "px"; 231 this._pageArea.style.left = cssVisiblePageRect.left + "px";
216 this._pageArea.style.top = cssVisiblePageRect.top + "px"; 232 this._pageArea.style.top = cssVisiblePageRect.top + "px";
217 this._pageArea.style.width = cssVisiblePageRect.width + "px"; 233 this._pageArea.style.width = cssVisiblePageRect.width + "px";
(...skipping 30 matching lines...) Expand all
248 this._leftRuler.show(this._contentArea); 264 this._leftRuler.show(this._contentArea);
249 } else { 265 } else {
250 this._topRuler.detach(); 266 this._topRuler.detach();
251 this._leftRuler.detach(); 267 this._leftRuler.detach();
252 } 268 }
253 contentAreaResized = true; 269 contentAreaResized = true;
254 callDoResize = true; 270 callDoResize = true;
255 this._cachedShowRulers = showRulers; 271 this._cachedShowRulers = showRulers;
256 } 272 }
257 273
274 if (showOutline !== this._cachedShowOutline) {
275 this._contentClip.classList.toggle("device-mode-frame-visible", show Outline);
276 contentAreaResized = true;
277 callDoResize = true;
278 this._cachedShowOutline = showOutline;
279 }
280
258 if (this._model.scale() !== this._cachedScale) { 281 if (this._model.scale() !== this._cachedScale) {
259 updateRulers = true; 282 updateRulers = true;
260 callDoResize = true; 283 callDoResize = true;
261 for (var block of this._presetBlocks) 284 for (var block of this._presetBlocks)
262 block.style.width = block.__width * this._model.scale() + "px"; 285 block.style.width = block.__width * this._model.scale() + "px";
263 this._cachedScale = this._model.scale(); 286 this._cachedScale = this._model.scale();
264 } 287 }
265 288
266 this._toolbar.update(); 289 this._toolbar.update();
267 this._loadScreenImage(this._model.screenImage()); 290 this._loadScreenImage(this._model.screenImage());
291 this._loadOutlineImage(this._model.outlineImage());
268 this._mediaInspector.setAxisTransform(-cssScreenRect.left * zoomFactor / this._model.scale(), this._model.scale()); 292 this._mediaInspector.setAxisTransform(-cssScreenRect.left * zoomFactor / this._model.scale(), this._model.scale());
269 if (callDoResize) 293 if (callDoResize)
270 this.doResize(); 294 this.doResize();
271 if (updateRulers) { 295 if (updateRulers) {
272 this._topRuler.render(this._cachedCssScreenRect ? this._cachedCssScr eenRect.left : 0, this._model.scale()); 296 this._topRuler.render(this._cachedCssScreenRect ? this._cachedCssScr eenRect.left : 0, this._model.scale());
273 this._leftRuler.render(0, this._model.scale()); 297 this._leftRuler.render(0, this._model.scale());
274 } 298 }
275 if (contentAreaResized) 299 if (contentAreaResized)
276 this._contentAreaResized(); 300 this._contentAreaResized();
277 }, 301 },
(...skipping 11 matching lines...) Expand all
289 }, 313 },
290 314
291 /** 315 /**
292 * @param {boolean} success 316 * @param {boolean} success
293 */ 317 */
294 _onScreenImageLoaded: function(success) 318 _onScreenImageLoaded: function(success)
295 { 319 {
296 this._screenImage.classList.toggle("hidden", !success); 320 this._screenImage.classList.toggle("hidden", !success);
297 }, 321 },
298 322
323 /**
324 * @param {string} srcset
325 */
326 _loadOutlineImage: function(srcset)
327 {
328 if (this._outlineImage.getAttribute("srcset") === srcset)
329 return;
330 this._outlineImage.setAttribute("srcset", srcset);
331 if (!srcset)
332 this._outlineImage.classList.toggle("hidden", true);
333 },
334
335 /**
336 * @param {boolean} success
337 */
338 _onOutlineImageLoaded: function(success)
339 {
340 this._outlineImage.classList.toggle("hidden", !success);
341 },
342
299 _contentAreaResized: function() 343 _contentAreaResized: function()
300 { 344 {
301 var zoomFactor = WebInspector.zoomManager.zoomFactor(); 345 var zoomFactor = WebInspector.zoomManager.zoomFactor();
302 var rect = this._contentArea.getBoundingClientRect(); 346 var rect = this._contentArea.getBoundingClientRect();
303 var availableSize = new Size(Math.max(rect.width * zoomFactor, 1), Math. max(rect.height * zoomFactor, 1)); 347 var availableSize = new Size(Math.max(rect.width * zoomFactor, 1), Math. max(rect.height * zoomFactor, 1));
304 var preferredSize = new Size(Math.max((rect.width - 2 * this._handleWidt h) * zoomFactor, 1), Math.max((rect.height - this._handleHeight) * zoomFactor, 1 )); 348 var preferredSize = new Size(Math.max((rect.width - 2 * this._handleWidt h) * zoomFactor, 1), Math.max((rect.height - this._handleHeight) * zoomFactor, 1 ));
305 this._model.setAvailableSize(availableSize, preferredSize); 349 this._model.setAvailableSize(availableSize, preferredSize);
306 }, 350 },
307 351
308 _measureHandles: function() 352 _measureHandles: function()
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 /** 499 /**
456 * @param {number} size 500 * @param {number} size
457 */ 501 */
458 _onMarkerClick: function(size) 502 _onMarkerClick: function(size)
459 { 503 {
460 this._applyCallback.call(null, size); 504 this._applyCallback.call(null, size);
461 }, 505 },
462 506
463 __proto__: WebInspector.VBox.prototype 507 __proto__: WebInspector.VBox.prototype
464 } 508 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698