blob: e10c68cd30de1d82228a9968d87e8cae9cccc352 [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
skye80dede22016-10-11 01:13:037#include "ash/common/wm/panels/panel_frame_view.h"
msw8329bfa32017-02-02 19:34:538#include "ash/public/cpp/window_properties.h"
[email protected]55ad8c12014-01-17 18:24:339#include "ash/screen_util.h"
[email protected]79a87b7e2013-01-25 05:08:2210#include "ash/shell.h"
[email protected]a4ea1f12013-06-07 18:37:0711#include "base/strings/utf_string_conversions.h"
[email protected]6b854932012-02-04 16:44:2712#include "ui/aura/window.h"
13#include "ui/gfx/canvas.h"
14#include "ui/views/widget/widget.h"
15
16namespace {
17const int kMinWidth = 100;
18const int kMinHeight = 100;
19const int kDefaultWidth = 200;
20const int kDefaultHeight = 300;
21}
22
23namespace ash {
24
25// static
26views::Widget* PanelWindow::CreatePanelWindow(const gfx::Rect& rect) {
27 PanelWindow* panel_window = new PanelWindow("Example Panel Window");
28 panel_window->params().bounds = rect;
[email protected]79a87b7e2013-01-25 05:08:2229 panel_window->params().context = Shell::GetPrimaryRootWindow();
[email protected]6b854932012-02-04 16:44:2730 return panel_window->CreateWidget();
31}
32
33PanelWindow::PanelWindow(const std::string& name)
jamescookb8dcef522016-06-25 14:42:5534 : name_(name), params_(views::Widget::InitParams::TYPE_PANEL) {
[email protected]6b854932012-02-04 16:44:2735 params_.delegate = this;
36}
37
jamescookb8dcef522016-06-25 14:42:5538PanelWindow::~PanelWindow() {}
[email protected]6b854932012-02-04 16:44:2739
40views::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]55ad8c12014-01-17 18:24:3347 params().bounds = ScreenUtil::ConvertRectToScreen(
jamescookb8dcef522016-06-25 14:42:5548 Shell::GetTargetRootWindow(), params().bounds);
[email protected]6b854932012-02-04 16:44:2749
50 widget->Init(params());
51 widget->GetNativeView()->SetName(name_);
mswdb454f32016-11-11 00:36:4652 widget->GetNativeWindow()->SetProperty<int>(kShelfItemTypeKey,
53 TYPE_APP_PANEL);
[email protected]6b854932012-02-04 16:44:2754 widget->Show();
55
56 return widget;
57}
58
[email protected]e1b62b72014-05-20 17:24:4459gfx::Size PanelWindow::GetPreferredSize() const {
[email protected]6b854932012-02-04 16:44:2760 return gfx::Size(kMinWidth, kMinHeight);
61}
62
63void PanelWindow::OnPaint(gfx::Canvas* canvas) {
64 canvas->FillRect(GetLocalBounds(), SK_ColorGREEN);
65}
66
[email protected]ed95e022013-04-11 04:03:3267base::string16 PanelWindow::GetWindowTitle() const {
[email protected]b57c9d52013-12-24 16:23:2568 return base::ASCIIToUTF16(name_);
[email protected]6b854932012-02-04 16:44:2769}
70
[email protected]6b854932012-02-04 16:44:2771bool PanelWindow::CanResize() const {
72 return true;
73}
74
75bool PanelWindow::CanMaximize() const {
76 return false;
77}
78
jackhou3fdb7322014-09-24 10:25:4879bool PanelWindow::CanMinimize() const {
80 return false;
81}
82
[email protected]eb642f32012-03-17 06:56:1683views::NonClientFrameView* PanelWindow::CreateNonClientFrameView(
84 views::Widget* widget) {
[email protected]dcf1a102012-11-30 21:37:1485 return new PanelFrameView(widget, PanelFrameView::FRAME_NONE);
[email protected]6b854932012-02-04 16:44:2786}
87
88} // namespace ash