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

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: Code cleaup, remove unused code and cl comments 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 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._onImageLoaded.bind(thi s, this._outlineImage, true), false);
47 this._outlineImage.addEventListener("error", this._onImageLoaded.bind(th is, 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._onImageLoaded.bind(this , this._screenImage, true), false);
48 this._screenImage.addEventListener("error", this._onScreenImageLoaded.bi nd(this, false), false); 53 this._screenImage.addEventListener("error", this._onImageLoaded.bind(thi s, 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, outlineRect);
237 callDoResize = true;
238 this._cachedOutlineRect = outlineRect;
239 }
240 this._outlineImage.classList.toggle("device-frame-visible", (this._model .deviceOutlineSetting().get() && this._model.outlineImage()));
241
223 var resizable = this._model.type() === WebInspector.DeviceModeModel.Type .Responsive; 242 var resizable = this._model.type() === WebInspector.DeviceModeModel.Type .Responsive;
224 if (resizable !== this._cachedResizable) { 243 if (resizable !== this._cachedResizable) {
225 this._rightResizerElement.classList.toggle("hidden", !resizable); 244 this._rightResizerElement.classList.toggle("hidden", !resizable);
226 this._leftResizerElement.classList.toggle("hidden", !resizable); 245 this._leftResizerElement.classList.toggle("hidden", !resizable);
227 this._bottomResizerElement.classList.toggle("hidden", !resizable); 246 this._bottomResizerElement.classList.toggle("hidden", !resizable);
228 this._bottomRightResizerElement.classList.toggle("hidden", !resizabl e); 247 this._bottomRightResizerElement.classList.toggle("hidden", !resizabl e);
229 this._bottomLeftResizerElement.classList.toggle("hidden", !resizable ); 248 this._bottomLeftResizerElement.classList.toggle("hidden", !resizable );
230 this._cachedResizable = resizable; 249 this._cachedResizable = resizable;
231 } 250 }
232 251
233 var mediaInspectorVisible = this._showMediaInspectorSetting.get() && thi s._model.type() !== WebInspector.DeviceModeModel.Type.None; 252 var mediaInspectorVisible = this._showMediaInspectorSetting.get() && thi s._model.type() !== WebInspector.DeviceModeModel.Type.None;
234 if (mediaInspectorVisible !== this._cachedMediaInspectorVisible) { 253 if (mediaInspectorVisible !== this._cachedMediaInspectorVisible) {
235 if (mediaInspectorVisible) 254 if (mediaInspectorVisible)
236 this._mediaInspector.show(this._mediaInspectorContainer); 255 this._mediaInspector.show(this._mediaInspectorContainer);
237 else 256 else
238 this._mediaInspector.detach(); 257 this._mediaInspector.detach();
239 contentAreaResized = true; 258 contentAreaResized = true;
240 callDoResize = true; 259 callDoResize = true;
241 this._cachedMediaInspectorVisible = mediaInspectorVisible; 260 this._cachedMediaInspectorVisible = mediaInspectorVisible;
242 } 261 }
243 262
244 if (showRulers !== this._cachedShowRulers) { 263 if (showRulers !== this._cachedShowRulers) {
245 this._contentClip.classList.toggle("device-mode-rulers-visible", sho wRulers); 264 this._contentClip.classList.toggle("device-mode-rulers-visible", sho wRulers);
246 if (showRulers) { 265 if (showRulers) {
247 this._topRuler.show(this._contentClip, this._contentArea); 266 // this._topRuler.show(this._contentClip, this._contentArea);
dgozman 2016/04/07 00:54:43 Commented code?
mmccoy 2016/04/11 14:51:24 Done.
267 this._topRuler.show(this._contentArea);
248 this._leftRuler.show(this._contentArea); 268 this._leftRuler.show(this._contentArea);
249 } else { 269 } else {
250 this._topRuler.detach(); 270 this._topRuler.detach();
251 this._leftRuler.detach(); 271 this._leftRuler.detach();
252 } 272 }
253 contentAreaResized = true; 273 contentAreaResized = true;
254 callDoResize = true; 274 callDoResize = true;
255 this._cachedShowRulers = showRulers; 275 this._cachedShowRulers = showRulers;
256 } 276 }
257 277
258 if (this._model.scale() !== this._cachedScale) { 278 if (this._model.scale() !== this._cachedScale) {
259 updateRulers = true; 279 updateRulers = true;
260 callDoResize = true; 280 callDoResize = true;
261 for (var block of this._presetBlocks) 281 for (var block of this._presetBlocks)
262 block.style.width = block.__width * this._model.scale() + "px"; 282 block.style.width = block.__width * this._model.scale() + "px";
263 this._cachedScale = this._model.scale(); 283 this._cachedScale = this._model.scale();
264 } 284 }
265 285
266 this._toolbar.update(); 286 this._toolbar.update();
267 this._loadScreenImage(this._model.screenImage()); 287 this._loadImage(this._screenImage, this._model.screenImage());
288 this._loadImage(this._outlineImage, this._model.outlineImage());
268 this._mediaInspector.setAxisTransform(this._model.scale()); 289 this._mediaInspector.setAxisTransform(this._model.scale());
269 if (callDoResize) 290 if (callDoResize)
270 this.doResize(); 291 this.doResize();
271 if (updateRulers) { 292 if (updateRulers) {
272 this._topRuler.render(this._cachedCssScreenRect ? this._cachedCssScr eenRect.left : 0, this._model.scale()); 293 var showingDevice = this._model.type() === WebInspector.DeviceModeMo del.Type.Device;
273 this._leftRuler.render(0, this._model.scale()); 294 this._topRuler.render(this._cachedCssScreenRect ? this._cachedCssScr eenRect.left : 0, this._model.scale(), showingDevice && this._cachedCssScreenRec t ? this._cachedCssScreenRect.width : 0);
295 this._leftRuler.render(0, this._model.scale(), showingDevice && this ._cachedCssScreenRect ? this._cachedCssScreenRect.height : 0);
296 this._topRuler.element.style.top = this._cachedCssScreenRect ? this. _cachedCssScreenRect.top + "px" : 0;
297 this._leftRuler.element.style.top = this._cachedCssScreenRect ? this ._cachedCssScreenRect.top + "px" : 0;
274 } 298 }
275 if (contentAreaResized) 299 if (contentAreaResized)
276 this._contentAreaResized(); 300 this._contentAreaResized();
277 }, 301 },
278 302
279 /** 303 /**
304 * @param {!Element} element
280 * @param {string} srcset 305 * @param {string} srcset
281 */ 306 */
282 _loadScreenImage: function(srcset) 307 _loadImage: function(element, srcset)
283 { 308 {
284 if (this._screenImage.getAttribute("srcset") === srcset) 309 if (element.getAttribute("srcset") === srcset)
285 return; 310 return;
286 this._screenImage.setAttribute("srcset", srcset); 311 element.setAttribute("srcset", srcset);
287 if (!srcset) 312 if (!srcset)
288 this._screenImage.classList.toggle("hidden", true); 313 element.classList.toggle("hidden", true);
289 }, 314 },
290 315
291 /** 316 /**
317 * @param {!Element} element
292 * @param {boolean} success 318 * @param {boolean} success
293 */ 319 */
294 _onScreenImageLoaded: function(success) 320 _onImageLoaded: function(element, success)
295 { 321 {
296 this._screenImage.classList.toggle("hidden", !success); 322 element.classList.toggle("hidden", !success);
297 }, 323 },
298 324
299 _contentAreaResized: function() 325 _contentAreaResized: function()
300 { 326 {
301 var zoomFactor = WebInspector.zoomManager.zoomFactor(); 327 var zoomFactor = WebInspector.zoomManager.zoomFactor();
302 var rect = this._contentArea.getBoundingClientRect(); 328 var rect = this._contentArea.getBoundingClientRect();
303 var availableSize = new Size(Math.max(rect.width * zoomFactor, 1), Math. max(rect.height * zoomFactor, 1)); 329 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 )); 330 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); 331 this._model.setAvailableSize(availableSize, preferredSize);
306 }, 332 },
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 this._offset = 0; 396 this._offset = 0;
371 this._count = 0; 397 this._count = 0;
372 this._throttler = new WebInspector.Throttler(0); 398 this._throttler = new WebInspector.Throttler(0);
373 this._applyCallback = applyCallback; 399 this._applyCallback = applyCallback;
374 } 400 }
375 401
376 WebInspector.DeviceModeView.Ruler.prototype = { 402 WebInspector.DeviceModeView.Ruler.prototype = {
377 /** 403 /**
378 * @param {number} offset 404 * @param {number} offset
379 * @param {number} scale 405 * @param {number} scale
406 * @param {number} maxLength
380 */ 407 */
381 render: function(offset, scale) 408 render: function(offset, scale, maxLength)
dgozman 2016/04/07 00:54:43 Please revert anything related to maxLength. Neith
samli 2016/04/07 01:09:55 mmccoy correctly determined what this is: "This co
382 { 409 {
383 this._scale = scale; 410 this._scale = scale;
384 this._offset = offset; 411 this._offset = offset;
385 if (this._horizontal) 412 if (this._horizontal)
386 this.element.style.paddingLeft = this._offset + "px"; 413 this.element.style.paddingLeft = this._offset + "px";
387 else 414 else
388 this.element.style.paddingTop = this._offset + "px"; 415 this.element.style.paddingTop = this._offset + "px";
389 this._throttler.schedule(this._update.bind(this)); 416 this._throttler.schedule(this._update.bind(this));
417 this._maxLength = maxLength;
390 }, 418 },
391 419
392 /** 420 /**
393 * @override 421 * @override
394 */ 422 */
395 onResize: function() 423 onResize: function()
396 { 424 {
397 this._throttler.schedule(this._update.bind(this)); 425 this._throttler.schedule(this._update.bind(this));
398 }, 426 },
399 427
400 /** 428 /**
401 * @return {!Promise.<?>} 429 * @return {!Promise.<?>}
402 */ 430 */
403 _update: function() 431 _update: function()
404 { 432 {
405 var zoomFactor = WebInspector.zoomManager.zoomFactor(); 433 var zoomFactor = WebInspector.zoomManager.zoomFactor();
406 var size = this._horizontal ? this._contentElement.offsetWidth : this._c ontentElement.offsetHeight; 434 var size = this._horizontal ? this._contentElement.offsetWidth : this._c ontentElement.offsetHeight;
435 if (this._maxLength)
436 size = Math.min(size, this._maxLength)
407 437
408 if (this._scale !== this._renderedScale || zoomFactor !== this._rendered ZoomFactor) { 438 if (this._scale !== this._renderedScale || zoomFactor !== this._rendered ZoomFactor) {
409 this._contentElement.removeChildren(); 439 this._contentElement.removeChildren();
410 this._count = 0; 440 this._count = 0;
411 this._renderedScale = this._scale; 441 this._renderedScale = this._scale;
412 this._renderedZoomFactor = zoomFactor; 442 this._renderedZoomFactor = zoomFactor;
413 } 443 }
414 444
415 var dipSize = size * zoomFactor / this._scale; 445 var dipSize = size * zoomFactor / this._scale;
416 var count = Math.ceil(dipSize / 5); 446 var count = Math.ceil(dipSize / 5);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 /** 485 /**
456 * @param {number} size 486 * @param {number} size
457 */ 487 */
458 _onMarkerClick: function(size) 488 _onMarkerClick: function(size)
459 { 489 {
460 this._applyCallback.call(null, size); 490 this._applyCallback.call(null, size);
461 }, 491 },
462 492
463 __proto__: WebInspector.VBox.prototype 493 __proto__: WebInspector.VBox.prototype
464 } 494 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698