summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-19 00:02:07 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-19 00:02:07 +0000
commitf56367ccb42c6af4a609b34a6b0f86b230ef8542 (patch)
treed0ee3714a58ae40d149c6f8c2446534c290406a4 /chrome/browser/chromeos
parent9870326b1412b1f3804eed8d9b6402ac60ddf8f0 (diff)
downloadchromium_src-f56367ccb42c6af4a609b34a6b0f86b230ef8542.zip
chromium_src-f56367ccb42c6af4a609b34a6b0f86b230ef8542.tar.gz
chromium_src-f56367ccb42c6af4a609b34a6b0f86b230ef8542.tar.bz2
*Add WidgetGtk::ClearNativeFocus so that subclass can implement cutomized behavior when clearning native focus.
This is necessary in ScreenLocker as the focus has to be set to the widget that is grabbing all input focus. * PasswordField that will set focus it itself when mouse is clicked. This is necessary again when the input is grabbed by other widget because the gtk textfield will never receive mouse event. * fix minor bug : locating the grab widget in wrong place. Review URL: http://codereview.chromium.org/2811015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50303 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos')
-rw-r--r--chrome/browser/chromeos/login/screen_lock_view.cc29
-rw-r--r--chrome/browser/chromeos/login/screen_locker.cc50
2 files changed, 74 insertions, 5 deletions
diff --git a/chrome/browser/chromeos/login/screen_lock_view.cc b/chrome/browser/chromeos/login/screen_lock_view.cc
index 3c879d7..c554f30 100644
--- a/chrome/browser/chromeos/login/screen_lock_view.cc
+++ b/chrome/browser/chromeos/login/screen_lock_view.cc
@@ -23,6 +23,31 @@
namespace chromeos {
+namespace {
+
+// A Textfield for password, which also sets focus to itself
+// when a mouse is clicked on it. This is necessary in screen locker
+// as mouse events are grabbed in the screen locker.
+class PasswordField : public views::Textfield {
+ public:
+ PasswordField()
+ : views::Textfield(views::Textfield::STYLE_PASSWORD) {
+ set_text_to_display_when_empty(
+ l10n_util::GetStringUTF16(IDS_LOGIN_EMPTY_PASSWORD_TEXT));
+ }
+
+ // views::View overrides.
+ virtual bool OnMousePressed(const views::MouseEvent& e) {
+ RequestFocus();
+ return false;
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PasswordField);
+};
+
+} // namespace
+
using views::GridLayout;
using login::kBorderSize;
@@ -45,9 +70,7 @@ void ScreenLockView::Init() {
views::Background::CreateSolidBackground(login::kBackgroundColor));
// Password field.
- password_field_ = new views::Textfield(views::Textfield::STYLE_PASSWORD);
- password_field_->set_text_to_display_when_empty(
- l10n_util::GetStringUTF16(IDS_LOGIN_EMPTY_PASSWORD_TEXT));
+ password_field_ = new PasswordField();
password_field_->SetController(this);
// Unlock button.
diff --git a/chrome/browser/chromeos/login/screen_locker.cc b/chrome/browser/chromeos/login/screen_locker.cc
index 1ea943a..e8d156a 100644
--- a/chrome/browser/chromeos/login/screen_locker.cc
+++ b/chrome/browser/chromeos/login/screen_locker.cc
@@ -145,6 +145,50 @@ class ScreenLockObserver : public chromeos::ScreenLockLibrary::Observer,
DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver);
};
+// A ScreenLock window that covers entire screen to keeps the keyboard
+// focus/events inside the grab widget.
+class LockWindow : public views::WidgetGtk {
+ public:
+ LockWindow()
+ : WidgetGtk(views::WidgetGtk::TYPE_POPUP),
+ toplevel_focus_widget_(NULL) {
+ }
+
+ // GTK propagates key events from parents to children.
+ // Make sure LockWindow will never handle key events.
+ virtual gboolean OnKeyPress(GtkWidget* widget, GdkEventKey* event) {
+ // Don't handle key event in the lock window.
+ return false;
+ }
+
+ virtual gboolean OnKeyRelease(GtkWidget* widget, GdkEventKey* event) {
+ // Don't handle key event in the lock window.
+ return false;
+ }
+
+ virtual void ClearNativeFocus() {
+ DCHECK(toplevel_focus_widget_);
+ gtk_widget_grab_focus(toplevel_focus_widget_);
+ }
+
+ // Sets the widget to move the focus to when clearning the native
+ // widget's focus.
+ void set_toplevel_focus_widget(GtkWidget* widget) {
+ GTK_WIDGET_SET_FLAGS(widget, GTK_CAN_FOCUS);
+ toplevel_focus_widget_ = widget;
+ }
+
+ private:
+ // The widget we set focus to when clearning the focus on native
+ // widget. In screen locker, gdk input is grabbed in GrabWidget,
+ // and resetting the focus by using gtk_window_set_focus seems to
+ // confuse gtk and doesn't let focus move to native widget under
+ // GrabWidget.
+ GtkWidget* toplevel_focus_widget_;
+
+ DISALLOW_COPY_AND_ASSIGN(LockWindow);
+};
+
// A child widget that grabs both keyboard and pointer input.
// TODO(oshima): catch grab-broke event and quit if it ever happenes.
class GrabWidget : public views::WidgetGtk {
@@ -352,7 +396,8 @@ ScreenLocker::ScreenLocker(const UserManager::User& user)
void ScreenLocker::Init(const gfx::Rect& bounds) {
// TODO(oshima): Figure out which UI to keep and remove in the background.
views::View* screen = new BackgroundView();
- lock_window_ = new views::WidgetGtk(views::WidgetGtk::TYPE_POPUP);
+ LockWindow* lock_window = new LockWindow();
+ lock_window_ = lock_window;
lock_window_->Init(NULL, bounds);
g_signal_connect(lock_window_->GetNativeView(),
"map-event",
@@ -383,7 +428,7 @@ void ScreenLocker::Init(const gfx::Rect& bounds) {
lock_widget_->MakeTransparent();
lock_widget_->InitWithWidget(lock_window_,
gfx::Rect((bounds.width() - size.width()) / 2,
- (bounds.height() - size.width()) / 2,
+ (bounds.height() - size.height()) / 2,
size.width(),
size.height()));
if (screen_lock_view_)
@@ -397,6 +442,7 @@ void ScreenLocker::Init(const gfx::Rect& bounds) {
NULL, false);
gdk_window_set_back_pixmap(lock_widget_->GetNativeView()->window,
NULL, false);
+ lock_window->set_toplevel_focus_widget(lock_widget_->window_contents());
}
void ScreenLocker::OnLoginFailure(const std::string& error) {