system_wallpaper_controller.cc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #include "ash/wm/system_wallpaper_controller.h"
  5. #include "ui/aura/window.h"
  6. #include "ui/compositor/layer.h"
  7. #include "ui/compositor/layer_type.h"
  8. namespace ash {
  9. SystemWallpaperController::SystemWallpaperController(aura::Window* root_window,
  10. SkColor color)
  11. : root_window_(root_window), layer_(new ui::Layer(ui::LAYER_SOLID_COLOR)) {
  12. root_window_->AddObserver(this);
  13. layer_->SetColor(color);
  14. ui::Layer* root_layer = root_window_->layer();
  15. layer_->SetBounds(gfx::Rect(root_layer->bounds().size()));
  16. root_layer->Add(layer_.get());
  17. root_layer->StackAtBottom(layer_.get());
  18. }
  19. SystemWallpaperController::~SystemWallpaperController() {
  20. root_window_->RemoveObserver(this);
  21. }
  22. void SystemWallpaperController::SetColor(SkColor color) {
  23. layer_->SetColor(color);
  24. }
  25. void SystemWallpaperController::OnWindowBoundsChanged(
  26. aura::Window* root,
  27. const gfx::Rect& old_bounds,
  28. const gfx::Rect& new_bounds,
  29. ui::PropertyChangeReason reason) {
  30. DCHECK_EQ(root_window_, root);
  31. layer_->SetBounds(gfx::Rect(root_window_->layer()->bounds().size()));
  32. }
  33. } // namespace ash