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