OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/renderer/device_orientation_dispatcher.h" | 5 #include "chrome/renderer/device_orientation_dispatcher.h" |
6 | 6 |
7 #include "chrome/common/render_messages_params.h" | 7 #include "chrome/common/render_messages_params.h" |
8 #include "chrome/renderer/render_view.h" | 8 #include "chrome/renderer/render_view.h" |
9 #include "third_party/WebKit/WebKit/chromium/public/WebDeviceOrientation.h" | 9 #include "third_party/WebKit/WebKit/chromium/public/WebDeviceOrientation.h" |
10 #include "third_party/WebKit/WebKit/chromium/public/WebDeviceOrientationControll
er.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebDeviceOrientationControll
er.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 } | 43 } |
44 | 44 |
45 void DeviceOrientationDispatcher::stopUpdating() { | 45 void DeviceOrientationDispatcher::stopUpdating() { |
46 render_view_->Send(new ViewHostMsg_DeviceOrientation_StopUpdating( | 46 render_view_->Send(new ViewHostMsg_DeviceOrientation_StopUpdating( |
47 render_view_->routing_id())); | 47 render_view_->routing_id())); |
48 started_ = false; | 48 started_ = false; |
49 } | 49 } |
50 | 50 |
51 WebKit::WebDeviceOrientation DeviceOrientationDispatcher::lastOrientation() | 51 WebKit::WebDeviceOrientation DeviceOrientationDispatcher::lastOrientation() |
52 const { | 52 const { |
53 if (!last_update_.get()) | 53 if (!last_orientation_.get()) |
54 return WebKit::WebDeviceOrientation::nullOrientation(); | 54 return WebKit::WebDeviceOrientation::nullOrientation(); |
55 | 55 |
56 return WebKit::WebDeviceOrientation(last_update_->can_provide_alpha, | 56 return *last_orientation_; |
57 last_update_->alpha, | |
58 last_update_->can_provide_beta, | |
59 last_update_->beta, | |
60 last_update_->can_provide_gamma, | |
61 last_update_->gamma); | |
62 } | 57 } |
63 | 58 |
| 59 namespace { |
| 60 bool OrientationsEqual(const ViewMsg_DeviceOrientationUpdated_Params& a, |
| 61 WebKit::WebDeviceOrientation* b) { |
| 62 if (a.can_provide_alpha != b->canProvideAlpha()) |
| 63 return false; |
| 64 if (a.can_provide_alpha && a.alpha != b->alpha()) |
| 65 return false; |
| 66 if (a.can_provide_beta != b->canProvideBeta()) |
| 67 return false; |
| 68 if (a.can_provide_beta && a.beta != b->beta()) |
| 69 return false; |
| 70 if (a.can_provide_gamma != b->canProvideGamma()) |
| 71 return false; |
| 72 if (a.can_provide_gamma && a.gamma != b->gamma()) |
| 73 return false; |
| 74 |
| 75 return true; |
| 76 } |
| 77 } // namespace |
| 78 |
64 void DeviceOrientationDispatcher::OnDeviceOrientationUpdated( | 79 void DeviceOrientationDispatcher::OnDeviceOrientationUpdated( |
65 const ViewMsg_DeviceOrientationUpdated_Params& p) { | 80 const ViewMsg_DeviceOrientationUpdated_Params& p) { |
66 last_update_.reset(new ViewMsg_DeviceOrientationUpdated_Params(p)); | |
67 | 81 |
68 WebKit::WebDeviceOrientation orientation(p.can_provide_alpha, p.alpha, | 82 if (last_orientation_.get() && OrientationsEqual(p, last_orientation_.get())) |
69 p.can_provide_beta, p.beta, | 83 return; |
70 p.can_provide_gamma, p.gamma); | |
71 | 84 |
72 controller_->didChangeDeviceOrientation(orientation); | 85 last_orientation_.reset(new WebKit::WebDeviceOrientation(p.can_provide_alpha, |
| 86 p.alpha, |
| 87 p.can_provide_beta, |
| 88 p.beta, |
| 89 p.can_provide_gamma, |
| 90 p.gamma)); |
| 91 |
| 92 controller_->didChangeDeviceOrientation(*last_orientation_); |
73 } | 93 } |
OLD | NEW |