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/strings/string16.h" | 12 #include "base/strings/string16.h" |
12 #include "ui/base/cursor/cursor.h" | 13 #include "ui/base/cursor/cursor.h" |
13 #include "ui/base/ui_base_export.h" | 14 #include "ui/base/ui_base_export.h" |
14 #include "ui/display/display.h" | 15 #include "ui/display/display.h" |
15 #include "ui/gfx/native_widget_types.h" | 16 #include "ui/gfx/native_widget_types.h" |
16 | 17 |
17 namespace ui { | 18 namespace ui { |
18 | 19 |
19 class CursorLoader; | 20 class CursorLoader; |
20 | 21 |
21 // 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 |
22 // image resources. | 23 // image resources. |
23 class UI_BASE_EXPORT ImageCursors { | 24 class UI_BASE_EXPORT ImageCursors { |
24 public: | 25 public: |
25 ImageCursors(); | 26 ImageCursors(); |
26 ~ImageCursors(); | 27 ~ImageCursors(); |
27 | 28 |
| 29 // Creates the |cursor_loader_|. This is optional as |cursor_loader_| is |
| 30 // lazily created if Initialize() isn't explictly called. |
| 31 // However note that it matters which thread is used to create |
| 32 // |cursor_loader_| (see CursorLoaderOzone, crbug.com/741106). Thus explicit |
| 33 // call to Initialize may be useful to ensure initialization happens on the |
| 34 // right thread. |
| 35 void Initialize(); |
| 36 |
28 // Returns the scale and rotation of the currently loaded cursor. | 37 // Returns the scale and rotation of the currently loaded cursor. |
29 float GetScale() const; | 38 float GetScale() const; |
30 display::Display::Rotation GetRotation() const; | 39 display::Display::Rotation GetRotation() const; |
31 | 40 |
32 // Sets the display the cursors are loaded for. |scale_factor| determines the | 41 // Sets the display the cursors are loaded for. |scale_factor| determines the |
33 // size of the image to load. Returns true if the cursor image is reloaded. | 42 // size of the image to load. Returns true if the cursor image is reloaded. |
34 bool SetDisplay(const display::Display& display, float scale_factor); | 43 bool SetDisplay(const display::Display& display, float scale_factor); |
35 | 44 |
36 // Sets the size of the mouse cursor icon. | 45 // Sets the size of the mouse cursor icon. |
37 void SetCursorSize(CursorSize cursor_size); | 46 void SetCursorSize(CursorSize cursor_size); |
38 | 47 |
39 // Sets the platform cursor based on the native type of |cursor|. | 48 // Sets the platform cursor based on the native type of |cursor|. |
40 void SetPlatformCursor(gfx::NativeCursor* cursor); | 49 void SetPlatformCursor(gfx::NativeCursor* cursor); |
41 | 50 |
| 51 base::WeakPtr<ImageCursors> GetWeakPtr(); |
| 52 |
42 private: | 53 private: |
43 // Reloads the all loaded cursors in the cursor loader. | 54 // Reloads the all loaded cursors in the cursor loader. |
44 void ReloadCursors(); | 55 void ReloadCursors(); |
45 | 56 |
46 std::unique_ptr<CursorLoader> cursor_loader_; | 57 std::unique_ptr<CursorLoader> cursor_loader_; |
47 CursorSize cursor_size_; | 58 CursorSize cursor_size_; |
| 59 base::WeakPtrFactory<ImageCursors> weak_ptr_factory_; |
48 | 60 |
49 DISALLOW_COPY_AND_ASSIGN(ImageCursors); | 61 DISALLOW_COPY_AND_ASSIGN(ImageCursors); |
50 }; | 62 }; |
51 | 63 |
52 } // namespace ui | 64 } // namespace ui |
53 | 65 |
54 #endif // UI_BASE_CURSOR_IMAGE_CURSORS_H_ | 66 #endif // UI_BASE_CURSOR_IMAGE_CURSORS_H_ |
OLD | NEW |