blob: e5d68ac6d967589c4bfe7bd30c5a85a01df34eb2 [file] [log] [blame]
[email protected]6b854932012-02-04 16:44:271// 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/shell/panel_window.h"
6
[email protected]52295042012-02-08 02:02:597#include "ash/wm/panel_frame_view.h"
[email protected]6b854932012-02-04 16:44:278#include "base/utf_string_conversions.h"
9#include "ui/aura/window.h"
10#include "ui/gfx/canvas.h"
11#include "ui/views/widget/widget.h"
12
13namespace {
14const int kMinWidth = 100;
15const int kMinHeight = 100;
16const int kDefaultWidth = 200;
17const int kDefaultHeight = 300;
18}
19
20namespace ash {
21
22// static
23views::Widget* PanelWindow::CreatePanelWindow(const gfx::Rect& rect) {
24 PanelWindow* panel_window = new PanelWindow("Example Panel Window");
25 panel_window->params().bounds = rect;
26 return panel_window->CreateWidget();
27}
28
29PanelWindow::PanelWindow(const std::string& name)
30 : name_(name),
31 params_(views::Widget::InitParams::TYPE_PANEL) {
32 params_.delegate = this;
33}
34
35PanelWindow::~PanelWindow() {
36}
37
38views::Widget* PanelWindow::CreateWidget() {
39 views::Widget* widget = new views::Widget;
40
41 if (params().bounds.width() == 0)
42 params().bounds.set_width(kDefaultWidth);
43 if (params().bounds.height() == 0)
44 params().bounds.set_height(kDefaultHeight);
45
46 widget->Init(params());
47 widget->GetNativeView()->SetName(name_);
48 widget->Show();
49
50 return widget;
51}
52
53gfx::Size PanelWindow::GetPreferredSize() {
54 return gfx::Size(kMinWidth, kMinHeight);
55}
56
57void PanelWindow::OnPaint(gfx::Canvas* canvas) {
58 canvas->FillRect(GetLocalBounds(), SK_ColorGREEN);
59}
60
61string16 PanelWindow::GetWindowTitle() const {
62 return ASCIIToUTF16(name_);
63}
64
65views::View* PanelWindow::GetContentsView() {
66 return this;
67}
68
69bool PanelWindow::CanResize() const {
70 return true;
71}
72
73bool PanelWindow::CanMaximize() const {
74 return false;
75}
76
[email protected]eb642f32012-03-17 06:56:1677views::NonClientFrameView* PanelWindow::CreateNonClientFrameView(
78 views::Widget* widget) {
79 return new PanelFrameView(widget);
[email protected]6b854932012-02-04 16:44:2780}
81
82} // namespace ash