OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/session/session_state_delegate.h" | 5 #include "ash/session/session_state_delegate.h" |
6 #include "ash/shell.h" | 6 #include "ash/shell.h" |
7 #include "ash/shell/example_factory.h" | 7 #include "ash/shell/example_factory.h" |
8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 class LockView : public views::WidgetDelegateView, | 26 class LockView : public views::WidgetDelegateView, |
27 public views::ButtonListener { | 27 public views::ButtonListener { |
28 public: | 28 public: |
29 LockView() : unlock_button_(new views::LabelButton( | 29 LockView() : unlock_button_(new views::LabelButton( |
30 this, base::ASCIIToUTF16("Unlock"))) { | 30 this, base::ASCIIToUTF16("Unlock"))) { |
31 unlock_button_->SetStyle(views::Button::STYLE_BUTTON); | 31 unlock_button_->SetStyle(views::Button::STYLE_BUTTON); |
32 AddChildView(unlock_button_); | 32 AddChildView(unlock_button_); |
33 unlock_button_->SetFocusable(true); | 33 unlock_button_->SetFocusable(true); |
34 } | 34 } |
35 virtual ~LockView() {} | 35 ~LockView() override {} |
36 | 36 |
37 // Overridden from views::View: | 37 // Overridden from views::View: |
38 virtual gfx::Size GetPreferredSize() const override { | 38 gfx::Size GetPreferredSize() const override { return gfx::Size(500, 400); } |
39 return gfx::Size(500, 400); | |
40 } | |
41 | 39 |
42 private: | 40 private: |
43 // Overridden from views::View: | 41 // Overridden from views::View: |
44 virtual void OnPaint(gfx::Canvas* canvas) override { | 42 void OnPaint(gfx::Canvas* canvas) override { |
45 canvas->FillRect(GetLocalBounds(), SK_ColorYELLOW); | 43 canvas->FillRect(GetLocalBounds(), SK_ColorYELLOW); |
46 base::string16 text = base::ASCIIToUTF16("LOCKED!"); | 44 base::string16 text = base::ASCIIToUTF16("LOCKED!"); |
47 int string_width = gfx::GetStringWidth(text, font_list_); | 45 int string_width = gfx::GetStringWidth(text, font_list_); |
48 canvas->DrawStringRect(text, font_list_, SK_ColorRED, | 46 canvas->DrawStringRect(text, font_list_, SK_ColorRED, |
49 gfx::Rect((width() - string_width)/ 2, | 47 gfx::Rect((width() - string_width)/ 2, |
50 (height() - font_list_.GetHeight()) / 2, | 48 (height() - font_list_.GetHeight()) / 2, |
51 string_width, font_list_.GetHeight())); | 49 string_width, font_list_.GetHeight())); |
52 } | 50 } |
53 virtual void Layout() override { | 51 void Layout() override { |
54 gfx::Rect bounds = GetLocalBounds(); | 52 gfx::Rect bounds = GetLocalBounds(); |
55 gfx::Size ps = unlock_button_->GetPreferredSize(); | 53 gfx::Size ps = unlock_button_->GetPreferredSize(); |
56 bounds.set_y(bounds.bottom() - ps.height() - 5); | 54 bounds.set_y(bounds.bottom() - ps.height() - 5); |
57 bounds.set_x((bounds.width() - ps.width()) / 2); | 55 bounds.set_x((bounds.width() - ps.width()) / 2); |
58 bounds.set_size(ps); | 56 bounds.set_size(ps); |
59 unlock_button_->SetBoundsRect(bounds); | 57 unlock_button_->SetBoundsRect(bounds); |
60 } | 58 } |
61 virtual void ViewHierarchyChanged( | 59 void ViewHierarchyChanged( |
62 const ViewHierarchyChangedDetails& details) override { | 60 const ViewHierarchyChangedDetails& details) override { |
63 if (details.is_add && details.child == this) | 61 if (details.is_add && details.child == this) |
64 unlock_button_->RequestFocus(); | 62 unlock_button_->RequestFocus(); |
65 } | 63 } |
66 | 64 |
67 // Overridden from views::WidgetDelegateView: | 65 // Overridden from views::WidgetDelegateView: |
68 virtual void WindowClosing() override { | 66 void WindowClosing() override { |
69 Shell::GetInstance()->session_state_delegate()->UnlockScreen(); | 67 Shell::GetInstance()->session_state_delegate()->UnlockScreen(); |
70 } | 68 } |
71 | 69 |
72 // Overridden from views::ButtonListener: | 70 // Overridden from views::ButtonListener: |
73 virtual void ButtonPressed(views::Button* sender, | 71 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
74 const ui::Event& event) override { | |
75 DCHECK(sender == unlock_button_); | 72 DCHECK(sender == unlock_button_); |
76 GetWidget()->Close(); | 73 GetWidget()->Close(); |
77 } | 74 } |
78 | 75 |
79 gfx::FontList font_list_; | 76 gfx::FontList font_list_; |
80 views::LabelButton* unlock_button_; | 77 views::LabelButton* unlock_button_; |
81 | 78 |
82 DISALLOW_COPY_AND_ASSIGN(LockView); | 79 DISALLOW_COPY_AND_ASSIGN(LockView); |
83 }; | 80 }; |
84 | 81 |
(...skipping 17 matching lines...) Expand all Loading... |
102 widget->GetNativeView()->SetName("LockView"); | 99 widget->GetNativeView()->SetName("LockView"); |
103 widget->GetNativeView()->Focus(); | 100 widget->GetNativeView()->Focus(); |
104 | 101 |
105 // TODO: it shouldn't be necessary to invoke UpdateTooltip() here. | 102 // TODO: it shouldn't be necessary to invoke UpdateTooltip() here. |
106 Shell::GetInstance()->tooltip_controller()->UpdateTooltip( | 103 Shell::GetInstance()->tooltip_controller()->UpdateTooltip( |
107 widget->GetNativeView()); | 104 widget->GetNativeView()); |
108 } | 105 } |
109 | 106 |
110 } // namespace shell | 107 } // namespace shell |
111 } // namespace ash | 108 } // namespace ash |
OLD | NEW |