Chromium Code Reviews| Index: components/exo/pointer.cc |
| diff --git a/components/exo/pointer.cc b/components/exo/pointer.cc |
| index 073c750192f374b967e3c25061542d8f88136460..3ff0501b82f91d61974d1664aa65354b06b13cf1 100644 |
| --- a/components/exo/pointer.cc |
| +++ b/components/exo/pointer.cc |
| @@ -4,6 +4,8 @@ |
| #include "components/exo/pointer.h" |
| +#include <utility> |
| + |
| #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 float kLocatedEventEpsilon = 1.0f / 2000.0f; |
| // Synthesized events typically lack floating point precision so to avoid |
| // generating mouse event jitter we consider the location of these events |
| @@ -41,7 +44,17 @@ 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. |
| + return std::abs(event->location_f().x() - location.x()) <= |
| + kLocatedEventEpsilon && |
| + std::abs(event->location_f().y() - location.y()) <= |
| + kLocatedEventEpsilon; |
|
reveman
2017/05/22 20:12:28
how about:
gfx::Vector2dF offset = event->locatio
|
| } |
| } // namespace |