[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] | 95db9c1 | 2013-01-31 11:47:44 | [diff] [blame] | 7 | #include "ash/screen_ash.h" |
[email protected] | 79a87b7e | 2013-01-25 05:08:22 | [diff] [blame] | 8 | #include "ash/shell.h" |
[email protected] | 7095a65 | 2013-03-07 19:41:49 | [diff] [blame] | 9 | #include "ash/wm/panels/panel_frame_view.h" |
[email protected] | 6b85493 | 2012-02-04 16:44:27 | [diff] [blame] | 10 | #include "base/utf_string_conversions.h" |
[email protected] | 79a87b7e | 2013-01-25 05:08:22 | [diff] [blame] | 11 | #include "ui/aura/root_window.h" |
[email protected] | 6b85493 | 2012-02-04 16:44:27 | [diff] [blame] | 12 | #include "ui/aura/window.h" |
13 | #include "ui/gfx/canvas.h" | ||||
14 | #include "ui/views/widget/widget.h" | ||||
15 | |||||
16 | namespace { | ||||
17 | const int kMinWidth = 100; | ||||
18 | const int kMinHeight = 100; | ||||
19 | const int kDefaultWidth = 200; | ||||
20 | const int kDefaultHeight = 300; | ||||
21 | } | ||||
22 | |||||
23 | namespace ash { | ||||
24 | |||||
25 | // static | ||||
26 | views::Widget* PanelWindow::CreatePanelWindow(const gfx::Rect& rect) { | ||||
27 | PanelWindow* panel_window = new PanelWindow("Example Panel Window"); | ||||
28 | panel_window->params().bounds = rect; | ||||
[email protected] | 79a87b7e | 2013-01-25 05:08:22 | [diff] [blame] | 29 | panel_window->params().context = Shell::GetPrimaryRootWindow(); |
[email protected] | 6b85493 | 2012-02-04 16:44:27 | [diff] [blame] | 30 | return panel_window->CreateWidget(); |
31 | } | ||||
32 | |||||
33 | PanelWindow::PanelWindow(const std::string& name) | ||||
34 | : name_(name), | ||||
35 | params_(views::Widget::InitParams::TYPE_PANEL) { | ||||
36 | params_.delegate = this; | ||||
37 | } | ||||
38 | |||||
39 | PanelWindow::~PanelWindow() { | ||||
40 | } | ||||
41 | |||||
42 | views::Widget* PanelWindow::CreateWidget() { | ||||
43 | views::Widget* widget = new views::Widget; | ||||
44 | |||||
45 | if (params().bounds.width() == 0) | ||||
46 | params().bounds.set_width(kDefaultWidth); | ||||
47 | if (params().bounds.height() == 0) | ||||
48 | params().bounds.set_height(kDefaultHeight); | ||||
[email protected] | 95db9c1 | 2013-01-31 11:47:44 | [diff] [blame] | 49 | params().bounds = ScreenAsh::ConvertRectToScreen( |
50 | Shell::GetActiveRootWindow(), | ||||
51 | params().bounds); | ||||
[email protected] | 6b85493 | 2012-02-04 16:44:27 | [diff] [blame] | 52 | |
53 | widget->Init(params()); | ||||
54 | widget->GetNativeView()->SetName(name_); | ||||
55 | widget->Show(); | ||||
56 | |||||
57 | return widget; | ||||
58 | } | ||||
59 | |||||
60 | gfx::Size PanelWindow::GetPreferredSize() { | ||||
61 | return gfx::Size(kMinWidth, kMinHeight); | ||||
62 | } | ||||
63 | |||||
64 | void PanelWindow::OnPaint(gfx::Canvas* canvas) { | ||||
65 | canvas->FillRect(GetLocalBounds(), SK_ColorGREEN); | ||||
66 | } | ||||
67 | |||||
[email protected] | ed95e02 | 2013-04-11 04:03:32 | [diff] [blame^] | 68 | base::string16 PanelWindow::GetWindowTitle() const { |
[email protected] | 6b85493 | 2012-02-04 16:44:27 | [diff] [blame] | 69 | return ASCIIToUTF16(name_); |
70 | } | ||||
71 | |||||
72 | views::View* PanelWindow::GetContentsView() { | ||||
73 | return this; | ||||
74 | } | ||||
75 | |||||
76 | bool PanelWindow::CanResize() const { | ||||
77 | return true; | ||||
78 | } | ||||
79 | |||||
80 | bool PanelWindow::CanMaximize() const { | ||||
81 | return false; | ||||
82 | } | ||||
83 | |||||
[email protected] | eb642f3 | 2012-03-17 06:56:16 | [diff] [blame] | 84 | views::NonClientFrameView* PanelWindow::CreateNonClientFrameView( |
85 | views::Widget* widget) { | ||||
[email protected] | dcf1a10 | 2012-11-30 21:37:14 | [diff] [blame] | 86 | return new PanelFrameView(widget, PanelFrameView::FRAME_NONE); |
[email protected] | 6b85493 | 2012-02-04 16:44:27 | [diff] [blame] | 87 | } |
88 | |||||
89 | } // namespace ash |