From 5bd1c88a74cefc0d924be9ba6b6f0eb23972f00c Mon Sep 17 00:00:00 2001 From: "jam@chromium.org" Date: Tue, 26 Oct 2010 23:13:11 +0000 Subject: Fix rounding errors when converting between zoom factor and zoom level. BUG=60640 Review URL: http://codereview.chromium.org/4117002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63971 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/glue/plugins/pepper_plugin_instance.cc | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'webkit/glue') diff --git a/webkit/glue/plugins/pepper_plugin_instance.cc b/webkit/glue/plugins/pepper_plugin_instance.cc index 54a1f42..bc40240 100644 --- a/webkit/glue/plugins/pepper_plugin_instance.cc +++ b/webkit/glue/plugins/pepper_plugin_instance.cc @@ -238,6 +238,15 @@ void ZoomChanged(PP_Instance instance_id, double factor) { if (!instance) return; double zoom_level = WebView::zoomFactorToZoomLevel(factor); + // The conversino from zoom level to factor, and back, can introduce rounding + // errors. i.e. WebKit originally tells us 3.0, but by the time we tell the + // plugin and it tells us back, the level becomes 3.000000000004. Need to + // round or else otherwise if the user zooms out, it will go to 3.0 instead of + // 2.0. + int rounded = + static_cast(zoom_level + (zoom_level > 0 ? 0.001 : -0.001)); + if (abs(rounded - zoom_level) < 0.001) + zoom_level = rounded; instance->container()->zoomLevelChanged(zoom_level); } -- cgit v1.1