Add abhijeet.k@samsung.com to AUTHORS list.
[chromium-blink-merge.git] / ash / shell / toplevel_window.cc
blob27c96d688ac3a18bc4271995b2ce5e407a95e61c
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/display/display_controller.h"
8 #include "ash/shell.h"
9 #include "ash/wm/window_positioner.h"
10 #include "ash/wm/window_state.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "ui/aura/window.h"
13 #include "ui/aura/window_event_dispatcher.h"
14 #include "ui/gfx/canvas.h"
15 #include "ui/views/widget/widget.h"
17 namespace ash {
18 namespace shell {
19 namespace {
21 struct SavedState {
22 gfx::Rect bounds;
23 ui::WindowShowState show_state;
26 // The last window state in ash_shell. We don't bother deleting
27 // this on shutdown.
28 SavedState* saved_state = NULL;
30 } // namespace
32 ToplevelWindow::CreateParams::CreateParams()
33 : can_resize(false),
34 can_maximize(false) {
37 // static
38 views::Widget* ToplevelWindow::CreateToplevelWindow(
39 const CreateParams& params) {
40 views::Widget* widget = views::Widget::CreateWindowWithContext(
41 new ToplevelWindow(params), Shell::GetPrimaryRootWindow());
42 widget->GetNativeView()->SetName("Examples:ToplevelWindow");
43 wm::WindowState* window_state = wm::GetWindowState(widget->GetNativeView());
44 window_state->set_window_position_managed(true);
45 widget->Show();
46 return widget;
49 // static
50 void ToplevelWindow::ClearSavedStateForTest() {
51 delete saved_state;
52 saved_state = NULL;
55 ToplevelWindow::ToplevelWindow(const CreateParams& params) : params_(params) {
58 ToplevelWindow::~ToplevelWindow() {
61 void ToplevelWindow::OnPaint(gfx::Canvas* canvas) {
62 canvas->FillRect(GetLocalBounds(), SK_ColorDKGRAY);
65 base::string16 ToplevelWindow::GetWindowTitle() const {
66 return base::ASCIIToUTF16("Examples: Toplevel Window");
69 void ToplevelWindow::SaveWindowPlacement(const gfx::Rect& bounds,
70 ui::WindowShowState show_state) {
71 if (!saved_state)
72 saved_state = new SavedState;
73 saved_state->bounds = bounds;
74 saved_state->show_state = show_state;
77 bool ToplevelWindow::GetSavedWindowPlacement(
78 const views::Widget* widget,
79 gfx::Rect* bounds,
80 ui::WindowShowState* show_state) const {
81 bool is_saved_bounds = !!saved_state;
82 if (saved_state) {
83 *bounds = saved_state->bounds;
84 *show_state = saved_state->show_state;
85 } else {
86 // Initial default bounds.
87 bounds->SetRect(10, 150, 300, 300);
89 ash::WindowPositioner::GetBoundsAndShowStateForNewWindow(
90 ash::Shell::GetScreen(),
91 NULL,
92 is_saved_bounds,
93 *show_state,
94 bounds,
95 show_state);
96 return true;
99 views::View* ToplevelWindow::GetContentsView() {
100 return this;
103 bool ToplevelWindow::CanResize() const {
104 return params_.can_resize;
107 bool ToplevelWindow::CanMaximize() const {
108 return params_.can_maximize;
111 bool ToplevelWindow::CanMinimize() const {
112 return params_.can_maximize;
115 } // namespace shell
116 } // namespace ash