From e1d081d0a287a7c5541af2c46444f73f2957cd41 Mon Sep 17 00:00:00 2001 From: "suzhe@chromium.org" Date: Tue, 2 Nov 2010 21:57:59 +0000 Subject: [Linux] Improve preedit string and Instant suggestion support in omnibox. This CL contains following major changes: 1. Uses GtkLabel instead of GtkTextView for displaying instant suggestion. 2. Attaches the instant view to a child anchor in the text view. 3. Treats preedit string as part of user input, so that autocomplete match can take effect with uncommitted preedit string. BUG=27547 TEST=Instant suggestion should work as normal. And preedit string should trigger autocomplete match and work with Instant suggestion. Review URL: http://codereview.chromium.org/4202005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64825 0039d316-1c4b-4281-b951-d872f2087c98 --- .../autocomplete/autocomplete_edit_view_gtk.h | 46 +++++++++++++++++----- 1 file changed, 36 insertions(+), 10 deletions(-) (limited to 'chrome/browser/autocomplete/autocomplete_edit_view_gtk.h') diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h index 34dd01c..07e0ed3 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h @@ -174,6 +174,12 @@ class AutocompleteEditViewGtk : public AutocompleteEditView, GtkTextBuffer*, GtkTextIter*, const gchar*, gint); CHROMEG_CALLBACK_0(AutocompleteEditViewGtk, void, HandleKeymapDirectionChanged, GdkKeymap*); + CHROMEG_CALLBACK_2(AutocompleteEditViewGtk, void, HandleDeleteRange, + GtkTextBuffer*, GtkTextIter*, GtkTextIter*); + // Unlike above HandleMarkSet and HandleMarkSetAfter, this handler will always + // be connected to the signal. + CHROMEG_CALLBACK_2(AutocompleteEditViewGtk, void, HandleMarkSetAlways, + GtkTextBuffer*, GtkTextIter*, GtkTextMark*); CHROMEGTK_CALLBACK_1(AutocompleteEditViewGtk, gboolean, HandleKeyPress, GdkEventKey*); @@ -214,12 +220,16 @@ class AutocompleteEditViewGtk : public AutocompleteEditView, // 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) +#if GTK_CHECK_VERSION(2, 20, 0) CHROMEGTK_CALLBACK_1(AutocompleteEditViewGtk, void, HandlePreeditChanged, const gchar*); #endif + // Undo/redo operations won't trigger "begin-user-action" and + // "end-user-action" signals, so we need to hook into "undo" and "redo" + // signals and call OnBeforePossibleChange()/OnAfterPossibleChange() by + // ourselves. + CHROMEGTK_CALLBACK_0(AutocompleteEditViewGtk, void, HandleUndoRedo); + CHROMEGTK_CALLBACK_0(AutocompleteEditViewGtk, void, HandleUndoRedoAfter); CHROMEG_CALLBACK_1(AutocompleteEditViewGtk, void, HandleWindowSetFocus, GtkWindow*, GtkWidget*); @@ -269,10 +279,7 @@ class AutocompleteEditViewGtk : public AutocompleteEditView, GtkTextIter* iter_max); // Return the number of characers in the current buffer. - int GetTextLength(); - - // Get the string contents for the given buffer. - std::wstring GetTextFromBuffer(GtkTextBuffer* buffer) const; + int GetTextLength() const; // Try to parse the current text as a URL and colorize the components. void EmphasizeURLComponents(); @@ -306,6 +313,18 @@ class AutocompleteEditViewGtk : public AutocompleteEditView, // If the selected text parses as a URL OwnPrimarySelection is invoked. void UpdatePrimarySelectionIfValidURL(); + // Retrieves the first and last iterators in the |text_buffer_|, but excludes + // the anchor holding the |instant_view_| widget. + void GetTextBufferBounds(GtkTextIter* start, GtkTextIter* end) const; + + // Validates an iterator in the |text_buffer_|, to make sure it doesn't go + // beyond the anchor for holding the |instant_view_| widget. + void ValidateTextBufferIter(GtkTextIter* iter) const; + + // Adjusts vertical alignment of the |instant_view_| in the |text_view_|, to + // make sure they have the same baseline. + void AdjustVerticalAlignmentOfInstantView(); + // The widget we expose, used for vertically centering the real text edit, // since the height will change based on the font / font size, etc. OwnedWidgetGtk alignment_; @@ -321,9 +340,16 @@ class AutocompleteEditViewGtk : public AutocompleteEditView, GtkTextTag* normal_text_tag_; // Objects for the instant suggestion text view. + GtkTextTag* instant_anchor_tag_; + + // A widget for displaying instant suggestion text. It'll be attached to a + // child anchor in the |text_buffer_| object. GtkWidget* instant_view_; - GtkTextBuffer* instant_buffer_; - GtkTextTag* instant_text_tag_; + + // A mark to split the content and the instant anchor. Wherever the end + // iterator of the text buffer is required, the iterator to this mark should + // be used. + GtkTextMark* instant_mark_; scoped_ptr model_; scoped_ptr popup_view_; @@ -434,7 +460,7 @@ 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) +#if GTK_CHECK_VERSION(2, 20, 0) // Stores the text being composed by the input method. std::wstring preedit_; #endif -- cgit v1.1