diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-01 22:53:51 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-01 22:53:51 +0000 |
commit | dc5e89230025a8202e0314410a388ad91138020c (patch) | |
tree | 41630518a44295112141de14f595c50e11fb84de /views/widget | |
parent | 668dd15b25cf7fd94fede92dd140b59c62009390 (diff) | |
download | chromium_src-dc5e89230025a8202e0314410a388ad91138020c.zip chromium_src-dc5e89230025a8202e0314410a388ad91138020c.tar.gz chromium_src-dc5e89230025a8202e0314410a388ad91138020c.tar.bz2 |
The FocusManager stores/restores focus when the top window becomes inactive/active.
BUG=None
TEST=Run the focus manager unit-tests.
Review URL: http://codereview.chromium.org/164448
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25108 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/widget')
-rw-r--r-- | views/widget/root_view.cc | 7 | ||||
-rw-r--r-- | views/widget/widget_gtk.cc | 18 | ||||
-rw-r--r-- | views/widget/widget_gtk.h | 14 |
3 files changed, 24 insertions, 15 deletions
diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc index a0d19ca..4469051 100644 --- a/views/widget/root_view.cc +++ b/views/widget/root_view.cc @@ -510,19 +510,12 @@ void RootView::ProcessMouseDragCanceled() { void RootView::FocusView(View* view) { if (view != GetFocusedView()) { -#if defined(OS_WIN) FocusManager* focus_manager = GetFocusManager(); DCHECK(focus_manager) << "No Focus Manager for Window " << (GetWidget() ? GetWidget()->GetNativeView() : 0); if (!focus_manager) return; - - View* prev_focused_view = focus_manager->GetFocusedView(); focus_manager->SetFocusedView(view); -#else - // TODO(port): Port the focus manager and this goes away. - NOTIMPLEMENTED(); -#endif } } diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc index 7ab2c31..49720f3 100644 --- a/views/widget/widget_gtk.cc +++ b/views/widget/widget_gtk.cc @@ -570,6 +570,24 @@ gboolean WidgetGtk::OnButtonRelease(GtkWidget* widget, GdkEventButton* event) { return true; } +gboolean WidgetGtk::OnFocusIn(GtkWidget* widget, GdkEventFocus* event) { + if (type_ == TYPE_CHILD) + return false; + + // The top-level window got focus, restore the last focused view. + focus_manager_->RestoreFocusedView(); + return false; +} + +gboolean WidgetGtk::OnFocusOut(GtkWidget* widget, GdkEventFocus* event) { + if (type_ == TYPE_CHILD) + return false; + + // The top-level window lost focus, store the focused view. + focus_manager_->StoreFocusedView(); + return false; +} + void WidgetGtk::OnPaint(GtkWidget* widget, GdkEventExpose* event) { root_view_->OnPaint(event); } diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h index a7e905e..7a3738a 100644 --- a/views/widget/widget_gtk.h +++ b/views/widget/widget_gtk.h @@ -110,6 +110,9 @@ class WidgetGtk : public Widget, public MessageLoopForUI::Observer { virtual void WillProcessEvent(GdkEvent* event); virtual void DidProcessEvent(GdkEvent* event); + // Retrieves the WidgetGtk associated with |widget|. + static WidgetGtk* GetViewForNative(GtkWidget* widget); + // Retrieves the WindowGtk associated with |widget|. static WindowGtk* GetWindowForNative(GtkWidget* widget); @@ -148,12 +151,8 @@ class WidgetGtk : public Widget, public MessageLoopForUI::Observer { virtual gboolean OnMotionNotify(GtkWidget* widget, GdkEventMotion* event); virtual gboolean OnButtonPress(GtkWidget* widget, GdkEventButton* event); virtual gboolean OnButtonRelease(GtkWidget* widget, GdkEventButton* event); - virtual gboolean OnFocusIn(GtkWidget* widget, GdkEventFocus* event) { - return false; - } - virtual gboolean OnFocusOut(GtkWidget* widget, GdkEventFocus* event) { - return false; - } + virtual gboolean OnFocusIn(GtkWidget* widget, GdkEventFocus* event); + virtual gboolean OnFocusOut(GtkWidget* widget, GdkEventFocus* event); virtual gboolean OnKeyPress(GtkWidget* widget, GdkEventKey* event); virtual gboolean OnKeyRelease(GtkWidget* widget, GdkEventKey* event); virtual gboolean OnScroll(GtkWidget* widget, GdkEventScroll* event) { @@ -200,8 +199,7 @@ class WidgetGtk : public Widget, public MessageLoopForUI::Observer { bool ProcessMousePressed(GdkEventButton* event); void ProcessMouseReleased(GdkEventButton* event); - // Sets and retrieves the WidgetGtk in the userdata section of the widget. - static WidgetGtk* GetViewForNative(GtkWidget* widget); + // Sets the WidgetGtk in the userdata section of the widget. static void SetViewForNative(GtkWidget* widget, WidgetGtk* view); static RootView* GetRootViewForWidget(GtkWidget* widget); |