summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhans@chromium.org <hans@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-27 08:06:31 +0000
committerhans@chromium.org <hans@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-27 08:06:31 +0000
commit85d2223f7c8c1d9504fd190259f349e6b9495164 (patch)
tree760304b178caae44123a0548f1178210f2acc575
parenta3a93a52038a65eca22006f49e880909800de962 (diff)
downloadchromium_src-85d2223f7c8c1d9504fd190259f349e6b9495164.zip
chromium_src-85d2223f7c8c1d9504fd190259f349e6b9495164.tar.gz
chromium_src-85d2223f7c8c1d9504fd190259f349e6b9495164.tar.bz2
DeviceOrientationDispatcher: no orientation updates equal to lastOrientation().
The DeviceOrientationDispatcher, which implements WebDeviceOrientationClient, must not send orientation updates that are equal to its lastOrientation(). This can happen when the client is stopped and then started again. BUG=44654 TEST=Manual Review URL: http://codereview.chromium.org/3104038 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57650 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/renderer/device_orientation_dispatcher.cc44
-rw-r--r--chrome/renderer/device_orientation_dispatcher.h3
2 files changed, 34 insertions, 13 deletions
diff --git a/chrome/renderer/device_orientation_dispatcher.cc b/chrome/renderer/device_orientation_dispatcher.cc
index 816cda8..edf9d03 100644
--- a/chrome/renderer/device_orientation_dispatcher.cc
+++ b/chrome/renderer/device_orientation_dispatcher.cc
@@ -50,24 +50,44 @@ void DeviceOrientationDispatcher::stopUpdating() {
WebKit::WebDeviceOrientation DeviceOrientationDispatcher::lastOrientation()
const {
- if (!last_update_.get())
+ if (!last_orientation_.get())
return WebKit::WebDeviceOrientation::nullOrientation();
- return WebKit::WebDeviceOrientation(last_update_->can_provide_alpha,
- last_update_->alpha,
- last_update_->can_provide_beta,
- last_update_->beta,
- last_update_->can_provide_gamma,
- last_update_->gamma);
+ return *last_orientation_;
}
+namespace {
+bool OrientationsEqual(const ViewMsg_DeviceOrientationUpdated_Params& a,
+ WebKit::WebDeviceOrientation* b) {
+ if (a.can_provide_alpha != b->canProvideAlpha())
+ return false;
+ if (a.can_provide_alpha && a.alpha != b->alpha())
+ return false;
+ if (a.can_provide_beta != b->canProvideBeta())
+ return false;
+ if (a.can_provide_beta && a.beta != b->beta())
+ return false;
+ if (a.can_provide_gamma != b->canProvideGamma())
+ return false;
+ if (a.can_provide_gamma && a.gamma != b->gamma())
+ return false;
+
+ return true;
+}
+} // namespace
+
void DeviceOrientationDispatcher::OnDeviceOrientationUpdated(
const ViewMsg_DeviceOrientationUpdated_Params& p) {
- last_update_.reset(new ViewMsg_DeviceOrientationUpdated_Params(p));
- WebKit::WebDeviceOrientation orientation(p.can_provide_alpha, p.alpha,
- p.can_provide_beta, p.beta,
- p.can_provide_gamma, p.gamma);
+ if (last_orientation_.get() && OrientationsEqual(p, last_orientation_.get()))
+ return;
+
+ last_orientation_.reset(new WebKit::WebDeviceOrientation(p.can_provide_alpha,
+ p.alpha,
+ p.can_provide_beta,
+ p.beta,
+ p.can_provide_gamma,
+ p.gamma));
- controller_->didChangeDeviceOrientation(orientation);
+ controller_->didChangeDeviceOrientation(*last_orientation_);
}
diff --git a/chrome/renderer/device_orientation_dispatcher.h b/chrome/renderer/device_orientation_dispatcher.h
index 0370f25..e2abf37 100644
--- a/chrome/renderer/device_orientation_dispatcher.h
+++ b/chrome/renderer/device_orientation_dispatcher.h
@@ -11,6 +11,7 @@
class RenderView;
namespace IPC { class Message; }
+namespace WebKit { class WebDeviceOrientation; }
struct ViewMsg_DeviceOrientationUpdated_Params;
@@ -34,7 +35,7 @@ class DeviceOrientationDispatcher : public WebKit::WebDeviceOrientationClient {
RenderView* render_view_;
scoped_ptr<WebKit::WebDeviceOrientationController> controller_;
- scoped_ptr<ViewMsg_DeviceOrientationUpdated_Params> last_update_;
+ scoped_ptr<WebKit::WebDeviceOrientation> last_orientation_;
bool started_;
};