OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_DEVICE_ORIENTATION_ORIENTATION_H_ | 5 #ifndef CONTENT_BROWSER_DEVICE_ORIENTATION_ORIENTATION_H_ |
6 #define CONTENT_BROWSER_DEVICE_ORIENTATION_ORIENTATION_H_ | 6 #define CONTENT_BROWSER_DEVICE_ORIENTATION_ORIENTATION_H_ |
7 | 7 |
| 8 #include "base/compiler_specific.h" |
| 9 #include "content/browser/device_orientation/device_data.h" |
| 10 |
8 namespace device_orientation { | 11 namespace device_orientation { |
9 class Orientation { | 12 |
| 13 class Orientation : public DeviceData { |
10 public: | 14 public: |
11 // alpha, beta, gamma and absolute are the rotations around the axes as | 15 // alpha, beta, gamma and absolute are the rotations around the axes as |
12 // specified in http://dev.w3.org/geo/api/spec-source-orientation.html | 16 // specified in http://dev.w3.org/geo/api/spec-source-orientation.html |
13 // | 17 // |
14 // can_provide_{alpha,beta,gamma,absolute} is true if data can be provided | 18 // can_provide_{alpha,beta,gamma,absolute} is true if data can be provided |
15 // for that variable. | 19 // for that variable. |
| 20 Orientation(); |
16 | 21 |
17 Orientation() | 22 // From DeviceData. |
18 : alpha_(0), | 23 virtual IPC::Message* CreateIPCMessage(int render_view_id) const OVERRIDE; |
19 beta_(0), | 24 virtual bool ShouldFireEvent(const DeviceData* old_data) const OVERRIDE; |
20 gamma_(0), | |
21 absolute_(false), | |
22 can_provide_alpha_(false), | |
23 can_provide_beta_(false), | |
24 can_provide_gamma_(false), | |
25 can_provide_absolute_(false) { | |
26 } | |
27 Orientation(const Orientation& orientation) | |
28 : alpha_(orientation.alpha()), | |
29 beta_(orientation.beta()), | |
30 gamma_(orientation.gamma()), | |
31 absolute_(orientation.absolute()), | |
32 can_provide_alpha_(orientation.can_provide_alpha()), | |
33 can_provide_beta_(orientation.can_provide_beta()), | |
34 can_provide_gamma_(orientation.can_provide_gamma()), | |
35 can_provide_absolute_(orientation.can_provide_absolute()) { | |
36 } | |
37 void operator=(const Orientation& source) { | |
38 alpha_ = source.alpha(); | |
39 beta_ = source.beta(); | |
40 gamma_ = source.gamma(); | |
41 absolute_ = source.absolute(); | |
42 can_provide_alpha_ = source.can_provide_alpha(); | |
43 can_provide_beta_ = source.can_provide_beta(); | |
44 can_provide_gamma_ = source.can_provide_gamma(); | |
45 can_provide_absolute_ = source.can_provide_absolute(); | |
46 } | |
47 | |
48 static Orientation Empty() { return Orientation(); } | |
49 | |
50 bool is_empty() const { | |
51 return !can_provide_alpha_ && !can_provide_beta_ && !can_provide_gamma_ | |
52 && !can_provide_absolute_; | |
53 } | |
54 | 25 |
55 void set_alpha(double alpha) { | 26 void set_alpha(double alpha) { |
56 can_provide_alpha_ = true; | 27 can_provide_alpha_ = true; |
57 alpha_ = alpha; | 28 alpha_ = alpha; |
58 } | 29 } |
59 bool can_provide_alpha() const { return can_provide_alpha_; } | 30 bool can_provide_alpha() const { return can_provide_alpha_; } |
60 double alpha() const { return alpha_; } | 31 double alpha() const { return alpha_; } |
61 | 32 |
62 void set_beta(double beta) { | 33 void set_beta(double beta) { |
63 can_provide_beta_ = true; | 34 can_provide_beta_ = true; |
(...skipping 10 matching lines...) Expand all Loading... |
74 double gamma() const { return gamma_; } | 45 double gamma() const { return gamma_; } |
75 | 46 |
76 void set_absolute(bool absolute) { | 47 void set_absolute(bool absolute) { |
77 can_provide_absolute_ = true; | 48 can_provide_absolute_ = true; |
78 absolute_ = absolute; | 49 absolute_ = absolute; |
79 } | 50 } |
80 bool can_provide_absolute() const { return can_provide_absolute_; } | 51 bool can_provide_absolute() const { return can_provide_absolute_; } |
81 bool absolute() const { return absolute_; } | 52 bool absolute() const { return absolute_; } |
82 | 53 |
83 private: | 54 private: |
| 55 virtual ~Orientation(); |
| 56 |
| 57 static bool IsElementSignificantlyDifferent(bool can_provide_element1, |
| 58 bool can_provide_element2, double element1, double element2); |
| 59 |
84 double alpha_; | 60 double alpha_; |
85 double beta_; | 61 double beta_; |
86 double gamma_; | 62 double gamma_; |
87 bool absolute_; | 63 bool absolute_; |
88 bool can_provide_alpha_; | 64 bool can_provide_alpha_; |
89 bool can_provide_beta_; | 65 bool can_provide_beta_; |
90 bool can_provide_gamma_; | 66 bool can_provide_gamma_; |
91 bool can_provide_absolute_; | 67 bool can_provide_absolute_; |
92 }; | 68 }; |
93 | 69 |
94 } // namespace device_orientation | 70 } // namespace device_orientation |
95 | 71 |
96 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_ORIENTATION_H_ | 72 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_ORIENTATION_H_ |
OLD | NEW |