base: Change DCHECK_IS_ON to a macro DCHECK_IS_ON().
[chromium-blink-merge.git] / ui / events / ozone / chromeos / cursor_controller.h
blob3e5de42bf160a1c39fd63370aca19ccf3db63766
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_
8 #include <map>
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"
17 namespace ui {
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.
24 // This has 3 uses:
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 {
36 public:
37 static CursorController* GetInstance();
39 // Changes the rotation & scale applied for a window.
40 void SetCursorConfigForWindow(gfx::AcceleratedWidget widget,
41 gfx::Display::Rotation rotation,
42 float scale);
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;
60 private:
61 CursorController();
62 ~CursorController();
63 friend struct DefaultSingletonTraits<CursorController>;
65 struct PerWindowCursorConfiguration {
66 gfx::Display::Rotation rotation;
67 float scale;
70 typedef std::map<gfx::AcceleratedWidget, PerWindowCursorConfiguration>
71 WindowToCursorConfigurationMap;
73 WindowToCursorConfigurationMap window_to_cursor_configuration_map_;
75 DISALLOW_COPY_AND_ASSIGN(CursorController);
78 } // namespace ui
80 #endif // UI_EVENTS_OZONE_CHROMEOS_CURSOR_CONTROLLER_H_