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

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

Issue 1631223003: [DevTools] Do not use OverridesSupport anywhere. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
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);
+}

Powered by Google App Engine
This is Rietveld 408576698