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"
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"
22 ui::WindowShowState show_state
;
25 // The last window state in ash_shell. We don't bother deleting
27 SavedState
* saved_state
= NULL
;
31 ToplevelWindow::CreateParams::CreateParams()
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);
49 void ToplevelWindow::ClearSavedStateForTest() {
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
) {
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
,
79 ui::WindowShowState
* show_state
) const {
80 bool is_saved_bounds
= !!saved_state
;
82 *bounds
= saved_state
->bounds
;
83 *show_state
= saved_state
->show_state
;
85 // Initial default bounds.
86 bounds
->SetRect(10, 150, 300, 300);
88 ash::WindowPositioner::GetBoundsAndShowStateForNewWindow(
89 ash::Shell::GetScreen(),
98 views::View
* ToplevelWindow::GetContentsView() {
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
;