| 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() | 201 LockWindow() : toplevel_focus_widget_(NULL) { |
| 202 : views::WidgetGtk(views::WidgetGtk::TYPE_WINDOW), | |
| 203 toplevel_focus_widget_(NULL) { | |
| 204 EnableDoubleBuffer(true); | 202 EnableDoubleBuffer(true); |
| 205 } | 203 } |
| 206 | 204 |
| 207 // GTK propagates key events from parents to children. | 205 // GTK propagates key events from parents to children. |
| 208 // Make sure LockWindow will never handle key events. | 206 // Make sure LockWindow will never handle key events. |
| 209 virtual gboolean OnEventKey(GtkWidget* widget, GdkEventKey* event) OVERRIDE { | 207 virtual gboolean OnEventKey(GtkWidget* widget, GdkEventKey* event) OVERRIDE { |
| 210 // Don't handle key event in the lock window. | 208 // Don't handle key event in the lock window. |
| 211 return false; | 209 return false; |
| 212 } | 210 } |
| 213 | 211 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 275 |
| 278 chromeos::ShutdownButton* shutdown_button_; | 276 chromeos::ShutdownButton* shutdown_button_; |
| 279 | 277 |
| 280 DISALLOW_COPY_AND_ASSIGN(GrabWidgetRootView); | 278 DISALLOW_COPY_AND_ASSIGN(GrabWidgetRootView); |
| 281 }; | 279 }; |
| 282 | 280 |
| 283 // A child widget that grabs both keyboard and pointer input. | 281 // A child widget that grabs both keyboard and pointer input. |
| 284 class GrabWidget : public views::WidgetGtk { | 282 class GrabWidget : public views::WidgetGtk { |
| 285 public: | 283 public: |
| 286 explicit GrabWidget(chromeos::ScreenLocker* screen_locker) | 284 explicit GrabWidget(chromeos::ScreenLocker* screen_locker) |
| 287 : views::WidgetGtk(views::WidgetGtk::TYPE_CHILD), | 285 : screen_locker_(screen_locker), |
| 288 screen_locker_(screen_locker), | |
| 289 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), | 286 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), |
| 290 grab_failure_count_(0), | 287 grab_failure_count_(0), |
| 291 kbd_grab_status_(GDK_GRAB_INVALID_TIME), | 288 kbd_grab_status_(GDK_GRAB_INVALID_TIME), |
| 292 mouse_grab_status_(GDK_GRAB_INVALID_TIME), | 289 mouse_grab_status_(GDK_GRAB_INVALID_TIME), |
| 293 signout_link_(NULL), | 290 signout_link_(NULL), |
| 294 shutdown_(NULL) { | 291 shutdown_(NULL) { |
| 295 } | 292 } |
| 296 | 293 |
| 297 virtual void Show() OVERRIDE { | 294 virtual void Show() OVERRIDE { |
| 298 views::WidgetGtk::Show(); | 295 views::WidgetGtk::Show(); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 XFlush(display); | 468 XFlush(display); |
| 472 } | 469 } |
| 473 } | 470 } |
| 474 | 471 |
| 475 // BackgroundView for ScreenLocker, which layouts a lock widget in | 472 // BackgroundView for ScreenLocker, which layouts a lock widget in |
| 476 // addition to other background components. | 473 // addition to other background components. |
| 477 class ScreenLockerBackgroundView | 474 class ScreenLockerBackgroundView |
| 478 : public chromeos::BackgroundView, | 475 : public chromeos::BackgroundView, |
| 479 public chromeos::ScreenLocker::ScreenLockViewContainer { | 476 public chromeos::ScreenLocker::ScreenLockViewContainer { |
| 480 public: | 477 public: |
| 481 ScreenLockerBackgroundView(views::WidgetGtk* lock_widget, | 478 ScreenLockerBackgroundView(views::Widget* lock_widget, |
| 482 views::View* screen_lock_view) | 479 views::View* screen_lock_view) |
| 483 : lock_widget_(lock_widget), | 480 : lock_widget_(lock_widget), |
| 484 screen_lock_view_(screen_lock_view) { | 481 screen_lock_view_(screen_lock_view) { |
| 485 } | 482 } |
| 486 | 483 |
| 487 virtual ScreenMode GetScreenMode() const OVERRIDE { | 484 virtual ScreenMode GetScreenMode() const OVERRIDE { |
| 488 return kScreenLockerMode; | 485 return kScreenLockerMode; |
| 489 } | 486 } |
| 490 | 487 |
| 491 virtual void Layout() OVERRIDE { | 488 virtual void Layout() OVERRIDE { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 504 } | 501 } |
| 505 } | 502 } |
| 506 | 503 |
| 507 // ScreenLocker::ScreenLockViewContainer implementation: | 504 // ScreenLocker::ScreenLockViewContainer implementation: |
| 508 virtual void SetScreenLockView(views::View* screen_lock_view) OVERRIDE { | 505 virtual void SetScreenLockView(views::View* screen_lock_view) OVERRIDE { |
| 509 screen_lock_view_ = screen_lock_view; | 506 screen_lock_view_ = screen_lock_view; |
| 510 Layout(); | 507 Layout(); |
| 511 } | 508 } |
| 512 | 509 |
| 513 private: | 510 private: |
| 514 views::WidgetGtk* lock_widget_; | 511 views::Widget* lock_widget_; |
| 515 | 512 |
| 516 views::View* screen_lock_view_; | 513 views::View* screen_lock_view_; |
| 517 | 514 |
| 518 DISALLOW_COPY_AND_ASSIGN(ScreenLockerBackgroundView); | 515 DISALLOW_COPY_AND_ASSIGN(ScreenLockerBackgroundView); |
| 519 }; | 516 }; |
| 520 | 517 |
| 521 } // namespace | 518 } // namespace |
| 522 | 519 |
| 523 namespace chromeos { | 520 namespace chromeos { |
| 524 | 521 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 } | 678 } |
| 682 | 679 |
| 683 void ScreenLocker::Init() { | 680 void ScreenLocker::Init() { |
| 684 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); | 681 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); |
| 685 | 682 |
| 686 gfx::Point left_top(1, 1); | 683 gfx::Point left_top(1, 1); |
| 687 gfx::Rect init_bounds(views::Screen::GetMonitorAreaNearestPoint(left_top)); | 684 gfx::Rect init_bounds(views::Screen::GetMonitorAreaNearestPoint(left_top)); |
| 688 | 685 |
| 689 LockWindow* lock_window = new LockWindow(); | 686 LockWindow* lock_window = new LockWindow(); |
| 690 lock_window_ = lock_window; | 687 lock_window_ = lock_window; |
| 691 lock_window_->Init(NULL, init_bounds); | 688 views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_WINDOW); |
| 689 params.bounds = init_bounds; |
| 690 lock_window_->Init(params); |
| 692 | 691 |
| 693 g_signal_connect(lock_window_->GetNativeView(), "client-event", | 692 g_signal_connect(lock_window_->GetNativeView(), "client-event", |
| 694 G_CALLBACK(OnClientEventThunk), this); | 693 G_CALLBACK(OnClientEventThunk), this); |
| 695 | 694 |
| 696 // GTK does not like zero width/height. | 695 // GTK does not like zero width/height. |
| 697 if (!unlock_on_input_) { | 696 if (!unlock_on_input_) { |
| 698 screen_lock_view_ = new ScreenLockView(this); | 697 screen_lock_view_ = new ScreenLockView(this); |
| 699 screen_lock_view_->Init(); | 698 screen_lock_view_->Init(); |
| 700 screen_lock_view_->SetEnabled(false); | 699 screen_lock_view_->SetEnabled(false); |
| 701 screen_lock_view_->StartThrobber(); | 700 screen_lock_view_->StartThrobber(); |
| 702 } else { | 701 } else { |
| 703 input_event_observer_.reset(new InputEventObserver(this)); | 702 input_event_observer_.reset(new InputEventObserver(this)); |
| 704 MessageLoopForUI::current()->AddObserver(input_event_observer_.get()); | 703 MessageLoopForUI::current()->AddObserver(input_event_observer_.get()); |
| 705 } | 704 } |
| 706 | 705 |
| 707 // Hang on to a cast version of the grab widget so we can call its | 706 // Hang on to a cast version of the grab widget so we can call its |
| 708 // TryGrabAllInputs() method later. (Nobody else needs to use it, so moving | 707 // TryGrabAllInputs() method later. (Nobody else needs to use it, so moving |
| 709 // its declaration to the header instead of keeping it in an anonymous | 708 // its declaration to the header instead of keeping it in an anonymous |
| 710 // namespace feels a bit ugly.) | 709 // namespace feels a bit ugly.) |
| 711 GrabWidget* cast_lock_widget = new GrabWidget(this); | 710 GrabWidget* cast_lock_widget = new GrabWidget(this); |
| 712 lock_widget_ = cast_lock_widget; | 711 lock_widget_ = cast_lock_widget; |
| 713 lock_widget_->MakeTransparent(); | 712 views::Widget::CreateParams lock_params( |
| 714 lock_widget_->InitWithWidget(lock_window_, gfx::Rect()); | 713 views::Widget::CreateParams::TYPE_CONTROL); |
| 714 lock_params.transparent = true; |
| 715 lock_params.parent_widget = lock_window_; |
| 716 lock_widget_->Init(lock_params); |
| 715 if (screen_lock_view_) { | 717 if (screen_lock_view_) { |
| 716 GrabWidgetRootView* root_view = new GrabWidgetRootView(screen_lock_view_); | 718 GrabWidgetRootView* root_view = new GrabWidgetRootView(screen_lock_view_); |
| 717 grab_container_ = root_view; | 719 grab_container_ = root_view; |
| 718 lock_widget_->SetContentsView(root_view); | 720 lock_widget_->SetContentsView(root_view); |
| 719 } | 721 } |
| 720 lock_widget_->Show(); | 722 lock_widget_->Show(); |
| 721 | 723 |
| 722 // Configuring the background url. | 724 // Configuring the background url. |
| 723 std::string url_string = | 725 std::string url_string = |
| 724 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 726 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 755 gtk_window_group_add_window(window_group, | 757 gtk_window_group_add_window(window_group, |
| 756 GTK_WINDOW(lock_window_->GetNativeView())); | 758 GTK_WINDOW(lock_window_->GetNativeView())); |
| 757 g_object_unref(window_group); | 759 g_object_unref(window_group); |
| 758 | 760 |
| 759 // Don't let X draw default background, which was causing flash on | 761 // Don't let X draw default background, which was causing flash on |
| 760 // resume. | 762 // resume. |
| 761 gdk_window_set_back_pixmap(lock_window_->GetNativeView()->window, | 763 gdk_window_set_back_pixmap(lock_window_->GetNativeView()->window, |
| 762 NULL, false); | 764 NULL, false); |
| 763 gdk_window_set_back_pixmap(lock_widget_->GetNativeView()->window, | 765 gdk_window_set_back_pixmap(lock_widget_->GetNativeView()->window, |
| 764 NULL, false); | 766 NULL, false); |
| 765 lock_window->set_toplevel_focus_widget(lock_widget_->window_contents()); | 767 lock_window->set_toplevel_focus_widget( |
| 768 static_cast<views::WidgetGtk*>(lock_widget_->native_widget())-> |
| 769 window_contents()); |
| 766 | 770 |
| 767 // Create the SystemKeyEventListener so it can listen for system keyboard | 771 // Create the SystemKeyEventListener so it can listen for system keyboard |
| 768 // messages regardless of focus while screen locked. | 772 // messages regardless of focus while screen locked. |
| 769 SystemKeyEventListener::GetInstance(); | 773 SystemKeyEventListener::GetInstance(); |
| 770 } | 774 } |
| 771 | 775 |
| 772 void ScreenLocker::OnLoginFailure(const LoginFailure& error) { | 776 void ScreenLocker::OnLoginFailure(const LoginFailure& error) { |
| 773 DVLOG(1) << "OnLoginFailure"; | 777 DVLOG(1) << "OnLoginFailure"; |
| 774 UserMetrics::RecordAction(UserMetricsAction("ScreenLocker_OnLoginFailure")); | 778 UserMetrics::RecordAction(UserMetricsAction("ScreenLocker_OnLoginFailure")); |
| 775 if (authentication_start_time_.is_null()) { | 779 if (authentication_start_time_.is_null()) { |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1145 | 1149 |
| 1146 bool ScreenLocker::AcceleratorPressed(const views::Accelerator& accelerator) { | 1150 bool ScreenLocker::AcceleratorPressed(const views::Accelerator& accelerator) { |
| 1147 if (!background_view_->IsScreenSaverVisible()) { | 1151 if (!background_view_->IsScreenSaverVisible()) { |
| 1148 StartScreenSaver(); | 1152 StartScreenSaver(); |
| 1149 return true; | 1153 return true; |
| 1150 } | 1154 } |
| 1151 return false; | 1155 return false; |
| 1152 } | 1156 } |
| 1153 | 1157 |
| 1154 } // namespace chromeos | 1158 } // namespace chromeos |
| OLD | NEW |