[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 | |||||
sky | e80dede2 | 2016-10-11 01:13:03 | [diff] [blame] | 7 | #include "ash/common/wm/panels/panel_frame_view.h" |
msw | 8329bfa3 | 2017-02-02 19:34:53 | [diff] [blame] | 8 | #include "ash/public/cpp/window_properties.h" |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 9 | #include "ash/screen_util.h" |
[email protected] | 79a87b7e | 2013-01-25 05:08:22 | [diff] [blame] | 10 | #include "ash/shell.h" |
[email protected] | a4ea1f1 | 2013-06-07 18:37:07 | [diff] [blame] | 11 | #include "base/strings/utf_string_conversions.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) | ||||
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 34 | : name_(name), params_(views::Widget::InitParams::TYPE_PANEL) { |
[email protected] | 6b85493 | 2012-02-04 16:44:27 | [diff] [blame] | 35 | params_.delegate = this; |
36 | } | ||||
37 | |||||
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 38 | PanelWindow::~PanelWindow() {} |
[email protected] | 6b85493 | 2012-02-04 16:44:27 | [diff] [blame] | 39 | |
40 | views::Widget* PanelWindow::CreateWidget() { | ||||
41 | views::Widget* widget = new views::Widget; | ||||
42 | |||||
43 | if (params().bounds.width() == 0) | ||||
44 | params().bounds.set_width(kDefaultWidth); | ||||
45 | if (params().bounds.height() == 0) | ||||
46 | params().bounds.set_height(kDefaultHeight); | ||||
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 47 | params().bounds = ScreenUtil::ConvertRectToScreen( |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 48 | Shell::GetTargetRootWindow(), params().bounds); |
[email protected] | 6b85493 | 2012-02-04 16:44:27 | [diff] [blame] | 49 | |
50 | widget->Init(params()); | ||||
51 | widget->GetNativeView()->SetName(name_); | ||||
msw | db454f3 | 2016-11-11 00:36:46 | [diff] [blame] | 52 | widget->GetNativeWindow()->SetProperty<int>(kShelfItemTypeKey, |
53 | TYPE_APP_PANEL); | ||||
[email protected] | 6b85493 | 2012-02-04 16:44:27 | [diff] [blame] | 54 | widget->Show(); |
55 | |||||
56 | return widget; | ||||
57 | } | ||||
58 | |||||
[email protected] | e1b62b7 | 2014-05-20 17:24:44 | [diff] [blame] | 59 | gfx::Size PanelWindow::GetPreferredSize() const { |
[email protected] | 6b85493 | 2012-02-04 16:44:27 | [diff] [blame] | 60 | return gfx::Size(kMinWidth, kMinHeight); |
61 | } | ||||
62 | |||||
63 | void PanelWindow::OnPaint(gfx::Canvas* canvas) { | ||||
64 | canvas->FillRect(GetLocalBounds(), SK_ColorGREEN); | ||||
65 | } | ||||
66 | |||||
[email protected] | ed95e02 | 2013-04-11 04:03:32 | [diff] [blame] | 67 | base::string16 PanelWindow::GetWindowTitle() const { |
[email protected] | b57c9d5 | 2013-12-24 16:23:25 | [diff] [blame] | 68 | return base::ASCIIToUTF16(name_); |
[email protected] | 6b85493 | 2012-02-04 16:44:27 | [diff] [blame] | 69 | } |
70 | |||||
[email protected] | 6b85493 | 2012-02-04 16:44:27 | [diff] [blame] | 71 | bool PanelWindow::CanResize() const { |
72 | return true; | ||||
73 | } | ||||
74 | |||||
75 | bool PanelWindow::CanMaximize() const { | ||||
76 | return false; | ||||
77 | } | ||||
78 | |||||
jackhou | 3fdb732 | 2014-09-24 10:25:48 | [diff] [blame] | 79 | bool PanelWindow::CanMinimize() const { |
80 | return false; | ||||
81 | } | ||||
82 | |||||
[email protected] | eb642f3 | 2012-03-17 06:56:16 | [diff] [blame] | 83 | views::NonClientFrameView* PanelWindow::CreateNonClientFrameView( |
84 | views::Widget* widget) { | ||||
[email protected] | dcf1a10 | 2012-11-30 21:37:14 | [diff] [blame] | 85 | return new PanelFrameView(widget, PanelFrameView::FRAME_NONE); |
[email protected] | 6b85493 | 2012-02-04 16:44:27 | [diff] [blame] | 86 | } |
87 | |||||
88 | } // namespace ash |