Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / ash / shell / toplevel_window.cc
blobab9cdc4e90a3ce5699a145fe6db9f3a4305a5596
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.
5 #include "ash/shell/toplevel_window.h"
7 #include "ash/shell.h"
8 #include "ash/wm/window_positioner.h"
9 #include "ash/wm/window_state.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "ui/aura/window.h"
12 #include "ui/aura/window_event_dispatcher.h"
13 #include "ui/gfx/canvas.h"
14 #include "ui/views/widget/widget.h"
16 namespace ash {
17 namespace shell {
18 namespace {
20 struct SavedState {
21 gfx::Rect bounds;
22 ui::WindowShowState show_state;
25 // The last window state in ash_shell. We don't bother deleting
26 // this on shutdown.
27 SavedState* saved_state = NULL;
29 } // namespace
31 ToplevelWindow::CreateParams::CreateParams()
32 : can_resize(false),
33 can_maximize(false) {
36 // static
37 views::Widget* ToplevelWindow::CreateToplevelWindow(
38 const CreateParams& params) {
39 views::Widget* widget = views::Widget::CreateWindowWithContext(
40 new ToplevelWindow(params), Shell::GetPrimaryRootWindow());
41 widget->GetNativeView()->SetName("Examples:ToplevelWindow");
42 wm::WindowState* window_state = wm::GetWindowState(widget->GetNativeView());
43 window_state->set_window_position_managed(true);
44 widget->Show();
45 return widget;
48 // static
49 void ToplevelWindow::ClearSavedStateForTest() {
50 delete saved_state;
51 saved_state = NULL;
54 ToplevelWindow::ToplevelWindow(const CreateParams& params) : params_(params) {
57 ToplevelWindow::~ToplevelWindow() {
60 void ToplevelWindow::OnPaint(gfx::Canvas* canvas) {
61 canvas->FillRect(GetLocalBounds(), SK_ColorDKGRAY);
64 base::string16 ToplevelWindow::GetWindowTitle() const {
65 return base::ASCIIToUTF16("Examples: Toplevel Window");
68 void ToplevelWindow::SaveWindowPlacement(const gfx::Rect& bounds,
69 ui::WindowShowState show_state) {
70 if (!saved_state)
71 saved_state = new SavedState;
72 saved_state->bounds = bounds;
73 saved_state->show_state = show_state;
76 bool ToplevelWindow::GetSavedWindowPlacement(
77 const views::Widget* widget,
78 gfx::Rect* bounds,
79 ui::WindowShowState* show_state) const {
80 bool is_saved_bounds = !!saved_state;
81 if (saved_state) {
82 *bounds = saved_state->bounds;
83 *show_state = saved_state->show_state;
84 } else {
85 // Initial default bounds.
86 bounds->SetRect(10, 150, 300, 300);
88 ash::WindowPositioner::GetBoundsAndShowStateForNewWindow(
89 ash::Shell::GetScreen(),
90 NULL,
91 is_saved_bounds,
92 *show_state,
93 bounds,
94 show_state);
95 return true;
98 views::View* ToplevelWindow::GetContentsView() {
99 return this;
102 bool ToplevelWindow::CanResize() const {
103 return params_.can_resize;
106 bool ToplevelWindow::CanMaximize() const {
107 return params_.can_maximize;
110 bool ToplevelWindow::CanMinimize() const {
111 return params_.can_maximize;
114 } // namespace shell
115 } // namespace ash