Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: ash/shell/lock_view.cc

Issue 9788001: Remove stops_event_propagation from Window, since it's broken. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/shell.h" 5 #include "ash/shell.h"
6 #include "ash/shell_delegate.h"
6 #include "ash/shell_window_ids.h" 7 #include "ash/shell_window_ids.h"
7 #include "ash/shell/example_factory.h" 8 #include "ash/shell/example_factory.h"
8 #include "ash/tooltips/tooltip_controller.h" 9 #include "ash/tooltips/tooltip_controller.h"
9 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
10 #include "ui/aura/root_window.h" 11 #include "ui/aura/root_window.h"
11 #include "ui/aura/window.h" 12 #include "ui/aura/window.h"
12 #include "ui/gfx/canvas.h" 13 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/font.h" 14 #include "ui/gfx/font.h"
15 #include "ui/views/controls/button/text_button.h"
14 #include "ui/views/widget/widget.h" 16 #include "ui/views/widget/widget.h"
15 #include "ui/views/widget/widget_delegate.h" 17 #include "ui/views/widget/widget_delegate.h"
16 18
17 using ash::Shell; 19 using ash::Shell;
18 20
19 namespace ash { 21 namespace ash {
20 namespace shell { 22 namespace shell {
21 23
22 class LockView : public views::WidgetDelegateView { 24 class LockView : public views::WidgetDelegateView,
25 public views::ButtonListener {
23 public: 26 public:
24 LockView() {} 27 LockView() : unlock_button_(ALLOW_THIS_IN_INITIALIZER_LIST(
28 new views::NativeTextButton(this, ASCIIToUTF16("Unlock")))) {
29 AddChildView(unlock_button_);
30 unlock_button_->set_focusable(true);
31 }
25 virtual ~LockView() {} 32 virtual ~LockView() {}
26 33
27 // Overridden from View: 34 // Overridden from views::View:
28 virtual gfx::Size GetPreferredSize() OVERRIDE { 35 virtual gfx::Size GetPreferredSize() OVERRIDE {
29 return gfx::Size(500, 400); 36 return gfx::Size(500, 400);
30 } 37 }
31 38
32 private: 39 private:
33 // Overridden from View: 40 // Overridden from views::View:
34 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { 41 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
35 canvas->FillRect(GetLocalBounds(), SK_ColorYELLOW); 42 canvas->FillRect(GetLocalBounds(), SK_ColorYELLOW);
36 string16 text = ASCIIToUTF16("LOCKED!"); 43 string16 text = ASCIIToUTF16("LOCKED!");
37 int string_width = font_.GetStringWidth(text); 44 int string_width = font_.GetStringWidth(text);
38 canvas->DrawStringInt(text, font_, SK_ColorRED, (width() - string_width)/ 2, 45 canvas->DrawStringInt(text, font_, SK_ColorRED, (width() - string_width)/ 2,
39 (height() - font_.GetHeight()) / 2, 46 (height() - font_.GetHeight()) / 2,
40 string_width, font_.GetHeight()); 47 string_width, font_.GetHeight());
41 } 48 }
42 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE { 49 virtual void Layout() OVERRIDE {
43 return true; 50 gfx::Rect bounds = GetLocalBounds();
51 gfx::Size ps = unlock_button_->GetPreferredSize();
52 bounds.set_y(bounds.bottom() - ps.height() - 5);
53 bounds.set_x((bounds.width() - ps.width()) / 2);
54 bounds.set_size(ps);
55 unlock_button_->SetBoundsRect(bounds);
44 } 56 }
45 virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE { 57 virtual void ViewHierarchyChanged(bool is_add,
58 views::View* parent,
59 views::View* child) OVERRIDE {
60 if (is_add && child == this)
61 unlock_button_->RequestFocus();
62 }
63
64 // Overridden from views::WidgetDelegateView:
65 virtual void WindowClosing() OVERRIDE {
66 Shell::GetInstance()->delegate()->UnlockScreen();
67 }
68
69 // Overridden from views::ButtonListener:
70 virtual void ButtonPressed(views::Button* sender,
71 const views::Event& event) OVERRIDE {
72 DCHECK(sender == unlock_button_);
46 GetWidget()->Close(); 73 GetWidget()->Close();
47 } 74 }
48 75
49 gfx::Font font_; 76 gfx::Font font_;
77 views::NativeTextButton* unlock_button_;
50 78
51 DISALLOW_COPY_AND_ASSIGN(LockView); 79 DISALLOW_COPY_AND_ASSIGN(LockView);
52 }; 80 };
53 81
54 void CreateLockScreen() { 82 void CreateLockScreen() {
55 LockView* lock_view = new LockView; 83 LockView* lock_view = new LockView;
56 views::Widget* widget = new views::Widget; 84 views::Widget* widget = new views::Widget;
57 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); 85 views::Widget::InitParams params(
86 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
58 gfx::Size ps = lock_view->GetPreferredSize(); 87 gfx::Size ps = lock_view->GetPreferredSize();
59 88
60 gfx::Size root_window_size = Shell::GetRootWindow()->GetHostSize(); 89 gfx::Size root_window_size = Shell::GetRootWindow()->GetHostSize();
61 params.bounds = gfx::Rect((root_window_size.width() - ps.width()) / 2, 90 params.bounds = gfx::Rect((root_window_size.width() - ps.width()) / 2,
62 (root_window_size.height() - ps.height()) / 2, 91 (root_window_size.height() - ps.height()) / 2,
63 ps.width(), ps.height()); 92 ps.width(), ps.height());
64 params.delegate = lock_view; 93 params.delegate = lock_view;
65 params.parent = 94 params.parent =
66 Shell::GetInstance()->GetContainer( 95 Shell::GetInstance()->GetContainer(
67 ash::internal::kShellWindowId_LockScreenContainer); 96 ash::internal::kShellWindowId_LockScreenContainer);
68 widget->Init(params); 97 widget->Init(params);
69 widget->SetContentsView(lock_view); 98 widget->SetContentsView(lock_view);
70 widget->Show(); 99 widget->Show();
71 widget->GetNativeView()->SetName("LockView"); 100 widget->GetNativeView()->SetName("LockView");
101 widget->GetNativeView()->Focus();
72 102
73 Shell::GetInstance()->tooltip_controller()->UpdateTooltip( 103 Shell::GetInstance()->tooltip_controller()->UpdateTooltip(
74 widget->GetNativeView()); 104 widget->GetNativeView());
75 } 105 }
76 106
77 } // namespace shell 107 } // namespace shell
78 } // namespace ash 108 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698