| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/chromeos/login/screen_locker.h" | 5 #include "chrome/browser/chromeos/login/screen_locker.h" |
| 6 | 6 |
| 7 #include <X11/extensions/XTest.h> | 7 #include <X11/extensions/XTest.h> |
| 8 #include <X11/keysym.h> | 8 #include <X11/keysym.h> |
| 9 #include <gdk/gdkkeysyms.h> | 9 #include <gdk/gdkkeysyms.h> |
| 10 #include <gdk/gdkx.h> | 10 #include <gdk/gdkx.h> |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver); | 191 DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver); |
| 192 }; | 192 }; |
| 193 | 193 |
| 194 static base::LazyInstance<ScreenLockObserver> g_screen_lock_observer( | 194 static base::LazyInstance<ScreenLockObserver> g_screen_lock_observer( |
| 195 base::LINKER_INITIALIZED); | 195 base::LINKER_INITIALIZED); |
| 196 | 196 |
| 197 // A ScreenLock window that covers entire screen to keep the keyboard | 197 // A ScreenLock window that covers entire screen to keep the keyboard |
| 198 // focus/events inside the grab widget. | 198 // focus/events inside the grab widget. |
| 199 class LockWindow : public views::WidgetGtk { | 199 class LockWindow : public views::WidgetGtk { |
| 200 public: | 200 public: |
| 201 LockWindow() : toplevel_focus_widget_(NULL) { | 201 LockWindow() |
| 202 : views::WidgetGtk(new views::Widget), |
| 203 toplevel_focus_widget_(NULL) { |
| 202 EnableDoubleBuffer(true); | 204 EnableDoubleBuffer(true); |
| 203 } | 205 } |
| 204 | 206 |
| 205 // GTK propagates key events from parents to children. | 207 // GTK propagates key events from parents to children. |
| 206 // Make sure LockWindow will never handle key events. | 208 // Make sure LockWindow will never handle key events. |
| 207 virtual gboolean OnEventKey(GtkWidget* widget, GdkEventKey* event) OVERRIDE { | 209 virtual gboolean OnEventKey(GtkWidget* widget, GdkEventKey* event) OVERRIDE { |
| 208 // Don't handle key event in the lock window. | 210 // Don't handle key event in the lock window. |
| 209 return false; | 211 return false; |
| 210 } | 212 } |
| 211 | 213 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 284 |
| 283 chromeos::ShutdownButton* shutdown_button_; | 285 chromeos::ShutdownButton* shutdown_button_; |
| 284 | 286 |
| 285 DISALLOW_COPY_AND_ASSIGN(GrabWidgetRootView); | 287 DISALLOW_COPY_AND_ASSIGN(GrabWidgetRootView); |
| 286 }; | 288 }; |
| 287 | 289 |
| 288 // A child widget that grabs both keyboard and pointer input. | 290 // A child widget that grabs both keyboard and pointer input. |
| 289 class GrabWidget : public views::WidgetGtk { | 291 class GrabWidget : public views::WidgetGtk { |
| 290 public: | 292 public: |
| 291 explicit GrabWidget(chromeos::ScreenLocker* screen_locker) | 293 explicit GrabWidget(chromeos::ScreenLocker* screen_locker) |
| 292 : screen_locker_(screen_locker), | 294 : views::WidgetGtk(new views::Widget), |
| 295 screen_locker_(screen_locker), |
| 293 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), | 296 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), |
| 294 grab_failure_count_(0), | 297 grab_failure_count_(0), |
| 295 kbd_grab_status_(GDK_GRAB_INVALID_TIME), | 298 kbd_grab_status_(GDK_GRAB_INVALID_TIME), |
| 296 mouse_grab_status_(GDK_GRAB_INVALID_TIME), | 299 mouse_grab_status_(GDK_GRAB_INVALID_TIME), |
| 297 signout_link_(NULL), | 300 signout_link_(NULL), |
| 298 shutdown_(NULL) { | 301 shutdown_(NULL) { |
| 299 } | 302 } |
| 300 | 303 |
| 301 virtual void Show() OVERRIDE { | 304 virtual void Show() OVERRIDE { |
| 302 views::WidgetGtk::Show(); | 305 views::WidgetGtk::Show(); |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 | 726 |
| 724 void ScreenLocker::Init() { | 727 void ScreenLocker::Init() { |
| 725 static const GdkColor kGdkBlack = {0, 0, 0, 0}; | 728 static const GdkColor kGdkBlack = {0, 0, 0, 0}; |
| 726 | 729 |
| 727 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); | 730 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); |
| 728 | 731 |
| 729 gfx::Point left_top(1, 1); | 732 gfx::Point left_top(1, 1); |
| 730 gfx::Rect init_bounds(views::Screen::GetMonitorAreaNearestPoint(left_top)); | 733 gfx::Rect init_bounds(views::Screen::GetMonitorAreaNearestPoint(left_top)); |
| 731 | 734 |
| 732 LockWindow* lock_window = new LockWindow(); | 735 LockWindow* lock_window = new LockWindow(); |
| 733 lock_window_ = lock_window; | 736 lock_window_ = lock_window->GetWidget(); |
| 734 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 737 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 735 params.bounds = init_bounds; | 738 params.bounds = init_bounds; |
| 739 params.native_widget = lock_window; |
| 736 lock_window_->Init(params); | 740 lock_window_->Init(params); |
| 737 gtk_widget_modify_bg( | 741 gtk_widget_modify_bg( |
| 738 lock_window_->GetNativeView(), GTK_STATE_NORMAL, &kGdkBlack); | 742 lock_window_->GetNativeView(), GTK_STATE_NORMAL, &kGdkBlack); |
| 739 | 743 |
| 740 g_signal_connect(lock_window_->GetNativeView(), "client-event", | 744 g_signal_connect(lock_window_->GetNativeView(), "client-event", |
| 741 G_CALLBACK(OnClientEventThunk), this); | 745 G_CALLBACK(OnClientEventThunk), this); |
| 742 | 746 |
| 743 // GTK does not like zero width/height. | 747 // GTK does not like zero width/height. |
| 744 if (!unlock_on_input_) { | 748 if (!unlock_on_input_) { |
| 745 screen_lock_view_ = new ScreenLockView(this); | 749 screen_lock_view_ = new ScreenLockView(this); |
| 746 screen_lock_view_->Init(); | 750 screen_lock_view_->Init(); |
| 747 screen_lock_view_->SetEnabled(false); | 751 screen_lock_view_->SetEnabled(false); |
| 748 screen_lock_view_->StartThrobber(); | 752 screen_lock_view_->StartThrobber(); |
| 749 } else { | 753 } else { |
| 750 input_event_observer_.reset(new InputEventObserver(this)); | 754 input_event_observer_.reset(new InputEventObserver(this)); |
| 751 MessageLoopForUI::current()->AddObserver(input_event_observer_.get()); | 755 MessageLoopForUI::current()->AddObserver(input_event_observer_.get()); |
| 752 } | 756 } |
| 753 | 757 |
| 754 // Hang on to a cast version of the grab widget so we can call its | 758 // Hang on to a cast version of the grab widget so we can call its |
| 755 // TryGrabAllInputs() method later. (Nobody else needs to use it, so moving | 759 // TryGrabAllInputs() method later. (Nobody else needs to use it, so moving |
| 756 // its declaration to the header instead of keeping it in an anonymous | 760 // its declaration to the header instead of keeping it in an anonymous |
| 757 // namespace feels a bit ugly.) | 761 // namespace feels a bit ugly.) |
| 758 GrabWidget* cast_lock_widget = new GrabWidget(this); | 762 GrabWidget* grab_widget = new GrabWidget(this); |
| 759 lock_widget_ = cast_lock_widget; | 763 lock_widget_ = grab_widget->GetWidget(); |
| 760 views::Widget::InitParams lock_params( | 764 views::Widget::InitParams lock_params( |
| 761 views::Widget::InitParams::TYPE_CONTROL); | 765 views::Widget::InitParams::TYPE_CONTROL); |
| 762 lock_params.transparent = true; | 766 lock_params.transparent = true; |
| 763 lock_params.parent_widget = lock_window_; | 767 lock_params.parent_widget = lock_window_; |
| 768 lock_params.native_widget = grab_widget; |
| 764 lock_widget_->Init(lock_params); | 769 lock_widget_->Init(lock_params); |
| 765 if (screen_lock_view_) { | 770 if (screen_lock_view_) { |
| 766 GrabWidgetRootView* root_view = new GrabWidgetRootView(screen_lock_view_); | 771 GrabWidgetRootView* root_view = new GrabWidgetRootView(screen_lock_view_); |
| 767 grab_container_ = root_view; | 772 grab_container_ = root_view; |
| 768 lock_widget_->SetContentsView(root_view); | 773 lock_widget_->SetContentsView(root_view); |
| 769 } | 774 } |
| 770 lock_widget_->Show(); | 775 lock_widget_->Show(); |
| 771 | 776 |
| 772 // Configuring the background url. | 777 // Configuring the background url. |
| 773 std::string url_string = | 778 std::string url_string = |
| 774 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 779 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 775 switches::kScreenSaverUrl); | 780 switches::kScreenSaverUrl); |
| 776 ScreenLockerBackgroundView* screen_lock_background_view_ = | 781 ScreenLockerBackgroundView* screen_lock_background_view_ = |
| 777 new ScreenLockerBackgroundView(lock_widget_, screen_lock_view_); | 782 new ScreenLockerBackgroundView(lock_widget_, screen_lock_view_); |
| 778 background_container_ = screen_lock_background_view_; | 783 background_container_ = screen_lock_background_view_; |
| 779 background_view_ = screen_lock_background_view_; | 784 background_view_ = screen_lock_background_view_; |
| 780 background_view_->Init(GURL(url_string)); | 785 background_view_->Init(GURL(url_string)); |
| 781 if (background_view_->ScreenSaverEnabled()) | 786 if (background_view_->ScreenSaverEnabled()) |
| 782 StartScreenSaver(); | 787 StartScreenSaver(); |
| 783 | 788 |
| 784 DCHECK(GTK_WIDGET_REALIZED(lock_window_->GetNativeView())); | 789 DCHECK(GTK_WIDGET_REALIZED(lock_window_->GetNativeView())); |
| 785 WmIpc::instance()->SetWindowType( | 790 WmIpc::instance()->SetWindowType( |
| 786 lock_window_->GetNativeView(), | 791 lock_window_->GetNativeView(), |
| 787 WM_IPC_WINDOW_CHROME_SCREEN_LOCKER, | 792 WM_IPC_WINDOW_CHROME_SCREEN_LOCKER, |
| 788 NULL); | 793 NULL); |
| 789 | 794 |
| 790 lock_window_->SetContentsView(background_view_); | 795 lock_window_->SetContentsView(background_view_); |
| 791 lock_window_->Show(); | 796 lock_window_->Show(); |
| 792 | 797 |
| 793 cast_lock_widget->ClearGtkGrab(); | 798 grab_widget->ClearGtkGrab(); |
| 794 | 799 |
| 795 // Call this after lock_window_->Show(); otherwise the 1st invocation | 800 // Call this after lock_window_->Show(); otherwise the 1st invocation |
| 796 // of gdk_xxx_grab() will always fail. | 801 // of gdk_xxx_grab() will always fail. |
| 797 cast_lock_widget->TryGrabAllInputs(); | 802 grab_widget->TryGrabAllInputs(); |
| 798 | 803 |
| 799 // Add the window to its own group so that its grab won't be stolen if | 804 // Add the window to its own group so that its grab won't be stolen if |
| 800 // gtk_grab_add() gets called on behalf on a non-screen-locker widget (e.g. | 805 // gtk_grab_add() gets called on behalf on a non-screen-locker widget (e.g. |
| 801 // a modal dialog) -- see http://crosbug.com/8999. We intentionally do this | 806 // a modal dialog) -- see http://crosbug.com/8999. We intentionally do this |
| 802 // after calling ClearGtkGrab(), as want to be in the default window group | 807 // after calling ClearGtkGrab(), as want to be in the default window group |
| 803 // then so we can break any existing GTK grabs. | 808 // then so we can break any existing GTK grabs. |
| 804 GtkWindowGroup* window_group = gtk_window_group_new(); | 809 GtkWindowGroup* window_group = gtk_window_group_new(); |
| 805 gtk_window_group_add_window(window_group, | 810 gtk_window_group_add_window(window_group, |
| 806 GTK_WINDOW(lock_window_->GetNativeView())); | 811 GTK_WINDOW(lock_window_->GetNativeView())); |
| 807 g_object_unref(window_group); | 812 g_object_unref(window_group); |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1191 | 1196 |
| 1192 bool ScreenLocker::AcceleratorPressed(const views::Accelerator& accelerator) { | 1197 bool ScreenLocker::AcceleratorPressed(const views::Accelerator& accelerator) { |
| 1193 if (!background_view_->IsScreenSaverVisible()) { | 1198 if (!background_view_->IsScreenSaverVisible()) { |
| 1194 StartScreenSaver(); | 1199 StartScreenSaver(); |
| 1195 return true; | 1200 return true; |
| 1196 } | 1201 } |
| 1197 return false; | 1202 return false; |
| 1198 } | 1203 } |
| 1199 | 1204 |
| 1200 } // namespace chromeos | 1205 } // namespace chromeos |
| OLD | NEW |