Home | History | Annotate | Download | only in shell
      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.
      4 
      5 #include "ash/shell/toplevel_window.h"
      6 
      7 #include "ash/display/display_controller.h"
      8 #include "ash/screen_ash.h"
      9 #include "ash/shell.h"
     10 #include "ash/wm/property_util.h"
     11 #include "base/strings/utf_string_conversions.h"
     12 #include "ui/aura/root_window.h"
     13 #include "ui/aura/window.h"
     14 #include "ui/gfx/canvas.h"
     15 #include "ui/views/widget/widget.h"
     16 
     17 namespace ash {
     18 namespace shell {
     19 
     20 ToplevelWindow::CreateParams::CreateParams()
     21     : can_resize(false),
     22       can_maximize(false) {
     23 }
     24 
     25 // static
     26 void ToplevelWindow::CreateToplevelWindow(const CreateParams& params) {
     27   static int count = 0;
     28   int x = count == 0 ? 150 : 750;
     29   count = (count + 1) % 2;
     30 
     31   gfx::Rect bounds(x, 150, 300, 300);
     32   gfx::Display display =
     33       ash::Shell::GetScreen()->GetDisplayMatching(bounds);
     34   aura::RootWindow* root = ash::Shell::GetInstance()->display_controller()->
     35       GetRootWindowForDisplayId(display.id());
     36   views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
     37       new ToplevelWindow(params), root, bounds);
     38   widget->GetNativeView()->SetName("Examples:ToplevelWindow");
     39   widget->Show();
     40 }
     41 
     42 ToplevelWindow::ToplevelWindow(const CreateParams& params) : params_(params) {
     43 }
     44 
     45 ToplevelWindow::~ToplevelWindow() {
     46 }
     47 
     48 void ToplevelWindow::OnPaint(gfx::Canvas* canvas) {
     49   canvas->FillRect(GetLocalBounds(), SK_ColorDKGRAY);
     50 }
     51 
     52 base::string16 ToplevelWindow::GetWindowTitle() const {
     53   return ASCIIToUTF16("Examples: Toplevel Window");
     54 }
     55 
     56 views::View* ToplevelWindow::GetContentsView() {
     57   return this;
     58 }
     59 
     60 bool ToplevelWindow::CanResize() const {
     61   return params_.can_resize;
     62 }
     63 
     64 bool ToplevelWindow::CanMaximize() const {
     65   return params_.can_maximize;
     66 }
     67 
     68 }  // namespace shell
     69 }  // namespace ash
     70