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

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

Issue 1178643004: [DevTools] Initial implementation of device modes. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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 15 matching lines...) Expand all
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, pageRect: !WebInspector.Geom etry.Rect, images: !WebInspector.EmulatedDevice.Images}} */ 36 /** @typedef {!{title: string, orientation: string, pageRect: !WebInspector.Geom etry.Rect, images: ?WebInspector.EmulatedDevice.Images}} */
37 WebInspector.EmulatedDevice.Mode; 37 WebInspector.EmulatedDevice.Mode;
38 38
39 /** @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}} */
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",
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 mode.title = /** @type {string} */ (parseValue(modes[i], "title", "s tring")); 205 mode.title = /** @type {string} */ (parseValue(modes[i], "title", "s tring"));
206 mode.orientation = /** @type {string} */ (parseValue(modes[i], "orie ntation", "string")); 206 mode.orientation = /** @type {string} */ (parseValue(modes[i], "orie ntation", "string"));
207 if (mode.orientation !== WebInspector.EmulatedDevice.Vertical && mod e.orientation !== WebInspector.EmulatedDevice.Horizontal) 207 if (mode.orientation !== WebInspector.EmulatedDevice.Vertical && mod e.orientation !== WebInspector.EmulatedDevice.Horizontal)
208 throw new Error("Emulated device mode has wrong orientation '" + mode.orientation + "'"); 208 throw new Error("Emulated device mode has wrong orientation '" + mode.orientation + "'");
209 var orientation = result.orientationByName(mode.orientation); 209 var orientation = result.orientationByName(mode.orientation);
210 mode.pageRect = parseIntRect(parseValue(modes[i], "page-rect", "obje ct")); 210 mode.pageRect = parseIntRect(parseValue(modes[i], "page-rect", "obje ct"));
211 if (mode.pageRect.top < 0 || mode.pageRect.left < 0 || mode.pageRect .width < 0 || mode.pageRect.height < 0 || 211 if (mode.pageRect.top < 0 || mode.pageRect.left < 0 || mode.pageRect .width < 0 || mode.pageRect.height < 0 ||
212 mode.pageRect.top + mode.pageRect.height > orientation.height || mode.pageRect.left + mode.pageRect.width > orientation.width) { 212 mode.pageRect.top + mode.pageRect.height > orientation.height || mode.pageRect.left + mode.pageRect.width > orientation.width) {
213 throw new Error("Emulated device mode '" + mode.title + "'has wr ong page rect"); 213 throw new Error("Emulated device mode '" + mode.title + "'has wr ong page rect");
214 } 214 }
215 mode.images = parseImages(parseValue(modes[i], "images", "object")); 215 if (modes[i].hasOwnProperty("images"))
216 mode.images = parseImages(parseValue(modes[i], "images", "object "));
216 result.modes.push(mode); 217 result.modes.push(mode);
217 } 218 }
218 219
219 result._showByDefault = /** @type {boolean} */ (parseValue(json, "show-b y-default", "boolean", true)); 220 result._showByDefault = /** @type {boolean} */ (parseValue(json, "show-b y-default", "boolean", true));
220 result._show = /** @type {string} */ (parseValue(json, "show", "string", WebInspector.EmulatedDevice._Show.Default)); 221 result._show = /** @type {string} */ (parseValue(json, "show", "string", WebInspector.EmulatedDevice._Show.Default));
221 222
223 result.createImplicitModes();
222 return result; 224 return result;
223 } catch (e) { 225 } catch (e) {
224 WebInspector.console.error("Failed to update emulated device list. " + S tring(e)); 226 WebInspector.console.error("Failed to update emulated device list. " + S tring(e));
225 return null; 227 return null;
226 } 228 }
227 } 229 }
228 230
229 /** 231 /**
230 * @param {!WebInspector.OverridesSupport.Device} device 232 * @param {!WebInspector.OverridesSupport.Device} device
231 * @param {string} title 233 * @param {string} title
232 * @param {string=} type 234 * @param {string=} type
233 * @return {!WebInspector.EmulatedDevice} 235 * @return {!WebInspector.EmulatedDevice}
234 */ 236 */
235 WebInspector.EmulatedDevice.fromOverridesDevice = function(device, title, type) 237 WebInspector.EmulatedDevice.fromOverridesDevice = function(device, title, type)
236 { 238 {
237 var result = new WebInspector.EmulatedDevice(); 239 var result = new WebInspector.EmulatedDevice();
238 result.title = title; 240 result.title = title;
239 result.type = type || WebInspector.EmulatedDevice.Type.Unknown; 241 result.type = type || WebInspector.EmulatedDevice.Type.Unknown;
240 result.vertical.width = device.width; 242 result.vertical.width = device.width;
241 result.vertical.height = device.height; 243 result.vertical.height = device.height;
242 result.horizontal.width = device.height; 244 result.horizontal.width = device.height;
243 result.horizontal.height = device.width; 245 result.horizontal.height = device.width;
244 result.deviceScaleFactor = device.deviceScaleFactor; 246 result.deviceScaleFactor = device.deviceScaleFactor;
245 result.userAgent = device.userAgent; 247 result.userAgent = device.userAgent;
246 result.capabilities = []; 248 result.capabilities = [];
247 if (device.touch) 249 if (device.touch)
248 result.capabilities.push(WebInspector.EmulatedDevice.Capability.Touch); 250 result.capabilities.push(WebInspector.EmulatedDevice.Capability.Touch);
249 if (device.mobile) 251 if (device.mobile)
250 result.capabilities.push(WebInspector.EmulatedDevice.Capability.Mobile); 252 result.capabilities.push(WebInspector.EmulatedDevice.Capability.Mobile);
253 result.createImplicitModes();
251 return result; 254 return result;
252 } 255 }
253 256
254 /** 257 /**
255 * @param {!WebInspector.EmulatedDevice} device1 258 * @param {!WebInspector.EmulatedDevice} device1
256 * @param {!WebInspector.EmulatedDevice} device2 259 * @param {!WebInspector.EmulatedDevice} device2
257 * @return {number} 260 * @return {number}
258 */ 261 */
259 WebInspector.EmulatedDevice.compareByTitle = function(device1, device2) 262 WebInspector.EmulatedDevice.compareByTitle = function(device1, device2)
260 { 263 {
(...skipping 10 matching lines...) Expand all
271 }, 274 },
272 275
273 /** 276 /**
274 * @param {?Runtime.Extension} extension 277 * @param {?Runtime.Extension} extension
275 */ 278 */
276 setExtension: function(extension) 279 setExtension: function(extension)
277 { 280 {
278 this._extension = extension; 281 this._extension = extension;
279 }, 282 },
280 283
284 createImplicitModes: function()
285 {
286 if (!Runtime.experiments.isEnabled("deviceArt")) {
287 this.modes = [];
288 if (this.type === WebInspector.EmulatedDevice.Type.Tablet)
289 this.modes.push({title: "", orientation: WebInspector.EmulatedDe vice.Vertical, pageRect: {top: 0, left: 0, width: this.horizontal.width, height: this.horizontal.height}, images: null});
pfeldman 2015/06/13 06:48:59 Why would you rotate the tablet and not the phone?
pfeldman 2015/06/13 06:48:59 defining rects as array would help readability her
dgozman 2015/06/16 15:09:30 We don't have legacy data anymore. It's all in des
290 else
291 this.modes.push({title: "", orientation: WebInspector.EmulatedDe vice.Vertical, pageRect: {top: 0, left: 0, width: this.vertical.width, height: t his.vertical.height}, images: null});
292 return;
293 }
294 if (this.modes.length)
295 return;
296 this.modes.push({title: "", orientation: WebInspector.EmulatedDevice.Ver tical, pageRect: {top: 0, left: 0, width: this.vertical.width, height: this.vert ical.height}, images: null});
297 if (this.type === WebInspector.EmulatedDevice.Type.Phone || this.type == = WebInspector.EmulatedDevice.Type.Tablet || this.type === WebInspector.Emulated Device.Type.Unknown)
pfeldman 2015/06/13 06:48:59 I don't think there should be a code that would ch
dgozman 2015/06/16 15:09:30 Added TODO, will remove in next patch.
298 this.modes.push({title: "", orientation: WebInspector.EmulatedDevice .Horizontal, pageRect: {top: 0, left: 0, width: this.horizontal.width, height: t his.horizontal.height}, images: null});
299 },
300
301 /**
302 * @param {string} orientation
303 * @return {!Array.<!WebInspector.EmulatedDevice.Mode>}
304 */
305 modesForOrientation: function(orientation)
306 {
307 var result = [];
308 for (var index = 0; index < this.modes.length; index++) {
309 if (this.modes[index].orientation === orientation)
310 result.push(this.modes[index]);
311 }
312 return result;
313 },
314
281 /** 315 /**
282 * @return {*} 316 * @return {*}
283 */ 317 */
284 _toJSON: function() 318 _toJSON: function()
285 { 319 {
286 var json = {}; 320 var json = {};
287 json["title"] = this.title; 321 json["title"] = this.title;
288 json["type"] = this.type; 322 json["type"] = this.type;
289 json["user-agent"] = this.userAgent; 323 json["user-agent"] = this.userAgent;
290 json["capabilities"] = this.capabilities; 324 json["capabilities"] = this.capabilities;
291 325
292 json["screen"] = {}; 326 json["screen"] = {};
293 json["screen"]["device-pixel-ratio"] = this.deviceScaleFactor; 327 json["screen"]["device-pixel-ratio"] = this.deviceScaleFactor;
294 json["screen"]["vertical"] = this._orientationToJSON(this.vertical); 328 json["screen"]["vertical"] = this._orientationToJSON(this.vertical);
295 json["screen"]["horizontal"] = this._orientationToJSON(this.horizontal); 329 json["screen"]["horizontal"] = this._orientationToJSON(this.horizontal);
296 330
297 json["modes"] = []; 331 json["modes"] = [];
298 for (var i = 0; i < this.modes.length; ++i) { 332 for (var i = 0; i < this.modes.length; ++i) {
299 var mode = {}; 333 var mode = {};
300 mode["title"] = this.modes[i].title; 334 mode["title"] = this.modes[i].title;
301 mode["orientation"] = this.modes[i].orientation; 335 mode["orientation"] = this.modes[i].orientation;
302 mode["page-rect"] = this.modes[i].pageRect; 336 mode["page-rect"] = this.modes[i].pageRect;
303 mode["images"] = this.modes[i].images._toJSON(); 337 if (this.modes[i].images)
338 mode["images"] = this.modes[i].images._toJSON();
304 json["modes"].push(mode); 339 json["modes"].push(mode);
305 } 340 }
306 341
307 json["show-by-default"] = this._showByDefault; 342 json["show-by-default"] = this._showByDefault;
308 json["show"] = this._show; 343 json["show"] = this._show;
309 344
310 return json; 345 return json;
311 }, 346 },
312 347
313 /** 348 /**
314 * @param {!WebInspector.EmulatedDevice.Orientation} orientation 349 * @param {!WebInspector.EmulatedDevice.Orientation} orientation
315 * @return {*} 350 * @return {*}
316 */ 351 */
317 _orientationToJSON: function(orientation) 352 _orientationToJSON: function(orientation)
318 { 353 {
319 var json = {}; 354 var json = {};
320 json["width"] = orientation.width; 355 json["width"] = orientation.width;
321 json["height"] = orientation.height; 356 json["height"] = orientation.height;
322 if (orientation.outlineInsets) { 357 if (orientation.outlineInsets) {
323 json["outline"] = {}; 358 json["outline"] = {};
324 json["outline"]["insets"] = orientation.outlineInsets; 359 json["outline"]["insets"] = orientation.outlineInsets;
325 json["outline"]["images"] = orientation.outlineImages._toJSON(); 360 json["outline"]["images"] = orientation.outlineImages._toJSON();
326 } 361 }
327 return json; 362 return json;
328 }, 363 },
329 364
330 /** 365 /**
366 * @param {!WebInspector.EmulatedDevice.Mode} mode
331 * @return {!WebInspector.OverridesSupport.Device} 367 * @return {!WebInspector.OverridesSupport.Device}
332 */ 368 */
333 toOverridesDevice: function() 369 modeToOverridesDevice: function(mode)
334 { 370 {
335 var result = {}; 371 var result = {};
336 result.width = this.vertical.width; 372 result.width = mode.pageRect.width;
337 result.height = this.vertical.height; 373 result.height = mode.pageRect.height;
338 result.deviceScaleFactor = this.deviceScaleFactor; 374 result.deviceScaleFactor = this.deviceScaleFactor;
339 result.userAgent = this.userAgent; 375 result.userAgent = this.userAgent;
340 result.touch = this.touch(); 376 result.touch = this.touch();
341 result.mobile = this.mobile(); 377 result.mobile = this.mobile();
342 return result; 378 return result;
343 }, 379 },
344 380
345 /** 381 /**
346 * @param {string} name 382 * @param {string} name
347 * @return {!WebInspector.EmulatedDevice.Orientation} 383 * @return {!WebInspector.EmulatedDevice.Orientation}
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 if (deviceById.has(title)) 588 if (deviceById.has(title))
553 to[i].copyShowFrom(/** @type {!WebInspector.EmulatedDevice} */ ( deviceById.get(title))); 589 to[i].copyShowFrom(/** @type {!WebInspector.EmulatedDevice} */ ( deviceById.get(title)));
554 } 590 }
555 }, 591 },
556 592
557 __proto__: WebInspector.Object.prototype 593 __proto__: WebInspector.Object.prototype
558 } 594 }
559 595
560 /** @type {!WebInspector.EmulatedDevicesList} */ 596 /** @type {!WebInspector.EmulatedDevicesList} */
561 WebInspector.emulatedDevicesList; 597 WebInspector.emulatedDevicesList;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698