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

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

Issue 2843763004: [DevTools] Introduce EmulationModel which will encapsulate emulation (Closed)
Patch Set: +throttling Created 3 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4 /**
5 * @unrestricted
6 */
7 Emulation.DeviceOrientation = class {
8 /**
9 * @param {number} alpha
10 * @param {number} beta
11 * @param {number} gamma
12 */
13 constructor(alpha, beta, gamma) {
14 this.alpha = alpha;
15 this.beta = beta;
16 this.gamma = gamma;
17 }
18
19 /**
20 * @return {!Emulation.DeviceOrientation}
21 */
22 static parseSetting(value) {
23 if (value) {
24 var jsonObject = JSON.parse(value);
25 return new Emulation.DeviceOrientation(jsonObject.alpha, jsonObject.beta, jsonObject.gamma);
26 }
27 return new Emulation.DeviceOrientation(0, 0, 0);
28 }
29
30 /**
31 * @return {?Emulation.DeviceOrientation}
32 */
33 static parseUserInput(alphaString, betaString, gammaString) {
34 if (!alphaString && !betaString && !gammaString)
35 return null;
36
37 var isAlphaValid = Emulation.DeviceOrientation.validator(alphaString);
38 var isBetaValid = Emulation.DeviceOrientation.validator(betaString);
39 var isGammaValid = Emulation.DeviceOrientation.validator(gammaString);
40
41 if (!isAlphaValid && !isBetaValid && !isGammaValid)
42 return null;
43
44 var alpha = isAlphaValid ? parseFloat(alphaString) : -1;
45 var beta = isBetaValid ? parseFloat(betaString) : -1;
46 var gamma = isGammaValid ? parseFloat(gammaString) : -1;
47
48 return new Emulation.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 SDK.targetManager.targets(SDK.Target.Capability.Browser))
68 target.deviceOrientationAgent().setDeviceOrientationOverride(this.alpha, t his.beta, this.gamma);
69 }
70
71 clear() {
72 for (var target of SDK.targetManager.targets(SDK.Target.Capability.Browser))
73 target.deviceOrientationAgent().clearDeviceOrientationOverride();
74 }
75 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698