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

Side by Side Diff: components/exo/pointer.cc

Issue 2894503002: Fixes rounding error when calculating MOVE event (Closed)
Patch Set: Fixes rounding error when calculating MOVE event Created 3 years, 6 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 <utility>
reveman 2017/05/25 23:59:12 why was this needed?
8
7 #include "ash/public/cpp/shell_window_ids.h" 9 #include "ash/public/cpp/shell_window_ids.h"
8 #include "cc/output/copy_output_request.h" 10 #include "cc/output/copy_output_request.h"
9 #include "cc/output/copy_output_result.h" 11 #include "cc/output/copy_output_result.h"
10 #include "components/exo/pointer_delegate.h" 12 #include "components/exo/pointer_delegate.h"
11 #include "components/exo/pointer_stylus_delegate.h" 13 #include "components/exo/pointer_stylus_delegate.h"
12 #include "components/exo/surface.h" 14 #include "components/exo/surface.h"
13 #include "components/exo/wm_helper.h" 15 #include "components/exo/wm_helper.h"
14 #include "ui/aura/client/cursor_client.h" 16 #include "ui/aura/client/cursor_client.h"
15 #include "ui/aura/env.h" 17 #include "ui/aura/env.h"
16 #include "ui/aura/window.h" 18 #include "ui/aura/window.h"
17 #include "ui/display/manager/display_manager.h" 19 #include "ui/display/manager/display_manager.h"
18 #include "ui/display/manager/managed_display_info.h" 20 #include "ui/display/manager/managed_display_info.h"
19 #include "ui/display/screen.h" 21 #include "ui/display/screen.h"
20 #include "ui/events/event.h" 22 #include "ui/events/event.h"
21 #include "ui/gfx/geometry/vector2d_conversions.h" 23 #include "ui/gfx/geometry/vector2d_conversions.h"
22 #include "ui/gfx/transform_util.h" 24 #include "ui/gfx/transform_util.h"
23 25
24 #if defined(USE_OZONE) 26 #if defined(USE_OZONE)
25 #include "ui/ozone/public/cursor_factory_ozone.h" 27 #include "ui/ozone/public/cursor_factory_ozone.h"
26 #endif 28 #endif
27 29
28 #if defined(USE_X11) 30 #if defined(USE_X11)
29 #include "ui/base/cursor/cursor_loader_x11.h" 31 #include "ui/base/cursor/cursor_loader_x11.h"
30 #endif 32 #endif
31 33
32 namespace exo { 34 namespace exo {
33 namespace { 35 namespace {
34 36
35 const float kLargeCursorScale = 2.8f; 37 const float kLargeCursorScale = 2.8f;
38 const double kLocatedEventEpsilonSquared = 1.0 / (2000.0 * 2000.0);
36 39
37 // Synthesized events typically lack floating point precision so to avoid 40 // Synthesized events typically lack floating point precision so to avoid
38 // generating mouse event jitter we consider the location of these events 41 // generating mouse event jitter we consider the location of these events
39 // to be the same as |location| if floored values match. 42 // to be the same as |location| if floored values match.
40 bool SameLocation(const ui::LocatedEvent* event, const gfx::PointF& location) { 43 bool SameLocation(const ui::LocatedEvent* event, const gfx::PointF& location) {
41 if (event->flags() & ui::EF_IS_SYNTHESIZED) 44 if (event->flags() & ui::EF_IS_SYNTHESIZED)
42 return event->location() == gfx::ToFlooredPoint(location); 45 return event->location() == gfx::ToFlooredPoint(location);
43 46
44 return event->location_f() == location; 47 // In general, it is good practice to compare floats using an epsilon.
48 // In particular, the mouse location_f() could differ between the
49 // MOUSE_PRESSED and MOUSE_RELEASED events. At MOUSE_RELEASED, it will have a
50 // targeter() already cached, while at MOUSE_PRESSED, it will have to
51 // calculate it passing through all the hierarchy of windows, and that could
52 // generate rounding error. std::numeric_limits<float>::epsilon() is not big
53 // enough to catch this rounding error.
54 gfx::Vector2dF offset = event->location_f() - location;
55 return offset.LengthSquared() < (2 * kLocatedEventEpsilonSquared);
45 } 56 }
46 57
47 } // namespace 58 } // namespace
48 59
49 //////////////////////////////////////////////////////////////////////////////// 60 ////////////////////////////////////////////////////////////////////////////////
50 // Pointer, public: 61 // Pointer, public:
51 62
52 Pointer::Pointer(PointerDelegate* delegate) 63 Pointer::Pointer(PointerDelegate* delegate)
53 : delegate_(delegate), 64 : delegate_(delegate),
54 cursor_(ui::CursorType::kNull), 65 cursor_(ui::CursorType::kNull),
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 if (!root_window) 406 if (!root_window)
396 return; 407 return;
397 408
398 aura::client::CursorClient* cursor_client = 409 aura::client::CursorClient* cursor_client =
399 aura::client::GetCursorClient(root_window); 410 aura::client::GetCursorClient(root_window);
400 if (cursor_client) 411 if (cursor_client)
401 cursor_client->SetCursor(cursor_); 412 cursor_client->SetCursor(cursor_);
402 } 413 }
403 414
404 } // namespace exo 415 } // 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