diff options
author | suzhe@chromium.org <suzhe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-27 23:12:03 +0000 |
---|---|---|
committer | suzhe@chromium.org <suzhe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-27 23:12:03 +0000 |
commit | 51808efc9c1b88b1a11a4897ef0b7d94c1c52cfc (patch) | |
tree | e487f864205071608948693872e20903dd0c06dd /chrome | |
parent | 9ac400986952037b777600f720f79215ee685037 (diff) | |
download | chromium_src-51808efc9c1b88b1a11a4897ef0b7d94c1c52cfc.zip chromium_src-51808efc9c1b88b1a11a4897ef0b7d94c1c52cfc.tar.gz chromium_src-51808efc9c1b88b1a11a4897ef0b7d94c1c52cfc.tar.bz2 |
[Linux] Handle preedit string in omnibox correctly (part1).
This CL hooks GtkTextView's "preedit-changed" signal (added since 2.20.0) to clear existing selection range when a preedit string is set.
BUG=18808 IME canidate and previous URL will show together in Omnibox when typing Chinese using SCIM
TEST=See bug reports.
Review URL: http://codereview.chromium.org/4190006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64170 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc | 25 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit_view_gtk.h | 9 |
2 files changed, 34 insertions, 0 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc index 0249c6b..e2d085e 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc @@ -304,6 +304,10 @@ void AutocompleteEditViewGtk::Init() { G_CALLBACK(&HandleWidgetDirectionChangedThunk), this); g_signal_connect(text_view_, "delete-from-cursor", G_CALLBACK(&HandleDeleteFromCursorThunk), this); +#if GTK_CHECK_VERSION(2,20,0) + g_signal_connect(text_view_, "preedit-changed", + G_CALLBACK(&HandlePreeditChangedThunk), this); +#endif // Setup for the Instant suggestion text view. instant_view_ = gtk_text_view_new(); @@ -1705,3 +1709,24 @@ void AutocompleteEditViewGtk::UpdatePrimarySelectionIfValidURL() { OwnPrimarySelection(selected_text_); } } + +#if GTK_CHECK_VERSION(2,20,0) +void AutocompleteEditViewGtk::HandlePreeditChanged(GtkWidget* sender, + const gchar* preedit) { + // GtkTextView won't fire "begin-user-action" and "end-user-action" signals + // when changing the preedit string, so we need to call + // OnBeforePossibleChange() and OnAfterPossibleChange() by ourselves. + OnBeforePossibleChange(); + if (preedit && *preedit) { + // GtkTextView will only delete the selection range when committing the + // preedit string, which will cause very strange behavior, so we need to + // delete the selection range here explicitly. See http://crbug.com/18808. + if (preedit_.empty()) + gtk_text_buffer_delete_selection(text_buffer_, false, true); + preedit_ = UTF8ToWide(preedit); + } else { + preedit_.clear(); + } + OnAfterPossibleChange(); +} +#endif diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h index 2cbbc2a..9feec20 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h @@ -211,6 +211,10 @@ class AutocompleteEditViewGtk : public AutocompleteEditView, HandleDeleteFromCursor, GtkDeleteType, gint); CHROMEGTK_CALLBACK_1(AutocompleteEditViewGtk, gboolean, HandleInstantViewButtonPress, GdkEventButton*); +#if GTK_CHECK_VERSION(2,20,0) + CHROMEGTK_CALLBACK_1(AutocompleteEditViewGtk, void, HandlePreeditChanged, + const gchar*); +#endif // Callback for the PRIMARY selection clipboard. static void ClipboardGetSelectionThunk(GtkClipboard* clipboard, @@ -422,6 +426,11 @@ class AutocompleteEditViewGtk : public AutocompleteEditView, // is not suggested text, that means the user manually made the selection. bool selection_suggested_; +#if GTK_CHECK_VERSION(2,20,0) + // Stores the text being composed by the input method. + std::wstring preedit_; +#endif + DISALLOW_COPY_AND_ASSIGN(AutocompleteEditViewGtk); }; |