Pointer/hover media query support: platform-dependent changes
[chromium-blink-merge.git] / ui / accelerometer / accelerometer_types.h
blobb3e513ddf240b1c5da4c040fe459ef916e6d8f99
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 UI_ACCELEROMETER_ACCELEROMETER_TYPES_H_
6 #define UI_ACCELEROMETER_ACCELEROMETER_TYPES_H_
8 #include "base/macros.h"
9 #include "ui/accelerometer/ui_accelerometer_export.h"
10 #include "ui/gfx/geometry/vector3d_f.h"
12 namespace ui {
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 UI_ACCELEROMETER_EXPORT AccelerometerReading {
34 AccelerometerReading();
35 ~AccelerometerReading();
37 // If true, this accelerometer is being updated.
38 bool present;
40 // The reading from this accelerometer measured in m/s^2.
41 gfx::Vector3dF reading;
44 // An accelerometer update contains the last known value for each of the
45 // accelerometers present on the device.
46 class UI_ACCELEROMETER_EXPORT AccelerometerUpdate {
47 public:
48 AccelerometerUpdate();
49 ~AccelerometerUpdate();
51 // Returns true if |source| has a valid value in this update.
52 bool has(AccelerometerSource source) const {
53 return data_[source].present;
56 // Returns the last known value for |source|.
57 const gfx::Vector3dF& get(AccelerometerSource source) const {
58 return data_[source].reading;
61 void Set(AccelerometerSource source, float x, float y, float z) {
62 data_[source].present = true;
63 data_[source].reading.set_x(x);
64 data_[source].reading.set_y(y);
65 data_[source].reading.set_z(z);
68 protected:
69 AccelerometerReading data_[ACCELEROMETER_SOURCE_COUNT];
71 DISALLOW_COPY_AND_ASSIGN(AccelerometerUpdate);
74 } // namespace ui
76 #endif // UI_ACCELEROMETER_ACCELEROMETER_TYPES_H_