toplevel_window.cc revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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/display/display_manager.h"
9#include "ash/shell.h"
10#include "ash/wm/property_util.h"
11#include "base/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      persist_across_all_workspaces(false) {
24}
25
26// static
27void ToplevelWindow::CreateToplevelWindow(const CreateParams& params) {
28  static int count = 0;
29  int x = count == 0 ? 150 : 750;
30  count = (count + 1) % 2;
31
32  gfx::Rect bounds(x, 150, 300, 300);
33  gfx::Display display =
34      ash::Shell::GetInstance()->display_manager()->GetDisplayMatching(bounds);
35  aura::RootWindow* root = ash::Shell::GetInstance()->display_controller()->
36      GetRootWindowForDisplayId(display.id());
37  views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
38      new ToplevelWindow(params), root, bounds);
39  widget->GetNativeView()->SetName("Examples:ToplevelWindow");
40  if (params.persist_across_all_workspaces) {
41    SetPersistsAcrossAllWorkspaces(
42        widget->GetNativeView(),
43        WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES);
44  }
45  widget->Show();
46}
47
48ToplevelWindow::ToplevelWindow(const CreateParams& params) : params_(params) {
49}
50
51ToplevelWindow::~ToplevelWindow() {
52}
53
54void ToplevelWindow::OnPaint(gfx::Canvas* canvas) {
55  canvas->FillRect(GetLocalBounds(), SK_ColorDKGRAY);
56}
57
58base::string16 ToplevelWindow::GetWindowTitle() const {
59  return params_.persist_across_all_workspaces ?
60      ASCIIToUTF16("Examples: Toplevel Window (P)") :
61      ASCIIToUTF16("Examples: Toplevel Window");
62}
63
64views::View* ToplevelWindow::GetContentsView() {
65  return this;
66}
67
68bool ToplevelWindow::CanResize() const {
69  return params_.can_resize;
70}
71
72bool ToplevelWindow::CanMaximize() const {
73  return params_.can_maximize;
74}
75
76}  // namespace shell
77}  // namespace ash
78