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

Side by Side Diff: chrome/browser/chromeos/login/screen_locker.cc

Issue 6881107: Rework the way Widget::Init works: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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) 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
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 OnKeyEvent(GtkWidget* widget, GdkEventKey* event) { 207 virtual gboolean OnKeyEvent(GtkWidget* widget, GdkEventKey* event) {
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
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() { 294 virtual void Show() {
298 views::WidgetGtk::Show(); 295 views::WidgetGtk::Show();
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 XFlush(display); 467 XFlush(display);
471 } 468 }
472 } 469 }
473 470
474 // BackgroundView for ScreenLocker, which layouts a lock widget in 471 // BackgroundView for ScreenLocker, which layouts a lock widget in
475 // addition to other background components. 472 // addition to other background components.
476 class ScreenLockerBackgroundView 473 class ScreenLockerBackgroundView
477 : public chromeos::BackgroundView, 474 : public chromeos::BackgroundView,
478 public chromeos::ScreenLocker::ScreenLockViewContainer { 475 public chromeos::ScreenLocker::ScreenLockViewContainer {
479 public: 476 public:
480 ScreenLockerBackgroundView(views::WidgetGtk* lock_widget, 477 ScreenLockerBackgroundView(views::Widget* lock_widget,
481 views::View* screen_lock_view) 478 views::View* screen_lock_view)
482 : lock_widget_(lock_widget), 479 : lock_widget_(lock_widget),
483 screen_lock_view_(screen_lock_view) { 480 screen_lock_view_(screen_lock_view) {
484 } 481 }
485 482
486 virtual ScreenMode GetScreenMode() const { 483 virtual ScreenMode GetScreenMode() const {
487 return kScreenLockerMode; 484 return kScreenLockerMode;
488 } 485 }
489 486
490 virtual void Layout() { 487 virtual void Layout() {
(...skipping 12 matching lines...) Expand all
503 } 500 }
504 } 501 }
505 502
506 // ScreenLocker::ScreenLockViewContainer implementation: 503 // ScreenLocker::ScreenLockViewContainer implementation:
507 void SetScreenLockView(views::View* screen_lock_view) { 504 void SetScreenLockView(views::View* screen_lock_view) {
508 screen_lock_view_ = screen_lock_view; 505 screen_lock_view_ = screen_lock_view;
509 Layout(); 506 Layout();
510 } 507 }
511 508
512 private: 509 private:
513 views::WidgetGtk* lock_widget_; 510 views::Widget* lock_widget_;
514 511
515 views::View* screen_lock_view_; 512 views::View* screen_lock_view_;
516 513
517 DISALLOW_COPY_AND_ASSIGN(ScreenLockerBackgroundView); 514 DISALLOW_COPY_AND_ASSIGN(ScreenLockerBackgroundView);
518 }; 515 };
519 516
520 } // namespace 517 } // namespace
521 518
522 namespace chromeos { 519 namespace chromeos {
523 520
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 } 677 }
681 678
682 void ScreenLocker::Init() { 679 void ScreenLocker::Init() {
683 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); 680 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this);
684 681
685 gfx::Point left_top(1, 1); 682 gfx::Point left_top(1, 1);
686 gfx::Rect init_bounds(views::Screen::GetMonitorAreaNearestPoint(left_top)); 683 gfx::Rect init_bounds(views::Screen::GetMonitorAreaNearestPoint(left_top));
687 684
688 LockWindow* lock_window = new LockWindow(); 685 LockWindow* lock_window = new LockWindow();
689 lock_window_ = lock_window; 686 lock_window_ = lock_window;
690 lock_window_->Init(NULL, init_bounds); 687 views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_WINDOW);
688 params.bounds = init_bounds;
689 lock_window_->Init(params);
691 690
692 g_signal_connect(lock_window_->GetNativeView(), "client-event", 691 g_signal_connect(lock_window_->GetNativeView(), "client-event",
693 G_CALLBACK(OnClientEventThunk), this); 692 G_CALLBACK(OnClientEventThunk), this);
694 693
695 // GTK does not like zero width/height. 694 // GTK does not like zero width/height.
696 if (!unlock_on_input_) { 695 if (!unlock_on_input_) {
697 screen_lock_view_ = new ScreenLockView(this); 696 screen_lock_view_ = new ScreenLockView(this);
698 screen_lock_view_->Init(); 697 screen_lock_view_->Init();
699 screen_lock_view_->SetEnabled(false); 698 screen_lock_view_->SetEnabled(false);
700 screen_lock_view_->StartThrobber(); 699 screen_lock_view_->StartThrobber();
701 } else { 700 } else {
702 input_event_observer_.reset(new InputEventObserver(this)); 701 input_event_observer_.reset(new InputEventObserver(this));
703 MessageLoopForUI::current()->AddObserver(input_event_observer_.get()); 702 MessageLoopForUI::current()->AddObserver(input_event_observer_.get());
704 } 703 }
705 704
706 // Hang on to a cast version of the grab widget so we can call its 705 // Hang on to a cast version of the grab widget so we can call its
707 // TryGrabAllInputs() method later. (Nobody else needs to use it, so moving 706 // TryGrabAllInputs() method later. (Nobody else needs to use it, so moving
708 // its declaration to the header instead of keeping it in an anonymous 707 // its declaration to the header instead of keeping it in an anonymous
709 // namespace feels a bit ugly.) 708 // namespace feels a bit ugly.)
710 GrabWidget* cast_lock_widget = new GrabWidget(this); 709 GrabWidget* cast_lock_widget = new GrabWidget(this);
711 lock_widget_ = cast_lock_widget; 710 lock_widget_ = cast_lock_widget;
712 lock_widget_->MakeTransparent(); 711 views::Widget::CreateParams lock_params(
713 lock_widget_->InitWithWidget(lock_window_, gfx::Rect()); 712 views::Widget::CreateParams::TYPE_CONTROL);
713 lock_params.transparent = true;
714 lock_params.parent_widget = lock_window_;
715 lock_widget_->Init(lock_params);
714 if (screen_lock_view_) { 716 if (screen_lock_view_) {
715 GrabWidgetRootView* root_view = new GrabWidgetRootView(screen_lock_view_); 717 GrabWidgetRootView* root_view = new GrabWidgetRootView(screen_lock_view_);
716 grab_container_ = root_view; 718 grab_container_ = root_view;
717 lock_widget_->SetContentsView(root_view); 719 lock_widget_->SetContentsView(root_view);
718 } 720 }
719 lock_widget_->Show(); 721 lock_widget_->Show();
720 722
721 // Configuring the background url. 723 // Configuring the background url.
722 std::string url_string = 724 std::string url_string =
723 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 725 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
(...skipping 30 matching lines...) Expand all
754 gtk_window_group_add_window(window_group, 756 gtk_window_group_add_window(window_group,
755 GTK_WINDOW(lock_window_->GetNativeView())); 757 GTK_WINDOW(lock_window_->GetNativeView()));
756 g_object_unref(window_group); 758 g_object_unref(window_group);
757 759
758 // Don't let X draw default background, which was causing flash on 760 // Don't let X draw default background, which was causing flash on
759 // resume. 761 // resume.
760 gdk_window_set_back_pixmap(lock_window_->GetNativeView()->window, 762 gdk_window_set_back_pixmap(lock_window_->GetNativeView()->window,
761 NULL, false); 763 NULL, false);
762 gdk_window_set_back_pixmap(lock_widget_->GetNativeView()->window, 764 gdk_window_set_back_pixmap(lock_widget_->GetNativeView()->window,
763 NULL, false); 765 NULL, false);
764 lock_window->set_toplevel_focus_widget(lock_widget_->window_contents()); 766 lock_window->set_toplevel_focus_widget(
767 static_cast<views::WidgetGtk*>(lock_widget_->native_widget())->
768 window_contents());
765 769
766 // Create the SystemKeyEventListener so it can listen for system keyboard 770 // Create the SystemKeyEventListener so it can listen for system keyboard
767 // messages regardless of focus while screen locked. 771 // messages regardless of focus while screen locked.
768 SystemKeyEventListener::GetInstance(); 772 SystemKeyEventListener::GetInstance();
769 } 773 }
770 774
771 void ScreenLocker::OnLoginFailure(const LoginFailure& error) { 775 void ScreenLocker::OnLoginFailure(const LoginFailure& error) {
772 DVLOG(1) << "OnLoginFailure"; 776 DVLOG(1) << "OnLoginFailure";
773 UserMetrics::RecordAction(UserMetricsAction("ScreenLocker_OnLoginFailure")); 777 UserMetrics::RecordAction(UserMetricsAction("ScreenLocker_OnLoginFailure"));
774 if (authentication_start_time_.is_null()) { 778 if (authentication_start_time_.is_null()) {
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 1148
1145 bool ScreenLocker::AcceleratorPressed(const views::Accelerator& accelerator) { 1149 bool ScreenLocker::AcceleratorPressed(const views::Accelerator& accelerator) {
1146 if (!background_view_->IsScreenSaverVisible()) { 1150 if (!background_view_->IsScreenSaverVisible()) {
1147 StartScreenSaver(); 1151 StartScreenSaver();
1148 return true; 1152 return true;
1149 } 1153 }
1150 return false; 1154 return false;
1151 } 1155 }
1152 1156
1153 } // namespace chromeos 1157 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698