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

Unified Diff: components/exo/pointer.cc

Issue 2894503002: Fixes rounding error when calculating MOVE event (Closed)
Patch Set: 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..6d6db757793e3f96485ec00e4300076c57c7edc1 100644
--- a/components/exo/pointer.cc
+++ b/components/exo/pointer.cc
@@ -41,7 +41,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, a 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 windows, and that could generate rounding error.
+ // std::numeric_limits<float>::epsilon() is not big enough to catch the
+ // rounding error generated by protation.
+ static const float epsilon_scale = 0.0005f;
Luis Héctor Chávez 2017/05/17 23:57:11 nit: constants are usually declared at the very to
reveman 2017/05/18 04:21:10 Yes, kLocatedEventEpsilon above is better. Also, m
+ return std::abs(event->location_f().x() - location.x()) <= epsilon_scale &&
+ std::abs(event->location_f().y() - location.y()) <= epsilon_scale;
}
} // 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