- add sources.
[platform/framework/web/crosswalk.git] / src / ash / wm / workspace / colored_window_controller.cc
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/workspace/colored_window_controller.h"
6
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"
14
15 namespace ash {
16 namespace internal {
17
18 // View implementation responsible for rendering the background.
19 class ColoredWindowController::View : public views::WidgetDelegateView {
20  public:
21   explicit View(ColoredWindowController* controller);
22   virtual ~View();
23
24   // Closes the hosting widget.
25   void Close();
26
27   // WidgetDelegate overrides:
28   virtual views::View* GetContentsView() OVERRIDE;
29
30  private:
31   ColoredWindowController* controller_;
32
33   DISALLOW_COPY_AND_ASSIGN(View);
34 };
35
36 ColoredWindowController::View::View(ColoredWindowController* controller)
37     : controller_(controller) {
38 }
39
40 ColoredWindowController::View::~View() {
41   if (controller_)
42     controller_->view_ = NULL;
43 }
44
45 void ColoredWindowController::View::Close() {
46   controller_ = NULL;
47   GetWidget()->Close();
48 }
49
50 views::View* ColoredWindowController::View::GetContentsView() {
51   return this;
52 }
53
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;
65   widget->Init(params);
66   // Do this so the parent doesn't attempt to enforce any bounds constraints on
67   // us.
68   wm::GetWindowState(widget->GetNativeView())->SetTrackedByWorkspace(false);
69   widget->GetNativeView()->SetProperty(aura::client::kAnimationsDisabledKey,
70                                        true);
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()));
75 }
76
77 ColoredWindowController::~ColoredWindowController() {
78   if (view_)
79     view_->Close();
80 }
81
82 void ColoredWindowController::SetColor(SkColor color) {
83   if (view_)
84     view_->GetWidget()->GetNativeView()->layer()->SetColor(color);
85 }
86
87 views::Widget* ColoredWindowController::GetWidget() {
88   return view_ ? view_->GetWidget() : NULL;
89 }
90
91 }  // namespace internal
92 }  // namespace ash