Remove LOG(ERROR)
[chromium-blink-merge.git] / ash / shell / lock_view.cc
bloba9ccd7b8850e472c3ab415ce4350ad186cb40174
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/session_state_delegate.h"
6 #include "ash/shell.h"
7 #include "ash/shell_window_ids.h"
8 #include "ash/shell/example_factory.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "ui/aura/root_window.h"
11 #include "ui/aura/window.h"
12 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/font.h"
14 #include "ui/views/controls/button/label_button.h"
15 #include "ui/views/corewm/tooltip_controller.h"
16 #include "ui/views/widget/widget.h"
17 #include "ui/views/widget/widget_delegate.h"
19 using ash::Shell;
21 namespace ash {
22 namespace shell {
24 class LockView : public views::WidgetDelegateView,
25 public views::ButtonListener {
26 public:
27 LockView() : unlock_button_(new views::LabelButton(
28 this, base::ASCIIToUTF16("Unlock"))) {
29 unlock_button_->SetStyle(views::Button::STYLE_BUTTON);
30 AddChildView(unlock_button_);
31 unlock_button_->SetFocusable(true);
33 virtual ~LockView() {}
35 // Overridden from views::View:
36 virtual gfx::Size GetPreferredSize() OVERRIDE {
37 return gfx::Size(500, 400);
40 private:
41 // Overridden from views::View:
42 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
43 canvas->FillRect(GetLocalBounds(), SK_ColorYELLOW);
44 base::string16 text = base::ASCIIToUTF16("LOCKED!");
45 int string_width = font_.GetStringWidth(text);
46 canvas->DrawStringInt(text, font_, SK_ColorRED, (width() - string_width)/ 2,
47 (height() - font_.GetHeight()) / 2,
48 string_width, font_.GetHeight());
50 virtual void Layout() OVERRIDE {
51 gfx::Rect bounds = GetLocalBounds();
52 gfx::Size ps = unlock_button_->GetPreferredSize();
53 bounds.set_y(bounds.bottom() - ps.height() - 5);
54 bounds.set_x((bounds.width() - ps.width()) / 2);
55 bounds.set_size(ps);
56 unlock_button_->SetBoundsRect(bounds);
58 virtual void ViewHierarchyChanged(
59 const ViewHierarchyChangedDetails& details) OVERRIDE {
60 if (details.is_add && details.child == this)
61 unlock_button_->RequestFocus();
64 // Overridden from views::WidgetDelegateView:
65 virtual void WindowClosing() OVERRIDE {
66 Shell::GetInstance()->session_state_delegate()->UnlockScreen();
69 // Overridden from views::ButtonListener:
70 virtual void ButtonPressed(views::Button* sender,
71 const ui::Event& event) OVERRIDE {
72 DCHECK(sender == unlock_button_);
73 GetWidget()->Close();
76 gfx::Font font_;
77 views::LabelButton* unlock_button_;
79 DISALLOW_COPY_AND_ASSIGN(LockView);
82 void CreateLockScreen() {
83 LockView* lock_view = new LockView;
84 views::Widget* widget = new views::Widget;
85 views::Widget::InitParams params(
86 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
87 gfx::Size ps = lock_view->GetPreferredSize();
89 gfx::Size root_window_size = Shell::GetPrimaryRootWindow()->bounds().size();
90 params.bounds = gfx::Rect((root_window_size.width() - ps.width()) / 2,
91 (root_window_size.height() - ps.height()) / 2,
92 ps.width(), ps.height());
93 params.delegate = lock_view;
94 params.parent = Shell::GetContainer(
95 Shell::GetPrimaryRootWindow(),
96 internal::kShellWindowId_LockScreenContainer);
97 widget->Init(params);
98 widget->SetContentsView(lock_view);
99 widget->Show();
100 widget->GetNativeView()->SetName("LockView");
101 widget->GetNativeView()->Focus();
103 // TODO: it shouldn't be necessary to invoke UpdateTooltip() here.
104 Shell::GetInstance()->tooltip_controller()->UpdateTooltip(
105 widget->GetNativeView());
108 } // namespace shell
109 } // namespace ash