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"
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"
23 ui::WindowShowState show_state
;
26 // The last window state in ash_shell. We don't bother deleting
28 SavedState
* saved_state
= NULL
;
32 ToplevelWindow::CreateParams::CreateParams()
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);
50 void ToplevelWindow::ClearSavedStateForTest() {
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
) {
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
,
80 ui::WindowShowState
* show_state
) const {
81 bool is_saved_bounds
= !!saved_state
;
83 *bounds
= saved_state
->bounds
;
84 *show_state
= saved_state
->show_state
;
86 // Initial default bounds.
87 bounds
->SetRect(10, 150, 300, 300);
89 ash::WindowPositioner::GetBoundsAndShowStateForNewWindow(
90 ash::Shell::GetScreen(),
99 views::View
* ToplevelWindow::GetContentsView() {
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
;