blob: 5cfaffa79bc1df392830b642b8c554a649a07160 [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
7#include "ash/wm/toplevel_frame_view.h"
8#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
77views::NonClientFrameView* PanelWindow::CreateNonClientFrameView() {
78 // TODO(stevenjb): Implement a custom frame view for panels.
79 // For now, use the default frame view (views::CustomFrameView)
80 // which implements close and resize for us.
81 return NULL;
82}
83
84} // namespace ash