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