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.
5 #include "ash/wm/workspace/colored_window_controller.h"
7 #include "ash/shell_window_ids.h"
8 #include "ash/wm/window_state.h"
9 #include "ui/aura/client/aura_constants.h"
10 #include "ui/aura/root_window.h"
11 #include "ui/gfx/canvas.h"
12 #include "ui/views/widget/widget.h"
13 #include "ui/views/widget/widget_delegate.h"
18 // View implementation responsible for rendering the background.
19 class ColoredWindowController::View : public views::WidgetDelegateView {
21 explicit View(ColoredWindowController* controller);
24 // Closes the hosting widget.
27 // WidgetDelegate overrides:
28 virtual views::View* GetContentsView() OVERRIDE;
31 ColoredWindowController* controller_;
33 DISALLOW_COPY_AND_ASSIGN(View);
36 ColoredWindowController::View::View(ColoredWindowController* controller)
37 : controller_(controller) {
40 ColoredWindowController::View::~View() {
42 controller_->view_ = NULL;
45 void ColoredWindowController::View::Close() {
50 views::View* ColoredWindowController::View::GetContentsView() {
54 ColoredWindowController::ColoredWindowController(aura::Window* parent,
55 const std::string& window_name)
56 : view_(new View(this)) {
57 views::Widget* widget = new views::Widget;
58 views::Widget::InitParams params(
59 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
60 params.delegate = view_;
61 params.parent = parent;
62 params.can_activate = false;
63 params.accept_events = false;
64 params.layer_type = ui::LAYER_SOLID_COLOR;
66 // Do this so the parent doesn't attempt to enforce any bounds constraints on
68 wm::GetWindowState(widget->GetNativeView())->SetTrackedByWorkspace(false);
69 widget->GetNativeView()->SetProperty(aura::client::kAnimationsDisabledKey,
71 widget->GetNativeView()->SetName(window_name);
72 // The bounds should match the parent exactly. We don't go through
73 // Widget::SetBounds() as that may try to place on a different display.
74 widget->GetNativeWindow()->SetBounds(gfx::Rect(parent->bounds()));
77 ColoredWindowController::~ColoredWindowController() {
82 void ColoredWindowController::SetColor(SkColor color) {
84 view_->GetWidget()->GetNativeView()->layer()->SetColor(color);
87 views::Widget* ColoredWindowController::GetWidget() {
88 return view_ ? view_->GetWidget() : NULL;
91 } // namespace internal