Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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. | |
| 4 | |
| 5 #ifndef SERVICES_UI_WS_THREADED_IMAGE_CURSORS_H_ | |
| 6 #define SERVICES_UI_WS_THREADED_IMAGE_CURSORS_H_ | |
| 7 | |
| 8 #include "base/memory/weak_ptr.h" | |
| 9 #include "ui/base/cursor/image_cursors.h" | |
| 10 | |
| 11 namespace base { | |
| 12 class SingleThreadTaskRunner; | |
| 13 } | |
| 14 | |
| 15 namespace ui { | |
| 16 class PlatformWindow; | |
| 17 | |
| 18 namespace ws { | |
| 19 | |
| 20 // Wrapper around ui::ImageCursors, capable of executing its methods | |
| 21 // asynchronously via the provided task runner. | |
| 22 class ThreadedImageCursors { | |
| 23 public: | |
| 24 // |resource_runner| is the task runner for the thread which can be used to | |
| 25 // load resources; |image_cursors_weak_ptr| is the object used to perform | |
| 26 // cursor operations, and should only be dereferenced on |resource_runner|. | |
| 27 ThreadedImageCursors( | |
| 28 scoped_refptr<base::SingleThreadTaskRunner>& resource_task_runner, | |
| 29 base::WeakPtr<ui::ImageCursors> image_cursors_weak_ptr); | |
| 30 ~ThreadedImageCursors(); | |
| 31 | |
| 32 // Executes ui::ImageCursors::SetDisplay asynchronously. | |
| 33 // 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. | |
| 35 void SetDisplay(const display::Display& display, float scale_factor); | |
| 36 | |
| 37 // Asynchronously sets the size of the mouse cursor icon. | |
| 38 void SetCursorSize(CursorSize cursor_size); | |
| 39 | |
| 40 // Asynchronously sets the cursor type and then sets the corresponding | |
| 41 // PlatformCursor on the provided |platform_window|. | |
| 42 // |platform_window| pointer needs to be valid while this object is alive. | |
| 43 void SetCursor(ui::CursorType cursor_type, | |
| 44 ui::PlatformWindow* platform_window); | |
| 45 | |
| 46 // Helper method. Sets |platform_cursor| on the |platform_window|. | |
| 47 void SetCursorOnPlatformWindow(ui::PlatformCursor platform_cursor, | |
| 48 ui::PlatformWindow* platform_window); | |
| 49 | |
| 50 private: | |
| 51 // Task runner used for accessing |image_cursors_weak_ptr_. | |
| 52 scoped_refptr<base::SingleThreadTaskRunner> resource_task_runner_; | |
| 53 | |
| 54 // Task runner of the Window Server thread (where this object is created and | |
|
sky
2017/06/27 19:58:57
In some comments you refer to the 'ui service' (th
mfomitchev
2017/07/11 21:47:00
Done.
| |
| 55 // destroyed). | |
| 56 scoped_refptr<base::SingleThreadTaskRunner> ws_task_runner_; | |
| 57 | |
| 58 // Weak pointer to the actual ui::ImageCursors object used to perform the | |
| 59 // cursor operations. | |
| 60 base::WeakPtr<ui::ImageCursors> image_cursors_weak_ptr_; | |
| 61 | |
| 62 base::WeakPtrFactory<ThreadedImageCursors> weak_ptr_factory_; | |
| 63 | |
| 64 DISALLOW_COPY_AND_ASSIGN(ThreadedImageCursors); | |
| 65 }; | |
| 66 | |
| 67 } // namespace ws | |
| 68 } // namespace ui | |
| 69 | |
| 70 #endif // SERVICES_UI_WS_THREADED_IMAGE_CURSORS_H_ | |
| OLD | NEW |