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

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: Disallow rulers and device frame to be show simultaneously 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;
dgozman 2016/04/13 22:52:06 Just set |showRulers| to false here if we have out
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._contentArea);
247 this._leftRuler.show(this._contentArea); 266 this._leftRuler.show(this._contentArea);
248 } else { 267 } else {
249 this._topRuler.detach(); 268 this._topRuler.detach();
250 this._leftRuler.detach(); 269 this._leftRuler.detach();
251 } 270 }
252 contentAreaResized = true; 271 contentAreaResized = true;
253 callDoResize = true; 272 callDoResize = true;
254 this._cachedShowRulers = showRulers; 273 this._cachedShowRulers = showRulers;
255 } 274 }
256 275
257 if (this._model.scale() !== this._cachedScale) { 276 if (this._model.scale() !== this._cachedScale) {
258 updateRulers = true; 277 updateRulers = true;
259 callDoResize = true; 278 callDoResize = true;
260 for (var block of this._presetBlocks) 279 for (var block of this._presetBlocks)
261 block.style.width = block.__width * this._model.scale() + "px"; 280 block.style.width = block.__width * this._model.scale() + "px";
262 this._cachedScale = this._model.scale(); 281 this._cachedScale = this._model.scale();
263 } 282 }
264 283
265 this._toolbar.update(); 284 this._toolbar.update();
266 this._loadScreenImage(this._model.screenImage()); 285 this._loadImage(this._screenImage, this._model.screenImage());
286 this._loadImage(this._outlineImage, this._model.outlineImage());
267 this._mediaInspector.setAxisTransform(this._model.scale()); 287 this._mediaInspector.setAxisTransform(this._model.scale());
268 if (callDoResize) 288 if (callDoResize)
269 this.doResize(); 289 this.doResize();
270 if (updateRulers) { 290 if (updateRulers) {
291 var showingDevice = this._model.type() === WebInspector.DeviceModeMo del.Type.Device;
dgozman 2016/04/13 22:52:06 Unused.
mmccoy 2016/04/19 14:42:19 Done.
271 this._topRuler.render(this._cachedCssScreenRect ? this._cachedCssScr eenRect.left : 0, this._model.scale()); 292 this._topRuler.render(this._cachedCssScreenRect ? this._cachedCssScr eenRect.left : 0, this._model.scale());
272 this._leftRuler.render(0, this._model.scale()); 293 this._leftRuler.render(0, this._model.scale());
294 this._topRuler.element.style.top = this._cachedCssScreenRect ? this. _cachedCssScreenRect.top + "px" : 0;
295 this._leftRuler.element.style.top = this._cachedCssScreenRect ? this ._cachedCssScreenRect.top + "px" : 0;
273 } 296 }
274 if (contentAreaResized) 297 if (contentAreaResized)
275 this._contentAreaResized(); 298 this._contentAreaResized();
276 }, 299 },
277 300
278 /** 301 /**
302 * @param {!Element} element
279 * @param {string} srcset 303 * @param {string} srcset
280 */ 304 */
281 _loadScreenImage: function(srcset) 305 _loadImage: function(element, srcset)
282 { 306 {
283 if (this._screenImage.getAttribute("srcset") === srcset) 307 if (element.getAttribute("srcset") === srcset)
284 return; 308 return;
285 this._screenImage.setAttribute("srcset", srcset); 309 element.setAttribute("srcset", srcset);
286 if (!srcset) 310 if (!srcset)
287 this._screenImage.classList.toggle("hidden", true); 311 element.classList.toggle("hidden", true);
288 }, 312 },
289 313
290 /** 314 /**
315 * @param {!Element} element
291 * @param {boolean} success 316 * @param {boolean} success
292 */ 317 */
293 _onScreenImageLoaded: function(success) 318 _onImageLoaded: function(element, success)
294 { 319 {
295 this._screenImage.classList.toggle("hidden", !success); 320 element.classList.toggle("hidden", !success);
296 }, 321 },
297 322
298 _contentAreaResized: function() 323 _contentAreaResized: function()
299 { 324 {
300 var zoomFactor = WebInspector.zoomManager.zoomFactor(); 325 var zoomFactor = WebInspector.zoomManager.zoomFactor();
301 var rect = this._contentArea.getBoundingClientRect(); 326 var rect = this._contentArea.getBoundingClientRect();
302 var availableSize = new Size(Math.max(rect.width * zoomFactor, 1), Math. max(rect.height * zoomFactor, 1)); 327 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 )); 328 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); 329 this._model.setAvailableSize(availableSize, preferredSize);
305 }, 330 },
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 this._throttler.schedule(this._update.bind(this)); 467 this._throttler.schedule(this._update.bind(this));
443 }, 468 },
444 469
445 /** 470 /**
446 * @return {!Promise.<?>} 471 * @return {!Promise.<?>}
447 */ 472 */
448 _update: function() 473 _update: function()
449 { 474 {
450 var zoomFactor = WebInspector.zoomManager.zoomFactor(); 475 var zoomFactor = WebInspector.zoomManager.zoomFactor();
451 var size = this._horizontal ? this._contentElement.offsetWidth : this._c ontentElement.offsetHeight; 476 var size = this._horizontal ? this._contentElement.offsetWidth : this._c ontentElement.offsetHeight;
477 if (this._maxLength)
dgozman 2016/04/13 22:52:06 This is not needed anymore.
mmccoy 2016/04/19 14:42:19 Removed.
478 size = Math.min(size, this._maxLength)
452 479
453 if (this._scale !== this._renderedScale || zoomFactor !== this._rendered ZoomFactor) { 480 if (this._scale !== this._renderedScale || zoomFactor !== this._rendered ZoomFactor) {
454 this._contentElement.removeChildren(); 481 this._contentElement.removeChildren();
455 this._count = 0; 482 this._count = 0;
456 this._renderedScale = this._scale; 483 this._renderedScale = this._scale;
457 this._renderedZoomFactor = zoomFactor; 484 this._renderedZoomFactor = zoomFactor;
458 } 485 }
459 486
460 var dipSize = size * zoomFactor / this._scale; 487 var dipSize = size * zoomFactor / this._scale;
461 var count = Math.ceil(dipSize / 5); 488 var count = Math.ceil(dipSize / 5);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 /** 527 /**
501 * @param {number} size 528 * @param {number} size
502 */ 529 */
503 _onMarkerClick: function(size) 530 _onMarkerClick: function(size)
504 { 531 {
505 this._applyCallback.call(null, size); 532 this._applyCallback.call(null, size);
506 }, 533 },
507 534
508 __proto__: WebInspector.VBox.prototype 535 __proto__: WebInspector.VBox.prototype
509 } 536 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698