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

Side by Side Diff: Source/devtools/front_end/emulation/EmulatedDevices.js

Issue 1160323004: [DevTools] Move emulated devices to separate module. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixed compile Created 5 years, 6 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 | Annotate | Revision Log
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} */
(...skipping 10 matching lines...) Expand all
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
32 /** @type {?Runtime.Extension} */
33 this._extension = null;
31 } 34 }
32 35
33 /** @typedef {!{title: string, orientation: string, pageRect: !WebInspector.Geom etry.Rect, images: !WebInspector.EmulatedDevice.Images}} */ 36 /** @typedef {!{title: string, orientation: string, pageRect: !WebInspector.Geom etry.Rect, images: !WebInspector.EmulatedDevice.Images}} */
34 WebInspector.EmulatedDevice.Mode; 37 WebInspector.EmulatedDevice.Mode;
35 38
36 /** @typedef {!{width: number, height: number, outlineInsets: ?WebInspector.Geom etry.Insets, outlineImages: ?WebInspector.EmulatedDevice.Images}} */ 39 /** @typedef {!{width: number, height: number, outlineInsets: ?WebInspector.Geom etry.Insets, outlineImages: ?WebInspector.EmulatedDevice.Images}} */
37 WebInspector.EmulatedDevice.Orientation; 40 WebInspector.EmulatedDevice.Orientation;
38 41
39 WebInspector.EmulatedDevice.Horizontal = "horizontal"; 42 WebInspector.EmulatedDevice.Horizontal = "horizontal";
40 WebInspector.EmulatedDevice.Vertical = "vertical"; 43 WebInspector.EmulatedDevice.Vertical = "vertical";
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 * @param {!WebInspector.EmulatedDevice} device2 256 * @param {!WebInspector.EmulatedDevice} device2
254 * @return {number} 257 * @return {number}
255 */ 258 */
256 WebInspector.EmulatedDevice.compareByTitle = function(device1, device2) 259 WebInspector.EmulatedDevice.compareByTitle = function(device1, device2)
257 { 260 {
258 return device1.title < device2.title ? -1 : (device1.title > device2.title ? 1 : 0); 261 return device1.title < device2.title ? -1 : (device1.title > device2.title ? 1 : 0);
259 } 262 }
260 263
261 WebInspector.EmulatedDevice.prototype = { 264 WebInspector.EmulatedDevice.prototype = {
262 /** 265 /**
266 * @return {?Runtime.Extension}
267 */
268 extension: function()
269 {
270 return this._extension;
271 },
272
273 /**
274 * @param {?Runtime.Extension} extension
275 */
276 setExtension: function(extension)
277 {
278 this._extension = extension;
279 },
280
281 /**
263 * @return {*} 282 * @return {*}
264 */ 283 */
265 _toJSON: function() 284 _toJSON: function()
266 { 285 {
267 var json = {}; 286 var json = {};
268 json["title"] = this.title; 287 json["title"] = this.title;
269 json["type"] = this.type; 288 json["type"] = this.type;
270 json["user-agent"] = this.userAgent; 289 json["user-agent"] = this.userAgent;
271 json["capabilities"] = this.capabilities; 290 json["capabilities"] = this.capabilities;
272 291
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 433
415 434
416 /** 435 /**
417 * @constructor 436 * @constructor
418 * @extends {WebInspector.Object} 437 * @extends {WebInspector.Object}
419 */ 438 */
420 WebInspector.EmulatedDevicesList = function() 439 WebInspector.EmulatedDevicesList = function()
421 { 440 {
422 WebInspector.Object.call(this); 441 WebInspector.Object.call(this);
423 442
424 /**
425 * @param {!Array.<*>} list
426 * @param {string} type
427 * @return {!Array.<*>}
428 */
429 function convert(list, type)
430 {
431 var result = [];
432 for (var i = 0; i < list.length; ++i) {
433 var device = WebInspector.EmulatedDevice.fromOverridesDevice(/** @ty pe {!WebInspector.OverridesSupport.Device} */ (list[i]), list[i].title, type);
434 result.push(device._toJSON());
435 }
436 return result;
437 }
438
439 // FIXME: shrink default list once external list is good enough.
440 var defaultValue = convert(WebInspector.OverridesUI._phones, "phone")
441 .concat(convert(WebInspector.OverridesUI._tablets, "tablet"))
442 .concat(convert(WebInspector.OverridesUI._notebooks, "notebook"));
443
444 /** @type {!WebInspector.Setting} */ 443 /** @type {!WebInspector.Setting} */
445 this._standardSetting = WebInspector.settings.createSetting("standardEmulate dDeviceList", defaultValue); 444 this._standardSetting = WebInspector.settings.createSetting("standardEmulate dDeviceList", []);
446 /** @type {!Array.<!WebInspector.EmulatedDevice>} */ 445 /** @type {!Array.<!WebInspector.EmulatedDevice>} */
447 this._standard = this._listFromJSONV1(this._standardSetting.get()); 446 this._standard = this._listFromJSONV1(this._standardSetting.get());
447 this._updateStandardDevices();
448 448
449 /** @type {!WebInspector.Setting} */ 449 /** @type {!WebInspector.Setting} */
450 this._customSetting = WebInspector.settings.createSetting("customEmulatedDev iceList", []); 450 this._customSetting = WebInspector.settings.createSetting("customEmulatedDev iceList", []);
451 /** @type {!Array.<!WebInspector.EmulatedDevice>} */ 451 /** @type {!Array.<!WebInspector.EmulatedDevice>} */
452 this._custom = this._listFromJSONV1(this._customSetting.get()); 452 this._custom = this._listFromJSONV1(this._customSetting.get());
453 } 453 }
454 454
455 WebInspector.EmulatedDevicesList.Events = { 455 WebInspector.EmulatedDevicesList.Events = {
456 CustomDevicesUpdated: "CustomDevicesUpdated", 456 CustomDevicesUpdated: "CustomDevicesUpdated",
457 StandardDevicesUpdated: "StandardDevicesUpdated" 457 StandardDevicesUpdated: "StandardDevicesUpdated"
458 } 458 }
459 459
460 WebInspector.EmulatedDevicesList.prototype = { 460 WebInspector.EmulatedDevicesList.prototype = {
461 _updateStandardDevices: function()
462 {
463 var devices = [];
464 var extensions = self.runtime.extensions("emulated-device");
465 for (var i = 0; i < extensions.length; ++i) {
466 var device = WebInspector.EmulatedDevice.fromJSONV1(extensions[i].de scriptor()["device"]);
467 device.setExtension(extensions[i]);
468 devices.push(device);
469 }
470 this._copyShowValues(this._standard, devices);
471 this._standard = devices;
472 this.saveStandardDevices();
473 },
474
461 /** 475 /**
462 * @param {!Array.<*>} jsonArray 476 * @param {!Array.<*>} jsonArray
463 * @return {!Array.<!WebInspector.EmulatedDevice>} 477 * @return {!Array.<!WebInspector.EmulatedDevice>}
464 */ 478 */
465 _listFromJSONV1: function(jsonArray) 479 _listFromJSONV1: function(jsonArray)
466 { 480 {
467 var result = []; 481 var result = [];
468 if (!Array.isArray(jsonArray)) 482 if (!Array.isArray(jsonArray))
469 return result; 483 return result;
470 for (var i = 0; i < jsonArray.length; ++i) { 484 for (var i = 0; i < jsonArray.length; ++i) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 if (deviceById.has(title)) 552 if (deviceById.has(title))
539 to[i].copyShowFrom(/** @type {!WebInspector.EmulatedDevice} */ ( deviceById.get(title))); 553 to[i].copyShowFrom(/** @type {!WebInspector.EmulatedDevice} */ ( deviceById.get(title)));
540 } 554 }
541 }, 555 },
542 556
543 __proto__: WebInspector.Object.prototype 557 __proto__: WebInspector.Object.prototype
544 } 558 }
545 559
546 /** @type {!WebInspector.EmulatedDevicesList} */ 560 /** @type {!WebInspector.EmulatedDevicesList} */
547 WebInspector.emulatedDevicesList; 561 WebInspector.emulatedDevicesList;
OLDNEW
« no previous file with comments | « Source/devtools/front_end/emulated_devices/module.json ('k') | Source/devtools/front_end/emulation/OverridesUI.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698