Removal of UpdateMultivaluedField() as we now don't have multiple values for name...
[chromium-blink-merge.git] / ash / shell / lock_view.cc
blobba5200fd48dd232ea1e3a4161d7f22824e24bda0
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/session_state_delegate.h"
6 #include "ash/shell.h"
7 #include "ash/shell/example_factory.h"
8 #include "ash/shell_window_ids.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "ui/aura/window.h"
11 #include "ui/aura/window_event_dispatcher.h"
12 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/font_list.h"
14 #include "ui/gfx/geometry/rect.h"
15 #include "ui/gfx/text_utils.h"
16 #include "ui/views/controls/button/label_button.h"
17 #include "ui/views/corewm/tooltip_controller.h"
18 #include "ui/views/widget/widget.h"
19 #include "ui/views/widget/widget_delegate.h"
21 using ash::Shell;
23 namespace ash {
24 namespace shell {
26 class LockView : public views::WidgetDelegateView,
27 public views::ButtonListener {
28 public:
29 LockView() : unlock_button_(new views::LabelButton(
30 this, base::ASCIIToUTF16("Unlock"))) {
31 unlock_button_->SetStyle(views::Button::STYLE_BUTTON);
32 AddChildView(unlock_button_);
33 unlock_button_->SetFocusable(true);
35 ~LockView() override {}
37 // Overridden from views::View:
38 gfx::Size GetPreferredSize() const override { return gfx::Size(500, 400); }
40 private:
41 // Overridden from views::View:
42 void OnPaint(gfx::Canvas* canvas) override {
43 canvas->FillRect(GetLocalBounds(), SK_ColorYELLOW);
44 base::string16 text = base::ASCIIToUTF16("LOCKED!");
45 int string_width = gfx::GetStringWidth(text, font_list_);
46 canvas->DrawStringRect(text, font_list_, SK_ColorRED,
47 gfx::Rect((width() - string_width)/ 2,
48 (height() - font_list_.GetHeight()) / 2,
49 string_width, font_list_.GetHeight()));
51 void Layout() override {
52 gfx::Rect bounds = GetLocalBounds();
53 gfx::Size ps = unlock_button_->GetPreferredSize();
54 bounds.set_y(bounds.bottom() - ps.height() - 5);
55 bounds.set_x((bounds.width() - ps.width()) / 2);
56 bounds.set_size(ps);
57 unlock_button_->SetBoundsRect(bounds);
59 void ViewHierarchyChanged(
60 const ViewHierarchyChangedDetails& details) override {
61 if (details.is_add && details.child == this)
62 unlock_button_->RequestFocus();
65 // Overridden from views::WidgetDelegateView:
66 void WindowClosing() override {
67 Shell::GetInstance()->session_state_delegate()->UnlockScreen();
70 // Overridden from views::ButtonListener:
71 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
72 DCHECK(sender == unlock_button_);
73 GetWidget()->Close();
76 gfx::FontList font_list_;
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(Shell::GetPrimaryRootWindow(),
95 kShellWindowId_LockScreenContainer);
96 widget->Init(params);
97 widget->SetContentsView(lock_view);
98 widget->Show();
99 widget->GetNativeView()->SetName("LockView");
100 widget->GetNativeView()->Focus();
102 // TODO: it shouldn't be necessary to invoke UpdateTooltip() here.
103 Shell::GetInstance()->tooltip_controller()->UpdateTooltip(
104 widget->GetNativeView());
107 } // namespace shell
108 } // namespace ash