| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_BASE_CURSOR_CURSOR_LOADER_X11_H_ | 5 #ifndef UI_BASE_CURSOR_CURSOR_LOADER_X11_H_ |
| 6 #define UI_BASE_CURSOR_CURSOR_LOADER_X11_H_ | 6 #define UI_BASE_CURSOR_CURSOR_LOADER_X11_H_ |
| 7 | 7 |
| 8 #include <X11/Xcursor/Xcursor.h> | 8 #include <X11/Xcursor/Xcursor.h> |
| 9 #include <unordered_map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "ui/base/cursor/cursor.h" | 13 #include "ui/base/cursor/cursor.h" |
| 14 #include "ui/base/cursor/cursor_loader.h" | 14 #include "ui/base/cursor/cursor_loader.h" |
| 15 #include "ui/base/ui_base_export.h" | 15 #include "ui/base/ui_base_export.h" |
| 16 #include "ui/base/x/x11_util.h" | 16 #include "ui/base/x/x11_util.h" |
| 17 | 17 |
| 18 namespace ui { | 18 namespace ui { |
| 19 | 19 |
| 20 class UI_BASE_EXPORT CursorLoaderX11 : public CursorLoader { | 20 class UI_BASE_EXPORT CursorLoaderX11 : public CursorLoader { |
| 21 public: | 21 public: |
| 22 CursorLoaderX11(); | 22 CursorLoaderX11(); |
| 23 ~CursorLoaderX11() override; | 23 ~CursorLoaderX11() override; |
| 24 | 24 |
| 25 // Overridden from CursorLoader: | 25 // Overridden from CursorLoader: |
| 26 void LoadImageCursor(int id, int resource_id, const gfx::Point& hot) override; | 26 void LoadImageCursor(CursorType id, |
| 27 void LoadAnimatedCursor(int id, | 27 int resource_id, |
| 28 const gfx::Point& hot) override; |
| 29 void LoadAnimatedCursor(CursorType id, |
| 28 int resource_id, | 30 int resource_id, |
| 29 const gfx::Point& hot, | 31 const gfx::Point& hot, |
| 30 int frame_delay_ms) override; | 32 int frame_delay_ms) override; |
| 31 void UnloadAll() override; | 33 void UnloadAll() override; |
| 32 void SetPlatformCursor(gfx::NativeCursor* cursor) override; | 34 void SetPlatformCursor(gfx::NativeCursor* cursor) override; |
| 33 | 35 |
| 34 const XcursorImage* GetXcursorImageForTest(int id); | 36 const XcursorImage* GetXcursorImageForTest(CursorType id); |
| 35 | 37 |
| 36 private: | 38 private: |
| 37 struct ImageCursor { | 39 struct ImageCursor { |
| 38 ImageCursor(XcursorImage* x_image, | 40 ImageCursor(XcursorImage* x_image, |
| 39 float scale, | 41 float scale, |
| 40 display::Display::Rotation rotation); | 42 display::Display::Rotation rotation); |
| 41 ~ImageCursor(); | 43 ~ImageCursor(); |
| 42 | 44 |
| 43 ::Cursor cursor; | 45 ::Cursor cursor; |
| 44 float scale; | 46 float scale; |
| 45 display::Display::Rotation rotation; | 47 display::Display::Rotation rotation; |
| 46 }; | 48 }; |
| 47 | 49 |
| 48 // Returns true if we have an image resource loaded for the |native_cursor|. | 50 // Returns true if we have an image resource loaded for the |native_cursor|. |
| 49 bool IsImageCursor(gfx::NativeCursor native_cursor); | 51 bool IsImageCursor(gfx::NativeCursor native_cursor); |
| 50 | 52 |
| 51 // Loads a new cursor corresponding to |id|. | 53 // Loads a new cursor corresponding to |id|. |
| 52 ::Cursor CursorFromId(int id); | 54 ::Cursor CursorFromId(CursorType id); |
| 53 | 55 |
| 54 XDisplay* display_; | 56 XDisplay* display_; |
| 55 | 57 |
| 56 // A map from a cursor native type to X cursor. | 58 // A map from a cursor native type to X cursor. |
| 57 std::unordered_map<int, ::Cursor> font_cursors_; | 59 std::map<CursorType, ::Cursor> font_cursors_; |
| 58 | 60 |
| 59 // A map to hold all image cursors. It maps the cursor ID to the X Cursor, the | 61 // A map to hold all image cursors. It maps the cursor ID to the X Cursor, the |
| 60 // display's scale factor, and the display's rotation. | 62 // display's scale factor, and the display's rotation. |
| 61 typedef std::unordered_map<int, std::unique_ptr<ImageCursor>> ImageCursorMap; | 63 typedef std::map<CursorType, std::unique_ptr<ImageCursor>> ImageCursorMap; |
| 62 ImageCursorMap image_cursors_; | 64 ImageCursorMap image_cursors_; |
| 63 | 65 |
| 64 // A map to hold all animated cursors. It maps the cursor ID to the pair of | 66 // A map to hold all animated cursors. It maps the cursor ID to the pair of |
| 65 // the X Cursor and the corresponding XcursorImages. We need a pointer to the | 67 // the X Cursor and the corresponding XcursorImages. We need a pointer to the |
| 66 // images so that we can free them on destruction. | 68 // images so that we can free them on destruction. |
| 67 typedef std::unordered_map<int, std::pair<::Cursor, XcursorImages*>> | 69 typedef std::map<CursorType, std::pair<::Cursor, XcursorImages*>> |
| 68 AnimatedCursorMap; | 70 AnimatedCursorMap; |
| 69 AnimatedCursorMap animated_cursors_; | 71 AnimatedCursorMap animated_cursors_; |
| 70 | 72 |
| 71 const XScopedCursor invisible_cursor_; | 73 const XScopedCursor invisible_cursor_; |
| 72 | 74 |
| 73 DISALLOW_COPY_AND_ASSIGN(CursorLoaderX11); | 75 DISALLOW_COPY_AND_ASSIGN(CursorLoaderX11); |
| 74 }; | 76 }; |
| 75 | 77 |
| 76 } // namespace ui | 78 } // namespace ui |
| 77 | 79 |
| 78 #endif // UI_BASE_CURSOR_CURSOR_LOADER_X11_H_ | 80 #endif // UI_BASE_CURSOR_CURSOR_LOADER_X11_H_ |
| OLD | NEW |