blob: b575654bdd60a65231d974e51d94eb54d41cd78e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_
#define ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_
#include "ash/ash_export.h"
#include "ash/desktop_background/desktop_background_resources.h"
#include "ash/wm/window_animations.h"
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/image/image_skia.h"
namespace aura {
class RootWindow;
}
namespace ash {
class UserWallpaperDelegate {
public:
virtual ~UserWallpaperDelegate() {}
// Returns type of window animation that should be used when showin wallpaper.
virtual ash::WindowVisibilityAnimationType GetAnimationType() = 0;
// Initialize wallpaper.
virtual void InitializeWallpaper() = 0;
// Opens the set wallpaper page in the browser.
virtual void OpenSetWallpaperPage() = 0;
// Returns true if user can open set wallpaper page. Only guest user returns
// false currently.
virtual bool CanOpenSetWallpaperPage() = 0;
// Notifies delegate that wallpaper animation has finished.
virtual void OnWallpaperAnimationFinished() = 0;
};
// Loads selected desktop wallpaper from file system asynchronously and updates
// background layer if loaded successfully.
class ASH_EXPORT DesktopBackgroundController {
public:
enum BackgroundMode {
BACKGROUND_IMAGE,
BACKGROUND_SOLID_COLOR
};
DesktopBackgroundController();
virtual ~DesktopBackgroundController();
// Gets the desktop background mode.
BackgroundMode desktop_background_mode() const {
return desktop_background_mode_;
}
gfx::ImageSkia GetWallpaper() const;
WallpaperLayout GetWallpaperLayout() const;
// Provides current image on the background, or empty SkBitmap if there is
// no image, e.g. background is solid color.
SkBitmap GetCurrentWallpaperImage();
// Initialize root window's background.
void OnRootWindowAdded(aura::RootWindow* root_window);
// Loads default wallpaper at |index| asynchronously and sets to current
// wallpaper after loaded.
void SetDefaultWallpaper(int index);
// Sets the user selected custom wallpaper. Called when user selected a file
// from file system or changed the layout of wallpaper.
void SetCustomWallpaper(const gfx::ImageSkia& wallpaper,
WallpaperLayout layout);
// Cancels the current wallpaper loading operation.
void CancelPendingWallpaperOperation();
// Sets the desktop background to solid color mode and creates a solid
// |color| layout.
void SetDesktopBackgroundSolidColorMode(SkColor color);
// Creates an empty wallpaper. Some tests require a wallpaper widget is ready
// when running. However, the wallpaper widgets are now created asynchronously
// . If loading a real wallpaper, there are cases that these tests crash
// because the required widget is not ready. This function synchronously
// creates an empty widget for those tests to prevent crashes. An example test
// is SystemGestureEventFilterTest.ThreeFingerSwipe.
void CreateEmptyWallpaper();
private:
// An operation to asynchronously loads wallpaper.
class WallpaperOperation;
struct WallpaperData;
// Creates a new background widget using the current wallpapaer image and
// use it as a background of the |root_window|. Deletes the old widget if any.
void SetDesktopBackgroundImage(aura::RootWindow* root_window);
// Update the background of all root windows using the current wallpaper image
// in |current_wallpaper_|.
void UpdateDesktopBackgroundImageMode();
// Creates a new background widget and sets the background mode to image mode.
// Called after wallpaper loaded successfully.
void OnWallpaperLoadCompleted(scoped_refptr<WallpaperOperation> wo);
// Can change at runtime.
BackgroundMode desktop_background_mode_;
SkColor background_color_;
// The current wallpaper.
scoped_ptr<WallpaperData> current_wallpaper_;
scoped_refptr<WallpaperOperation> wallpaper_op_;
base::WeakPtrFactory<DesktopBackgroundController> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundController);
};
} // namespace ash
#endif // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_
|