ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / ui / ozone / platform / dri / dri_cursor.h
blob59747a5114c90650d92737609cb6f763ee18d7c7
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_OZONE_PLATFORM_DRI_DRI_CURSOR_H_
6 #define UI_OZONE_PLATFORM_DRI_DRI_CURSOR_H_
8 #include "base/callback.h"
9 #include "base/logging.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/synchronization/lock.h"
12 #include "ui/base/cursor/cursor.h"
13 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
14 #include "ui/gfx/geometry/point_f.h"
15 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/native_widget_types.h"
17 #include "ui/ozone/public/gpu_platform_support_host.h"
19 namespace gfx {
20 class PointF;
21 class Vector2dF;
22 class Rect;
25 namespace ui {
27 class BitmapCursorOzone;
28 class BitmapCursorFactoryOzone;
29 class DriGpuPlatformSupportHost;
30 class DriWindowManager;
32 class DriCursor : public CursorDelegateEvdev, public GpuPlatformSupportHost {
33 public:
34 explicit DriCursor(DriWindowManager* window_manager,
35 DriGpuPlatformSupportHost* sender);
36 ~DriCursor() override;
38 void Init();
40 // Change the cursor over the specifed window.
41 void SetCursor(gfx::AcceleratedWidget window, PlatformCursor platform_cursor);
43 // Handle window lifecycle.
44 void OnWindowAdded(gfx::AcceleratedWidget window,
45 const gfx::Rect& bounds_in_screen,
46 const gfx::Rect& cursor_confined_bounds);
47 void OnWindowRemoved(gfx::AcceleratedWidget window);
49 // Handle window bounds changes.
50 void PrepareForBoundsChange(gfx::AcceleratedWidget window);
51 void CommitBoundsChange(gfx::AcceleratedWidget window,
52 const gfx::Rect& new_display_bounds_in_screen,
53 const gfx::Rect& new_confined_bounds);
55 // Confines the cursor to |confined_bounds| for |window|.
56 void ConfineCursorToBounds(gfx::AcceleratedWidget window,
57 const gfx::Rect& bounds);
59 // CursorDelegateEvdev:
60 void MoveCursorTo(gfx::AcceleratedWidget window,
61 const gfx::PointF& location) override;
62 void MoveCursorTo(const gfx::PointF& screen_location) override;
63 void MoveCursor(const gfx::Vector2dF& delta) override;
64 bool IsCursorVisible() override;
65 gfx::PointF GetLocation() override;
66 gfx::Rect GetCursorConfinedBounds() override;
68 // GpuPlatformSupportHost:
69 void OnChannelEstablished(
70 int host_id,
71 scoped_refptr<base::SingleThreadTaskRunner> send_runner,
72 const base::Callback<void(IPC::Message*)>& sender) override;
73 void OnChannelDestroyed(int host_id) override;
75 // IPC::Listener:
76 bool OnMessageReceived(const IPC::Message& message) override;
78 private:
79 // Set the location (clamps to cursor bounds).
80 void SetCursorLocationLocked(const gfx::PointF& location);
82 // The location of the bitmap (the cursor location is the hotspot location).
83 gfx::Point GetBitmapLocationLocked();
85 // IPC-related functions.
86 bool IsConnectedLocked();
87 void SendCursorShowLocked();
88 void SendCursorHideLocked();
89 void SendCursorMoveLocked();
90 void SendLocked(IPC::Message* message);
92 DriWindowManager* window_manager_; // Not owned.
93 DriGpuPlatformSupportHost* gpu_platform_support_host_; // Not owned.
95 // Task runner for main thread.
96 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
98 struct CursorState {
99 CursorState();
100 ~CursorState();
102 // The current cursor bitmap (immutable).
103 scoped_refptr<BitmapCursorOzone> bitmap;
105 // The window under the cursor.
106 gfx::AcceleratedWidget window;
108 // The location of the cursor within the window.
109 gfx::PointF location;
111 // The bounds of the display under the cursor.
112 gfx::Rect display_bounds_in_screen;
114 // The bounds that the cursor is confined to in |window|.
115 gfx::Rect confined_bounds;
117 int host_id;
119 // Callback for IPC updates.
120 base::Callback<void(IPC::Message*)> send_callback;
121 scoped_refptr<base::SingleThreadTaskRunner> send_runner;
123 // The mutex synchronizing this object.
124 base::Lock lock;
127 CursorState state_;
130 } // namespace ui
132 #endif // UI_OZONE_PLATFORM_DRI_DRI_CURSOR_H_