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

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: Place device frame art options behind experiment Created 4 years, 8 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 {
(...skipping 23 matching lines...) Expand all
34 { 34 {
35 this._toolbar = new WebInspector.DeviceModeToolbar(this._model, this._sh owMediaInspectorSetting, this._showRulersSetting); 35 this._toolbar = new WebInspector.DeviceModeToolbar(this._model, this._sh owMediaInspectorSetting, this._showRulersSetting);
36 this.contentElement.appendChild(this._toolbar.element()); 36 this.contentElement.appendChild(this._toolbar.element());
37 37
38 this._contentClip = this.contentElement.createChild("div", "device-mode- content-clip vbox"); 38 this._contentClip = this.contentElement.createChild("div", "device-mode- content-clip vbox");
39 this._responsivePresetsContainer = this._contentClip.createChild("div", "device-mode-presets-container"); 39 this._responsivePresetsContainer = this._contentClip.createChild("div", "device-mode-presets-container");
40 this._populatePresetsContainer(); 40 this._populatePresetsContainer();
41 this._mediaInspectorContainer = this._contentClip.createChild("div", "de vice-mode-media-container"); 41 this._mediaInspectorContainer = this._contentClip.createChild("div", "de vice-mode-media-container");
42 this._contentArea = this._contentClip.createChild("div", "device-mode-co ntent-area"); 42 this._contentArea = this._contentClip.createChild("div", "device-mode-co ntent-area");
43 43
44 this._outlineImage = this._contentArea.createChild("img", "device-mode-o utline-image hidden fill");
45 this._outlineImage.addEventListener("load", this._onImageLoaded.bind(thi s, this._outlineImage, true), false);
46 this._outlineImage.addEventListener("error", this._onImageLoaded.bind(th is, this._outlineImage, false), false);
47 this._outlineImage.classList.toggle("device-frame-visible", this._model. deviceOutlineSetting().get());
48
44 this._screenArea = this._contentArea.createChild("div", "device-mode-scr een-area"); 49 this._screenArea = this._contentArea.createChild("div", "device-mode-scr een-area");
45 this._screenImage = this._screenArea.createChild("img", "device-mode-scr een-image hidden"); 50 this._screenImage = this._screenArea.createChild("img", "device-mode-scr een-image hidden");
46 this._screenImage.addEventListener("load", this._onScreenImageLoaded.bin d(this, true), false); 51 this._screenImage.addEventListener("load", this._onImageLoaded.bind(this , this._screenImage, true), false);
47 this._screenImage.addEventListener("error", this._onScreenImageLoaded.bi nd(this, false), false); 52 this._screenImage.addEventListener("error", this._onImageLoaded.bind(thi s, this._screenImage, false), false);
48 53
49 this._bottomRightResizerElement = this._screenArea.createChild("div", "d evice-mode-resizer device-mode-bottom-right-resizer"); 54 this._bottomRightResizerElement = this._screenArea.createChild("div", "d evice-mode-resizer device-mode-bottom-right-resizer");
50 this._bottomRightResizerElement.createChild("div", ""); 55 this._bottomRightResizerElement.createChild("div", "");
51 this._createResizer(this._bottomRightResizerElement, 2, 1); 56 this._createResizer(this._bottomRightResizerElement, 2, 1);
52 57
53 this._bottomLeftResizerElement = this._screenArea.createChild("div", "de vice-mode-resizer device-mode-bottom-left-resizer"); 58 this._bottomLeftResizerElement = this._screenArea.createChild("div", "de vice-mode-resizer device-mode-bottom-left-resizer");
54 this._bottomLeftResizerElement.createChild("div", ""); 59 this._bottomLeftResizerElement.createChild("div", "");
55 this._createResizer(this._bottomLeftResizerElement, -2, 1); 60 this._createResizer(this._bottomLeftResizerElement, -2, 1);
56 61
57 this._rightResizerElement = this._screenArea.createChild("div", "device- mode-resizer device-mode-right-resizer"); 62 this._rightResizerElement = this._screenArea.createChild("div", "device- mode-resizer device-mode-right-resizer");
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 * @param {!WebInspector.Event} event 186 * @param {!WebInspector.Event} event
182 */ 187 */
183 _onResizeEnd: function(event) 188 _onResizeEnd: function(event)
184 { 189 {
185 delete this._resizeStart; 190 delete this._resizeStart;
186 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Res izedViewInResponsiveMode); 191 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Res izedViewInResponsiveMode);
187 }, 192 },
188 193
189 _updateUI: function() 194 _updateUI: function()
190 { 195 {
196 /**
197 * @param {!Element} element
198 * @param {!WebInspector.Rect} rect
199 */
200 function applyRect(element, rect)
201 {
202 element.style.left = rect.left + "px";
203 element.style.top = rect.top + "px";
204 element.style.width = rect.width + "px";
205 element.style.height = rect.height + "px";
206 }
207
191 if (!this.isShowing()) 208 if (!this.isShowing())
192 return; 209 return;
193 210
194 var zoomFactor = WebInspector.zoomManager.zoomFactor(); 211 var zoomFactor = WebInspector.zoomManager.zoomFactor();
195 var callDoResize = false; 212 var callDoResize = false;
196 var showRulers = this._showRulersSetting.get() && this._model.type() !== WebInspector.DeviceModeModel.Type.None; 213 var showRulers = this._showRulersSetting.get() && this._model.type() !== WebInspector.DeviceModeModel.Type.None;
197 var contentAreaResized = false; 214 var contentAreaResized = false;
198 var updateRulers = false; 215 var updateRulers = false;
199 216
200 var cssScreenRect = this._model.screenRect().scale(1 / zoomFactor); 217 var cssScreenRect = this._model.screenRect().scale(1 / zoomFactor);
201 if (!cssScreenRect.isEqual(this._cachedCssScreenRect)) { 218 if (!cssScreenRect.isEqual(this._cachedCssScreenRect)) {
202 this._screenArea.style.left = cssScreenRect.left + "px"; 219 applyRect(this._screenArea, cssScreenRect);
203 this._screenArea.style.top = cssScreenRect.top + "px";
204 this._screenArea.style.width = cssScreenRect.width + "px";
205 this._screenArea.style.height = cssScreenRect.height + "px";
206 this._leftRuler.element.style.left = cssScreenRect.left + "px"; 220 this._leftRuler.element.style.left = cssScreenRect.left + "px";
207 updateRulers = true; 221 updateRulers = true;
208 callDoResize = true; 222 callDoResize = true;
209 this._cachedCssScreenRect = cssScreenRect; 223 this._cachedCssScreenRect = cssScreenRect;
210 } 224 }
211 225
212 var cssVisiblePageRect = this._model.visiblePageRect().scale(1 / zoomFac tor); 226 var cssVisiblePageRect = this._model.visiblePageRect().scale(1 / zoomFac tor);
213 if (!cssVisiblePageRect.isEqual(this._cachedCssVisiblePageRect)) { 227 if (!cssVisiblePageRect.isEqual(this._cachedCssVisiblePageRect)) {
214 this._pageArea.style.left = cssVisiblePageRect.left + "px"; 228 applyRect(this._pageArea, cssVisiblePageRect);
215 this._pageArea.style.top = cssVisiblePageRect.top + "px";
216 this._pageArea.style.width = cssVisiblePageRect.width + "px";
217 this._pageArea.style.height = cssVisiblePageRect.height + "px";
218 callDoResize = true; 229 callDoResize = true;
219 this._cachedCssVisiblePageRect = cssVisiblePageRect; 230 this._cachedCssVisiblePageRect = cssVisiblePageRect;
220 } 231 }
221 232
233 var outlineRect = this._model.outlineRect().scale(1 / zoomFactor);
234 if (!outlineRect.isEqual(this._cachedOutlineRect)) {
235 applyRect(this._outlineImage, outlineRect);
236 callDoResize = true;
237 this._cachedOutlineRect = outlineRect;
238 }
239 this._outlineImage.classList.toggle("device-frame-visible", (this._model .deviceOutlineSetting().get() && this._model.outlineImage()));
240
222 var resizable = this._model.type() === WebInspector.DeviceModeModel.Type .Responsive; 241 var resizable = this._model.type() === WebInspector.DeviceModeModel.Type .Responsive;
223 if (resizable !== this._cachedResizable) { 242 if (resizable !== this._cachedResizable) {
224 this._rightResizerElement.classList.toggle("hidden", !resizable); 243 this._rightResizerElement.classList.toggle("hidden", !resizable);
225 this._leftResizerElement.classList.toggle("hidden", !resizable); 244 this._leftResizerElement.classList.toggle("hidden", !resizable);
226 this._bottomResizerElement.classList.toggle("hidden", !resizable); 245 this._bottomResizerElement.classList.toggle("hidden", !resizable);
227 this._bottomRightResizerElement.classList.toggle("hidden", !resizabl e); 246 this._bottomRightResizerElement.classList.toggle("hidden", !resizabl e);
228 this._bottomLeftResizerElement.classList.toggle("hidden", !resizable ); 247 this._bottomLeftResizerElement.classList.toggle("hidden", !resizable );
229 this._cachedResizable = resizable; 248 this._cachedResizable = resizable;
230 } 249 }
231 250
232 var mediaInspectorVisible = this._showMediaInspectorSetting.get() && thi s._model.type() !== WebInspector.DeviceModeModel.Type.None; 251 var mediaInspectorVisible = this._showMediaInspectorSetting.get() && thi s._model.type() !== WebInspector.DeviceModeModel.Type.None;
233 if (mediaInspectorVisible !== this._cachedMediaInspectorVisible) { 252 if (mediaInspectorVisible !== this._cachedMediaInspectorVisible) {
234 if (mediaInspectorVisible) 253 if (mediaInspectorVisible)
235 this._mediaInspector.show(this._mediaInspectorContainer); 254 this._mediaInspector.show(this._mediaInspectorContainer);
236 else 255 else
237 this._mediaInspector.detach(); 256 this._mediaInspector.detach();
238 contentAreaResized = true; 257 contentAreaResized = true;
239 callDoResize = true; 258 callDoResize = true;
240 this._cachedMediaInspectorVisible = mediaInspectorVisible; 259 this._cachedMediaInspectorVisible = mediaInspectorVisible;
241 } 260 }
242 261
243 if (showRulers !== this._cachedShowRulers) { 262 if (showRulers !== this._cachedShowRulers) {
244 this._contentClip.classList.toggle("device-mode-rulers-visible", sho wRulers); 263 this._contentClip.classList.toggle("device-mode-rulers-visible", sho wRulers);
245 if (showRulers) { 264 if (showRulers) {
246 this._topRuler.show(this._contentClip, this._contentArea); 265 this._topRuler.show(this._contentClip, this._contentArea);
266 this._topRuler.show(this._contentArea);
dgozman 2016/04/11 17:24:52 You show topRuler twice. Let's revert.
mmccoy 2016/04/13 22:36:01 Done.
247 this._leftRuler.show(this._contentArea); 267 this._leftRuler.show(this._contentArea);
248 } else { 268 } else {
249 this._topRuler.detach(); 269 this._topRuler.detach();
250 this._leftRuler.detach(); 270 this._leftRuler.detach();
251 } 271 }
252 contentAreaResized = true; 272 contentAreaResized = true;
253 callDoResize = true; 273 callDoResize = true;
254 this._cachedShowRulers = showRulers; 274 this._cachedShowRulers = showRulers;
255 } 275 }
256 276
257 if (this._model.scale() !== this._cachedScale) { 277 if (this._model.scale() !== this._cachedScale) {
258 updateRulers = true; 278 updateRulers = true;
259 callDoResize = true; 279 callDoResize = true;
260 for (var block of this._presetBlocks) 280 for (var block of this._presetBlocks)
261 block.style.width = block.__width * this._model.scale() + "px"; 281 block.style.width = block.__width * this._model.scale() + "px";
262 this._cachedScale = this._model.scale(); 282 this._cachedScale = this._model.scale();
263 } 283 }
264 284
265 this._toolbar.update(); 285 this._toolbar.update();
266 this._loadScreenImage(this._model.screenImage()); 286 this._loadImage(this._screenImage, this._model.screenImage());
287 this._loadImage(this._outlineImage, this._model.outlineImage());
267 this._mediaInspector.setAxisTransform(this._model.scale()); 288 this._mediaInspector.setAxisTransform(this._model.scale());
268 if (callDoResize) 289 if (callDoResize)
269 this.doResize(); 290 this.doResize();
270 if (updateRulers) { 291 if (updateRulers) {
271 this._topRuler.render(this._cachedCssScreenRect ? this._cachedCssScr eenRect.left : 0, this._model.scale()); 292 var showingDevice = this._model.type() === WebInspector.DeviceModeMo del.Type.Device;
272 this._leftRuler.render(0, this._model.scale()); 293 this._topRuler.render(this._cachedCssScreenRect ? this._cachedCssScr eenRect.left : 0, this._model.scale(), showingDevice && this._cachedCssScreenRec t ? this._cachedCssScreenRect.width : 0);
294 this._leftRuler.render(0, this._model.scale(), showingDevice && this ._cachedCssScreenRect ? this._cachedCssScreenRect.height : 0);
295 this._topRuler.element.style.top = this._cachedCssScreenRect ? this. _cachedCssScreenRect.top + "px" : 0;
296 this._leftRuler.element.style.top = this._cachedCssScreenRect ? this ._cachedCssScreenRect.top + "px" : 0;
273 } 297 }
274 if (contentAreaResized) 298 if (contentAreaResized)
275 this._contentAreaResized(); 299 this._contentAreaResized();
276 }, 300 },
277 301
278 /** 302 /**
303 * @param {!Element} element
279 * @param {string} srcset 304 * @param {string} srcset
280 */ 305 */
281 _loadScreenImage: function(srcset) 306 _loadImage: function(element, srcset)
282 { 307 {
283 if (this._screenImage.getAttribute("srcset") === srcset) 308 if (element.getAttribute("srcset") === srcset)
284 return; 309 return;
285 this._screenImage.setAttribute("srcset", srcset); 310 element.setAttribute("srcset", srcset);
286 if (!srcset) 311 if (!srcset)
287 this._screenImage.classList.toggle("hidden", true); 312 element.classList.toggle("hidden", true);
288 }, 313 },
289 314
290 /** 315 /**
316 * @param {!Element} element
291 * @param {boolean} success 317 * @param {boolean} success
292 */ 318 */
293 _onScreenImageLoaded: function(success) 319 _onImageLoaded: function(element, success)
294 { 320 {
295 this._screenImage.classList.toggle("hidden", !success); 321 element.classList.toggle("hidden", !success);
296 }, 322 },
297 323
298 _contentAreaResized: function() 324 _contentAreaResized: function()
299 { 325 {
300 var zoomFactor = WebInspector.zoomManager.zoomFactor(); 326 var zoomFactor = WebInspector.zoomManager.zoomFactor();
301 var rect = this._contentArea.getBoundingClientRect(); 327 var rect = this._contentArea.getBoundingClientRect();
302 var availableSize = new Size(Math.max(rect.width * zoomFactor, 1), Math. max(rect.height * zoomFactor, 1)); 328 var availableSize = new Size(Math.max(rect.width * zoomFactor, 1), Math. max(rect.height * zoomFactor, 1));
303 var preferredSize = new Size(Math.max((rect.width - 2 * this._handleWidt h) * zoomFactor, 1), Math.max((rect.height - this._handleHeight) * zoomFactor, 1 )); 329 var preferredSize = new Size(Math.max((rect.width - 2 * this._handleWidt h) * zoomFactor, 1), Math.max((rect.height - this._handleHeight) * zoomFactor, 1 ));
304 this._model.setAvailableSize(availableSize, preferredSize); 330 this._model.setAvailableSize(availableSize, preferredSize);
305 }, 331 },
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 this._offset = 0; 441 this._offset = 0;
416 this._count = 0; 442 this._count = 0;
417 this._throttler = new WebInspector.Throttler(0); 443 this._throttler = new WebInspector.Throttler(0);
418 this._applyCallback = applyCallback; 444 this._applyCallback = applyCallback;
419 } 445 }
420 446
421 WebInspector.DeviceModeView.Ruler.prototype = { 447 WebInspector.DeviceModeView.Ruler.prototype = {
422 /** 448 /**
423 * @param {number} offset 449 * @param {number} offset
424 * @param {number} scale 450 * @param {number} scale
451 * @param {number} maxLength
425 */ 452 */
426 render: function(offset, scale) 453 render: function(offset, scale, maxLength)
dgozman 2016/04/11 17:24:52 Thanks for screenshot, now it's clear. I still don
427 { 454 {
428 this._scale = scale; 455 this._scale = scale;
429 this._offset = offset; 456 this._offset = offset;
430 if (this._horizontal) 457 if (this._horizontal)
431 this.element.style.paddingLeft = this._offset + "px"; 458 this.element.style.paddingLeft = this._offset + "px";
432 else 459 else
433 this.element.style.paddingTop = this._offset + "px"; 460 this.element.style.paddingTop = this._offset + "px";
434 this._throttler.schedule(this._update.bind(this)); 461 this._throttler.schedule(this._update.bind(this));
462 this._maxLength = maxLength;
435 }, 463 },
436 464
437 /** 465 /**
438 * @override 466 * @override
439 */ 467 */
440 onResize: function() 468 onResize: function()
441 { 469 {
442 this._throttler.schedule(this._update.bind(this)); 470 this._throttler.schedule(this._update.bind(this));
443 }, 471 },
444 472
445 /** 473 /**
446 * @return {!Promise.<?>} 474 * @return {!Promise.<?>}
447 */ 475 */
448 _update: function() 476 _update: function()
449 { 477 {
450 var zoomFactor = WebInspector.zoomManager.zoomFactor(); 478 var zoomFactor = WebInspector.zoomManager.zoomFactor();
451 var size = this._horizontal ? this._contentElement.offsetWidth : this._c ontentElement.offsetHeight; 479 var size = this._horizontal ? this._contentElement.offsetWidth : this._c ontentElement.offsetHeight;
480 if (this._maxLength)
481 size = Math.min(size, this._maxLength)
452 482
453 if (this._scale !== this._renderedScale || zoomFactor !== this._rendered ZoomFactor) { 483 if (this._scale !== this._renderedScale || zoomFactor !== this._rendered ZoomFactor) {
454 this._contentElement.removeChildren(); 484 this._contentElement.removeChildren();
455 this._count = 0; 485 this._count = 0;
456 this._renderedScale = this._scale; 486 this._renderedScale = this._scale;
457 this._renderedZoomFactor = zoomFactor; 487 this._renderedZoomFactor = zoomFactor;
458 } 488 }
459 489
460 var dipSize = size * zoomFactor / this._scale; 490 var dipSize = size * zoomFactor / this._scale;
461 var count = Math.ceil(dipSize / 5); 491 var count = Math.ceil(dipSize / 5);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 /** 530 /**
501 * @param {number} size 531 * @param {number} size
502 */ 532 */
503 _onMarkerClick: function(size) 533 _onMarkerClick: function(size)
504 { 534 {
505 this._applyCallback.call(null, size); 535 this._applyCallback.call(null, size);
506 }, 536 },
507 537
508 __proto__: WebInspector.VBox.prototype 538 __proto__: WebInspector.VBox.prototype
509 } 539 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698