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

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: Trimming some dead code Created 4 years, 9 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 24 matching lines...) Expand all
35 { 35 {
36 this._toolbar = new WebInspector.DeviceModeToolbar(this._model, this._sh owMediaInspectorSetting, this._showRulersSetting); 36 this._toolbar = new WebInspector.DeviceModeToolbar(this._model, this._sh owMediaInspectorSetting, this._showRulersSetting);
37 this.contentElement.appendChild(this._toolbar.element()); 37 this.contentElement.appendChild(this._toolbar.element());
38 38
39 this._contentClip = this.contentElement.createChild("div", "device-mode- content-clip vbox"); 39 this._contentClip = this.contentElement.createChild("div", "device-mode- content-clip vbox");
40 this._responsivePresetsContainer = this._contentClip.createChild("div", "device-mode-presets-container"); 40 this._responsivePresetsContainer = this._contentClip.createChild("div", "device-mode-presets-container");
41 this._populatePresetsContainer(); 41 this._populatePresetsContainer();
42 this._mediaInspectorContainer = this._contentClip.createChild("div", "de vice-mode-media-container"); 42 this._mediaInspectorContainer = this._contentClip.createChild("div", "de vice-mode-media-container");
43 this._contentArea = this._contentClip.createChild("div", "device-mode-co ntent-area"); 43 this._contentArea = this._contentClip.createChild("div", "device-mode-co ntent-area");
44 44
45 this._outlineImage = this._contentArea.createChild("img", "device-mode-o utline-image hidden fill");
46 this._outlineImage.addEventListener("load", this._onScreenImageLoaded.bi nd(this, this._outlineImage, true), false);
47 this._outlineImage.addEventListener("error", this._onScreenImageLoaded.b ind(this, this._outlineImage, false), false);
48 this._outlineImage.classList.toggle("device-frame-visible", this._model. deviceOutlineSetting().get());
49
45 this._screenArea = this._contentArea.createChild("div", "device-mode-scr een-area"); 50 this._screenArea = this._contentArea.createChild("div", "device-mode-scr een-area");
46 this._screenImage = this._screenArea.createChild("img", "device-mode-scr een-image hidden"); 51 this._screenImage = this._screenArea.createChild("img", "device-mode-scr een-image hidden");
47 this._screenImage.addEventListener("load", this._onScreenImageLoaded.bin d(this, true), false); 52 this._screenImage.addEventListener("load", this._onScreenImageLoaded.bin d(this, this._screenImage, true), false);
48 this._screenImage.addEventListener("error", this._onScreenImageLoaded.bi nd(this, false), false); 53 this._screenImage.addEventListener("error", this._onScreenImageLoaded.bi nd(this, this._screenImage, false), false);
49 54
50 this._bottomRightResizerElement = this._screenArea.createChild("div", "d evice-mode-resizer device-mode-bottom-right-resizer"); 55 this._bottomRightResizerElement = this._screenArea.createChild("div", "d evice-mode-resizer device-mode-bottom-right-resizer");
51 this._bottomRightResizerElement.createChild("div", ""); 56 this._bottomRightResizerElement.createChild("div", "");
52 this._createResizer(this._bottomRightResizerElement, 2, 1); 57 this._createResizer(this._bottomRightResizerElement, 2, 1);
53 58
54 this._bottomLeftResizerElement = this._screenArea.createChild("div", "de vice-mode-resizer device-mode-bottom-left-resizer"); 59 this._bottomLeftResizerElement = this._screenArea.createChild("div", "de vice-mode-resizer device-mode-bottom-left-resizer");
55 this._bottomLeftResizerElement.createChild("div", ""); 60 this._bottomLeftResizerElement.createChild("div", "");
56 this._createResizer(this._bottomLeftResizerElement, -2, 1); 61 this._createResizer(this._bottomLeftResizerElement, -2, 1);
57 62
58 this._rightResizerElement = this._screenArea.createChild("div", "device- mode-resizer device-mode-right-resizer"); 63 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
182 * @param {!WebInspector.Event} event 187 * @param {!WebInspector.Event} event
183 */ 188 */
184 _onResizeEnd: function(event) 189 _onResizeEnd: function(event)
185 { 190 {
186 delete this._resizeStart; 191 delete this._resizeStart;
187 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Res izedViewInResponsiveMode); 192 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Res izedViewInResponsiveMode);
188 }, 193 },
189 194
190 _updateUI: function() 195 _updateUI: function()
191 { 196 {
197 /**
198 * @param {!Element} element
199 * @param {!WebInspector.Rect} rect
200 */
201 function applyRect(element, rect)
202 {
203 element.style.left = rect.left + "px";
204 element.style.top = rect.top + "px";
205 element.style.width = rect.width + "px";
206 element.style.height = rect.height + "px";
207 }
208
192 if (!this.isShowing()) 209 if (!this.isShowing())
193 return; 210 return;
194 211
195 var zoomFactor = WebInspector.zoomManager.zoomFactor(); 212 var zoomFactor = WebInspector.zoomManager.zoomFactor();
196 var callDoResize = false; 213 var callDoResize = false;
197 var showRulers = this._showRulersSetting.get() && this._model.type() !== WebInspector.DeviceModeModel.Type.None; 214 var showRulers = this._showRulersSetting.get() && this._model.type() !== WebInspector.DeviceModeModel.Type.None;
198 var contentAreaResized = false; 215 var contentAreaResized = false;
199 var updateRulers = false; 216 var updateRulers = false;
200 217
201 var cssScreenRect = this._model.screenRect().scale(1 / zoomFactor); 218 var cssScreenRect = this._model.screenRect().scale(1 / zoomFactor);
202 if (!cssScreenRect.isEqual(this._cachedCssScreenRect)) { 219 if (!cssScreenRect.isEqual(this._cachedCssScreenRect)) {
203 this._screenArea.style.left = cssScreenRect.left + "px"; 220 applyRect(this._screenArea, cssScreenRect);
204 this._screenArea.style.top = cssScreenRect.top + "px";
205 this._screenArea.style.width = cssScreenRect.width + "px";
206 this._screenArea.style.height = cssScreenRect.height + "px";
207 this._leftRuler.element.style.left = cssScreenRect.left + "px"; 221 this._leftRuler.element.style.left = cssScreenRect.left + "px";
208 updateRulers = true; 222 updateRulers = true;
209 callDoResize = true; 223 callDoResize = true;
210 this._cachedCssScreenRect = cssScreenRect; 224 this._cachedCssScreenRect = cssScreenRect;
211 } 225 }
212 226
213 var cssVisiblePageRect = this._model.visiblePageRect().scale(1 / zoomFac tor); 227 var cssVisiblePageRect = this._model.visiblePageRect().scale(1 / zoomFac tor);
214 if (!cssVisiblePageRect.isEqual(this._cachedCssVisiblePageRect)) { 228 if (!cssVisiblePageRect.isEqual(this._cachedCssVisiblePageRect)) {
215 this._pageArea.style.left = cssVisiblePageRect.left + "px"; 229 applyRect(this._pageArea, cssVisiblePageRect);
216 this._pageArea.style.top = cssVisiblePageRect.top + "px";
217 this._pageArea.style.width = cssVisiblePageRect.width + "px";
218 this._pageArea.style.height = cssVisiblePageRect.height + "px";
219 callDoResize = true; 230 callDoResize = true;
220 this._cachedCssVisiblePageRect = cssVisiblePageRect; 231 this._cachedCssVisiblePageRect = cssVisiblePageRect;
221 } 232 }
222 233
234 var outlineRect = this._model.outlineRect().scale(1 / zoomFactor);
235 if (!outlineRect.isEqual(this._cachedOutlineRect)) {
236 applyRect(this._outlineImage, this._model.outlineRect().scale(1 / zo omFactor));
dgozman 2016/03/21 21:08:38 Just |outlineRect|.
mmccoy 2016/03/21 22:03:05 Done.
237 callDoResize = true;
238 this._cachedOutlineRect = outlineRect;
239 }
240 this._outlineImage.classList.toggle("device-frame-visible", this._model. deviceOutlineSetting().get());
241
242
dgozman 2016/03/21 21:08:38 nit: extra blank lines
mmccoy 2016/03/21 22:03:05 Done.
243
223 var resizable = this._model.type() === WebInspector.DeviceModeModel.Type .Responsive; 244 var resizable = this._model.type() === WebInspector.DeviceModeModel.Type .Responsive;
224 if (resizable !== this._cachedResizable) { 245 if (resizable !== this._cachedResizable) {
225 this._rightResizerElement.classList.toggle("hidden", !resizable); 246 this._rightResizerElement.classList.toggle("hidden", !resizable);
226 this._leftResizerElement.classList.toggle("hidden", !resizable); 247 this._leftResizerElement.classList.toggle("hidden", !resizable);
227 this._bottomResizerElement.classList.toggle("hidden", !resizable); 248 this._bottomResizerElement.classList.toggle("hidden", !resizable);
228 this._bottomRightResizerElement.classList.toggle("hidden", !resizabl e); 249 this._bottomRightResizerElement.classList.toggle("hidden", !resizabl e);
229 this._bottomLeftResizerElement.classList.toggle("hidden", !resizable ); 250 this._bottomLeftResizerElement.classList.toggle("hidden", !resizable );
230 this._cachedResizable = resizable; 251 this._cachedResizable = resizable;
231 } 252 }
232 253
(...skipping 24 matching lines...) Expand all
257 278
258 if (this._model.scale() !== this._cachedScale) { 279 if (this._model.scale() !== this._cachedScale) {
259 updateRulers = true; 280 updateRulers = true;
260 callDoResize = true; 281 callDoResize = true;
261 for (var block of this._presetBlocks) 282 for (var block of this._presetBlocks)
262 block.style.width = block.__width * this._model.scale() + "px"; 283 block.style.width = block.__width * this._model.scale() + "px";
263 this._cachedScale = this._model.scale(); 284 this._cachedScale = this._model.scale();
264 } 285 }
265 286
266 this._toolbar.update(); 287 this._toolbar.update();
267 this._loadScreenImage(this._model.screenImage()); 288 this._loadImage(this._screenImage, this._model.screenImage());
289 this._loadImage(this._outlineImage, this._model.outlineImage());
268 this._mediaInspector.setAxisTransform(this._model.scale()); 290 this._mediaInspector.setAxisTransform(this._model.scale());
269 if (callDoResize) 291 if (callDoResize)
270 this.doResize(); 292 this.doResize();
271 if (updateRulers) { 293 if (updateRulers) {
272 this._topRuler.render(this._cachedCssScreenRect ? this._cachedCssScr eenRect.left : 0, this._model.scale()); 294 var showingDevice = this._model.type() === WebInspector.DeviceModeMo del.Type.Device;
273 this._leftRuler.render(0, this._model.scale()); 295 this._topRuler.render(this._cachedCssScreenRect ? this._cachedCssScr eenRect.left : 0, this._model.scale(), showingDevice && this._cachedCssScreenRec t ? this._cachedCssScreenRect.width : 0);
296 this._leftRuler.render(0, this._model.scale(), showingDevice && this ._cachedCssScreenRect ? this._cachedCssScreenRect.height : 0);
297 this._topRuler.element.style.top = this._cachedCssScreenRect ? this. _cachedCssScreenRect.top + "px" : 0;
298 this._leftRuler.element.style.top = this._cachedCssScreenRect ? this ._cachedCssScreenRect.top + "px" : 0;
274 } 299 }
275 if (contentAreaResized) 300 if (contentAreaResized)
276 this._contentAreaResized(); 301 this._contentAreaResized();
277 }, 302 },
278 303
279 /** 304 /**
305 * @param {!Element} element
280 * @param {string} srcset 306 * @param {string} srcset
281 */ 307 */
282 _loadScreenImage: function(srcset) 308 _loadImage: function(element, srcset)
283 { 309 {
284 if (this._screenImage.getAttribute("srcset") === srcset) 310 if (element.getAttribute("srcset") === srcset)
285 return; 311 return;
286 this._screenImage.setAttribute("srcset", srcset); 312 element.setAttribute("srcset", srcset);
287 if (!srcset) 313 if (!srcset)
288 this._screenImage.classList.toggle("hidden", true); 314 element.classList.toggle("hidden", true);
289 }, 315 },
290 316
291 /** 317 /**
318 * @param {!Element} element
292 * @param {boolean} success 319 * @param {boolean} success
293 */ 320 */
294 _onScreenImageLoaded: function(success) 321 _onScreenImageLoaded: function(element, success)
dgozman 2016/03/21 21:08:38 nit: rename to _onImageLoaded for consistency.
mmccoy 2016/03/21 22:03:05 Done.
295 { 322 {
296 this._screenImage.classList.toggle("hidden", !success); 323 element.classList.toggle("hidden", !success);
297 }, 324 },
298 325
299 _contentAreaResized: function() 326 _contentAreaResized: function()
300 { 327 {
301 var zoomFactor = WebInspector.zoomManager.zoomFactor(); 328 var zoomFactor = WebInspector.zoomManager.zoomFactor();
302 var rect = this._contentArea.getBoundingClientRect(); 329 var rect = this._contentArea.getBoundingClientRect();
303 var availableSize = new Size(Math.max(rect.width * zoomFactor, 1), Math. max(rect.height * zoomFactor, 1)); 330 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 )); 331 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); 332 this._model.setAvailableSize(availableSize, preferredSize);
306 }, 333 },
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 this._offset = 0; 397 this._offset = 0;
371 this._count = 0; 398 this._count = 0;
372 this._throttler = new WebInspector.Throttler(0); 399 this._throttler = new WebInspector.Throttler(0);
373 this._applyCallback = applyCallback; 400 this._applyCallback = applyCallback;
374 } 401 }
375 402
376 WebInspector.DeviceModeView.Ruler.prototype = { 403 WebInspector.DeviceModeView.Ruler.prototype = {
377 /** 404 /**
378 * @param {number} offset 405 * @param {number} offset
379 * @param {number} scale 406 * @param {number} scale
407 * @param {number} maxLength
380 */ 408 */
381 render: function(offset, scale) 409 render: function(offset, scale, maxLength)
382 { 410 {
383 this._scale = scale; 411 this._scale = scale;
384 this._offset = offset; 412 this._offset = offset;
385 if (this._horizontal) 413 if (this._horizontal)
386 this.element.style.paddingLeft = this._offset + "px"; 414 this.element.style.paddingLeft = this._offset + "px";
387 else 415 else
388 this.element.style.paddingTop = this._offset + "px"; 416 this.element.style.paddingTop = this._offset + "px";
389 this._throttler.schedule(this._update.bind(this)); 417 this._throttler.schedule(this._update.bind(this));
418 this._maxLength = maxLength;
dgozman 2016/03/21 21:08:38 I'm not completely sure why do we need this.
mmccoy 2016/03/21 22:03:05 @samli I blindly poached this from your patch..
dgozman 2016/03/22 20:30:49 Let's revert and see what's broken. Have you teste
390 }, 419 },
391 420
392 /** 421 /**
393 * @override 422 * @override
394 */ 423 */
395 onResize: function() 424 onResize: function()
396 { 425 {
397 this._throttler.schedule(this._update.bind(this)); 426 this._throttler.schedule(this._update.bind(this));
398 }, 427 },
399 428
400 /** 429 /**
401 * @return {!Promise.<?>} 430 * @return {!Promise.<?>}
402 */ 431 */
403 _update: function() 432 _update: function()
404 { 433 {
405 var zoomFactor = WebInspector.zoomManager.zoomFactor(); 434 var zoomFactor = WebInspector.zoomManager.zoomFactor();
406 var size = this._horizontal ? this._contentElement.offsetWidth : this._c ontentElement.offsetHeight; 435 var size = this._horizontal ? this._contentElement.offsetWidth : this._c ontentElement.offsetHeight;
436 if (this._maxLength)
437 size = Math.min(size, this._maxLength)
407 438
408 if (this._scale !== this._renderedScale || zoomFactor !== this._rendered ZoomFactor) { 439 if (this._scale !== this._renderedScale || zoomFactor !== this._rendered ZoomFactor) {
409 this._contentElement.removeChildren(); 440 this._contentElement.removeChildren();
410 this._count = 0; 441 this._count = 0;
411 this._renderedScale = this._scale; 442 this._renderedScale = this._scale;
412 this._renderedZoomFactor = zoomFactor; 443 this._renderedZoomFactor = zoomFactor;
413 } 444 }
414 445
415 var dipSize = size * zoomFactor / this._scale; 446 var dipSize = size * zoomFactor / this._scale;
416 var count = Math.ceil(dipSize / 5); 447 var count = Math.ceil(dipSize / 5);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 /** 486 /**
456 * @param {number} size 487 * @param {number} size
457 */ 488 */
458 _onMarkerClick: function(size) 489 _onMarkerClick: function(size)
459 { 490 {
460 this._applyCallback.call(null, size); 491 this._applyCallback.call(null, size);
461 }, 492 },
462 493
463 __proto__: WebInspector.VBox.prototype 494 __proto__: WebInspector.VBox.prototype
464 } 495 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698