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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/exo/pointer.h" 5 #include "components/exo/pointer.h"
6 6
7 #include "ash/public/cpp/shell_window_ids.h" 7 #include "ash/public/cpp/shell_window_ids.h"
8 #include "cc/output/copy_output_request.h" 8 #include "cc/output/copy_output_request.h"
9 #include "cc/output/copy_output_result.h" 9 #include "cc/output/copy_output_result.h"
10 #include "components/exo/pointer_delegate.h" 10 #include "components/exo/pointer_delegate.h"
(...skipping 23 matching lines...) Expand all
34 34
35 const float kLargeCursorScale = 2.8f; 35 const float kLargeCursorScale = 2.8f;
36 36
37 // Synthesized events typically lack floating point precision so to avoid 37 // Synthesized events typically lack floating point precision so to avoid
38 // generating mouse event jitter we consider the location of these events 38 // generating mouse event jitter we consider the location of these events
39 // to be the same as |location| if floored values match. 39 // to be the same as |location| if floored values match.
40 bool SameLocation(const ui::LocatedEvent* event, const gfx::PointF& location) { 40 bool SameLocation(const ui::LocatedEvent* event, const gfx::PointF& location) {
41 if (event->flags() & ui::EF_IS_SYNTHESIZED) 41 if (event->flags() & ui::EF_IS_SYNTHESIZED)
42 return event->location() == gfx::ToFlooredPoint(location); 42 return event->location() == gfx::ToFlooredPoint(location);
43 43
44 return event->location_f() == location; 44 // In general, it is good practice to compare floats using an Epsilon.
45 // In particular, a mouse location_f() could differ between the MOUSE_PRESSED
46 // and MOUSE_RELEASED events. At MOUSE_RELEASED, it will have a targeter()
47 // already cached, while at MOUSE_PRESSED, it will have to calculate it
48 // passing through all windows, and that could generate rounding error.
49 // std::numeric_limits<float>::epsilon() is not big enough to catch the
50 // rounding error generated by protation.
51 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
52 return std::abs(event->location_f().x() - location.x()) <= epsilon_scale &&
53 std::abs(event->location_f().y() - location.y()) <= epsilon_scale;
45 } 54 }
46 55
47 } // namespace 56 } // namespace
48 57
49 //////////////////////////////////////////////////////////////////////////////// 58 ////////////////////////////////////////////////////////////////////////////////
50 // Pointer, public: 59 // Pointer, public:
51 60
52 Pointer::Pointer(PointerDelegate* delegate) 61 Pointer::Pointer(PointerDelegate* delegate)
53 : delegate_(delegate), 62 : delegate_(delegate),
54 cursor_(ui::CursorType::kNull), 63 cursor_(ui::CursorType::kNull),
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 if (!root_window) 404 if (!root_window)
396 return; 405 return;
397 406
398 aura::client::CursorClient* cursor_client = 407 aura::client::CursorClient* cursor_client =
399 aura::client::GetCursorClient(root_window); 408 aura::client::GetCursorClient(root_window);
400 if (cursor_client) 409 if (cursor_client)
401 cursor_client->SetCursor(cursor_); 410 cursor_client->SetCursor(cursor_);
402 } 411 }
403 412
404 } // namespace exo 413 } // namespace exo
OLDNEW
« 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