diff options
author | jered@chromium.org <jered@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-11 15:11:41 +0000 |
---|---|---|
committer | jered@chromium.org <jered@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-11 15:11:41 +0000 |
commit | b1a843a461ca94274a5a1959a0c0aea71463545a (patch) | |
tree | 62660ce4db28185fa07fa2a11980342e92c79adc | |
parent | a6da59e8dd0de10af11b469f392fbfa1cce66fd9 (diff) | |
download | chromium_src-b1a843a461ca94274a5a1959a0c0aea71463545a.zip chromium_src-b1a843a461ca94274a5a1959a0c0aea71463545a.tar.gz chromium_src-b1a843a461ca94274a5a1959a0c0aea71463545a.tar.bz2 |
InstantExtended: Omnibox and location bar cleanup.
Remove the methods previously used to poke an InstantSuggestion object
into the OmniboxEditModel through the LocationBar, since we're not doing
that anymore. Keep but rename the view and model methods to draw gray
text and deal with committing it, since it seems likely we'll revisit
that UI; but rename methods which call gray text the "instant
suggestion" to "gray text", since this is a generic autocompletion
behavior not specific to Instant.
BUG=251262
TEST=none
R=erg@chromium.org, pkasting@chromium.org, shess@chromium.org, sky@chromium.org
Review URL: https://codereview.chromium.org/18923004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@211117 0039d316-1c4b-4281-b951-d872f2087c98
31 files changed, 162 insertions, 346 deletions
diff --git a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h index eadb217..cf21ce0 100644 --- a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h +++ b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h @@ -155,8 +155,8 @@ class AutocompleteTextFieldObserver { // Sets the suggest text that shows at the end of the field's normal text. // This can't be simply appended to the field's text storage because that // will end any pending IME session. -- (void)setInstantSuggestion:(NSString*)suggestText - textColor:(NSColor*)suggestColor; +- (void)setGrayTextAutocompletion:(NSString*)suggestText + textColor:(NSColor*)suggestColor; - (NSString*)suggestText; - (NSColor*)suggestColor; @@ -165,12 +165,12 @@ class AutocompleteTextFieldObserver { namespace autocomplete_text_field { -// Draw instant suggestion text in |controlView|. -void DrawInstantSuggestion(NSAttributedString* mainText, - NSString* suggestText, - NSColor* suggestColor, - NSView* controlView, - NSRect frame); +// Draw gray text suggestion in |controlView|. +void DrawGrayTextAutocompletion(NSAttributedString* mainText, + NSString* suggestText, + NSColor* suggestColor, + NSView* controlView, + NSRect frame); } // namespace autocomplete_text_field diff --git a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.mm b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.mm index addda9c..ee2dc0f0 100644 --- a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.mm +++ b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.mm @@ -234,8 +234,8 @@ [self addToolTipRect:aRect owner:tooltip userData:nil]; } -- (void)setInstantSuggestion:(NSString*)suggestText - textColor:(NSColor*)suggestColor { +- (void)setGrayTextAutocompletion:(NSString*)suggestText + textColor:(NSColor*)suggestColor { [self setNeedsDisplay:YES]; suggestText_.reset([suggestText retain]); suggestColor_.reset([suggestColor retain]); @@ -388,7 +388,7 @@ - (void)drawRect:(NSRect)rect { [super drawRect:rect]; - autocomplete_text_field::DrawInstantSuggestion( + autocomplete_text_field::DrawGrayTextAutocompletion( [self attributedStringValue], suggestText_, suggestColor_, @@ -441,11 +441,11 @@ namespace autocomplete_text_field { -void DrawInstantSuggestion(NSAttributedString* mainText, - NSString* suggestText, - NSColor* suggestColor, - NSView* controlView, - NSRect frame) { +void DrawGrayTextAutocompletion(NSAttributedString* mainText, + NSString* suggestText, + NSColor* suggestColor, + NSView* controlView, + NSRect frame) { if (![suggestText length]) return; diff --git a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm index 1c7b087..9e67806 100644 --- a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm +++ b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm @@ -539,7 +539,7 @@ BOOL ThePasteboardIsTooDamnBig() { - (void)drawRect:(NSRect)rect { [super drawRect:rect]; - autocomplete_text_field::DrawInstantSuggestion( + autocomplete_text_field::DrawGrayTextAutocompletion( [self textStorage], [[self delegate] suggestText], [[self delegate] suggestColor], diff --git a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor_unittest.mm b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor_unittest.mm index dac079a..b2382f3 100644 --- a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor_unittest.mm +++ b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor_unittest.mm @@ -188,11 +188,11 @@ TEST_F(AutocompleteTextFieldEditorTest, Display) { [editor_ display]; } -// Test setting instant suggestion, mostly to ensure nothing leaks or crashes. -TEST_F(AutocompleteTextFieldEditorTest, InstantSuggestion) { +// Test setting gray text, mostly to ensure nothing leaks or crashes. +TEST_F(AutocompleteTextFieldEditorTest, GrayText) { [editor_ display]; EXPECT_FALSE([editor_ needsDisplay]); - [field_ setInstantSuggestion:@"foo" textColor:[NSColor redColor]]; + [field_ setGrayTextAutocompletion:@"foo" textColor:[NSColor redColor]]; EXPECT_TRUE([editor_ needsDisplay]); [editor_ display]; } diff --git a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_unittest.mm b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_unittest.mm index 72ffc7a..f6673977 100644 --- a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_unittest.mm +++ b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_unittest.mm @@ -217,11 +217,11 @@ TEST_F(AutocompleteTextFieldTest, Display) { [field_ display]; } -// Test setting instant suggestion, mostly to ensure nothing leaks or crashes. -TEST_F(AutocompleteTextFieldTest, InstantSuggestion) { +// Test setting gray text, mostly to ensure nothing leaks or crashes. +TEST_F(AutocompleteTextFieldTest, GrayText) { [field_ display]; EXPECT_FALSE([field_ needsDisplay]); - [field_ setInstantSuggestion:@"foo" textColor:[NSColor redColor]]; + [field_ setGrayTextAutocompletion:@"foo" textColor:[NSColor redColor]]; EXPECT_TRUE([field_ needsDisplay]); [field_ display]; } diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h index 3948654..5d52480 100644 --- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h +++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h @@ -54,8 +54,6 @@ class LocationBarViewMac : public LocationBar, // Overridden from LocationBar: virtual void ShowFirstRunBubble() OVERRIDE; - virtual void SetInstantSuggestion( - const InstantSuggestion& suggestion) OVERRIDE; virtual string16 GetInputString() const OVERRIDE; virtual WindowOpenDisposition GetWindowOpenDisposition() const OVERRIDE; virtual content::PageTransition GetPageTransition() const OVERRIDE; diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm index 8e871d2..477b6a6 100644 --- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm +++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm @@ -165,11 +165,6 @@ string16 LocationBarViewMac::GetInputString() const { return location_input_; } -void LocationBarViewMac::SetInstantSuggestion( - const InstantSuggestion& suggestion) { - omnibox_view_->model()->SetInstantSuggestion(suggestion); -} - WindowOpenDisposition LocationBarViewMac::GetWindowOpenDisposition() const { return disposition_; } diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h index 0012560..b52da56 100644 --- a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h +++ b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h @@ -60,8 +60,8 @@ class OmniboxViewMac : public OmniboxView, virtual bool OnAfterPossibleChange() OVERRIDE; virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual gfx::NativeView GetRelativeWindowForPopup() const OVERRIDE; - virtual void SetInstantSuggestion(const string16& input) OVERRIDE; - virtual string16 GetInstantSuggestion() const OVERRIDE; + virtual void SetGrayTextAutocompletion(const string16& input) OVERRIDE; + virtual string16 GetGrayTextAutocompletion() const OVERRIDE; virtual int TextWidth() const OVERRIDE; virtual bool IsImeComposing() const OVERRIDE; diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm index 7a2ce85..e0bc46d 100644 --- a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm +++ b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm @@ -525,16 +525,9 @@ bool OmniboxViewMac::OnInlineAutocompleteTextMaybeChanged( void OmniboxViewMac::OnRevertTemporaryText() { SetSelectedRange(saved_temporary_selection_); // We got here because the user hit the Escape key. We explicitly don't call - // TextChanged(), since calling it breaks Instant-Extended, and isn't needed - // otherwise (in regular non-Instant or Instant-but-not-Extended modes). - // - // Why it breaks Instant-Extended: Instant handles the Escape key separately - // (cf: OmniboxEditModel::RevertTemporaryText). Calling TextChanged() makes - // the page think the user additionally typed some text, causing it to update - // its suggestions dropdown with new suggestions, which is wrong. - // - // Why it isn't needed: OmniboxPopupModel::ResetToDefaultMatch() has already - // been called by now; it would've called TextChanged() if it was warranted. + // TextChanged(), since OmniboxPopupModel::ResetToDefaultMatch() has already + // been called by now, and it would've called TextChanged() if it was + // warranted. } bool OmniboxViewMac::IsFirstResponder() const { @@ -611,15 +604,15 @@ gfx::NativeView OmniboxViewMac::GetRelativeWindowForPopup() const { return NULL; } -void OmniboxViewMac::SetInstantSuggestion(const string16& suggest_text) { +void OmniboxViewMac::SetGrayTextAutocompletion(const string16& suggest_text) { if (suggest_text == suggest_text_) return; suggest_text_ = suggest_text; - [field_ setInstantSuggestion:base::SysUTF16ToNSString(suggest_text) - textColor:SuggestTextColor()]; + [field_ setGrayTextAutocompletion:base::SysUTF16ToNSString(suggest_text) + textColor:SuggestTextColor()]; } -string16 OmniboxViewMac::GetInstantSuggestion() const { +string16 OmniboxViewMac::GetGrayTextAutocompletion() const { return suggest_text_; } diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac_unittest.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac_unittest.mm index e9d77a3..de9f42a 100644 --- a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac_unittest.mm +++ b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac_unittest.mm @@ -144,7 +144,7 @@ TEST_F(OmniboxViewMacTest, TabToAutocomplete) { EXPECT_EQ(-1, model->up_or_down_count()); } -TEST_F(OmniboxViewMacTest, SetInstantSuggestion) { +TEST_F(OmniboxViewMacTest, SetGrayTextAutocompletion) { const NSRect frame = NSMakeRect(0, 0, 50, 30); base::scoped_nsobject<AutocompleteTextField> field( [[AutocompleteTextField alloc] initWithFrame:frame]); @@ -164,13 +164,13 @@ TEST_F(OmniboxViewMacTest, SetInstantSuggestion) { view.SetUserText(ASCIIToUTF16("Alfred")); EXPECT_EQ("Alfred", UTF16ToUTF8(view.GetText())); - view.SetInstantSuggestion(ASCIIToUTF16(" Hitchcock")); + view.SetGrayTextAutocompletion(ASCIIToUTF16(" Hitchcock")); EXPECT_EQ("Alfred", UTF16ToUTF8(view.GetText())); - EXPECT_EQ(" Hitchcock", UTF16ToUTF8(view.GetInstantSuggestion())); + EXPECT_EQ(" Hitchcock", UTF16ToUTF8(view.GetGrayTextAutocompletion())); view.SetUserText(string16()); EXPECT_EQ(string16(), view.GetText()); - EXPECT_EQ(string16(), view.GetInstantSuggestion()); + EXPECT_EQ(string16(), view.GetGrayTextAutocompletion()); } TEST_F(OmniboxViewMacTest, UpDownArrow) { diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.cc b/chrome/browser/ui/gtk/location_bar_view_gtk.cc index 66500a4..a0a0ab5 100644 --- a/chrome/browser/ui/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/ui/gtk/location_bar_view_gtk.cc @@ -860,11 +860,6 @@ void LocationBarViewGtk::ShowFirstRunBubble() { weak_ptr_factory_.GetWeakPtr())); } -void LocationBarViewGtk::SetInstantSuggestion( - const InstantSuggestion& suggestion) { - location_entry_->model()->SetInstantSuggestion(suggestion); -} - string16 LocationBarViewGtk::GetInputString() const { return location_input_; } diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.h b/chrome/browser/ui/gtk/location_bar_view_gtk.h index 2e4bbf4..30ca178 100644 --- a/chrome/browser/ui/gtk/location_bar_view_gtk.h +++ b/chrome/browser/ui/gtk/location_bar_view_gtk.h @@ -130,8 +130,6 @@ class LocationBarViewGtk : public OmniboxEditController, // LocationBar: virtual void ShowFirstRunBubble() OVERRIDE; - virtual void SetInstantSuggestion( - const InstantSuggestion& suggestion) OVERRIDE; virtual string16 GetInputString() const OVERRIDE; virtual WindowOpenDisposition GetWindowOpenDisposition() const OVERRIDE; virtual content::PageTransition GetPageTransition() const OVERRIDE; diff --git a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc index b1b5045..cbcd650 100644 --- a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc +++ b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc @@ -191,9 +191,9 @@ OmniboxViewGtk::OmniboxViewGtk(OmniboxEditController* controller, secure_scheme_tag_(NULL), security_error_scheme_tag_(NULL), normal_text_tag_(NULL), - instant_anchor_tag_(NULL), - instant_view_(NULL), - instant_mark_(NULL), + gray_text_anchor_tag_(NULL), + gray_text_view_(NULL), + gray_text_mark_(NULL), popup_window_mode_(popup_window_mode), security_level_(ToolbarModel::NONE), mark_set_handler_id_(0), @@ -362,46 +362,46 @@ void OmniboxViewGtk::Init() { g_signal_connect(text_view_, "destroy", G_CALLBACK(>k_widget_destroyed), &text_view_); - // Setup for the Instant suggestion text view. + // Setup for the gray suggestion text view. // GtkLabel is used instead of GtkTextView to get transparent background. - instant_view_ = gtk_label_new(NULL); - gtk_widget_set_no_show_all(instant_view_, TRUE); - gtk_label_set_selectable(GTK_LABEL(instant_view_), TRUE); + gray_text_view_ = gtk_label_new(NULL); + gtk_widget_set_no_show_all(gray_text_view_, TRUE); + gtk_label_set_selectable(GTK_LABEL(gray_text_view_), TRUE); GtkTextIter end_iter; gtk_text_buffer_get_end_iter(text_buffer_, &end_iter); - // Insert a Zero Width Space character just before the Instant anchor. + // Insert a Zero Width Space character just before the gray text anchor. // It's a hack to workaround a bug of GtkTextView which can not align the // pre-edit string and a child anchor correctly when there is no other content // around the pre-edit string. gtk_text_buffer_insert(text_buffer_, &end_iter, "\342\200\213", -1); - GtkTextChildAnchor* instant_anchor = + GtkTextChildAnchor* gray_text_anchor = gtk_text_buffer_create_child_anchor(text_buffer_, &end_iter); gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(text_view_), - instant_view_, - instant_anchor); + gray_text_view_, + gray_text_anchor); - instant_anchor_tag_ = gtk_text_buffer_create_tag(text_buffer_, NULL, NULL); + gray_text_anchor_tag_ = gtk_text_buffer_create_tag(text_buffer_, NULL, NULL); GtkTextIter anchor_iter; gtk_text_buffer_get_iter_at_child_anchor(text_buffer_, &anchor_iter, - instant_anchor); - gtk_text_buffer_apply_tag(text_buffer_, instant_anchor_tag_, + gray_text_anchor); + gtk_text_buffer_apply_tag(text_buffer_, gray_text_anchor_tag_, &anchor_iter, &end_iter); GtkTextIter start_iter; gtk_text_buffer_get_start_iter(text_buffer_, &start_iter); - instant_mark_ = + gray_text_mark_ = gtk_text_buffer_create_mark(text_buffer_, NULL, &start_iter, FALSE); - // Hooking up this handler after setting up above hacks for Instant view, so + // Hooking up this handler after setting up above hacks for gray text view, so // that we won't filter out the special ZWP mark itself. g_signal_connect(text_buffer_, "insert-text", G_CALLBACK(&HandleInsertTextThunk), this); - AdjustVerticalAlignmentOfInstantView(); + AdjustVerticalAlignmentOfGrayTextView(); registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, @@ -606,16 +606,9 @@ void OmniboxViewGtk::OnRevertTemporaryText() { SetSelectedRange(saved_temporary_selection_); FinishUpdatingHighlightedText(); // We got here because the user hit the Escape key. We explicitly don't call - // TextChanged(), since calling it breaks Instant-Extended, and isn't needed - // otherwise (in regular non-Instant or Instant-but-not-Extended modes). - // - // Why it breaks Instant-Extended: Instant handles the Escape key separately - // (cf: OmniboxEditModel::RevertTemporaryText). Calling TextChanged() makes - // the page think the user additionally typed some text, causing it to update - // its suggestions dropdown with new suggestions, which is wrong. - // - // Why it isn't needed: OmniboxPopupModel::ResetToDefaultMatch() has already - // been called by now; it would've called TextChanged() if it was warranted. + // TextChanged(), since OmniboxPopupModel::ResetToDefaultMatch() has already + // been called by now, and it would've called TextChanged() if it was + // warranted. } void OmniboxViewGtk::OnBeforePossibleChange() { @@ -721,23 +714,23 @@ gfx::NativeView OmniboxViewGtk::GetRelativeWindowForPopup() const { return toplevel; } -void OmniboxViewGtk::SetInstantSuggestion(const string16& suggestion) { +void OmniboxViewGtk::SetGrayTextAutocompletion(const string16& suggestion) { std::string suggestion_utf8 = UTF16ToUTF8(suggestion); - gtk_label_set_text(GTK_LABEL(instant_view_), suggestion_utf8.c_str()); + gtk_label_set_text(GTK_LABEL(gray_text_view_), suggestion_utf8.c_str()); if (suggestion.empty()) { - gtk_widget_hide(instant_view_); + gtk_widget_hide(gray_text_view_); return; } - gtk_widget_show(instant_view_); - AdjustVerticalAlignmentOfInstantView(); - UpdateInstantViewColors(); + gtk_widget_show(gray_text_view_); + AdjustVerticalAlignmentOfGrayTextView(); + UpdateGrayTextViewColors(); } -string16 OmniboxViewGtk::GetInstantSuggestion() const { - const gchar* suggestion = gtk_label_get_text(GTK_LABEL(instant_view_)); +string16 OmniboxViewGtk::GetGrayTextAutocompletion() const { + const gchar* suggestion = gtk_label_get_text(GTK_LABEL(gray_text_view_)); return suggestion ? UTF8ToUTF16(suggestion) : string16(); } @@ -761,8 +754,8 @@ int OmniboxViewGtk::TextWidth() const { GdkRectangle first_char_bounds, last_char_bounds; gtk_text_buffer_get_start_iter(text_buffer_, &start); - // Use the real end iterator here to take the width of Instant suggestion - // text into account, so that location bar can layout its children correctly. + // Use the real end iterator here to take the width of gray suggestion text + // into account, so that location bar can layout its children correctly. gtk_text_buffer_get_end_iter(text_buffer_, &end); gtk_text_view_get_iter_location(GTK_TEXT_VIEW(text_view_), &start, &first_char_bounds); @@ -811,7 +804,7 @@ void OmniboxViewGtk::SetBaseColor() { gtk_widget_modify_text(text_view_, GTK_STATE_ACTIVE, NULL); gtk_util::UndoForceFontSize(text_view_); - gtk_util::UndoForceFontSize(instant_view_); + gtk_util::UndoForceFontSize(gray_text_view_); // Grab the text colors out of the style and set our tags to use them. GtkStyle* style = gtk_rc_get_style(text_view_); @@ -851,26 +844,26 @@ void OmniboxViewGtk::SetBaseColor() { // Until we switch to vector graphics, force the font size. gtk_util::ForceFontSizePixels(text_view_, GetFont().GetFontSize()); - gtk_util::ForceFontSizePixels(instant_view_, GetFont().GetFontSize()); + gtk_util::ForceFontSizePixels(gray_text_view_, GetFont().GetFontSize()); g_object_set(faded_text_tag_, "foreground", kTextBaseColor, NULL); g_object_set(normal_text_tag_, "foreground", "#000000", NULL); } - AdjustVerticalAlignmentOfInstantView(); - UpdateInstantViewColors(); + AdjustVerticalAlignmentOfGrayTextView(); + UpdateGrayTextViewColors(); } -void OmniboxViewGtk::UpdateInstantViewColors() { +void OmniboxViewGtk::UpdateGrayTextViewColors() { GdkColor faded_text; if (theme_service_->UsingNativeTheme()) { - GtkStyle* style = gtk_rc_get_style(instant_view_); + GtkStyle* style = gtk_rc_get_style(gray_text_view_); faded_text = gtk_util::AverageColors( style->text[GTK_STATE_NORMAL], style->base[GTK_STATE_NORMAL]); } else { gdk_color_parse(kTextBaseColor, &faded_text); } - gtk_widget_modify_fg(instant_view_, GTK_STATE_NORMAL, &faded_text); + gtk_widget_modify_fg(gray_text_view_, GTK_STATE_NORMAL, &faded_text); } void OmniboxViewGtk::HandleBeginUserAction(GtkTextBuffer* sender) { @@ -1472,7 +1465,7 @@ void OmniboxViewGtk::HandleInsertText(GtkTextBuffer* buffer, p = g_utf8_next_char(p)) { gunichar c = g_utf8_get_char(p); - // 0x200B is Zero Width Space, which is inserted just before the Instant + // 0x200B is Zero Width Space, which is inserted just before the gray text // anchor for working around the GtkTextView's misalignment bug. // This character might be captured and inserted into the content by undo // manager, so we need to filter it out here. @@ -1489,7 +1482,7 @@ void OmniboxViewGtk::HandleInsertText(GtkTextBuffer* buffer, } if (!filtered_text.empty()) { - // Avoid inserting the text after the Instant anchor. + // Avoid inserting the text after the gray text anchor. ValidateTextBufferIter(location); // Call the default handler to insert filtered text. @@ -1558,7 +1551,7 @@ void OmniboxViewGtk::HandleViewMoveFocus(GtkWidget* widget, if (supports_pre_edit_ && !handled && !pre_edit_.empty()) handled = true; - if (!handled && gtk_widget_get_visible(instant_view_)) + if (!handled && gtk_widget_get_visible(gray_text_view_)) handled = model()->CommitSuggestedText(); if (handled) { @@ -1625,7 +1618,7 @@ void OmniboxViewGtk::HandleCopyOrCutClipboard(bool copy) { int OmniboxViewGtk::GetOmniboxTextLength() const { GtkTextIter end; - gtk_text_buffer_get_iter_at_mark(text_buffer_, &end, instant_mark_); + gtk_text_buffer_get_iter_at_mark(text_buffer_, &end, gray_text_mark_); if (supports_pre_edit_) { // We need to count the length of the text being composed, because we treat // it as part of the content in GetText(). @@ -1993,9 +1986,9 @@ void OmniboxViewGtk::HandleKeymapDirectionChanged(GdkKeymap* sender) { void OmniboxViewGtk::HandleDeleteRange(GtkTextBuffer* buffer, GtkTextIter* start, GtkTextIter* end) { - // Prevent the user from deleting the Instant anchor. We can't simply set the - // Instant anchor readonly by applying a tag with "editable" = FALSE, because - // it'll prevent the insert caret from blinking. + // Prevent the user from deleting the gray text anchor. We can't simply set + // the gray text anchor readonly by applying a tag with "editable" = FALSE, + // because it'll prevent the insert caret from blinking. ValidateTextBufferIter(start); ValidateTextBufferIter(end); if (!gtk_text_iter_compare(start, end)) { @@ -2008,7 +2001,7 @@ void OmniboxViewGtk::HandleDeleteRange(GtkTextBuffer* buffer, void OmniboxViewGtk::HandleMarkSetAlways(GtkTextBuffer* buffer, GtkTextIter* location, GtkTextMark* mark) { - if (mark == instant_mark_ || !instant_mark_) + if (mark == gray_text_mark_ || !gray_text_mark_) return; GtkTextIter new_iter = *location; @@ -2017,7 +2010,7 @@ void OmniboxViewGtk::HandleMarkSetAlways(GtkTextBuffer* buffer, static guint signal_id = g_signal_lookup("mark-set", GTK_TYPE_TEXT_BUFFER); // "mark-set" signal is actually emitted after the mark's location is already - // set, so if the location is beyond the Instant anchor, we need to move the + // set, so if the location is beyond the gray text anchor, we need to move the // mark again, which will emit the signal again. In order to prevent other // signal handlers from being called twice, we need to stop signal emission // before moving the mark again. @@ -2041,7 +2034,7 @@ void OmniboxViewGtk::HandleMarkSetAlways(GtkTextBuffer* buffer, gtk_text_buffer_get_selection_bound(buffer)); GtkTextIter end; - gtk_text_buffer_get_iter_at_mark(text_buffer_, &end, instant_mark_); + gtk_text_buffer_get_iter_at_mark(text_buffer_, &end, gray_text_mark_); if (gtk_text_iter_compare(&insert, &end) > 0 || gtk_text_iter_compare(&selection_bound, &end) > 0) { @@ -2137,26 +2130,26 @@ void OmniboxViewGtk::HandleUndoRedoAfter(GtkWidget* sender) { void OmniboxViewGtk::GetTextBufferBounds(GtkTextIter* start, GtkTextIter* end) const { gtk_text_buffer_get_start_iter(text_buffer_, start); - gtk_text_buffer_get_iter_at_mark(text_buffer_, end, instant_mark_); + gtk_text_buffer_get_iter_at_mark(text_buffer_, end, gray_text_mark_); } void OmniboxViewGtk::ValidateTextBufferIter(GtkTextIter* iter) const { - if (!instant_mark_) + if (!gray_text_mark_) return; GtkTextIter end; - gtk_text_buffer_get_iter_at_mark(text_buffer_, &end, instant_mark_); + gtk_text_buffer_get_iter_at_mark(text_buffer_, &end, gray_text_mark_); if (gtk_text_iter_compare(iter, &end) > 0) *iter = end; } -void OmniboxViewGtk::AdjustVerticalAlignmentOfInstantView() { +void OmniboxViewGtk::AdjustVerticalAlignmentOfGrayTextView() { // By default, GtkTextView layouts an anchored child widget just above the - // baseline, so we need to move the |instant_view_| down to make sure it + // baseline, so we need to move the |gray_text_view_| down to make sure it // has the same baseline as the |text_view_|. - PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); + PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(gray_text_view_)); int height; pango_layout_get_size(layout, NULL, &height); int baseline = pango_layout_get_baseline(layout); - g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); + g_object_set(gray_text_anchor_tag_, "rise", baseline - height, NULL); } diff --git a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h index b19343d..8ec060f 100644 --- a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h +++ b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h @@ -97,8 +97,8 @@ class OmniboxViewGtk : public OmniboxView, virtual bool OnAfterPossibleChange() OVERRIDE; virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual gfx::NativeView GetRelativeWindowForPopup() const OVERRIDE; - virtual void SetInstantSuggestion(const string16& suggestion) OVERRIDE; - virtual string16 GetInstantSuggestion() const OVERRIDE; + virtual void SetGrayTextAutocompletion(const string16& suggestion) OVERRIDE; + virtual string16 GetGrayTextAutocompletion() const OVERRIDE; virtual int TextWidth() const OVERRIDE; virtual bool IsImeComposing() const OVERRIDE; @@ -109,8 +109,8 @@ class OmniboxViewGtk : public OmniboxView, // Sets the colors of the text view according to the theme. void SetBaseColor(); - // Sets the colors of the Instant suggestion view according to the theme. - void UpdateInstantViewColors(); + // Sets the colors of the gray text suggestion view according to the theme. + void UpdateGrayTextViewColors(); // Returns the text view gtk widget. May return NULL if the widget // has already been destroyed. @@ -283,16 +283,16 @@ class OmniboxViewGtk : public OmniboxView, void UpdatePrimarySelectionIfValidURL(); // Retrieves the first and last iterators in the |text_buffer_|, but excludes - // the anchor holding the |instant_view_| widget. + // the anchor holding the |gray_text_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. + // beyond the anchor for holding the |gray_text_view_| widget. void ValidateTextBufferIter(GtkTextIter* iter) const; - // Adjusts vertical alignment of the |instant_view_| in the |text_view_|, to + // Adjusts vertical alignment of the |gray_text_view_| in the |text_view_|, to // make sure they have the same baseline. - void AdjustVerticalAlignmentOfInstantView(); + void AdjustVerticalAlignmentOfGrayTextView(); // The Browser that contains this omnibox. Browser* browser_; @@ -314,17 +314,17 @@ class OmniboxViewGtk : public OmniboxView, GtkTextTag* security_error_scheme_tag_; GtkTextTag* normal_text_tag_; - // Objects for the Instant suggestion text view. - GtkTextTag* instant_anchor_tag_; + // Objects for the gray suggestion text view. + GtkTextTag* gray_text_anchor_tag_; - // A widget for displaying Instant suggestion text. It'll be attached to a + // A widget for displaying gray autocompletion text. It'll be attached to a // child anchor in the |text_buffer_| object. - GtkWidget* instant_view_; + GtkWidget* gray_text_view_; - // A mark to split the content and the Instant anchor. Wherever the end + // A mark to split the content and the gray text anchor. Wherever the end // iterator of the text buffer is required, the iterator to this mark should // be used. - GtkTextMark* instant_mark_; + GtkTextMark* gray_text_mark_; scoped_ptr<OmniboxPopupView> popup_view_; diff --git a/chrome/browser/ui/omnibox/location_bar.h b/chrome/browser/ui/omnibox/location_bar.h index 119e29e..66166f4 100644 --- a/chrome/browser/ui/omnibox/location_bar.h +++ b/chrome/browser/ui/omnibox/location_bar.h @@ -14,7 +14,6 @@ #include <string> #include "base/strings/string16.h" -#include "chrome/common/instant_types.h" #include "content/public/common/page_transition_types.h" #include "ui/base/window_open_disposition.h" @@ -31,10 +30,6 @@ class LocationBar { // Shows the first run bubble anchored to the location bar. virtual void ShowFirstRunBubble() = 0; - // Sets the suggested text to show in the omnibox. This is shown in addition - // to the current text of the omnibox. - virtual void SetInstantSuggestion(const InstantSuggestion& suggestion) = 0; - // Returns the string of text entered in the location bar. virtual string16 GetInputString() const = 0; diff --git a/chrome/browser/ui/omnibox/omnibox_controller.cc b/chrome/browser/ui/omnibox/omnibox_controller.cc index cd75dda..196fef7 100644 --- a/chrome/browser/ui/omnibox/omnibox_controller.cc +++ b/chrome/browser/ui/omnibox/omnibox_controller.cc @@ -15,13 +15,10 @@ #include "chrome/browser/prerender/prerender_manager_factory.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search/search.h" -#include "chrome/browser/search_engines/template_url_service.h" -#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" #include "chrome/browser/ui/omnibox/omnibox_popup_view.h" -#include "chrome/browser/ui/search/instant_controller.h" #include "extensions/common/constants.h" #include "ui/gfx/rect.h" @@ -64,8 +61,6 @@ void OmniboxController::StartAutocomplete( } void OmniboxController::OnResultChanged(bool default_match_changed) { - // TODO(beaudoin): There should be no need to access the popup when using - // instant extended, remove this reference. const bool was_open = popup_->IsOpen(); if (default_match_changed) { // The default match has changed, we need to let the OmniboxEditModel know @@ -109,11 +104,6 @@ void OmniboxController::OnResultChanged(bool default_match_changed) { } } -void OmniboxController::SetInstantSuggestion( - const InstantSuggestion& suggestion) { - // TODO(jered): Delete this. -} - void OmniboxController::InvalidateCurrentMatch() { current_match_ = AutocompleteMatch(); } @@ -139,46 +129,3 @@ void OmniboxController::DoPreconnect(const AutocompleteMatch& match) { // the OS DNS cache could suffer eviction problems for minimal gain. } } - -bool OmniboxController::UseVerbatimInstant(bool just_deleted_text) const { -#if defined(OS_MACOSX) - // TODO(suzhe): Fix Mac port to display Instant suggest in a separated NSView, - // so that we can display Instant suggest along with composition text. - const AutocompleteInput& input = autocomplete_controller_->input(); - if (input.prevent_inline_autocomplete()) - return true; -#endif - - // The value of input.prevent_inline_autocomplete() is determined by the - // following conditions: - // 1. If the caret is at the end of the text. - // 2. If it's in IME composition mode. - // We send the caret position to Instant (so it can determine #1 itself), and - // we use a separated widget for displaying the Instant suggest (so it doesn't - // interfere with #2). So, we don't need to care about the value of - // input.prevent_inline_autocomplete() here. - return just_deleted_text || popup_->selected_line() != 0; -} - -InstantController* OmniboxController::GetInstantController() const { - return omnibox_edit_model_->GetInstantController(); -} - -void OmniboxController::CreateAndSetInstantMatch( - string16 query_string, - string16 input_text, - AutocompleteMatchType::Type match_type) { - TemplateURLService* template_url_service = - TemplateURLServiceFactory::GetForProfile(profile_); - if (!template_url_service) - return; - - TemplateURL* template_url = - template_url_service->GetDefaultSearchProvider(); - if (!template_url) - return; - - current_match_ = SearchProvider::CreateSearchSuggestion( - NULL, 0, match_type, template_url, query_string, input_text, - AutocompleteInput(), false, 0, -1, true); -} diff --git a/chrome/browser/ui/omnibox/omnibox_controller.h b/chrome/browser/ui/omnibox/omnibox_controller.h index 2259ae7..690acab 100644 --- a/chrome/browser/ui/omnibox/omnibox_controller.h +++ b/chrome/browser/ui/omnibox/omnibox_controller.h @@ -17,7 +17,6 @@ struct AutocompleteMatch; class AutocompleteResult; class GURL; class InstantController; -struct InstantSuggestion; class OmniboxEditModel; class OmniboxPopupModel; class Profile; @@ -35,7 +34,6 @@ class Rect; // As the refactor progresses, keep the class comment up-to-date to // precisely explain what this class is doing. class OmniboxController : public AutocompleteControllerDelegate { - public: OmniboxController(OmniboxEditModel* omnibox_edit_model, Profile* profile); @@ -57,9 +55,6 @@ class OmniboxController : public AutocompleteControllerDelegate { return autocomplete_controller_.get(); } - // Sets the suggestion text. - void SetInstantSuggestion(const InstantSuggestion& suggestion); - // Set |current_match_| to an invalid value, indicating that we do not yet // have a valid match for the current text in the omnibox. void InvalidateCurrentMatch(); @@ -85,22 +80,6 @@ class OmniboxController : public AutocompleteControllerDelegate { void DoPreconnect(const AutocompleteMatch& match); private: - - // Returns true if a verbatim query should be used for Instant. A verbatim - // query is forced in certain situations, such as pressing delete at the end - // of the edit. - bool UseVerbatimInstant(bool just_deleted_text) const; - - // Access the instant controller from the OmniboxEditModel. We need to do this - // because the only valid pointer to InstantController is kept in Browser, - // which OmniboxEditModel has some ways of reaching. - InstantController* GetInstantController() const; - - // Creates an AutocompleteMatch for an instant result and sets it into - // |current_match_|. - void CreateAndSetInstantMatch(string16 query_string, - string16 input_text, - AutocompleteMatchType::Type match_type); // Weak, it owns us. // TODO(beaudoin): Consider defining a delegate to ease unit testing. OmniboxEditModel* omnibox_edit_model_; @@ -109,8 +88,6 @@ class OmniboxController : public AutocompleteControllerDelegate { OmniboxPopupModel* popup_; - InstantController* instant_controller_; - scoped_ptr<AutocompleteController> autocomplete_controller_; // TODO(beaudoin): This AutocompleteMatch is used to let the OmniboxEditModel diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.cc b/chrome/browser/ui/omnibox/omnibox_edit_model.cc index 5211c36..6b9cd4f 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_model.cc +++ b/chrome/browser/ui/omnibox/omnibox_edit_model.cc @@ -104,13 +104,13 @@ const char kFocusToEditTimeHistogram[] = "Omnibox.FocusToEditTime"; OmniboxEditModel::State::State(bool user_input_in_progress, const string16& user_text, - const string16& instant_suggestion, + const string16& gray_text, const string16& keyword, bool is_keyword_hint, OmniboxFocusState focus_state) : user_input_in_progress(user_input_in_progress), user_text(user_text), - instant_suggestion(instant_suggestion), + gray_text(gray_text), keyword(keyword), is_keyword_hint(is_keyword_hint), focus_state(focus_state) { @@ -164,7 +164,7 @@ const OmniboxEditModel::State OmniboxEditModel::GetStateForTabSwitch() { return State(user_input_in_progress_, user_text_, - view_->GetInstantSuggestion(), + view_->GetGrayTextAutocompletion(), keyword_, is_keyword_hint_, focus_state_); @@ -180,7 +180,7 @@ void OmniboxEditModel::RestoreState(const State& state) { is_keyword_hint_ = state.is_keyword_hint; view_->SetUserText(state.user_text, DisplayTextFromUserText(state.user_text), false); - view_->SetInstantSuggestion(state.instant_suggestion); + view_->SetGrayTextAutocompletion(state.gray_text); } } @@ -204,19 +204,19 @@ bool OmniboxEditModel::UpdatePermanentText(const string16& new_permanent_text) { // common case where the edit doesn't have focus is when the user has started // an edit and then abandoned it and clicked a link on the page.) // - // If the page is auto-committing an instant suggestion, however, we generally - // don't want to make any change to the edit. While auto-commits modify the - // underlying permanent URL, they're intended to have no effect on the user's - // editing process -- before and after the auto-commit, the omnibox should - // show the same user text and the same instant suggestion, even if the - // auto-commit happens while the edit doesn't have focus. - string16 instant_suggestion = view_->GetInstantSuggestion(); + // If the page is auto-committing gray text, however, we generally don't want + // to make any change to the edit. While auto-commits modify the underlying + // permanent URL, they're intended to have no effect on the user's editing + // process -- before and after the auto-commit, the omnibox should show the + // same user text and the same instant suggestion, even if the auto-commit + // happens while the edit doesn't have focus. + string16 gray_text = view_->GetGrayTextAutocompletion(); const bool visibly_changed_permanent_text = (permanent_text_ != new_permanent_text) && (!has_focus() || (!user_input_in_progress_ && !popup_model()->IsOpen())) && - (instant_suggestion.empty() || - new_permanent_text != user_text_ + instant_suggestion); + (gray_text.empty() || + new_permanent_text != user_text_ + gray_text); permanent_text_ = new_permanent_text; return visibly_changed_permanent_text; @@ -234,16 +234,11 @@ void OmniboxEditModel::SetUserText(const string16& text) { has_temporary_text_ = false; } -void OmniboxEditModel::SetInstantSuggestion( - const InstantSuggestion& suggestion) { -} - bool OmniboxEditModel::CommitSuggestedText() { - const string16 suggestion = view_->GetInstantSuggestion(); + const string16 suggestion = view_->GetGrayTextAutocompletion(); if (suggestion.empty()) return false; - // Assume that the gray text we are committing is a search suggestion. const string16 final_text = view_->GetText() + suggestion; view_->OnBeforePossibleChange(); view_->SetWindowTextAndCaretPos(final_text, final_text.length(), false, @@ -281,7 +276,7 @@ void OmniboxEditModel::OnChanged() { AutocompleteActionPredictor::LAST_PREDICT_ACTION); // Hide any suggestions we might be showing. - view_->SetInstantSuggestion(string16()); + view_->SetGrayTextAutocompletion(string16()); switch (recommended_action) { case AutocompleteActionPredictor::ACTION_PRERENDER: @@ -1215,11 +1210,8 @@ bool OmniboxEditModel::CreatedKeywordSearchByInsertingSpaceInMiddle( // Then check if the text before the inserted space matches a keyword. string16 keyword; TrimWhitespace(new_text.substr(0, space_position), TRIM_LEADING, &keyword); - // TODO(sreeram): Once the Instant extended API supports keywords properly, - // keyword_provider() should never be NULL. Remove that clause. - return !keyword.empty() && autocomplete_controller()->keyword_provider() && - !autocomplete_controller()->keyword_provider()-> - GetKeywordForText(keyword).empty(); + return !keyword.empty() && !autocomplete_controller()->keyword_provider()-> + GetKeywordForText(keyword).empty(); } // static diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.h b/chrome/browser/ui/omnibox/omnibox_edit_model.h index ad525de..4dff4ef 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_model.h +++ b/chrome/browser/ui/omnibox/omnibox_edit_model.h @@ -22,7 +22,6 @@ class AutocompleteController; class AutocompleteResult; -struct InstantSuggestion; class OmniboxCurrentPageDelegate; class OmniboxEditController; class OmniboxPopupModel; @@ -48,7 +47,7 @@ class OmniboxEditModel { struct State { State(bool user_input_in_progress, const string16& user_text, - const string16& instant_suggestion, + const string16& gray_text, const string16& keyword, bool is_keyword_hint, OmniboxFocusState focus_state); @@ -56,7 +55,7 @@ class OmniboxEditModel { bool user_input_in_progress; const string16 user_text; - const string16 instant_suggestion; + const string16 gray_text; const string16 keyword; const bool is_keyword_hint; OmniboxFocusState focus_state; @@ -140,16 +139,13 @@ class OmniboxEditModel { // Sets the user_text_ to |text|. Only the View should call this. void SetUserText(const string16& text); - // Sets the suggestion text. - void SetInstantSuggestion(const InstantSuggestion& suggestion); - // Commits the gray suggested text as if it's been input by the user. // Returns true if the text was committed. // TODO: can the return type be void? bool CommitSuggestedText(); - // Invoked any time the text may have changed in the edit. Updates Instant and - // notifies the controller. + // Invoked any time the text may have changed in the edit. Notifies the + // controller. void OnChanged(); // Reverts the edit model back to its unedited state (permanent text showing, @@ -312,7 +308,6 @@ class OmniboxEditModel { InstantController* GetInstantController() const; private: - friend class InstantTestBase; friend class OmniboxControllerTest; enum PasteState { @@ -508,21 +503,8 @@ class OmniboxEditModel { Profile* profile_; - // This is needed as prior to accepting the current text the model is - // reverted, which triggers resetting Instant. We don't want to update Instant - // in this case, so we use the flag to determine if this is happening. - // - // For example: The permanent text is "foo". The user has typed "bar" and - // Instant is showing a search results preview for "bar". The user hits Enter. - // in_revert_ is used to tell Instant, "The omnibox text is about to change to - // 'foo', thus TextChanged() will be called, leading to DoInstant(), but - // please don't change what you are showing. I'll commit the real match - // ("bar") immediately after the revert." - // - // Without in_revert_, Instant would erroneously change its search results to - // "foo". Because of the way the code is structured (specifically, DoInstant() - // is NOT called for "bar" again), this leaves Instant showing results for - // "foo", which is wrong. + // This is needed to properly update the SearchModel state when the user + // presses escape. bool in_revert_; // Indicates if the upcoming autocomplete search is allowed to be treated as diff --git a/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc b/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc index cd1e0d7..7fd366a 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc +++ b/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc @@ -63,8 +63,10 @@ class TestingOmniboxView : public OmniboxView { virtual gfx::NativeView GetRelativeWindowForPopup() const OVERRIDE { return NULL; } - virtual void SetInstantSuggestion(const string16& input) OVERRIDE {} - virtual string16 GetInstantSuggestion() const OVERRIDE { return string16(); } + virtual void SetGrayTextAutocompletion(const string16& input) OVERRIDE {} + virtual string16 GetGrayTextAutocompletion() const OVERRIDE { + return string16(); + } virtual int TextWidth() const OVERRIDE { return 0; } virtual bool IsImeComposing() const OVERRIDE { return false; } diff --git a/chrome/browser/ui/omnibox/omnibox_view.h b/chrome/browser/ui/omnibox/omnibox_view.h index 972cac8..9fb5b94 100644 --- a/chrome/browser/ui/omnibox/omnibox_view.h +++ b/chrome/browser/ui/omnibox/omnibox_view.h @@ -196,11 +196,11 @@ class OmniboxView { // the top-most window is the relative window. virtual gfx::NativeView GetRelativeWindowForPopup() const = 0; - // Shows the instant suggestion text. - virtual void SetInstantSuggestion(const string16& input) = 0; + // Shows |input| as gray suggested text after what the user has typed. + virtual void SetGrayTextAutocompletion(const string16& input) = 0; - // Returns the current instant suggestion text. - virtual string16 GetInstantSuggestion() const = 0; + // Returns the current gray suggested text. + virtual string16 GetGrayTextAutocompletion() const = 0; // Returns the width in pixels needed to display the current text. The // returned value includes margins. diff --git a/chrome/browser/ui/search/instant_test_utils.cc b/chrome/browser/ui/search/instant_test_utils.cc index 1ccbd03..cc683c2 100644 --- a/chrome/browser/ui/search/instant_test_utils.cc +++ b/chrome/browser/ui/search/instant_test_utils.cc @@ -139,14 +139,6 @@ bool InstantTestBase::CheckVisibilityIs(content::WebContents* contents, actual == expected; } -bool InstantTestBase::HasUserInputInProgress() { - return omnibox()->model()->user_input_in_progress_; -} - -bool InstantTestBase::HasTemporaryText() { - return omnibox()->model()->has_temporary_text_; -} - std::string InstantTestBase::GetOmniboxText() { return UTF16ToUTF8(omnibox()->GetText()); } @@ -169,7 +161,3 @@ string16 InstantTestBase::GetBlueText() { std::swap(start, end); return omnibox()->GetText().substr(start, end - start); } - -string16 InstantTestBase::GetGrayText() { - return omnibox()->GetInstantSuggestion(); -} diff --git a/chrome/browser/ui/search/instant_test_utils.h b/chrome/browser/ui/search/instant_test_utils.h index a591fde..47c273d 100644 --- a/chrome/browser/ui/search/instant_test_utils.h +++ b/chrome/browser/ui/search/instant_test_utils.h @@ -88,8 +88,6 @@ class InstantTestBase { bool ExecuteScript(const std::string& script) WARN_UNUSED_RESULT; bool CheckVisibilityIs(content::WebContents* contents, bool expected) WARN_UNUSED_RESULT; - bool HasUserInputInProgress(); - bool HasTemporaryText(); std::string GetOmniboxText(); @@ -103,9 +101,6 @@ class InstantTestBase { // Returns the omnibox's inline autocompletion (shown in blue highlight). string16 GetBlueText(); - // Returns the omnibox's suggest text (shown as gray text). - string16 GetGrayText(); - private: GURL instant_url_; diff --git a/chrome/browser/ui/views/frame/browser_view_interactive_uitest.cc b/chrome/browser/ui/views/frame/browser_view_interactive_uitest.cc index 832637a..7db80b4 100644 --- a/chrome/browser/ui/views/frame/browser_view_interactive_uitest.cc +++ b/chrome/browser/ui/views/frame/browser_view_interactive_uitest.cc @@ -267,17 +267,6 @@ IN_PROC_BROWSER_TEST_F(BrowserViewImmersiveInstantExtendedTest, // Type in the omnibox, which should generate suggestions in the main page // contents. SetOmniboxText("claus"); - // The autocomplete controller isn't done until all the providers are done. - // Though we don't care about the SearchProvider when we send autocomplete - // results to the page, we do need to cause it to be "done" to make this test - // work. Setting the suggestion calls SearchProvider::FinalizeInstantQuery(), - // thus causing it to be done. - omnibox()->model()->SetInstantSuggestion( - InstantSuggestion(ASCIIToUTF16("query"), - INSTANT_COMPLETE_NOW, - INSTANT_SUGGESTION_SEARCH, - ASCIIToUTF16("query"), - kNoMatchIndex)); while (!omnibox()->model()->autocomplete_controller()->done()) { content::WindowedNotificationObserver autocomplete_observer( chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY, diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc index cd2deb9..a521591 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -629,7 +629,7 @@ void LocationBarView::SetImeInlineAutocompletion(const string16& text) { ime_inline_autocomplete_view_->SetVisible(!text.empty()); } -void LocationBarView::SetInstantSuggestion(const string16& text) { +void LocationBarView::SetGrayTextAutocompletion(const string16& text) { if (suggested_text_view_->text() != text) { suggested_text_view_->SetText(text); suggested_text_view_->SetVisible(!text.empty()); @@ -638,7 +638,7 @@ void LocationBarView::SetInstantSuggestion(const string16& text) { } } -string16 LocationBarView::GetInstantSuggestion() const { +string16 LocationBarView::GetGrayTextAutocompletion() const { return HasValidSuggestText() ? suggested_text_view_->text() : string16(); } @@ -1356,11 +1356,6 @@ void LocationBarView::ShowFirstRunBubble() { ShowFirstRunBubbleInternal(); } -void LocationBarView::SetInstantSuggestion( - const InstantSuggestion& suggestion) { - location_entry_->model()->SetInstantSuggestion(suggestion); -} - string16 LocationBarView::GetInputString() const { return location_input_; } diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.h b/chrome/browser/ui/views/location_bar/location_bar_view.h index 61a112f..3ed517c 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.h +++ b/chrome/browser/ui/views/location_bar/location_bar_view.h @@ -195,11 +195,11 @@ class LocationBarView : public LocationBar, // comments on |ime_inline_autocomplete_view_|. void SetImeInlineAutocompletion(const string16& text); - // Invoked from OmniboxViewWin to show the instant suggestion. - void SetInstantSuggestion(const string16& text); + // Invoked from OmniboxViewWin to show gray text autocompletion. + void SetGrayTextAutocompletion(const string16& text); - // Returns the current instant suggestion text. - string16 GetInstantSuggestion() const; + // Returns the current gray text autocompletion. + string16 GetGrayTextAutocompletion() const; // Sets whether the location entry can accept focus. void SetLocationEntryFocusable(bool focusable); @@ -278,8 +278,6 @@ class LocationBarView : public LocationBar, // LocationBar: virtual void ShowFirstRunBubble() OVERRIDE; - virtual void SetInstantSuggestion( - const InstantSuggestion& suggestion) OVERRIDE; virtual string16 GetInputString() const OVERRIDE; virtual WindowOpenDisposition GetWindowOpenDisposition() const OVERRIDE; virtual content::PageTransition GetPageTransition() const OVERRIDE; diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc index 133270d..0c59dbc 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc +++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc @@ -517,16 +517,9 @@ bool OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged( void OmniboxViewViews::OnRevertTemporaryText() { SelectRange(saved_temporary_selection_); // We got here because the user hit the Escape key. We explicitly don't call - // TextChanged(), since calling it breaks Instant-Extended, and isn't needed - // otherwise (in regular non-Instant or Instant-but-not-Extended modes). - // - // Why it breaks Instant-Extended: Instant handles the Escape key separately - // (cf: OmniboxEditModel::RevertTemporaryText). Calling TextChanged() makes - // the page think the user additionally typed some text, causing it to update - // its suggestions dropdown with new suggestions, which is wrong. - // - // Why it isn't needed: OmniboxPopupModel::ResetToDefaultMatch() has already - // been called by now; it would've called TextChanged() if it was warranted. + // TextChanged(), since OmniboxPopupModel::ResetToDefaultMatch() has already + // been called by now, and it would've called TextChanged() if it was + // warranted. } void OmniboxViewViews::OnBeforePossibleChange() { @@ -581,15 +574,15 @@ gfx::NativeView OmniboxViewViews::GetRelativeWindowForPopup() const { return GetWidget()->GetTopLevelWidget()->GetNativeView(); } -void OmniboxViewViews::SetInstantSuggestion(const string16& input) { +void OmniboxViewViews::SetGrayTextAutocompletion(const string16& input) { #if defined(OS_WIN) || defined(USE_AURA) - location_bar_view_->SetInstantSuggestion(input); + location_bar_view_->SetGrayTextAutocompletion(input); #endif } -string16 OmniboxViewViews::GetInstantSuggestion() const { +string16 OmniboxViewViews::GetGrayTextAutocompletion() const { #if defined(OS_WIN) || defined(USE_AURA) - return location_bar_view_->GetInstantSuggestion(); + return location_bar_view_->GetGrayTextAutocompletion(); #else return string16(); #endif @@ -661,7 +654,7 @@ bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield, } // Handle the right-arrow key for LTR text and the left-arrow key for RTL text - // if there is an Instant suggestion (gray text) that needs to be committed. + // if there is gray text that needs to be committed. if (GetCursorPosition() == text().length()) { base::i18n::TextDirection direction = GetTextDirection(); if ((direction == base::i18n::LEFT_TO_RIGHT && @@ -853,7 +846,7 @@ void OmniboxViewViews::CandidateWindowClosed( // OmniboxViewViews, private: int OmniboxViewViews::GetOmniboxTextLength() const { - // TODO(oshima): Support instant, IME. + // TODO(oshima): Support IME. return static_cast<int>(text().length()); } @@ -903,7 +896,7 @@ void OmniboxViewViews::SetTextAndSelectedRange(const string16& text, } string16 OmniboxViewViews::GetSelectedText() const { - // TODO(oshima): Support instant, IME. + // TODO(oshima): Support IME. return views::Textfield::GetSelectedText(); } diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.h b/chrome/browser/ui/views/omnibox/omnibox_view_views.h index 2ddf4fb..b757c69 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_views.h +++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.h @@ -100,8 +100,8 @@ class OmniboxViewViews virtual bool OnAfterPossibleChange() OVERRIDE; virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual gfx::NativeView GetRelativeWindowForPopup() const OVERRIDE; - virtual void SetInstantSuggestion(const string16& input) OVERRIDE; - virtual string16 GetInstantSuggestion() const OVERRIDE; + virtual void SetGrayTextAutocompletion(const string16& input) OVERRIDE; + virtual string16 GetGrayTextAutocompletion() const OVERRIDE; virtual int TextWidth() const OVERRIDE; virtual bool IsImeComposing() const OVERRIDE; virtual bool IsImeShowingPopup() const OVERRIDE; diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc index e3f006b..0fc64f5 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc +++ b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc @@ -901,16 +901,9 @@ bool OmniboxViewWin::OnInlineAutocompleteTextMaybeChanged( void OmniboxViewWin::OnRevertTemporaryText() { SetSelectionRange(original_selection_); // We got here because the user hit the Escape key. We explicitly don't call - // TextChanged(), since calling it breaks Instant-Extended, and isn't needed - // otherwise (in regular non-Instant or Instant-but-not-Extended modes). - // - // Why it breaks Instant-Extended: Instant handles the Escape key separately - // (cf: OmniboxEditModel::RevertTemporaryText). Calling TextChanged() makes - // the page think the user additionally typed some text, causing it to update - // its suggestions dropdown with new suggestions, which is wrong. - // - // Why it isn't needed: OmniboxPopupModel::ResetToDefaultMatch() has already - // been called by now; it would've called TextChanged() if it was warranted. + // TextChanged(), since OmniboxPopupModel::ResetToDefaultMatch() has already + // been called by now, and it would've called TextChanged() if it was + // warranted. } void OmniboxViewWin::OnBeforePossibleChange() { @@ -1028,16 +1021,16 @@ gfx::NativeView OmniboxViewWin::GetRelativeWindowForPopup() const { return GetRelativeWindowForNativeView(GetNativeView()); } -void OmniboxViewWin::SetInstantSuggestion(const string16& suggestion) { - location_bar_->SetInstantSuggestion(suggestion); +void OmniboxViewWin::SetGrayTextAutocompletion(const string16& suggestion) { + location_bar_->SetGrayTextAutocompletion(suggestion); } int OmniboxViewWin::TextWidth() const { return WidthNeededToDisplay(GetText()); } -string16 OmniboxViewWin::GetInstantSuggestion() const { - return location_bar_->GetInstantSuggestion(); +string16 OmniboxViewWin::GetGrayTextAutocompletion() const { + return location_bar_->GetGrayTextAutocompletion(); } bool OmniboxViewWin::IsImeComposing() const { diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_win.h b/chrome/browser/ui/views/omnibox/omnibox_view_win.h index e61a007..7caecff 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_win.h +++ b/chrome/browser/ui/views/omnibox/omnibox_view_win.h @@ -110,9 +110,9 @@ class OmniboxViewWin virtual bool OnAfterPossibleChange() OVERRIDE; virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual gfx::NativeView GetRelativeWindowForPopup() const OVERRIDE; - virtual void SetInstantSuggestion(const string16& suggestion) OVERRIDE; + virtual void SetGrayTextAutocompletion(const string16& suggestion) OVERRIDE; virtual int TextWidth() const OVERRIDE; - virtual string16 GetInstantSuggestion() const OVERRIDE; + virtual string16 GetGrayTextAutocompletion() const OVERRIDE; virtual bool IsImeComposing() const OVERRIDE; virtual int GetMaxEditWidth(int entry_width) const OVERRIDE; virtual views::View* AddToView(views::View* parent) OVERRIDE; diff --git a/chrome/test/base/test_location_bar.h b/chrome/test/base/test_location_bar.h index 5cb042b..41de7eb 100644 --- a/chrome/test/base/test_location_bar.h +++ b/chrome/test/base/test_location_bar.h @@ -28,8 +28,6 @@ class TestLocationBar : public LocationBar { // Overridden from LocationBar: virtual void ShowFirstRunBubble() OVERRIDE {} - virtual void SetInstantSuggestion( - const InstantSuggestion& suggestion) OVERRIDE {} virtual string16 GetInputString() const OVERRIDE; virtual WindowOpenDisposition GetWindowOpenDisposition() const OVERRIDE; virtual content::PageTransition GetPageTransition() const OVERRIDE; |