diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-01 20:35:08 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-01 20:35:08 +0000 |
commit | ba6680fcdf06ea6bbb14e78f6b32d79e6d57c03e (patch) | |
tree | 64a6413c070f83fd9c47046092c810f4155f51cb /chrome/browser/autocomplete | |
parent | 9852f63e347fb158463f4437b7ee9422384f02e6 (diff) | |
download | chromium_src-ba6680fcdf06ea6bbb14e78f6b32d79e6d57c03e.zip chromium_src-ba6680fcdf06ea6bbb14e78f6b32d79e6d57c03e.tar.gz chromium_src-ba6680fcdf06ea6bbb14e78f6b32d79e6d57c03e.tar.bz2 |
Instant - move AutocompleteLosingFocus implementation to InstantController.
This way Linux and Windows can share.
BUG=58937
TEST=manual
Review URL: http://codereview.chromium.org/4157004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64657 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc | 33 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit_view_gtk.h | 14 |
2 files changed, 44 insertions, 3 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc index 6cc084f..422aadd6 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc @@ -23,6 +23,7 @@ #include "chrome/browser/defaults.h" #include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/view_id_util.h" +#include "chrome/browser/platform_util.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/toolbar_model.h" #include "chrome/common/notification_service.h" @@ -176,7 +177,8 @@ AutocompleteEditViewGtk::AutocompleteEditViewGtk( paste_clipboard_requested_(false), enter_was_inserted_(false), enable_tab_to_search_(true), - selection_suggested_(false) { + selection_suggested_(false), + going_to_focus_(NULL) { model_->SetPopupModel(popup_view_->GetModel()); } @@ -301,6 +303,8 @@ void AutocompleteEditViewGtk::Init() { G_CALLBACK(&HandleWidgetDirectionChangedThunk), this); g_signal_connect(text_view_, "delete-from-cursor", G_CALLBACK(&HandleDeleteFromCursorThunk), this); + g_signal_connect(text_view_, "hierarchy-changed", + G_CALLBACK(&HandleHierarchyChangedThunk), this); #if GTK_CHECK_VERSION(2,20,0) g_signal_connect(text_view_, "preedit-changed", G_CALLBACK(&HandlePreeditChangedThunk), this); @@ -333,6 +337,17 @@ void AutocompleteEditViewGtk::Init() { ViewIDUtil::SetID(GetNativeView(), VIEW_ID_AUTOCOMPLETE); } +void AutocompleteEditViewGtk::HandleHierarchyChanged( + GtkWidget* sender, GtkWidget* old_toplevel) { + GtkWindow* new_toplevel = platform_util::GetTopLevel(sender); + if (!new_toplevel) + return; + + // Use |signals_| to make sure we don't get called back after destruction. + signals_.Connect(new_toplevel, "set-focus", + G_CALLBACK(&HandleWindowSetFocusThunk), this); +} + void AutocompleteEditViewGtk::SetFocus() { gtk_widget_grab_focus(text_view_); } @@ -962,9 +977,13 @@ gboolean AutocompleteEditViewGtk::HandleViewFocusIn(GtkWidget* sender, gboolean AutocompleteEditViewGtk::HandleViewFocusOut(GtkWidget* sender, GdkEventFocus* event) { + GtkWidget* view_getting_focus = NULL; + GtkWindow* toplevel = platform_util::GetTopLevel(sender); + if (gtk_window_is_active(toplevel)) + view_getting_focus = going_to_focus_; + // This must be invoked before ClosePopup. - // TODO: figure out who is getting focus. - controller_->OnAutocompleteLosingFocus(NULL); + controller_->OnAutocompleteLosingFocus(view_getting_focus); // Close the popup. ClosePopup(); @@ -1732,3 +1751,11 @@ void AutocompleteEditViewGtk::HandlePreeditChanged(GtkWidget* sender, OnAfterPossibleChange(); } #endif + +void AutocompleteEditViewGtk::HandleWindowSetFocus( + GtkWindow* sender, GtkWidget* focus) { + // This is actually a guess. If the focused widget changes in "focus-out" + // event handler, then the window will respect that and won't focus + // |focus|. I doubt that is likely to happen however. + going_to_focus_ = focus; +} diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h index 9feec20..34dd01c 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h @@ -12,6 +12,7 @@ #include <string> #include "app/gtk_signal.h" +#include "app/gtk_signal_registrar.h" #include "base/basictypes.h" #include "base/scoped_ptr.h" #include "base/string_util.h" @@ -209,6 +210,10 @@ class AutocompleteEditViewGtk : public AutocompleteEditView, HandleWidgetDirectionChanged, GtkTextDirection); CHROMEGTK_CALLBACK_2(AutocompleteEditViewGtk, void, HandleDeleteFromCursor, GtkDeleteType, gint); + // We connect to this so we can determine our toplevel window, so we can + // listen to focus change events on it. + CHROMEGTK_CALLBACK_1(AutocompleteEditViewGtk, void, HandleHierarchyChanged, + GtkWidget*); CHROMEGTK_CALLBACK_1(AutocompleteEditViewGtk, gboolean, HandleInstantViewButtonPress, GdkEventButton*); #if GTK_CHECK_VERSION(2,20,0) @@ -216,6 +221,9 @@ class AutocompleteEditViewGtk : public AutocompleteEditView, const gchar*); #endif + CHROMEG_CALLBACK_1(AutocompleteEditViewGtk, void, HandleWindowSetFocus, + GtkWindow*, GtkWidget*); + // Callback for the PRIMARY selection clipboard. static void ClipboardGetSelectionThunk(GtkClipboard* clipboard, GtkSelectionData* selection_data, @@ -431,6 +439,12 @@ class AutocompleteEditViewGtk : public AutocompleteEditView, std::wstring preedit_; #endif + // The view that is going to be focused next. Only valid while handling + // "focus-out" events. + GtkWidget* going_to_focus_; + + GtkSignalRegistrar signals_; + DISALLOW_COPY_AND_ASSIGN(AutocompleteEditViewGtk); }; |