Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / base / cursor / cursor_loader_x11.h
blob8c947d175f743f0fdc7ce2581bb44075b98938fb
1 // Copyright (c) 2012 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_BASE_CURSOR_CURSOR_LOADER_X11_H_
6 #define UI_BASE_CURSOR_CURSOR_LOADER_X11_H_
8 #include <X11/Xcursor/Xcursor.h>
9 #include <map>
11 #include "base/compiler_specific.h"
12 #include "ui/base/cursor/cursor.h"
13 #include "ui/base/cursor/cursor_loader.h"
14 #include "ui/base/ui_base_export.h"
15 #include "ui/base/x/x11_util.h"
16 #include "ui/gfx/display.h"
18 namespace ui {
20 class UI_BASE_EXPORT CursorLoaderX11 : public CursorLoader {
21 public:
22 CursorLoaderX11();
23 ~CursorLoaderX11() override;
25 // Overridden from CursorLoader:
26 void LoadImageCursor(int id, int resource_id, const gfx::Point& hot) override;
27 void LoadAnimatedCursor(int id,
28 int resource_id,
29 const gfx::Point& hot,
30 int frame_delay_ms) override;
31 void UnloadAll() override;
32 void SetPlatformCursor(gfx::NativeCursor* cursor) override;
34 const XcursorImage* GetXcursorImageForTest(int id);
36 private:
37 // Returns true if we have an image resource loaded for the |native_cursor|.
38 bool IsImageCursor(gfx::NativeCursor native_cursor);
40 // Gets the X Cursor corresponding to the |native_cursor|.
41 ::Cursor ImageCursorFromNative(gfx::NativeCursor native_cursor);
43 // A map to hold all image cursors. It maps the cursor ID to the X Cursor.
44 typedef std::map<int, ::Cursor> ImageCursorMap;
45 ImageCursorMap cursors_;
47 // A map to hold all animated cursors. It maps the cursor ID to the pair of
48 // the X Cursor and the corresponding XcursorImages. We need a pointer to the
49 // images so that we can free them on destruction.
50 typedef std::map<int, std::pair< ::Cursor, XcursorImages*> >
51 AnimatedCursorMap;
52 AnimatedCursorMap animated_cursors_;
54 const XScopedCursor invisible_cursor_;
56 DISALLOW_COPY_AND_ASSIGN(CursorLoaderX11);
59 } // namespace ui
61 #endif // UI_BASE_CURSOR_CURSOR_LOADER_X11_H_