summaryrefslogtreecommitdiffstats
path: root/chromium/ash/shell/panel_window.cc
blob: 9593a4066f5b01f9c507b62f1266e7f0bb489358 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/shell/panel_window.h"

#include "ash/screen_ash.h"
#include "ash/shell.h"
#include "ash/wm/panels/panel_frame_view.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/gfx/canvas.h"
#include "ui/views/widget/widget.h"

namespace {
const int kMinWidth = 100;
const int kMinHeight = 100;
const int kDefaultWidth = 200;
const int kDefaultHeight = 300;
}

namespace ash {

// static
views::Widget* PanelWindow::CreatePanelWindow(const gfx::Rect& rect) {
  PanelWindow* panel_window = new PanelWindow("Example Panel Window");
  panel_window->params().bounds = rect;
  panel_window->params().context = Shell::GetPrimaryRootWindow();
  return panel_window->CreateWidget();
}

PanelWindow::PanelWindow(const std::string& name)
    : name_(name),
      params_(views::Widget::InitParams::TYPE_PANEL) {
  params_.delegate = this;
}

PanelWindow::~PanelWindow() {
}

views::Widget* PanelWindow::CreateWidget() {
  views::Widget* widget = new views::Widget;

  if (params().bounds.width() == 0)
    params().bounds.set_width(kDefaultWidth);
  if (params().bounds.height() == 0)
    params().bounds.set_height(kDefaultHeight);
  params().bounds = ScreenAsh::ConvertRectToScreen(
      Shell::GetTargetRootWindow(),
      params().bounds);

  widget->Init(params());
  widget->GetNativeView()->SetName(name_);
  widget->Show();

  return widget;
}

gfx::Size PanelWindow::GetPreferredSize() {
  return gfx::Size(kMinWidth, kMinHeight);
}

void PanelWindow::OnPaint(gfx::Canvas* canvas) {
  canvas->FillRect(GetLocalBounds(), SK_ColorGREEN);
}

base::string16 PanelWindow::GetWindowTitle() const {
  return ASCIIToUTF16(name_);
}

views::View* PanelWindow::GetContentsView() {
  return this;
}

bool PanelWindow::CanResize() const {
  return true;
}

bool PanelWindow::CanMaximize() const {
  return false;
}

views::NonClientFrameView* PanelWindow::CreateNonClientFrameView(
    views::Widget* widget) {
  return new PanelFrameView(widget, PanelFrameView::FRAME_NONE);
}

}  // namespace ash