summaryrefslogtreecommitdiffstats
path: root/ash/shell/toplevel_window.cc
blob: af18151ace6cd57abb0c47fa723ca50f898423e9 (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
// 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/toplevel_window.h"

#include "ash/display/display_controller.h"
#include "ash/display/display_manager.h"
#include "ash/shell.h"
#include "ash/wm/property_util.h"
#include "base/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 ash {
namespace shell {

ToplevelWindow::CreateParams::CreateParams()
    : can_resize(false),
      can_maximize(false),
      persist_across_all_workspaces(false) {
}

// static
void ToplevelWindow::CreateToplevelWindow(const CreateParams& params) {
  static int count = 0;
  int x = count == 0 ? 150 : 750;
  count = (count + 1) % 2;

  gfx::Rect bounds(x, 150, 300, 300);
  gfx::Display display =
      ash::Shell::GetInstance()->display_manager()->GetDisplayMatching(bounds);
  aura::RootWindow* root = ash::Shell::GetInstance()->display_controller()->
      GetRootWindowForDisplayId(display.id());
  views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
      new ToplevelWindow(params), root, bounds);
  widget->GetNativeView()->SetName("Examples:ToplevelWindow");
  if (params.persist_across_all_workspaces) {
    SetPersistsAcrossAllWorkspaces(
        widget->GetNativeView(),
        WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES);
  }
  widget->Show();
}

ToplevelWindow::ToplevelWindow(const CreateParams& params) : params_(params) {
}

ToplevelWindow::~ToplevelWindow() {
}

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

base::string16 ToplevelWindow::GetWindowTitle() const {
  return params_.persist_across_all_workspaces ?
      ASCIIToUTF16("Examples: Toplevel Window (P)") :
      ASCIIToUTF16("Examples: Toplevel Window");
}

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

bool ToplevelWindow::CanResize() const {
  return params_.can_resize;
}

bool ToplevelWindow::CanMaximize() const {
  return params_.can_maximize;
}

}  // namespace shell
}  // namespace ash