Roll src/third_party/WebKit c63b89c:29324ab (svn 202546:202547)
[chromium-blink-merge.git] / chromeos / accelerometer / accelerometer_types.h
blob99120b071a976ad3ba312ba5fc13f2c25c1ea5ea
1 // Copyright 2014 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.
5 #ifndef CHROMEOS_ACCELEROMETER_ACCELEROMETER_TYPES_H_
6 #define CHROMEOS_ACCELEROMETER_ACCELEROMETER_TYPES_H_
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "chromeos/chromeos_export.h"
12 namespace chromeos {
14 enum AccelerometerSource {
15 // Accelerometer is located in the device's screen. In the screen's natural
16 // orientation, positive X points to the right, consistent with the pixel
17 // position. Positive Y points up the screen. Positive Z is perpendicular to
18 // the screen, pointing outwards towards the user. The orientation is
19 // described at:
20 // http://www.html5rocks.com/en/tutorials/device/orientation/.
21 ACCELEROMETER_SOURCE_SCREEN = 0,
23 // Accelerometer is located in a keyboard attached to the device's screen.
24 // If the device is open 180 degrees the orientation is consistent with the
25 // screen. I.e. Positive X points to the right, positive Y points up on the
26 // keyboard and positive Z is perpendicular to the keyboard pointing out
27 // towards the user.
28 ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD,
30 ACCELEROMETER_SOURCE_COUNT
33 struct CHROMEOS_EXPORT AccelerometerReading {
34 AccelerometerReading();
35 ~AccelerometerReading();
37 // If true, this accelerometer is being updated.
38 bool present;
40 // The readings from this accelerometer measured in m/s^2.
41 float x;
42 float y;
43 float z;
46 // An accelerometer update contains the last known value for each of the
47 // accelerometers present on the device.
48 class CHROMEOS_EXPORT AccelerometerUpdate
49 : public base::RefCountedThreadSafe<AccelerometerUpdate> {
50 public:
51 AccelerometerUpdate();
53 // Returns true if |source| has a valid value in this update.
54 bool has(AccelerometerSource source) const { return data_[source].present; }
56 // Returns the last known value for |source|.
57 const AccelerometerReading& get(AccelerometerSource source) const {
58 return data_[source];
61 void Set(AccelerometerSource source, float x, float y, float z) {
62 data_[source].present = true;
63 data_[source].x = x;
64 data_[source].y = y;
65 data_[source].z = z;
68 protected:
69 AccelerometerReading data_[ACCELEROMETER_SOURCE_COUNT];
71 private:
72 friend class base::RefCountedThreadSafe<AccelerometerUpdate>;
74 virtual ~AccelerometerUpdate();
76 DISALLOW_COPY_AND_ASSIGN(AccelerometerUpdate);
79 } // namespace chromeos
81 #endif // CHROMEOS_ACCELEROMETER_ACCELEROMETER_TYPES_H_