Index: third_party/WebKit/Source/devtools/front_end/emulation/DeviceOrientation.js |
diff --git a/third_party/WebKit/Source/devtools/front_end/emulation/DeviceOrientation.js b/third_party/WebKit/Source/devtools/front_end/emulation/DeviceOrientation.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cb4acf12e34fc21e4807fee6d5e4775d2d8c8b35 |
--- /dev/null |
+++ b/third_party/WebKit/Source/devtools/front_end/emulation/DeviceOrientation.js |
@@ -0,0 +1,79 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+/** |
+ * @constructor |
+ * @param {number} alpha |
+ * @param {number} beta |
+ * @param {number} gamma |
+ */ |
+WebInspector.DeviceOrientation = function(alpha, beta, gamma) |
pfeldman
2016/01/27 17:53:18
Should this be a part of sdk?
|
+{ |
+ this.alpha = alpha; |
+ this.beta = beta; |
+ this.gamma = gamma; |
+} |
+ |
+WebInspector.DeviceOrientation.prototype = { |
+ /** |
+ * @return {string} |
+ */ |
+ toSetting: function() |
+ { |
+ return JSON.stringify(this); |
+ }, |
+ |
+ apply: function() |
+ { |
+ for (var target of WebInspector.targetManager.targets(WebInspector.Target.Type.Page)) |
+ target.deviceOrientationAgent().setDeviceOrientationOverride(this.alpha, this.beta, this.gamma); |
+ }, |
+ |
+ clear: function() |
+ { |
+ for (var target of WebInspector.targetManager.targets(WebInspector.Target.Type.Page)) |
+ target.deviceOrientationAgent().clearDeviceOrientationOverride(); |
+ } |
+} |
+ |
+/** |
+ * @return {!WebInspector.DeviceOrientation} |
+ */ |
+WebInspector.DeviceOrientation.parseSetting = function(value) |
+{ |
+ if (value) { |
+ var jsonObject = JSON.parse(value); |
+ return new WebInspector.DeviceOrientation(jsonObject.alpha, jsonObject.beta, jsonObject.gamma); |
+ } |
+ return new WebInspector.DeviceOrientation(0, 0, 0); |
+} |
+ |
+/** |
+ * @return {?WebInspector.DeviceOrientation} |
+ */ |
+WebInspector.DeviceOrientation.parseUserInput = function(alphaString, betaString, gammaString) |
+{ |
+ function isUserInputValid(value) |
+ { |
+ if (!value) |
+ return true; |
+ return /^[-]?[0-9]*[.]?[0-9]*$/.test(value); |
+ } |
+ |
+ if (!alphaString && !betaString && !gammaString) |
+ return null; |
+ |
+ var isAlphaValid = isUserInputValid(alphaString); |
+ var isBetaValid = isUserInputValid(betaString); |
+ var isGammaValid = isUserInputValid(gammaString); |
+ |
+ if (!isAlphaValid && !isBetaValid && !isGammaValid) |
+ return null; |
+ |
+ var alpha = isAlphaValid ? parseFloat(alphaString) : -1; |
+ var beta = isBetaValid ? parseFloat(betaString) : -1; |
+ var gamma = isGammaValid ? parseFloat(gammaString) : -1; |
+ |
+ return new WebInspector.DeviceOrientation(alpha, beta, gamma); |
+} |