Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(471)

Unified Diff: components/exo/pointer.cc

Issue 2894503002: Fixes rounding error when calculating MOVE event (Closed)
Patch Set: Fixes rounding error when calculating MOVE event Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/exo/pointer.cc
diff --git a/components/exo/pointer.cc b/components/exo/pointer.cc
index 073c750192f374b967e3c25061542d8f88136460..ac3423212e360366d321ee95d8cbfe520942d2a5 100644
--- a/components/exo/pointer.cc
+++ b/components/exo/pointer.cc
@@ -4,6 +4,8 @@
#include "components/exo/pointer.h"
+#include <utility>
reveman 2017/05/24 13:14:01 nit: what is this for? please remove if not needed
+
#include "ash/public/cpp/shell_window_ids.h"
#include "cc/output/copy_output_request.h"
#include "cc/output/copy_output_result.h"
@@ -33,6 +35,7 @@ namespace exo {
namespace {
const float kLargeCursorScale = 2.8f;
+const double kLocatedEventEpsilon = 1.0 / 2000.0;
// Synthesized events typically lack floating point precision so to avoid
// generating mouse event jitter we consider the location of these events
@@ -41,7 +44,16 @@ bool SameLocation(const ui::LocatedEvent* event, const gfx::PointF& location) {
if (event->flags() & ui::EF_IS_SYNTHESIZED)
return event->location() == gfx::ToFlooredPoint(location);
- return event->location_f() == location;
+ // In general, it is good practice to compare floats using an epsilon.
+ // In particular, the mouse location_f() could differ between the
+ // MOUSE_PRESSED and MOUSE_RELEASED events. At MOUSE_RELEASED, it will have a
+ // targeter() already cached, while at MOUSE_PRESSED, it will have to
+ // calculate it passing through all the hierarchy of windows, and that could
+ // generate rounding error. std::numeric_limits<float>::epsilon() is not big
+ // enough to catch this rounding error.
+ gfx::Vector2dF offset = event->location_f() - location;
+ return offset.LengthSquared() <
reveman 2017/05/24 13:14:01 optional nit: const double kLocatedEventEpsilonSq
+ (2 * kLocatedEventEpsilon * kLocatedEventEpsilon);
}
} // namespace
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698