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 #include "ash/desktop_background/desktop_background_controller.h" | 5 #include "ash/desktop_background/desktop_background_controller.h" |
6 | 6 |
7 #include "ash/desktop_background/desktop_background_resources.h" | 7 #include "ash/desktop_background/desktop_background_resources.h" |
8 #include "ash/desktop_background/desktop_background_view.h" | 8 #include "ash/desktop_background/desktop_background_view.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/shell_factory.h" | 10 #include "ash/shell_factory.h" |
11 #include "ash/shell_window_ids.h" | 11 #include "ash/shell_window_ids.h" |
12 #include "ash/wm/root_window_layout_manager.h" | 12 #include "ash/wm/root_window_layout_manager.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "grit/ui_resources.h" | 14 #include "grit/ui_resources.h" |
15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
16 #include "ui/gfx/compositor/layer.h" | 16 #include "ui/gfx/compositor/layer.h" |
17 #include "ui/gfx/image/image.h" | 17 #include "ui/gfx/image/image.h" |
18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
20 | 20 |
21 namespace ash { | 21 namespace ash { |
22 | 22 |
23 DesktopBackgroundController::DesktopBackgroundController() : | 23 DesktopBackgroundController::DesktopBackgroundController() : |
24 previous_wallpaper_index_(GetDefaultWallpaperIndex()), | |
25 desktop_background_mode_(BACKGROUND_IMAGE) { | 24 desktop_background_mode_(BACKGROUND_IMAGE) { |
26 } | 25 } |
27 | 26 |
28 DesktopBackgroundController::~DesktopBackgroundController() { | 27 DesktopBackgroundController::~DesktopBackgroundController() { |
29 } | 28 } |
30 | 29 |
31 void DesktopBackgroundController::OnDesktopBackgroundChanged(int index) { | 30 void DesktopBackgroundController::OnDesktopBackgroundChanged(int index) { |
32 internal::RootWindowLayoutManager* root_window_layout = | 31 internal::RootWindowLayoutManager* root_window_layout = |
33 Shell::GetInstance()->root_window_layout(); | 32 Shell::GetInstance()->root_window_layout(); |
34 if (desktop_background_mode_ == BACKGROUND_SOLID_COLOR) | 33 if (desktop_background_mode_ == BACKGROUND_SOLID_COLOR) |
35 return; | 34 return; |
36 | 35 |
37 DCHECK(root_window_layout->background_widget()->widget_delegate()); | 36 DCHECK(root_window_layout->background_widget()->widget_delegate()); |
38 static_cast<internal::DesktopBackgroundView*>( | 37 static_cast<internal::DesktopBackgroundView*>( |
39 root_window_layout->background_widget()->widget_delegate())-> | 38 root_window_layout->background_widget()->widget_delegate())-> |
40 SetWallpaper(GetWallpaper(index)); | 39 SetWallpaper(GetWallpaper(index)); |
41 previous_wallpaper_index_ = index; | 40 } |
41 | |
42 void DesktopBackgroundController::OnUserLoginOrSwitchToImageMode() { | |
flackr
2012/03/21 17:44:20
Rather than adding this method, how about changing
bshe
2012/03/22 02:16:03
Done.
On 2012/03/21 17:44:20, flackr wrote:
| |
43 int index = Shell::GetInstance()->user_wallpaper_delegate()-> | |
44 GetUserWallpaperIndex(); | |
45 OnDesktopBackgroundChanged(index); | |
42 } | 46 } |
43 | 47 |
44 void DesktopBackgroundController::SetDesktopBackgroundImageMode( | 48 void DesktopBackgroundController::SetDesktopBackgroundImageMode( |
45 const SkBitmap& wallpaper) { | 49 const SkBitmap& wallpaper) { |
46 internal::RootWindowLayoutManager* root_window_layout = | 50 internal::RootWindowLayoutManager* root_window_layout = |
47 Shell::GetInstance()->root_window_layout(); | 51 Shell::GetInstance()->root_window_layout(); |
48 root_window_layout->SetBackgroundLayer(NULL); | 52 root_window_layout->SetBackgroundLayer(NULL); |
49 root_window_layout->SetBackgroundWidget( | 53 root_window_layout->SetBackgroundWidget( |
50 internal::CreateDesktopBackground(wallpaper)); | 54 internal::CreateDesktopBackground(wallpaper)); |
51 desktop_background_mode_ = BACKGROUND_IMAGE; | 55 desktop_background_mode_ = BACKGROUND_IMAGE; |
52 } | 56 } |
53 | 57 |
54 void DesktopBackgroundController::SetDefaultDesktopBackgroundImage() { | |
55 SetDesktopBackgroundImageMode(GetWallpaper(GetDefaultWallpaperIndex())); | |
56 } | |
57 | |
58 void DesktopBackgroundController::SetPreviousDesktopBackgroundImage() { | |
59 SetDesktopBackgroundImageMode(GetWallpaper(previous_wallpaper_index_)); | |
60 } | |
61 | |
62 void DesktopBackgroundController::SetDesktopBackgroundSolidColorMode() { | 58 void DesktopBackgroundController::SetDesktopBackgroundSolidColorMode() { |
63 // Set a solid black background. | 59 // Set a solid black background. |
64 // TODO(derat): Remove this in favor of having the compositor only clear the | 60 // TODO(derat): Remove this in favor of having the compositor only clear the |
65 // viewport when there are regions not covered by a layer: | 61 // viewport when there are regions not covered by a layer: |
66 // http://crbug.com/113445 | 62 // http://crbug.com/113445 |
67 Shell* shell = Shell::GetInstance(); | 63 Shell* shell = Shell::GetInstance(); |
68 ui::Layer* background_layer = new ui::Layer(ui::Layer::LAYER_SOLID_COLOR); | 64 ui::Layer* background_layer = new ui::Layer(ui::Layer::LAYER_SOLID_COLOR); |
69 background_layer->SetColor(SK_ColorBLACK); | 65 background_layer->SetColor(SK_ColorBLACK); |
70 shell->GetContainer(internal::kShellWindowId_DesktopBackgroundContainer)-> | 66 shell->GetContainer(internal::kShellWindowId_DesktopBackgroundContainer)-> |
71 layer()->Add(background_layer); | 67 layer()->Add(background_layer); |
72 shell->root_window_layout()->SetBackgroundLayer(background_layer); | 68 shell->root_window_layout()->SetBackgroundLayer(background_layer); |
73 shell->root_window_layout()->SetBackgroundWidget(NULL); | 69 shell->root_window_layout()->SetBackgroundWidget(NULL); |
74 desktop_background_mode_ = BACKGROUND_SOLID_COLOR; | 70 desktop_background_mode_ = BACKGROUND_SOLID_COLOR; |
75 } | 71 } |
76 | 72 |
77 } // namespace ash | 73 } // namespace ash |
OLD | NEW |