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