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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/emulation/EmulatedDevices.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: 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 */ 7 */
8 WebInspector.EmulatedDevice = function() 8 WebInspector.EmulatedDevice = function()
9 { 9 {
10 /** @type {string} */ 10 /** @type {string} */
11 this.title = ""; 11 this.title = "";
12 /** @type {string} */ 12 /** @type {string} */
13 this.type = WebInspector.EmulatedDevice.Type.Unknown; 13 this.type = WebInspector.EmulatedDevice.Type.Unknown;
14 /** @type {!WebInspector.EmulatedDevice.Orientation} */ 14 /** @type {!WebInspector.EmulatedDevice.Orientation} */
15 this.vertical = {width: 0, height: 0, outlineInsets: null, outlineImage: nul l}; 15 this.vertical = {width: 0, height: 0, outlineInsets: null, outlineImage: nul l, outlineWidth: 0, outlineHeight: 0};
dgozman 2016/02/01 17:18:27 I think outlineWidth === width + insets.left + ins
mmccoy 2016/02/10 20:06:34 Done!
16 /** @type {!WebInspector.EmulatedDevice.Orientation} */ 16 /** @type {!WebInspector.EmulatedDevice.Orientation} */
17 this.horizontal = {width: 0, height: 0, outlineInsets: null, outlineImage: n ull}; 17 this.horizontal = {width: 0, height: 0, outlineInsets: null, outlineImage: n ull, outlineWidth: 0, outlineHeight: 0};
18 /** @type {number} */ 18 /** @type {number} */
19 this.deviceScaleFactor = 1; 19 this.deviceScaleFactor = 1;
20 /** @type {!Array.<string>} */ 20 /** @type {!Array.<string>} */
21 this.capabilities = [WebInspector.EmulatedDevice.Capability.Touch, WebInspec tor.EmulatedDevice.Capability.Mobile]; 21 this.capabilities = [WebInspector.EmulatedDevice.Capability.Touch, WebInspec tor.EmulatedDevice.Capability.Mobile];
22 /** @type {string} */ 22 /** @type {string} */
23 this.userAgent = ""; 23 this.userAgent = "";
24 /** @type {!Array.<!WebInspector.EmulatedDevice.Mode>} */ 24 /** @type {!Array.<!WebInspector.EmulatedDevice.Mode>} */
25 this.modes = []; 25 this.modes = [];
26 26
27 /** @type {string} */ 27 /** @type {string} */
28 this._show = WebInspector.EmulatedDevice._Show.Default; 28 this._show = WebInspector.EmulatedDevice._Show.Default;
29 /** @type {boolean} */ 29 /** @type {boolean} */
30 this._showByDefault = true; 30 this._showByDefault = true;
31 31
32 /** @type {?Runtime.Extension} */ 32 /** @type {?Runtime.Extension} */
33 this._extension = null; 33 this._extension = null;
34 } 34 }
35 35
36 /** @typedef {!{title: string, orientation: string, insets: !Insets, image: ?str ing}} */ 36 /** @typedef {!{title: string, orientation: string, insets: !Insets, image: ?str ing}} */
37 WebInspector.EmulatedDevice.Mode; 37 WebInspector.EmulatedDevice.Mode;
38 38
39 /** @typedef {!{width: number, height: number, outlineInsets: ?Insets, outlineIm age: ?string}} */ 39 /** @typedef {!{width: number, height: number, outlineInsets: ?Insets, outlineIm age: ?string, outlineWidth: ?number, outlineHeight: ?number}} */
40 WebInspector.EmulatedDevice.Orientation; 40 WebInspector.EmulatedDevice.Orientation;
41 41
42 WebInspector.EmulatedDevice.Horizontal = "horizontal"; 42 WebInspector.EmulatedDevice.Horizontal = "horizontal";
43 WebInspector.EmulatedDevice.Vertical = "vertical"; 43 WebInspector.EmulatedDevice.Vertical = "vertical";
44 44
45 WebInspector.EmulatedDevice.Type = { 45 WebInspector.EmulatedDevice.Type = {
46 Phone: "phone", 46 Phone: "phone",
47 Tablet: "tablet", 47 Tablet: "tablet",
48 Notebook: "notebook", 48 Notebook: "notebook",
49 Desktop: "desktop", 49 Desktop: "desktop",
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 result.height = parseIntValue(json, "height"); 125 result.height = parseIntValue(json, "height");
126 if (result.height < 0 || result.height > WebInspector.DeviceModeMode l.MaxDeviceSize || result.height < WebInspector.DeviceModeModel.MinDeviceSize) 126 if (result.height < 0 || result.height > WebInspector.DeviceModeMode l.MaxDeviceSize || result.height < WebInspector.DeviceModeModel.MinDeviceSize)
127 throw new Error("Emulated device has wrong height: " + result.he ight); 127 throw new Error("Emulated device has wrong height: " + result.he ight);
128 128
129 var outlineInsets = parseValue(json["outline"], "insets", "object", null); 129 var outlineInsets = parseValue(json["outline"], "insets", "object", null);
130 if (outlineInsets) { 130 if (outlineInsets) {
131 result.outlineInsets = parseInsets(outlineInsets); 131 result.outlineInsets = parseInsets(outlineInsets);
132 if (result.outlineInsets.left < 0 || result.outlineInsets.top < 0) 132 if (result.outlineInsets.left < 0 || result.outlineInsets.top < 0)
133 throw new Error("Emulated device has wrong outline insets"); 133 throw new Error("Emulated device has wrong outline insets");
134 result.outlineImage = /** @type {string} */ (parseValue(json["ou tline"], "image", "string")); 134 result.outlineImage = /** @type {string} */ (parseValue(json["ou tline"], "image", "string"));
135 result.outlineWidth = /** @type {number} */ (parseIntValue(json[ "outline"], "width"));
136 result.outlineHeight = /** @type {number} */ (parseIntValue(json ["outline"], "height"));
135 } 137 }
136
137 return /** @type {!WebInspector.EmulatedDevice.Orientation} */ (resu lt); 138 return /** @type {!WebInspector.EmulatedDevice.Orientation} */ (resu lt);
138 } 139 }
139 140
140 var result = new WebInspector.EmulatedDevice(); 141 var result = new WebInspector.EmulatedDevice();
141 result.title = /** @type {string} */ (parseValue(json, "title", "string" )); 142 result.title = /** @type {string} */ (parseValue(json, "title", "string" ));
142 result.type = /** @type {string} */ (parseValue(json, "type", "string")) ; 143 result.type = /** @type {string} */ (parseValue(json, "type", "string")) ;
143 result.userAgent = /** @type {string} */ (parseValue(json, "user-agent", "string")); 144 result.userAgent = /** @type {string} */ (parseValue(json, "user-agent", "string"));
144 145
145 var capabilities = parseValue(json, "capabilities", "object", []); 146 var capabilities = parseValue(json, "capabilities", "object", []);
146 if (!Array.isArray(capabilities)) 147 if (!Array.isArray(capabilities))
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 var json = {}; 283 var json = {};
283 json["width"] = orientation.width; 284 json["width"] = orientation.width;
284 json["height"] = orientation.height; 285 json["height"] = orientation.height;
285 if (orientation.outlineInsets) { 286 if (orientation.outlineInsets) {
286 json["outline"] = {}; 287 json["outline"] = {};
287 json["outline"]["insets"] = {}; 288 json["outline"]["insets"] = {};
288 json["outline"]["insets"]["left"] = orientation.outlineInsets.left; 289 json["outline"]["insets"]["left"] = orientation.outlineInsets.left;
289 json["outline"]["insets"]["top"] = orientation.outlineInsets.top; 290 json["outline"]["insets"]["top"] = orientation.outlineInsets.top;
290 json["outline"]["insets"]["right"] = orientation.outlineInsets.right ; 291 json["outline"]["insets"]["right"] = orientation.outlineInsets.right ;
291 json["outline"]["insets"]["bottom"] = orientation.outlineInsets.bott om; 292 json["outline"]["insets"]["bottom"] = orientation.outlineInsets.bott om;
293 json["outline"]["width"] = orientation.outlineWidth;
294 json["outline"]["height"] = orientation.outlineHeight;
292 json["outline"]["image"] = orientation.outlineImage; 295 json["outline"]["image"] = orientation.outlineImage;
293 } 296 }
294 return json; 297 return json;
295 }, 298 },
296 299
297 /** 300 /**
298 * @param {!WebInspector.EmulatedDevice.Mode} mode 301 * @param {!WebInspector.EmulatedDevice.Mode} mode
299 * @return {string} 302 * @return {string}
300 */ 303 */
301 modeImage: function(mode) 304 modeImage: function(mode)
302 { 305 {
303 if (!mode.image) 306 if (!mode.image)
304 return ""; 307 return "";
305 if (!this._extension) 308 if (!this._extension)
306 return mode.image; 309 return mode.image;
307 return this._extension.module().substituteURL(mode.image); 310 return this._extension.module().substituteURL(mode.image);
308 }, 311 },
309 312
310 /** 313 /**
314 * @param {!WebInspector.EmulatedDevice.Mode} mode
315 * @return {string}
316 */
317 outlineImage: function(mode)
318 {
319 var orientation = this.orientationByName(mode.orientation);
320 if (!orientation.outlineImage)
321 return "";
322 if (!this._extension)
323 return orientation.outlineImage;
324 return this._extension.module().substituteURL(orientation.outlineImage);
325 },
326
327 /**
328 * @param {!WebInspector.EmulatedDevice.Mode} mode
329 * @return {Insets|string}
dgozman 2016/02/01 17:18:27 ?Insets
mmccoy 2016/02/10 20:06:34 Done
330 */
331 outlineInsets: function(mode)
332 {
333 var orientation = this.orientationByName(mode.orientation);
334 if (!orientation.outlineImage)
335 return "";
dgozman 2016/02/01 17:18:27 return null
mmccoy 2016/02/10 20:06:33 Done.
336 return orientation.outlineInsets;
337 },
338
339 /**
340 * @param {!WebInspector.EmulatedDevice.Mode} mode
341 * @return {Object|string}
342 */
343 outlineDimensions: function(mode)
344 {
345 var orientation = this.orientationByName(mode.orientation);
346 if (!orientation)
347 return "";
348 var dimensions = {
349 "width": orientation.outlineWidth,
350 "height": orientation.outlineHeight
351 }
352 return dimensions;
353 },
354
355 /**
311 * @param {string} name 356 * @param {string} name
312 * @return {!WebInspector.EmulatedDevice.Orientation} 357 * @return {!WebInspector.EmulatedDevice.Orientation}
313 */ 358 */
314 orientationByName: function(name) 359 orientationByName: function(name)
315 { 360 {
316 return name === WebInspector.EmulatedDevice.Vertical ? this.vertical : t his.horizontal; 361 return name === WebInspector.EmulatedDevice.Vertical ? this.vertical : t his.horizontal;
317 }, 362 },
318 363
319 /** 364 /**
320 * @return {boolean} 365 * @return {boolean}
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 if (deviceById.has(title)) 535 if (deviceById.has(title))
491 to[i].copyShowFrom(/** @type {!WebInspector.EmulatedDevice} */ ( deviceById.get(title))); 536 to[i].copyShowFrom(/** @type {!WebInspector.EmulatedDevice} */ ( deviceById.get(title)));
492 } 537 }
493 }, 538 },
494 539
495 __proto__: WebInspector.Object.prototype 540 __proto__: WebInspector.Object.prototype
496 } 541 }
497 542
498 /** @type {!WebInspector.EmulatedDevicesList} */ 543 /** @type {!WebInspector.EmulatedDevicesList} */
499 WebInspector.emulatedDevicesList; 544 WebInspector.emulatedDevicesList;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698