Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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/wm/system_background_controller.h" |
| 6 | |
Torne (Richard Coles) | f2477e0 | 2013-11-28 11:55:43 +0000 | [diff] [blame] | 7 | #include "ui/aura/window.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 8 | #include "ui/compositor/layer.h" |
| 9 | #include "ui/compositor/layer_type.h" |
| 10 | |
| 11 | namespace ash { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 12 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 13 | SystemBackgroundController::SystemBackgroundController( |
Torne (Richard Coles) | f2477e0 | 2013-11-28 11:55:43 +0000 | [diff] [blame] | 14 | aura::Window* root_window, |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 15 | SkColor color) |
| 16 | : root_window_(root_window), |
| 17 | layer_(new ui::Layer(ui::LAYER_SOLID_COLOR)) { |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 18 | root_window_->AddObserver(this); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 19 | layer_->SetColor(color); |
| 20 | |
| 21 | ui::Layer* root_layer = root_window_->layer(); |
| 22 | layer_->SetBounds(gfx::Rect(root_layer->bounds().size())); |
| 23 | root_layer->Add(layer_.get()); |
| 24 | root_layer->StackAtBottom(layer_.get()); |
| 25 | } |
| 26 | |
| 27 | SystemBackgroundController::~SystemBackgroundController() { |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 28 | root_window_->RemoveObserver(this); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | void SystemBackgroundController::SetColor(SkColor color) { |
| 32 | layer_->SetColor(color); |
| 33 | } |
| 34 | |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 35 | void SystemBackgroundController::OnWindowBoundsChanged( |
| 36 | aura::Window* root, |
| 37 | const gfx::Rect& old_bounds, |
| 38 | const gfx::Rect& new_bounds) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 39 | DCHECK_EQ(root_window_, root); |
| 40 | layer_->SetBounds(gfx::Rect(root_window_->layer()->bounds().size())); |
| 41 | } |
| 42 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 43 | } // namespace ash |