Index: chrome/browser/ui/omnibox/omnibox_edit_model.cc |
diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.cc b/chrome/browser/ui/omnibox/omnibox_edit_model.cc |
index deb105362a9cd45f974c0adc4da5215d8926a8f8..ec4e36ae91c1f45e1754e01b30b0759c0ae74cca 100644 |
--- a/chrome/browser/ui/omnibox/omnibox_edit_model.cc |
+++ b/chrome/browser/ui/omnibox/omnibox_edit_model.cc |
@@ -184,7 +184,10 @@ void OmniboxEditModel::RestoreState(const State& state) { |
} |
} |
-AutocompleteMatch OmniboxEditModel::CurrentMatch() { |
+AutocompleteMatch OmniboxEditModel::CurrentMatch() const { |
+ // If we have a valid match use it. Otherwise get one for the current text. |
+ if (omnibox_controller_->current_match().destination_url.is_valid()) |
Peter Kasting
2013/06/11 22:42:55
I think you can have a valid match without a valid
beaudoin
2013/06/14 21:39:38
Thanks for pointing this out. I don't think it has
|
+ return omnibox_controller_->current_match(); |
AutocompleteMatch match; |
GetInfoForCurrentText(&match, NULL); |
return match; |
@@ -220,6 +223,7 @@ GURL OmniboxEditModel::PermanentURL() { |
void OmniboxEditModel::SetUserText(const string16& text) { |
SetInputInProgress(true); |
InternalSetUserText(text); |
+ omnibox_controller_->InvalidateCurrentMatch(); |
paste_state_ = NONE; |
has_temporary_text_ = false; |
is_temporary_text_set_by_instant_ = false; |
@@ -227,55 +231,9 @@ void OmniboxEditModel::SetUserText(const string16& text) { |
is_instant_temporary_text_a_search_query_ = false; |
} |
-void OmniboxEditModel::FinalizeInstantQuery( |
- const string16& input_text, |
- const InstantSuggestion& suggestion) { |
- if (!popup_model()->result().empty()) { |
- // When a IME is active and a candidate window is open, we don't show |
- // the omnibox popup, though |result()| may be available. Thus we check |
- // whether result().empty() or not instead of whether IsOpen() or not. |
- // We need the finalization of instant query when result() is available. |
- SearchProvider* search_provider = |
- autocomplete_controller()->search_provider(); |
- // There may be no providers during testing; guard against that. |
- if (search_provider) |
- search_provider->FinalizeInstantQuery(input_text, suggestion); |
- } |
-} |
- |
void OmniboxEditModel::SetInstantSuggestion( |
const InstantSuggestion& suggestion) { |
- switch (suggestion.behavior) { |
- case INSTANT_COMPLETE_NOW: |
- view_->SetInstantSuggestion(string16()); |
- if (!suggestion.text.empty()) |
- FinalizeInstantQuery(view_->GetText(), suggestion); |
- break; |
- |
- case INSTANT_COMPLETE_NEVER: { |
- DCHECK_EQ(INSTANT_SUGGESTION_SEARCH, suggestion.type); |
- view_->SetInstantSuggestion(suggestion.text); |
- autocomplete_controller()->search_provider()->ClearInstantSuggestion(); |
- break; |
- } |
- |
- case INSTANT_COMPLETE_REPLACE: { |
- const bool save_original_selection = !has_temporary_text_; |
- view_->SetInstantSuggestion(string16()); |
- has_temporary_text_ = true; |
- is_temporary_text_set_by_instant_ = true; |
- selected_instant_autocomplete_match_index_ = |
- suggestion.autocomplete_match_index; |
- is_instant_temporary_text_a_search_query_ = |
- suggestion.type == INSTANT_SUGGESTION_SEARCH; |
- // Instant suggestions are never a keyword. |
- keyword_ = string16(); |
- is_keyword_hint_ = false; |
- view_->OnTemporaryTextMaybeChanged(suggestion.text, |
- save_original_selection, true); |
- break; |
- } |
- } |
+ omnibox_controller_->SetInstantSuggestion(suggestion); |
} |
bool OmniboxEditModel::CommitSuggestedText() { |
@@ -339,7 +297,7 @@ void OmniboxEditModel::OnChanged() { |
view_->SetInstantSuggestion(string16()); |
// No need to wait any longer for Instant. |
- FinalizeInstantQuery(string16(), InstantSuggestion()); |
+ omnibox_controller_->FinalizeInstantQuery(string16(), InstantSuggestion()); |
} |
switch (recommended_action) { |
@@ -367,8 +325,7 @@ void OmniboxEditModel::OnChanged() { |
void OmniboxEditModel::GetDataForURLExport(GURL* url, |
string16* title, |
gfx::Image* favicon) { |
- AutocompleteMatch match; |
- GetInfoForCurrentText(&match, NULL); |
+ AutocompleteMatch match = CurrentMatch(); |
Peter Kasting
2013/06/11 22:42:55
Nit: Just inline into the next statement
beaudoin
2013/06/14 21:39:38
Done.
|
*url = match.destination_url; |
if (*url == URLFixerUpper::FixupURL(UTF16ToUTF8(permanent_text_), |
std::string())) { |
@@ -390,15 +347,12 @@ bool OmniboxEditModel::CurrentTextIsURL() const { |
if (!user_input_in_progress_) |
return true; |
- AutocompleteMatch match; |
- GetInfoForCurrentText(&match, NULL); |
+ AutocompleteMatch match = CurrentMatch(); |
Peter Kasting
2013/06/11 22:42:55
Nit: Here too
beaudoin
2013/06/14 21:39:38
Done.
|
return !AutocompleteMatch::IsSearchType(match.type); |
} |
AutocompleteMatch::Type OmniboxEditModel::CurrentTextType() const { |
- AutocompleteMatch match; |
- GetInfoForCurrentText(&match, NULL); |
- return match.type; |
+ return CurrentMatch().type; |
} |
void OmniboxEditModel::AdjustTextForCopy(int sel_min, |
@@ -556,9 +510,18 @@ bool OmniboxEditModel::IsPasteAndSearch(const string16& text) const { |
void OmniboxEditModel::AcceptInput(WindowOpenDisposition disposition, |
bool for_drop) { |
// Get the URL and transition type for the selected entry. |
- AutocompleteMatch match; |
+ AutocompleteMatch match = omnibox_controller_->current_match(); |
GURL alternate_nav_url; |
- GetInfoForCurrentText(&match, &alternate_nav_url); |
+ |
+ if (!match.destination_url.is_valid()) { |
+ GetInfoForCurrentText(&match, &alternate_nav_url); |
Peter Kasting
2013/06/11 22:42:55
Nit: Maybe CurrentMatch() should take an |alternat
beaudoin
2013/06/14 21:39:38
Done.
|
+ } else if (AutocompleteMatch::IsSearchType(match.type)) { |
+ // Compute the |alternate_nav_url| if needed. |
Peter Kasting
2013/06/11 22:42:55
Why do we need this new block? It worries me beca
beaudoin
2013/06/14 21:39:38
The problem is that |alternate_nav_url| is compute
Peter Kasting
2013/06/15 00:29:21
I see. I think we should factor out the last piec
beaudoin
2013/06/17 17:22:33
For the moment, the autocomplete controller is sta
|
+ alternate_nav_url = URLFixerUpper::FixupURL( |
+ UTF16ToUTF8(match.fill_into_edit), std::string()); |
+ if (alternate_nav_url == match.destination_url) |
+ alternate_nav_url = GURL(); |
+ } |
// If CTRL is down it means the user wants to append ".com" to the text he |
// typed. If we can successfully generate a URL_WHAT_YOU_TYPED match doing |
@@ -626,6 +589,7 @@ void OmniboxEditModel::OpenMatch(const AutocompleteMatch& match, |
WindowOpenDisposition disposition, |
const GURL& alternate_nav_url, |
size_t index) { |
+ |
Peter Kasting
2013/06/11 22:42:55
Nit: Extra newline
beaudoin
2013/06/14 21:39:38
Done.
|
// We only care about cases where there is a selection (i.e. the popup is |
// open). |
if (popup_model()->IsOpen()) { |
@@ -695,11 +659,8 @@ void OmniboxEditModel::OpenMatch(const AutocompleteMatch& match, |
if (match.transition == content::PAGE_TRANSITION_KEYWORD) { |
// The user is using a non-substituting keyword or is explicitly in |
// keyword mode. |
- |
- AutocompleteMatch current_match; |
- GetInfoForCurrentText(¤t_match, NULL); |
const AutocompleteMatch& match = (index == OmniboxPopupModel::kNoMatch) ? |
- current_match : result().match_at(index); |
+ CurrentMatch() : result().match_at(index); |
// Don't increment usage count for extension keywords. |
if (delegate_->ProcessExtensionKeyword(template_url, match, |
@@ -884,9 +845,7 @@ void OmniboxEditModel::OnKillFocus() { |
bool OmniboxEditModel::OnEscapeKeyPressed() { |
if (has_temporary_text_) { |
- AutocompleteMatch match; |
- GetInfoForCurrentText(&match, NULL); |
- if (match.destination_url != original_url_) { |
+ if (CurrentMatch().destination_url != original_url_) { |
RevertTemporaryText(true); |
return true; |
} |
@@ -1160,7 +1119,37 @@ bool OmniboxEditModel::OnAfterPossibleChange(const string16& old_text, |
MaybeAcceptKeywordBySpace(user_text_)); |
} |
-void OmniboxEditModel::OnResultChanged(bool default_match_changed) { |
+void OmniboxEditModel::OnCurrentMatchChanged(bool is_temporary_set_by_instant) { |
+ const bool save_original_selection = |
+ is_temporary_set_by_instant && !has_temporary_text_; |
+ has_temporary_text_ = is_temporary_set_by_instant; |
+ is_temporary_text_set_by_instant_ = is_temporary_set_by_instant; |
+ |
+ const AutocompleteMatch& match = omnibox_controller_->current_match(); |
+ match.GetKeywordUIState(profile_, &keyword_, &is_keyword_hint_); |
+ |
+ view_->SetInstantSuggestion(match.gray_suggestion); |
+ string16 inline_autocomplete_text; |
+ if ((match.inline_autocomplete_offset != string16::npos) && |
Peter Kasting
2013/06/11 22:42:55
Nit: This first condition is unnecessary; in cases
beaudoin
2013/06/14 21:39:38
Done.
|
+ (match.inline_autocomplete_offset < |
+ match.fill_into_edit.length())) { |
+ // We have blue text, go through OnPopupDataChanged. |
+ // TODO(beaudoin): Merge OnPopupDataChanged with this method once the popup |
+ // handling has completely migrated to omnibox_controller. |
+ inline_autocomplete_text = |
+ match.fill_into_edit.substr(match.inline_autocomplete_offset); |
+ popup_model()->OnResultChanged(); |
+ OnPopupDataChanged(inline_autocomplete_text, NULL, keyword_, |
+ is_keyword_hint_); |
+ } else { |
+ view_->OnTemporaryTextMaybeChanged( |
Peter Kasting
2013/06/11 22:42:55
I'm trying to figure out where this used to happen
|
+ DisplayTextFromUserText(match.fill_into_edit), save_original_selection, |
+ false); |
+ } |
+} |
+ |
+string16 OmniboxEditModel::GetViewText() const { |
+ return view_->GetText(); |
} |
InstantController* OmniboxEditModel::GetInstantController() const { |