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 3dd4190cfa8b5449af1f62f48292b916b6ad8ee2..ba2cbb92ca343fd7d0e9bf56e4892d4cd6d6cf27 100644 |
--- a/chrome/browser/ui/omnibox/omnibox_edit_model.cc |
+++ b/chrome/browser/ui/omnibox/omnibox_edit_model.cc |
@@ -120,7 +120,6 @@ OmniboxEditModel::OmniboxEditModel(OmniboxView* view, |
OmniboxEditController* controller, |
Profile* profile) |
: view_(view), |
- popup_(NULL), |
controller_(controller), |
focus_state_(OMNIBOX_FOCUS_NONE), |
user_input_in_progress_(false), |
@@ -231,7 +230,7 @@ void OmniboxEditModel::FinalizeInstantQuery(const string16& input_text, |
view_->SetWindowTextAndCaretPos(final_text, final_text.length(), false, |
false); |
view_->OnAfterPossibleChange(); |
- } else if (popup_->IsOpen()) { |
+ } else if (popup_model()->IsOpen()) { |
SearchProvider* search_provider = |
autocomplete_controller()->search_provider(); |
// There may be no providers during testing; guard against that. |
@@ -342,7 +341,7 @@ void OmniboxEditModel::OnChanged() { |
delegate_->DoPrerender(current_match); |
break; |
case AutocompleteActionPredictor::ACTION_PRECONNECT: |
- DoPreconnect(current_match); |
+ omnibox_controller_->DoPreconnect(current_match); |
break; |
case AutocompleteActionPredictor::ACTION_NONE: |
break; |
@@ -381,7 +380,7 @@ bool OmniboxEditModel::UseVerbatimInstant() { |
// 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 view_->DeleteAtEndPressed() || popup_->selected_line() != 0 || |
+ return view_->DeleteAtEndPressed() || popup_model()->selected_line() != 0 || |
just_deleted_text_; |
} |
@@ -494,7 +493,7 @@ void OmniboxEditModel::StartAutocomplete( |
ClearPopupKeywordMode(); |
bool keyword_is_selected = KeywordIsSelected(); |
- popup_->SetHoveredLine(OmniboxPopupModel::kNoMatch); |
+ popup_model()->SetHoveredLine(OmniboxPopupModel::kNoMatch); |
size_t cursor_position; |
if (inline_autocomplete_text_.empty()) { |
@@ -636,14 +635,14 @@ void OmniboxEditModel::OpenMatch(const AutocompleteMatch& match, |
size_t index) { |
// We only care about cases where there is a selection (i.e. the popup is |
// open). |
- if (popup_->IsOpen()) { |
+ if (popup_model()->IsOpen()) { |
const base::TimeTicks& now(base::TimeTicks::Now()); |
// TODO(sreeram): Handle is_temporary_text_set_by_instant_ correctly. |
AutocompleteLog log( |
autocomplete_controller()->input().text(), |
just_deleted_text_, |
autocomplete_controller()->input().type(), |
- popup_->selected_line(), |
+ popup_model()->selected_line(), |
-1, // don't yet know tab ID; set later if appropriate |
delegate_->CurrentPageExists() ? ClassifyPage(delegate_->GetURL()) : |
metrics::OmniboxEventProto_PageClassification_OTHER, |
@@ -761,8 +760,8 @@ bool OmniboxEditModel::AcceptKeyword(EnteredKeywordModeMethod entered_method) { |
autocomplete_controller()->Stop(false); |
is_keyword_hint_ = false; |
- if (popup_->IsOpen()) |
- popup_->SetSelectedLineState(OmniboxPopupModel::KEYWORD); |
+ if (popup_model()->IsOpen()) |
+ popup_model()->SetSelectedLineState(OmniboxPopupModel::KEYWORD); |
else |
StartAutocomplete(false, true); |
@@ -783,6 +782,14 @@ bool OmniboxEditModel::AcceptKeyword(EnteredKeywordModeMethod entered_method) { |
return true; |
} |
+void OmniboxEditModel::AcceptTemporaryTextAsUserText() { |
+ InternalSetUserText(UserTextFromDisplayText(view_->GetText())); |
+ has_temporary_text_ = false; |
+ is_temporary_text_set_by_instant_ = false; |
+ OnPopupBoundsChanged(gfx::Rect()); |
+ delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_); |
+} |
+ |
void OmniboxEditModel::ClearKeyword(const string16& visible_text) { |
autocomplete_controller()->Stop(false); |
ClearPopupKeywordMode(); |
@@ -791,7 +798,7 @@ void OmniboxEditModel::ClearKeyword(const string16& visible_text) { |
// Only reset the result if the edit text has changed since the |
// keyword was accepted, or if the popup is closed. |
- if (just_deleted_text_ || !visible_text.empty() || !popup_->IsOpen()) { |
+ if (just_deleted_text_ || !visible_text.empty() || !popup_model()->IsOpen()) { |
view_->OnBeforePossibleChange(); |
view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length(), |
false, false); |
@@ -808,10 +815,6 @@ void OmniboxEditModel::ClearKeyword(const string16& visible_text) { |
} |
} |
-const AutocompleteResult& OmniboxEditModel::result() const { |
- return autocomplete_controller()->result(); |
-} |
- |
void OmniboxEditModel::OnSetFocus(bool control_down) { |
// If the omnibox lost focus while the caret was hidden and then regained |
// focus, OnSetFocus() is called and should restore visibility. Note that |
@@ -912,7 +915,7 @@ void OmniboxEditModel::OnControlKeyChanged(bool pressed) { |
has_temporary_text_ = false; |
is_temporary_text_set_by_instant_ = false; |
} |
- if ((old_state != DOWN_WITH_CHANGE) && popup_->IsOpen()) { |
+ if ((old_state != DOWN_WITH_CHANGE) && popup_model()->IsOpen()) { |
// Autocomplete history provider results may change, so refresh the |
// popup. This will force user_input_in_progress_ to true, but if the |
// popup is open, that should have already been the case. |
@@ -923,7 +926,7 @@ void OmniboxEditModel::OnControlKeyChanged(bool pressed) { |
void OmniboxEditModel::OnUpOrDownKeyPressed(int count) { |
// NOTE: This purposefully doesn't trigger any code that resets paste_state_. |
- if (!popup_->IsOpen()) { |
+ if (!popup_model()->IsOpen()) { |
if (!query_in_progress()) { |
// The popup is neither open nor working on a query already. So, start an |
// autocomplete query for the current text. This also sets |
@@ -951,7 +954,7 @@ void OmniboxEditModel::OnUpOrDownKeyPressed(int count) { |
} else { |
// The popup is open, so the user should be able to interact with it |
// normally. |
- popup_->Move(count); |
+ popup_model()->Move(count); |
} |
} |
} |
@@ -1071,7 +1074,7 @@ bool OmniboxEditModel::OnAfterPossibleChange(const string16& old_text, |
if ((text_differs || selection_differs) && |
(control_key_state_ == DOWN_WITHOUT_CHANGE)) { |
control_key_state_ = DOWN_WITH_CHANGE; |
- if (!text_differs && !popup_->IsOpen()) |
+ if (!text_differs && !popup_model()->IsOpen()) |
return false; // Don't open the popup for no reason. |
} else if (!user_text_changed) { |
return false; |
@@ -1142,55 +1145,6 @@ void OmniboxEditModel::OnPopupBoundsChanged(const gfx::Rect& bounds) { |
} |
void OmniboxEditModel::OnResultChanged(bool default_match_changed) { |
- const bool was_open = popup_->IsOpen(); |
- if (default_match_changed) { |
- string16 inline_autocomplete_text; |
- string16 keyword; |
- bool is_keyword_hint = false; |
- const AutocompleteResult& result = this->result(); |
- const AutocompleteResult::const_iterator match(result.default_match()); |
- if (match != result.end()) { |
- if ((match->inline_autocomplete_offset != string16::npos) && |
- (match->inline_autocomplete_offset < |
- match->fill_into_edit.length())) { |
- inline_autocomplete_text = |
- match->fill_into_edit.substr(match->inline_autocomplete_offset); |
- } |
- |
- if (!prerender::IsOmniboxEnabled(profile_)) |
- DoPreconnect(*match); |
- |
- // We could prefetch the alternate nav URL, if any, but because there |
- // can be many of these as a user types an initial series of characters, |
- // the OS DNS cache could suffer eviction problems for minimal gain. |
- |
- match->GetKeywordUIState(profile_, &keyword, &is_keyword_hint); |
- } |
- |
- popup_->OnResultChanged(); |
- OnPopupDataChanged(inline_autocomplete_text, NULL, keyword, |
- is_keyword_hint); |
- } else { |
- popup_->OnResultChanged(); |
- } |
- |
- if (popup_->IsOpen()) { |
- OnPopupBoundsChanged(popup_->view()->GetTargetBounds()); |
- |
- InstantController* instant = controller_->GetInstant(); |
- if (instant && !in_revert_) { |
- instant->HandleAutocompleteResults( |
- *autocomplete_controller_->providers()); |
- } |
- } else if (was_open) { |
- // Accepts the temporary text as the user text, because it makes little |
- // sense to have temporary text when the popup is closed. |
- InternalSetUserText(UserTextFromDisplayText(view_->GetText())); |
- has_temporary_text_ = false; |
- is_temporary_text_set_by_instant_ = false; |
- OnPopupBoundsChanged(gfx::Rect()); |
- delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_); |
- } |
} |
bool OmniboxEditModel::query_in_progress() const { |
@@ -1207,12 +1161,6 @@ bool OmniboxEditModel::KeywordIsSelected() const { |
return !is_keyword_hint_ && !keyword_.empty(); |
} |
-void OmniboxEditModel::ClearPopupKeywordMode() const { |
- if (popup_->IsOpen() && |
- popup_->selected_line_state() == OmniboxPopupModel::KEYWORD) |
- popup_->SetSelectedLineState(OmniboxPopupModel::NORMAL); |
-} |
- |
string16 OmniboxEditModel::DisplayTextFromUserText(const string16& text) const { |
return KeywordIsSelected() ? |
KeywordProvider::SplitReplacementStringFromInput(text, false) : text; |
@@ -1222,37 +1170,11 @@ string16 OmniboxEditModel::UserTextFromDisplayText(const string16& text) const { |
return KeywordIsSelected() ? (keyword_ + char16(' ') + text) : text; |
} |
-void OmniboxEditModel::InfoForCurrentSelection(AutocompleteMatch* match, |
- GURL* alternate_nav_url) const { |
- DCHECK(match != NULL); |
- const AutocompleteResult& result = this->result(); |
- if (!autocomplete_controller()->done()) { |
- // It's technically possible for |result| to be empty if no provider returns |
- // a synchronous result but the query has not completed synchronously; |
- // pratically, however, that should never actually happen. |
- if (result.empty()) |
- return; |
- // The user cannot have manually selected a match, or the query would have |
- // stopped. So the default match must be the desired selection. |
- *match = *result.default_match(); |
- } else { |
- CHECK(popup_->IsOpen()); |
- // If there are no results, the popup should be closed (so we should have |
- // failed the CHECK above), and URLsForDefaultMatch() should have been |
- // called instead. |
- CHECK(!result.empty()); |
- CHECK(popup_->selected_line() < result.size()); |
- *match = result.match_at(popup_->selected_line()); |
- } |
- if (alternate_nav_url && popup_->manually_selected_match().empty()) |
- *alternate_nav_url = result.alternate_nav_url(); |
-} |
- |
void OmniboxEditModel::GetInfoForCurrentText(AutocompleteMatch* match, |
GURL* alternate_nav_url) const { |
// If there's temporary text and it has been set by Instant, we won't find it |
// in the popup model, so classify the text anew. |
- if ((popup_->IsOpen() || query_in_progress()) && |
+ if ((popup_model()->IsOpen() || query_in_progress()) && |
!is_temporary_text_set_by_instant_) { |
InfoForCurrentSelection(match, alternate_nav_url); |
} else { |
@@ -1290,7 +1212,7 @@ void OmniboxEditModel::RevertTemporaryText(bool revert_popup) { |
user_text_ + inline_autocomplete_text_); |
} |
if (revert_popup) |
- popup_->ResetToDefaultMatch(); |
+ popup_model()->ResetToDefaultMatch(); |
view_->OnRevertTemporaryText(); |
} |
@@ -1361,26 +1283,10 @@ bool OmniboxEditModel::DoInstant(const AutocompleteMatch& match) { |
view_->GetSelectionBounds(&start, &end); |
return instant->Update(match, user_text, full_text, start, end, |
- UseVerbatimInstant(), user_input_in_progress_, popup_->IsOpen(), |
+ UseVerbatimInstant(), user_input_in_progress_, popup_model()->IsOpen(), |
in_escape_handler_, KeywordIsSelected()); |
} |
-void OmniboxEditModel::DoPreconnect(const AutocompleteMatch& match) { |
- if (!match.destination_url.SchemeIs(extensions::kExtensionScheme)) { |
- // Warm up DNS Prefetch cache, or preconnect to a search service. |
- UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type, |
- AutocompleteMatch::NUM_TYPES); |
- if (profile_->GetNetworkPredictor()) { |
- profile_->GetNetworkPredictor()->AnticipateOmniboxUrl( |
- match.destination_url, |
- AutocompleteActionPredictor::IsPreconnectable(match)); |
- } |
- // We could prefetch the alternate nav URL, if any, but because there |
- // can be many of these as a user types an initial series of characters, |
- // the OS DNS cache could suffer eviction problems for minimal gain. |
- } |
-} |
- |
// static |
bool OmniboxEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { |
switch (c) { |