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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/emulation/DeviceOrientation.js

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 years, 1 month 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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
5 /** 4 /**
6 * @constructor 5 * @unrestricted
7 * @param {number} alpha
8 * @param {number} beta
9 * @param {number} gamma
10 */ 6 */
11 WebInspector.DeviceOrientation = function(alpha, beta, gamma) 7 WebInspector.DeviceOrientation = class {
12 { 8 /**
9 * @param {number} alpha
10 * @param {number} beta
11 * @param {number} gamma
12 */
13 constructor(alpha, beta, gamma) {
13 this.alpha = alpha; 14 this.alpha = alpha;
14 this.beta = beta; 15 this.beta = beta;
15 this.gamma = gamma; 16 this.gamma = gamma;
16 }; 17 }
17 18
18 WebInspector.DeviceOrientation.prototype = { 19 /**
19 /** 20 * @return {!WebInspector.DeviceOrientation}
20 * @return {string} 21 */
21 */ 22 static parseSetting(value) {
22 toSetting: function()
23 {
24 return JSON.stringify(this);
25 },
26
27 apply: function()
28 {
29 for (var target of WebInspector.targetManager.targets(WebInspector.Targe t.Capability.Browser))
30 target.deviceOrientationAgent().setDeviceOrientationOverride(this.al pha, this.beta, this.gamma);
31 },
32
33 clear: function()
34 {
35 for (var target of WebInspector.targetManager.targets(WebInspector.Targe t.Capability.Browser))
36 target.deviceOrientationAgent().clearDeviceOrientationOverride();
37 }
38 };
39
40 /**
41 * @return {!WebInspector.DeviceOrientation}
42 */
43 WebInspector.DeviceOrientation.parseSetting = function(value)
44 {
45 if (value) { 23 if (value) {
46 var jsonObject = JSON.parse(value); 24 var jsonObject = JSON.parse(value);
47 return new WebInspector.DeviceOrientation(jsonObject.alpha, jsonObject.b eta, jsonObject.gamma); 25 return new WebInspector.DeviceOrientation(jsonObject.alpha, jsonObject.bet a, jsonObject.gamma);
48 } 26 }
49 return new WebInspector.DeviceOrientation(0, 0, 0); 27 return new WebInspector.DeviceOrientation(0, 0, 0);
50 }; 28 }
51 29
52 /** 30 /**
53 * @return {?WebInspector.DeviceOrientation} 31 * @return {?WebInspector.DeviceOrientation}
54 */ 32 */
55 WebInspector.DeviceOrientation.parseUserInput = function(alphaString, betaString , gammaString) 33 static parseUserInput(alphaString, betaString, gammaString) {
56 {
57 if (!alphaString && !betaString && !gammaString) 34 if (!alphaString && !betaString && !gammaString)
58 return null; 35 return null;
59 36
60 var isAlphaValid = WebInspector.DeviceOrientation.validator(alphaString); 37 var isAlphaValid = WebInspector.DeviceOrientation.validator(alphaString);
61 var isBetaValid = WebInspector.DeviceOrientation.validator(betaString); 38 var isBetaValid = WebInspector.DeviceOrientation.validator(betaString);
62 var isGammaValid = WebInspector.DeviceOrientation.validator(gammaString); 39 var isGammaValid = WebInspector.DeviceOrientation.validator(gammaString);
63 40
64 if (!isAlphaValid && !isBetaValid && !isGammaValid) 41 if (!isAlphaValid && !isBetaValid && !isGammaValid)
65 return null; 42 return null;
66 43
67 var alpha = isAlphaValid ? parseFloat(alphaString) : -1; 44 var alpha = isAlphaValid ? parseFloat(alphaString) : -1;
68 var beta = isBetaValid ? parseFloat(betaString) : -1; 45 var beta = isBetaValid ? parseFloat(betaString) : -1;
69 var gamma = isGammaValid ? parseFloat(gammaString) : -1; 46 var gamma = isGammaValid ? parseFloat(gammaString) : -1;
70 47
71 return new WebInspector.DeviceOrientation(alpha, beta, gamma); 48 return new WebInspector.DeviceOrientation(alpha, beta, gamma);
49 }
50
51 /**
52 * @param {string} value
53 * @return {boolean}
54 */
55 static validator(value) {
56 return /^([+-]?[\d]+(\.\d+)?|[+-]?\.\d+)$/.test(value);
57 }
58
59 /**
60 * @return {string}
61 */
62 toSetting() {
63 return JSON.stringify(this);
64 }
65
66 apply() {
67 for (var target of WebInspector.targetManager.targets(WebInspector.Target.Ca pability.Browser))
68 target.deviceOrientationAgent().setDeviceOrientationOverride(this.alpha, t his.beta, this.gamma);
69 }
70
71 clear() {
72 for (var target of WebInspector.targetManager.targets(WebInspector.Target.Ca pability.Browser))
73 target.deviceOrientationAgent().clearDeviceOrientationOverride();
74 }
72 }; 75 };
73 76
74 /** 77
75 * @param {string} value
76 * @return {boolean}
77 */
78 WebInspector.DeviceOrientation.validator = function(value)
79 {
80 return /^([+-]?[\d]+(\.\d+)?|[+-]?\.\d+)$/.test(value);
81 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698