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