Index: content/browser/device_orientation/orientation.cc |
diff --git a/content/browser/device_orientation/orientation.cc b/content/browser/device_orientation/orientation.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c15a48b5e0c016387b61ee50125522cdb2a81d81 |
--- /dev/null |
+++ b/content/browser/device_orientation/orientation.cc |
@@ -0,0 +1,65 @@ |
+// Copyright (c) 2012 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. |
+ |
+#include "content/browser/device_orientation/orientation.h" |
+#include "content/common/device_orientation_messages.h" |
+ |
+namespace device_orientation { |
+ |
+DeviceData* Orientation::Clone() const { |
+ Orientation* orientation = new Orientation(); |
+ orientation->alpha_ = alpha_; |
+ orientation->beta_ = beta_; |
+ orientation->gamma_ = gamma_; |
+ orientation->absolute_ = absolute_; |
+ orientation->can_provide_alpha_ = can_provide_alpha_; |
+ orientation->can_provide_beta_ = can_provide_beta_; |
+ orientation->can_provide_gamma_ = can_provide_gamma_; |
+ orientation->can_provide_absolute_ = can_provide_absolute_; |
+ return orientation; |
+} |
+ |
+bool Orientation::IsEmpty() const { |
+ return !can_provide_alpha_ && !can_provide_beta_ && !can_provide_gamma_ && |
+ !can_provide_absolute_; |
+} |
+ |
+// Returns true if two orientations are considered different enough that |
+// observers should be notified of the new orientation. |
+bool Orientation::SignificantlyDifferentFrom( |
+ const DeviceData& other_device_data) const { |
+ const Orientation& other_orientation = |
+ static_cast<const Orientation&>(other_device_data); |
+ |
+ return IsElementSignificantlyDifferent(can_provide_alpha_, |
+ other_orientation.can_provide_alpha(), |
+ alpha_, |
+ other_orientation.alpha()) || |
+ IsElementSignificantlyDifferent(can_provide_beta_, |
+ other_orientation.can_provide_beta(), |
+ beta_, |
+ other_orientation.beta()) || |
+ IsElementSignificantlyDifferent(can_provide_gamma_, |
+ other_orientation.can_provide_gamma(), |
+ gamma_, |
+ other_orientation.gamma()) || |
+ can_provide_absolute_ != other_orientation.can_provide_absolute() || |
+ absolute_ != other_orientation.absolute(); |
+} |
+ |
+IPC::Message* Orientation::CreateIPCMessage(int render_view_id) const { |
+ DeviceOrientationMsg_Updated_Params params; |
+ params.can_provide_alpha = can_provide_alpha_; |
+ params.alpha = alpha_; |
+ params.can_provide_beta = can_provide_beta_; |
+ params.beta = beta_; |
+ params.can_provide_gamma = can_provide_gamma_; |
+ params.gamma = gamma_; |
+ params.can_provide_absolute = can_provide_absolute_; |
+ params.absolute = absolute_; |
+ |
+ return new DeviceOrientationMsg_Updated(render_view_id, params); |
+} |
+ |
+} // namespace device_orientation |