Chromium Code Reviews| 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 |