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