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
3 // found in the LICENSE file.
5 #ifndef UI_EVENTS_OZONE_CHROMEOS_CURSOR_CONTROLLER_H_
6 #define UI_EVENTS_OZONE_CHROMEOS_CURSOR_CONTROLLER_H_
10 #include "base/event_types.h"
11 #include "base/memory/singleton.h"
12 #include "ui/events/ozone/events_ozone_export.h"
13 #include "ui/gfx/display.h"
14 #include "ui/gfx/geometry/vector2d_f.h"
15 #include "ui/gfx/native_widget_types.h"
19 // Manager for per-window cursor settings.
21 // This is used to apply a rotation & acceleration to each vector added to the
22 // cursor position on ChromeOS.
26 // (1) Fixing cursor movement direction for rotated displays.
27 // (2) Fixing cursor movement speed based on scale factor.
28 // (3) Tweaking cursor movement speed on external displays.
30 // This HACK is necessary because ash handles rotation and handles scaling but
31 // does NOT handle the cursor movement (except that it sends a message to x11 or
32 // ozone to activate this hack).
34 // TODO(spang): Don't worry, we have a plan to remove this.
35 class EVENTS_OZONE_EXPORT CursorController
{
37 static CursorController
* GetInstance();
39 // Changes the rotation & scale applied for a window.
40 void SetCursorConfigForWindow(gfx::AcceleratedWidget widget
,
41 gfx::Display::Rotation rotation
,
44 // Cleans up all state associated with a window.
45 void ClearCursorConfigForWindow(gfx::AcceleratedWidget widget
);
47 // Applies the current settings for a window to a cursor movement vector.
49 // The rotation applies counter-clockwise (to negate clockwise display
50 // rotation) and the result is multiplied by scale.
52 // e.g. if (dx, dy) = (2, 3) and (scale, rotation) = (2.f, 90deg)
53 // then we set (dx, dy) = (-6, 4)
55 // Since scale generally includes DSF, you can think of the input
56 // vector unit as DIP and the output vector unit as pixels.
57 void ApplyCursorConfigForWindow(gfx::AcceleratedWidget widget
,
58 gfx::Vector2dF
* delta
) const;
63 friend struct DefaultSingletonTraits
<CursorController
>;
65 struct PerWindowCursorConfiguration
{
66 gfx::Display::Rotation rotation
;
70 typedef std::map
<gfx::AcceleratedWidget
, PerWindowCursorConfiguration
>
71 WindowToCursorConfigurationMap
;
73 WindowToCursorConfigurationMap window_to_cursor_configuration_map_
;
75 DISALLOW_COPY_AND_ASSIGN(CursorController
);
80 #endif // UI_EVENTS_OZONE_CHROMEOS_CURSOR_CONTROLLER_H_