[email protected] | 6b85493 | 2012-02-04 16:44:27 | [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/shell/panel_window.h" |
| 6 | |
[email protected] | 5229504 | 2012-02-08 02:02:59 | [diff] [blame] | 7 | #include "ash/wm/panel_frame_view.h" |
[email protected] | 6b85493 | 2012-02-04 16:44:27 | [diff] [blame] | 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 | |
| 13 | namespace { |
| 14 | const int kMinWidth = 100; |
| 15 | const int kMinHeight = 100; |
| 16 | const int kDefaultWidth = 200; |
| 17 | const int kDefaultHeight = 300; |
| 18 | } |
| 19 | |
| 20 | namespace ash { |
| 21 | |
| 22 | // static |
| 23 | views::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 | |
| 29 | PanelWindow::PanelWindow(const std::string& name) |
| 30 | : name_(name), |
| 31 | params_(views::Widget::InitParams::TYPE_PANEL) { |
| 32 | params_.delegate = this; |
| 33 | } |
| 34 | |
| 35 | PanelWindow::~PanelWindow() { |
| 36 | } |
| 37 | |
| 38 | views::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 | |
| 53 | gfx::Size PanelWindow::GetPreferredSize() { |
| 54 | return gfx::Size(kMinWidth, kMinHeight); |
| 55 | } |
| 56 | |
| 57 | void PanelWindow::OnPaint(gfx::Canvas* canvas) { |
| 58 | canvas->FillRect(GetLocalBounds(), SK_ColorGREEN); |
| 59 | } |
| 60 | |
| 61 | string16 PanelWindow::GetWindowTitle() const { |
| 62 | return ASCIIToUTF16(name_); |
| 63 | } |
| 64 | |
| 65 | views::View* PanelWindow::GetContentsView() { |
| 66 | return this; |
| 67 | } |
| 68 | |
| 69 | bool PanelWindow::CanResize() const { |
| 70 | return true; |
| 71 | } |
| 72 | |
| 73 | bool PanelWindow::CanMaximize() const { |
| 74 | return false; |
| 75 | } |
| 76 | |
[email protected] | eb642f3 | 2012-03-17 06:56:16 | [diff] [blame^] | 77 | views::NonClientFrameView* PanelWindow::CreateNonClientFrameView( |
| 78 | views::Widget* widget) { |
| 79 | return new PanelFrameView(widget); |
[email protected] | 6b85493 | 2012-02-04 16:44:27 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | } // namespace ash |