Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 /** | |
| 6 * @constructor | |
| 7 * @param {number} alpha | |
| 8 * @param {number} beta | |
| 9 * @param {number} gamma | |
| 10 */ | |
| 11 WebInspector.DeviceOrientation = function(alpha, beta, gamma) | |
|
pfeldman
2016/01/27 17:53:18
Should this be a part of sdk?
| |
| 12 { | |
| 13 this.alpha = alpha; | |
| 14 this.beta = beta; | |
| 15 this.gamma = gamma; | |
| 16 } | |
| 17 | |
| 18 WebInspector.DeviceOrientation.prototype = { | |
| 19 /** | |
| 20 * @return {string} | |
| 21 */ | |
| 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.Type.Page)) | |
| 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.Type.Page)) | |
| 36 target.deviceOrientationAgent().clearDeviceOrientationOverride(); | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 /** | |
| 41 * @return {!WebInspector.DeviceOrientation} | |
| 42 */ | |
| 43 WebInspector.DeviceOrientation.parseSetting = function(value) | |
| 44 { | |
| 45 if (value) { | |
| 46 var jsonObject = JSON.parse(value); | |
| 47 return new WebInspector.DeviceOrientation(jsonObject.alpha, jsonObject.b eta, jsonObject.gamma); | |
| 48 } | |
| 49 return new WebInspector.DeviceOrientation(0, 0, 0); | |
| 50 } | |
| 51 | |
| 52 /** | |
| 53 * @return {?WebInspector.DeviceOrientation} | |
| 54 */ | |
| 55 WebInspector.DeviceOrientation.parseUserInput = function(alphaString, betaString , gammaString) | |
| 56 { | |
| 57 function isUserInputValid(value) | |
| 58 { | |
| 59 if (!value) | |
| 60 return true; | |
| 61 return /^[-]?[0-9]*[.]?[0-9]*$/.test(value); | |
| 62 } | |
| 63 | |
| 64 if (!alphaString && !betaString && !gammaString) | |
| 65 return null; | |
| 66 | |
| 67 var isAlphaValid = isUserInputValid(alphaString); | |
| 68 var isBetaValid = isUserInputValid(betaString); | |
| 69 var isGammaValid = isUserInputValid(gammaString); | |
| 70 | |
| 71 if (!isAlphaValid && !isBetaValid && !isGammaValid) | |
| 72 return null; | |
| 73 | |
| 74 var alpha = isAlphaValid ? parseFloat(alphaString) : -1; | |
| 75 var beta = isBetaValid ? parseFloat(betaString) : -1; | |
| 76 var gamma = isGammaValid ? parseFloat(gammaString) : -1; | |
| 77 | |
| 78 return new WebInspector.DeviceOrientation(alpha, beta, gamma); | |
| 79 } | |
| OLD | NEW |