| 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 #include "content/renderer/device_orientation_dispatcher.h" | 5 #include "content/renderer/device_orientation_dispatcher.h" |
| 6 | 6 |
| 7 #include "content/common/device_orientation_messages.h" | 7 #include "content/common/device_orientation_messages.h" |
| 8 #include "content/renderer/render_view_impl.h" | 8 #include "content/renderer/render_view_impl.h" |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDeviceOrientation.
h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDeviceOrientation.
h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDeviceOrientationC
ontroller.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDeviceOrientationC
ontroller.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 started_ = true; | 41 started_ = true; |
| 42 } | 42 } |
| 43 | 43 |
| 44 void DeviceOrientationDispatcher::stopUpdating() { | 44 void DeviceOrientationDispatcher::stopUpdating() { |
| 45 Send(new DeviceOrientationHostMsg_StopUpdating(routing_id())); | 45 Send(new DeviceOrientationHostMsg_StopUpdating(routing_id())); |
| 46 started_ = false; | 46 started_ = false; |
| 47 } | 47 } |
| 48 | 48 |
| 49 WebKit::WebDeviceOrientation DeviceOrientationDispatcher::lastOrientation() | 49 WebKit::WebDeviceOrientation DeviceOrientationDispatcher::lastOrientation() |
| 50 const { | 50 const { |
| 51 if (!last_orientation_.get()) | 51 return last_orientation_; |
| 52 return WebKit::WebDeviceOrientation::nullOrientation(); | |
| 53 | |
| 54 return *last_orientation_; | |
| 55 } | 52 } |
| 56 | 53 |
| 57 namespace { | 54 namespace { |
| 58 bool OrientationsEqual(const DeviceOrientationMsg_Updated_Params& a, | 55 bool OrientationsEqual(const DeviceOrientationMsg_Updated_Params& a, |
| 59 WebKit::WebDeviceOrientation* b) { | 56 WebKit::WebDeviceOrientation* b) { |
| 60 if (a.can_provide_alpha != b->canProvideAlpha()) | 57 if (a.can_provide_alpha != b->canProvideAlpha()) |
| 61 return false; | 58 return false; |
| 62 if (a.can_provide_alpha && a.alpha != b->alpha()) | 59 if (a.can_provide_alpha && a.alpha != b->alpha()) |
| 63 return false; | 60 return false; |
| 64 if (a.can_provide_beta != b->canProvideBeta()) | 61 if (a.can_provide_beta != b->canProvideBeta()) |
| 65 return false; | 62 return false; |
| 66 if (a.can_provide_beta && a.beta != b->beta()) | 63 if (a.can_provide_beta && a.beta != b->beta()) |
| 67 return false; | 64 return false; |
| 68 if (a.can_provide_gamma != b->canProvideGamma()) | 65 if (a.can_provide_gamma != b->canProvideGamma()) |
| 69 return false; | 66 return false; |
| 70 if (a.can_provide_gamma && a.gamma != b->gamma()) | 67 if (a.can_provide_gamma && a.gamma != b->gamma()) |
| 71 return false; | 68 return false; |
| 72 if (a.can_provide_absolute != b->canProvideAbsolute()) | 69 if (a.can_provide_absolute != b->canProvideAbsolute()) |
| 73 return false; | 70 return false; |
| 74 if (a.can_provide_absolute && a.absolute != b->absolute()) | 71 if (a.can_provide_absolute && a.absolute != b->absolute()) |
| 75 return false; | 72 return false; |
| 76 | 73 |
| 77 return true; | 74 return true; |
| 78 } | 75 } |
| 79 } // namespace | 76 } // namespace |
| 80 | 77 |
| 81 void DeviceOrientationDispatcher::OnDeviceOrientationUpdated( | 78 void DeviceOrientationDispatcher::OnDeviceOrientationUpdated( |
| 82 const DeviceOrientationMsg_Updated_Params& p) { | 79 const DeviceOrientationMsg_Updated_Params& p) { |
| 83 if (last_orientation_.get() && OrientationsEqual(p, last_orientation_.get())) | 80 if (!last_orientation_.isNull() && OrientationsEqual(p, &last_orientation_)) |
| 84 return; | 81 return; |
| 85 | 82 |
| 86 last_orientation_.reset(new WebKit::WebDeviceOrientation(p.can_provide_alpha, | 83 last_orientation_.setNull(false); |
| 87 p.alpha, | 84 if (p.can_provide_alpha) |
| 88 p.can_provide_beta, | 85 last_orientation_.setAlpha(p.alpha); |
| 89 p.beta, | 86 if (p.can_provide_beta) |
| 90 p.can_provide_gamma, | 87 last_orientation_.setBeta(p.beta); |
| 91 p.gamma, | 88 if (p.can_provide_gamma) |
| 92 p.can_provide_absolute, | 89 last_orientation_.setGamma(p.gamma); |
| 93 p.absolute)); | 90 if (p.can_provide_absolute) |
| 94 | 91 last_orientation_.setAbsolute(p.absolute); |
| 95 controller_->didChangeDeviceOrientation(*last_orientation_); | 92 controller_->didChangeDeviceOrientation(last_orientation_); |
| 96 } | 93 } |
| OLD | NEW |