| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_IMAGE_CURSORS_H_ | 5 #ifndef UI_BASE_CURSOR_IMAGE_CURSORS_H_ |
| 6 #define UI_BASE_CURSOR_IMAGE_CURSORS_H_ | 6 #define UI_BASE_CURSOR_IMAGE_CURSORS_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "ui/base/cursor/cursor.h" | 13 #include "ui/base/cursor/cursor.h" |
| 14 #include "ui/base/ui_base_export.h" | 14 #include "ui/base/ui_base_export.h" |
| 15 #include "ui/display/display.h" | 15 #include "ui/display/display.h" |
| 16 #include "ui/gfx/native_widget_types.h" | 16 #include "ui/gfx/native_widget_types.h" |
| 17 | 17 |
| 18 namespace ui { | 18 namespace ui { |
| 19 | 19 |
| 20 class CursorLoader; | 20 class CursorLoader; |
| 21 | 21 |
| 22 // A utility class that provides cursors for NativeCursors for which we have | 22 // A utility class that provides cursors for NativeCursors for which we have |
| 23 // image resources. | 23 // image resources. |
| 24 class UI_BASE_EXPORT ImageCursors { | 24 class UI_BASE_EXPORT ImageCursors { |
| 25 public: | 25 public: |
| 26 ImageCursors(); | 26 ImageCursors(); |
| 27 ~ImageCursors(); | 27 ~ImageCursors(); |
| 28 | 28 |
| 29 void Initialize(); |
| 30 |
| 29 // Returns the scale and rotation of the currently loaded cursor. | 31 // Returns the scale and rotation of the currently loaded cursor. |
| 30 float GetScale() const; | 32 float GetScale() const; |
| 31 display::Display::Rotation GetRotation() const; | 33 display::Display::Rotation GetRotation() const; |
| 32 | 34 |
| 33 // Sets the display the cursors are loaded for. |scale_factor| determines the | 35 // Sets the display the cursors are loaded for. |scale_factor| determines the |
| 34 // size of the image to load. Returns true if the cursor image is reloaded. | 36 // size of the image to load. Returns true if the cursor image is reloaded. |
| 35 bool SetDisplay(const display::Display& display, float scale_factor); | 37 bool SetDisplay(const display::Display& display, float scale_factor); |
| 36 | 38 |
| 37 // Sets the size of the mouse cursor icon. | 39 // Sets the size of the mouse cursor icon. |
| 38 void SetCursorSize(CursorSize cursor_size); | 40 void SetCursorSize(CursorSize cursor_size); |
| 39 | 41 |
| 40 // Sets the platform cursor based on the native type of |cursor|. | 42 // Sets the platform cursor based on the native type of |cursor|. |
| 41 void SetPlatformCursor(gfx::NativeCursor* cursor); | 43 void SetPlatformCursor(gfx::NativeCursor* cursor); |
| 42 | 44 |
| 43 base::WeakPtr<ImageCursors> GetWeakPtr(); | 45 base::WeakPtr<ImageCursors> GetWeakPtr(); |
| 44 | 46 |
| 45 private: | 47 private: |
| 46 // Reloads the all loaded cursors in the cursor loader. | 48 // Reloads the all loaded cursors in the cursor loader. |
| 47 void ReloadCursors(); | 49 void ReloadCursors(); |
| 48 | 50 |
| 49 std::unique_ptr<CursorLoader> cursor_loader_; | 51 std::unique_ptr<CursorLoader> cursor_loader_; |
| 50 CursorSize cursor_size_; | 52 CursorSize cursor_size_; |
| 51 base::WeakPtrFactory<ImageCursors> weak_ptr_factory_; | 53 base::WeakPtrFactory<ImageCursors> weak_ptr_factory_; |
| 52 | 54 |
| 53 DISALLOW_COPY_AND_ASSIGN(ImageCursors); | 55 DISALLOW_COPY_AND_ASSIGN(ImageCursors); |
| 54 }; | 56 }; |
| 55 | 57 |
| 58 // Helper class that holds an ImageCursors unique pointer. |
| 59 class UI_BASE_EXPORT ImageCursorsHolder { |
| 60 public: |
| 61 ImageCursorsHolder(); |
| 62 ~ImageCursorsHolder(); |
| 63 |
| 64 ImageCursors* GetImageCursors(); |
| 65 |
| 66 void SetImageCursors(std::unique_ptr<ImageCursors> image_cursors); |
| 67 |
| 68 base::WeakPtr<ImageCursorsHolder> GetWeakPtr(); |
| 69 |
| 70 private: |
| 71 std::unique_ptr<ImageCursors> image_cursors_; |
| 72 base::WeakPtrFactory<ImageCursorsHolder> weak_ptr_factory_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(ImageCursorsHolder); |
| 75 }; |
| 76 |
| 56 } // namespace ui | 77 } // namespace ui |
| 57 | 78 |
| 58 #endif // UI_BASE_CURSOR_IMAGE_CURSORS_H_ | 79 #endif // UI_BASE_CURSOR_IMAGE_CURSORS_H_ |
| OLD | NEW |