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 ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ | 5 #ifndef ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ |
6 #define ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ | 6 #define ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "ash/ash_export.h" | 9 #include "ash/ash_export.h" |
10 #include "ash/desktop_background/desktop_background_resources.h" | 10 #include "ash/desktop_background/desktop_background_resources.h" |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 | 13 |
14 class SkBitmap; | 14 class SkBitmap; |
15 | 15 |
16 namespace ash { | 16 namespace ash { |
17 | 17 |
18 class UserWallpaperDelegate { | 18 class UserWallpaperDelegate { |
19 public: | 19 public: |
20 virtual ~UserWallpaperDelegate() {} | 20 virtual ~UserWallpaperDelegate() {} |
21 | 21 |
22 // Gets the index of user selected wallpaper. | 22 // Gets the index of user selected wallpaper. |
23 virtual const int GetUserWallpaperIndex() = 0; | 23 virtual const int GetUserWallpaperIndex() = 0; |
24 | 24 |
25 // Open the set wallpaper page in the browser. | 25 // Opens the set wallpaper page in the browser. |
26 virtual void OpenSetWallpaperPage() = 0; | 26 virtual void OpenSetWallpaperPage() = 0; |
27 | 27 |
28 // Returns true if user can open set wallpaper page. Only guest user returns | 28 // Returns true if user can open set wallpaper page. Only guest user returns |
29 // false currently. | 29 // false currently. |
30 virtual bool CanOpenSetWallpaperPage() = 0; | 30 virtual bool CanOpenSetWallpaperPage() = 0; |
31 }; | 31 }; |
32 | 32 |
33 // A class to listen for login and desktop background change events and set the | 33 // Loads selected desktop wallpaper from file system asynchronously and updates |
34 // corresponding default wallpaper in Aura shell. | 34 // background layer if loaded successfully. |
35 class ASH_EXPORT DesktopBackgroundController { | 35 class ASH_EXPORT DesktopBackgroundController { |
36 public: | 36 public: |
37 enum BackgroundMode { | 37 enum BackgroundMode { |
38 BACKGROUND_IMAGE, | 38 BACKGROUND_IMAGE, |
39 BACKGROUND_SOLID_COLOR | 39 BACKGROUND_SOLID_COLOR |
40 }; | 40 }; |
41 | 41 |
42 DesktopBackgroundController(); | 42 DesktopBackgroundController(); |
43 virtual ~DesktopBackgroundController(); | 43 virtual ~DesktopBackgroundController(); |
44 | 44 |
45 // Get the desktop background mode. | 45 // Gets the desktop background mode. |
46 BackgroundMode desktop_background_mode() const { | 46 BackgroundMode desktop_background_mode() const { |
47 return desktop_background_mode_; | 47 return desktop_background_mode_; |
48 } | 48 } |
49 | 49 |
50 // Load default wallpaper at |index| asynchronously and set to current | 50 // Loads default wallpaper at |index| asynchronously and sets to current |
51 // wallpaper after loaded. | 51 // wallpaper after loaded. |
52 void SetDefaultWallpaper(int index); | 52 void SetDefaultWallpaper(int index); |
53 | 53 |
54 // Cancel the current wallpaper loading operation. | 54 // Sets the user selected custom wallpaper. Called when user selected a file |
| 55 // from file system or changed the layout of wallpaper. |
| 56 void SetCustomWallpaper(const SkBitmap& wallpaper, WallpaperLayout layout); |
| 57 |
| 58 // Cancels the current wallpaper loading operation. |
55 void CancelPendingWallpaperOperation(); | 59 void CancelPendingWallpaperOperation(); |
56 | 60 |
57 // Load logged in user wallpaper asynchronously and set to current wallpaper | 61 // Loads logged in user wallpaper asynchronously and sets to current wallpaper |
58 // after loaded. | 62 // after loaded. |
59 void SetLoggedInUserWallpaper(); | 63 void SetLoggedInUserWallpaper(); |
60 | 64 |
61 // Sets the desktop background to solid color mode and create a solid color | 65 // Sets the desktop background to solid color mode and creates a solid color |
62 // layout. | 66 // layout. |
63 void SetDesktopBackgroundSolidColorMode(); | 67 void SetDesktopBackgroundSolidColorMode(); |
64 | 68 |
65 private: | 69 private: |
66 // An operation to asynchronously load wallpaper. | 70 // An operation to asynchronously loads wallpaper. |
67 class WallpaperOperation; | 71 class WallpaperOperation; |
68 | 72 |
69 // Sets the desktop background to image mode and create a new background | 73 // Sets the desktop background to image mode and creates a new background |
70 // widget with user selected wallpaper or default wallpaper. Delete the old | 74 // widget with user selected wallpaper or default wallpaper. Deletes the old |
71 // widget if any. | 75 // widget if any. |
72 void SetDesktopBackgroundImageMode(scoped_refptr<WallpaperOperation> wo); | 76 void SetDesktopBackgroundImageMode(scoped_refptr<WallpaperOperation> wo); |
73 | 77 |
74 // Default wallpapper loaded, set the background mode to image mode. | 78 // Creates a new background widget and sets the background mode to image mode. |
| 79 // Called after wallpaper loaded successfully. |
75 void OnWallpaperLoadCompleted(scoped_refptr<WallpaperOperation> wo); | 80 void OnWallpaperLoadCompleted(scoped_refptr<WallpaperOperation> wo); |
76 | 81 |
77 // Create an empty wallpaper. Some tests require a wallpaper widget is ready | 82 // Creates an empty wallpaper. Some tests require a wallpaper widget is ready |
78 // when running. However, the wallpaper widgets are now created asynchronously | 83 // when running. However, the wallpaper widgets are now created asynchronously |
79 // . If loading a real wallpaper, there are cases that these tests crash | 84 // . If loading a real wallpaper, there are cases that these tests crash |
80 // because the required widget is not ready. This function synchronously | 85 // because the required widget is not ready. This function synchronously |
81 // creates an empty widget for those tests to prevent crashes. An example test | 86 // creates an empty widget for those tests to prevent crashes. An example test |
82 // is SystemGestureEventFilterTest.ThreeFingerSwipe. | 87 // is SystemGestureEventFilterTest.ThreeFingerSwipe. |
83 void CreateEmptyWallpaper(); | 88 void CreateEmptyWallpaper(); |
84 | 89 |
85 // Can change at runtime. | 90 // Can change at runtime. |
86 BackgroundMode desktop_background_mode_; | 91 BackgroundMode desktop_background_mode_; |
87 | 92 |
88 // The previous successfully loaded wallpaper. | 93 // The previous successfully loaded wallpaper. |
89 int previous_index_; | 94 int previous_index_; |
90 | 95 |
91 scoped_refptr<WallpaperOperation> wallpaper_op_; | 96 scoped_refptr<WallpaperOperation> wallpaper_op_; |
92 | 97 |
93 base::WeakPtrFactory<DesktopBackgroundController> weak_ptr_factory_; | 98 base::WeakPtrFactory<DesktopBackgroundController> weak_ptr_factory_; |
94 | 99 |
95 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundController); | 100 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundController); |
96 }; | 101 }; |
97 | 102 |
98 } // namespace ash | 103 } // namespace ash |
99 | 104 |
100 #endif // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ | 105 #endif // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ |
OLD | NEW |