OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef UI_EVENTS_OZONE_CHROMEOS_CURSOR_CONTROLLER_H_ | 5 #ifndef UI_EVENTS_OZONE_CHROMEOS_CURSOR_CONTROLLER_H_ |
6 #define UI_EVENTS_OZONE_CHROMEOS_CURSOR_CONTROLLER_H_ | 6 #define UI_EVENTS_OZONE_CHROMEOS_CURSOR_CONTROLLER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/event_types.h" | 10 #include "base/event_types.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 14 #include "ui/display/display.h" |
14 #include "ui/events/ozone/events_ozone_export.h" | 15 #include "ui/events/ozone/events_ozone_export.h" |
15 #include "ui/gfx/display.h" | |
16 #include "ui/gfx/geometry/vector2d_f.h" | 16 #include "ui/gfx/geometry/vector2d_f.h" |
17 #include "ui/gfx/native_widget_types.h" | 17 #include "ui/gfx/native_widget_types.h" |
18 | 18 |
19 namespace ui { | 19 namespace ui { |
20 | 20 |
21 // Manager for per-window cursor settings. | 21 // Manager for per-window cursor settings. |
22 // | 22 // |
23 // This is used to apply a rotation & acceleration to each vector added to the | 23 // This is used to apply a rotation & acceleration to each vector added to the |
24 // cursor position on ChromeOS. | 24 // cursor position on ChromeOS. |
25 // | 25 // |
26 // This has 3 uses: | 26 // This has 3 uses: |
27 // | 27 // |
28 // (1) Fixing cursor movement direction for rotated displays. | 28 // (1) Fixing cursor movement direction for rotated displays. |
29 // (2) Fixing cursor movement speed based on scale factor. | 29 // (2) Fixing cursor movement speed based on scale factor. |
30 // (3) Tweaking cursor movement speed on external displays. | 30 // (3) Tweaking cursor movement speed on external displays. |
31 // | 31 // |
32 // This HACK is necessary because ash handles rotation and handles scaling but | 32 // This HACK is necessary because ash handles rotation and handles scaling but |
33 // does NOT handle the cursor movement (except that it sends a message to x11 or | 33 // does NOT handle the cursor movement (except that it sends a message to x11 or |
34 // ozone to activate this hack). | 34 // ozone to activate this hack). |
35 // | 35 // |
36 // TODO(spang): Don't worry, we have a plan to remove this. | 36 // TODO(spang): Don't worry, we have a plan to remove this. |
37 class EVENTS_OZONE_EXPORT CursorController { | 37 class EVENTS_OZONE_EXPORT CursorController { |
38 public: | 38 public: |
39 static CursorController* GetInstance(); | 39 static CursorController* GetInstance(); |
40 | 40 |
41 // Changes the rotation & scale applied for a window. | 41 // Changes the rotation & scale applied for a window. |
42 void SetCursorConfigForWindow(gfx::AcceleratedWidget widget, | 42 void SetCursorConfigForWindow(gfx::AcceleratedWidget widget, |
43 gfx::Display::Rotation rotation, | 43 display::Display::Rotation rotation, |
44 float scale); | 44 float scale); |
45 | 45 |
46 // Cleans up all state associated with a window. | 46 // Cleans up all state associated with a window. |
47 void ClearCursorConfigForWindow(gfx::AcceleratedWidget widget); | 47 void ClearCursorConfigForWindow(gfx::AcceleratedWidget widget); |
48 | 48 |
49 // Applies the current settings for a window to a cursor movement vector. | 49 // Applies the current settings for a window to a cursor movement vector. |
50 // | 50 // |
51 // The rotation applies counter-clockwise (to negate clockwise display | 51 // The rotation applies counter-clockwise (to negate clockwise display |
52 // rotation) and the result is multiplied by scale. | 52 // rotation) and the result is multiplied by scale. |
53 // | 53 // |
54 // e.g. if (dx, dy) = (2, 3) and (scale, rotation) = (2.f, 90deg) | 54 // e.g. if (dx, dy) = (2, 3) and (scale, rotation) = (2.f, 90deg) |
55 // then we set (dx, dy) = (-6, 4) | 55 // then we set (dx, dy) = (-6, 4) |
56 // | 56 // |
57 // Since scale generally includes DSF, you can think of the input | 57 // Since scale generally includes DSF, you can think of the input |
58 // vector unit as DIP and the output vector unit as pixels. | 58 // vector unit as DIP and the output vector unit as pixels. |
59 void ApplyCursorConfigForWindow(gfx::AcceleratedWidget widget, | 59 void ApplyCursorConfigForWindow(gfx::AcceleratedWidget widget, |
60 gfx::Vector2dF* delta) const; | 60 gfx::Vector2dF* delta) const; |
61 | 61 |
62 private: | 62 private: |
63 CursorController(); | 63 CursorController(); |
64 ~CursorController(); | 64 ~CursorController(); |
65 friend struct base::DefaultSingletonTraits<CursorController>; | 65 friend struct base::DefaultSingletonTraits<CursorController>; |
66 | 66 |
67 struct PerWindowCursorConfiguration { | 67 struct PerWindowCursorConfiguration { |
68 gfx::Display::Rotation rotation; | 68 display::Display::Rotation rotation; |
69 float scale; | 69 float scale; |
70 }; | 70 }; |
71 | 71 |
72 typedef std::map<gfx::AcceleratedWidget, PerWindowCursorConfiguration> | 72 typedef std::map<gfx::AcceleratedWidget, PerWindowCursorConfiguration> |
73 WindowToCursorConfigurationMap; | 73 WindowToCursorConfigurationMap; |
74 | 74 |
75 WindowToCursorConfigurationMap window_to_cursor_configuration_map_; | 75 WindowToCursorConfigurationMap window_to_cursor_configuration_map_; |
76 mutable base::Lock window_to_cursor_configuration_map_lock_; | 76 mutable base::Lock window_to_cursor_configuration_map_lock_; |
77 | 77 |
78 DISALLOW_COPY_AND_ASSIGN(CursorController); | 78 DISALLOW_COPY_AND_ASSIGN(CursorController); |
79 }; | 79 }; |
80 | 80 |
81 } // namespace ui | 81 } // namespace ui |
82 | 82 |
83 #endif // UI_EVENTS_OZONE_CHROMEOS_CURSOR_CONTROLLER_H_ | 83 #endif // UI_EVENTS_OZONE_CHROMEOS_CURSOR_CONTROLLER_H_ |
OLD | NEW |