15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell/panel_window.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/screen_util.h"
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/shell.h"
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/wm/panels/panel_frame_view.h"
10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/window.h"
12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window_event_dispatcher.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/canvas.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int kMinWidth = 100;
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int kMinHeight = 100;
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int kDefaultWidth = 200;
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int kDefaultHeight = 300;
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash {
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)views::Widget* PanelWindow::CreatePanelWindow(const gfx::Rect& rect) {
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PanelWindow* panel_window = new PanelWindow("Example Panel Window");
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  panel_window->params().bounds = rect;
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  panel_window->params().context = Shell::GetPrimaryRootWindow();
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return panel_window->CreateWidget();
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)PanelWindow::PanelWindow(const std::string& name)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : name_(name),
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      params_(views::Widget::InitParams::TYPE_PANEL) {
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  params_.delegate = this;
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)PanelWindow::~PanelWindow() {
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)views::Widget* PanelWindow::CreateWidget() {
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  views::Widget* widget = new views::Widget;
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (params().bounds.width() == 0)
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    params().bounds.set_width(kDefaultWidth);
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (params().bounds.height() == 0)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    params().bounds.set_height(kDefaultHeight);
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  params().bounds = ScreenUtil::ConvertRectToScreen(
50d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      Shell::GetTargetRootWindow(),
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      params().bounds);
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  widget->Init(params());
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  widget->GetNativeView()->SetName(name_);
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  widget->Show();
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return widget;
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
60cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)gfx::Size PanelWindow::GetPreferredSize() const {
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return gfx::Size(kMinWidth, kMinHeight);
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void PanelWindow::OnPaint(gfx::Canvas* canvas) {
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  canvas->FillRect(GetLocalBounds(), SK_ColorGREEN);
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
68c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)base::string16 PanelWindow::GetWindowTitle() const {
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return base::ASCIIToUTF16(name_);
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)views::View* PanelWindow::GetContentsView() {
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return this;
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool PanelWindow::CanResize() const {
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool PanelWindow::CanMaximize() const {
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return false;
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccibool PanelWindow::CanMinimize() const {
851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return false;
861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)views::NonClientFrameView* PanelWindow::CreateNonClientFrameView(
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    views::Widget* widget) {
902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return new PanelFrameView(widget, PanelFrameView::FRAME_NONE);
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ash
94