toplevel_window.cc revision 68043e1e95eeb07d5cae7aca370b26518b0867d6
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/toplevel_window.h" 6 7#include "ash/display/display_controller.h" 8#include "ash/screen_ash.h" 9#include "ash/shell.h" 10#include "base/strings/utf_string_conversions.h" 11#include "ui/aura/root_window.h" 12#include "ui/aura/window.h" 13#include "ui/gfx/canvas.h" 14#include "ui/views/widget/widget.h" 15 16namespace ash { 17namespace shell { 18 19ToplevelWindow::CreateParams::CreateParams() 20 : can_resize(false), 21 can_maximize(false) { 22} 23 24// static 25void ToplevelWindow::CreateToplevelWindow(const CreateParams& params) { 26 static int count = 0; 27 int x = count == 0 ? 150 : 750; 28 count = (count + 1) % 2; 29 30 gfx::Rect bounds(x, 150, 300, 300); 31 gfx::Display display = 32 ash::Shell::GetScreen()->GetDisplayMatching(bounds); 33 aura::RootWindow* root = ash::Shell::GetInstance()->display_controller()-> 34 GetRootWindowForDisplayId(display.id()); 35 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( 36 new ToplevelWindow(params), root, bounds); 37 widget->GetNativeView()->SetName("Examples:ToplevelWindow"); 38 widget->Show(); 39} 40 41ToplevelWindow::ToplevelWindow(const CreateParams& params) : params_(params) { 42} 43 44ToplevelWindow::~ToplevelWindow() { 45} 46 47void ToplevelWindow::OnPaint(gfx::Canvas* canvas) { 48 canvas->FillRect(GetLocalBounds(), SK_ColorDKGRAY); 49} 50 51base::string16 ToplevelWindow::GetWindowTitle() const { 52 return ASCIIToUTF16("Examples: Toplevel Window"); 53} 54 55views::View* ToplevelWindow::GetContentsView() { 56 return this; 57} 58 59bool ToplevelWindow::CanResize() const { 60 return params_.can_resize; 61} 62 63bool ToplevelWindow::CanMaximize() const { 64 return params_.can_maximize; 65} 66 67} // namespace shell 68} // namespace ash 69