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

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..273a74208214f2b2ab82ffb7c1ed1a3cc69cc6cb 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/25 23:59:12 why was this 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 kLocatedEventEpsilonSquared = 1.0 / (2000.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,15 @@ 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() < (2 * kLocatedEventEpsilonSquared);
}
} // 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