blob: 168649f032fbe31eec1674af5ac0fc88bfa837c8 [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"
[email protected]55ad8c12014-01-17 18:24:338#include "ash/screen_util.h"
[email protected]79a87b7e2013-01-25 05:08:229#include "ash/shell.h"
[email protected]a4ea1f12013-06-07 18:37:0710#include "base/strings/utf_string_conversions.h"
[email protected]6b854932012-02-04 16:44:2711#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2612#include "ui/aura/window_event_dispatcher.h"
[email protected]6b854932012-02-04 16:44:2713#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_);
52 widget->Show();
53
54 return widget;
55}
56
[email protected]e1b62b72014-05-20 17:24:4457gfx::Size PanelWindow::GetPreferredSize() const {
[email protected]6b854932012-02-04 16:44:2758 return gfx::Size(kMinWidth, kMinHeight);
59}
60
61void PanelWindow::OnPaint(gfx::Canvas* canvas) {
62 canvas->FillRect(GetLocalBounds(), SK_ColorGREEN);
63}
64
[email protected]ed95e022013-04-11 04:03:3265base::string16 PanelWindow::GetWindowTitle() const {
[email protected]b57c9d52013-12-24 16:23:2566 return base::ASCIIToUTF16(name_);
[email protected]6b854932012-02-04 16:44:2767}
68
[email protected]6b854932012-02-04 16:44:2769bool PanelWindow::CanResize() const {
70 return true;
71}
72
73bool PanelWindow::CanMaximize() const {
74 return false;
75}
76
jackhou3fdb7322014-09-24 10:25:4877bool PanelWindow::CanMinimize() const {
78 return false;
79}
80
[email protected]eb642f32012-03-17 06:56:1681views::NonClientFrameView* PanelWindow::CreateNonClientFrameView(
82 views::Widget* widget) {
[email protected]dcf1a102012-11-30 21:37:1483 return new PanelFrameView(widget, PanelFrameView::FRAME_NONE);
[email protected]6b854932012-02-04 16:44:2784}
85
86} // namespace ash