1 // Copyright (c) 2011 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.
6 #include "ash/shell_window_ids.h"
7 #include "ash/shell/example_factory.h"
8 #include "base/utf_string_conversions.h"
9 #include "ui/aura/root_window.h"
10 #include "ui/aura/window.h"
11 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/font.h"
13 #include "ui/views/widget/widget.h"
14 #include "ui/views/widget/widget_delegate.h"
21 class LockView
: public views::WidgetDelegateView
{
24 virtual ~LockView() {}
26 // Overridden from View:
27 virtual gfx::Size
GetPreferredSize() OVERRIDE
{
28 return gfx::Size(500, 400);
32 // Overridden from View:
33 virtual void OnPaint(gfx::Canvas
* canvas
) OVERRIDE
{
34 canvas
->FillRect(SK_ColorYELLOW
, GetLocalBounds());
35 string16 text
= ASCIIToUTF16("LOCKED!");
36 int string_width
= font_
.GetStringWidth(text
);
37 canvas
->DrawStringInt(text
, font_
, SK_ColorRED
, (width() - string_width
)/ 2,
38 (height() - font_
.GetHeight()) / 2,
39 string_width
, font_
.GetHeight());
41 virtual bool OnMousePressed(const views::MouseEvent
& event
) OVERRIDE
{
44 virtual void OnMouseReleased(const views::MouseEvent
& event
) OVERRIDE
{
50 DISALLOW_COPY_AND_ASSIGN(LockView
);
53 void CreateLockScreen() {
54 LockView
* lock_view
= new LockView
;
55 views::Widget
* widget
= new views::Widget
;
56 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_CONTROL
);
57 gfx::Size ps
= lock_view
->GetPreferredSize();
59 gfx::Size root_window_size
= aura::RootWindow::GetInstance()->GetHostSize();
60 params
.bounds
= gfx::Rect((root_window_size
.width() - ps
.width()) / 2,
61 (root_window_size
.height() - ps
.height()) / 2,
62 ps
.width(), ps
.height());
63 params
.delegate
= lock_view
;
65 Shell::GetInstance()->GetContainer(
66 ash::internal::kShellWindowId_LockScreenContainer
)->
67 AddChild(widget
->GetNativeView());
68 widget
->SetContentsView(lock_view
);
70 widget
->GetNativeView()->SetName("LockView");