| 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 903cf2c2d8d82fd444b2846432cbd1580b1f63b0..399dd216f7f2fd95edd2764d58c39fd75f0cf6ad 100644
|
| --- a/chrome/browser/ui/omnibox/omnibox_edit_model.cc
|
| +++ b/chrome/browser/ui/omnibox/omnibox_edit_model.cc
|
| @@ -137,7 +137,8 @@ OmniboxEditModel::OmniboxEditModel(OmniboxView* view,
|
| in_revert_(false),
|
| in_escape_handler_(false),
|
| allow_exact_keyword_match_(false) {
|
| - omnibox_controller_.reset(new OmniboxController(this, profile));
|
| + omnibox_controller_.reset(new OmniboxController(this, profile,
|
| + controller->GetInstant()));
|
| delegate_.reset(new OmniboxCurrentPageDelegateImpl(controller, profile));
|
| }
|
|
|
| @@ -227,16 +228,10 @@ void OmniboxEditModel::SetUserText(const string16& text) {
|
| is_instant_temporary_text_a_search_query_ = false;
|
| }
|
|
|
| -void OmniboxEditModel::FinalizeInstantQuery(const string16& input_text,
|
| - const InstantSuggestion& suggestion,
|
| - bool skip_inline_autocomplete) {
|
| - if (skip_inline_autocomplete) {
|
| - const string16 final_text = input_text + suggestion.text;
|
| - view_->OnBeforePossibleChange();
|
| - view_->SetWindowTextAndCaretPos(final_text, final_text.length(), false,
|
| - false);
|
| - view_->OnAfterPossibleChange();
|
| - } else if (popup_model()->IsOpen()) {
|
| +void OmniboxEditModel::FinalizeInstantQuery(
|
| + const string16& input_text,
|
| + const InstantSuggestion& suggestion) {
|
| + if (popup_model()->IsOpen()) {
|
| SearchProvider* search_provider =
|
| autocomplete_controller()->search_provider();
|
| // There may be no providers during testing; guard against that.
|
| @@ -251,13 +246,16 @@ void OmniboxEditModel::SetInstantSuggestion(
|
| case INSTANT_COMPLETE_NOW:
|
| view_->SetInstantSuggestion(string16());
|
| if (!suggestion.text.empty())
|
| - FinalizeInstantQuery(view_->GetText(), suggestion, false);
|
| + 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();
|
| + SearchProvider* search_provider =
|
| + autocomplete_controller()->search_provider();
|
| + if (search_provider)
|
| + search_provider->ClearInstantSuggestion();
|
| break;
|
| }
|
|
|
| @@ -280,7 +278,7 @@ void OmniboxEditModel::SetInstantSuggestion(
|
| }
|
| }
|
|
|
| -bool OmniboxEditModel::CommitSuggestedText(bool skip_inline_autocomplete) {
|
| +bool OmniboxEditModel::CommitSuggestedText() {
|
| if (!controller_->GetInstant())
|
| return false;
|
|
|
| @@ -289,13 +287,11 @@ bool OmniboxEditModel::CommitSuggestedText(bool skip_inline_autocomplete) {
|
| return false;
|
|
|
| // Assume that the gray text we are committing is a search suggestion.
|
| - FinalizeInstantQuery(view_->GetText(),
|
| - InstantSuggestion(suggestion,
|
| - INSTANT_COMPLETE_NOW,
|
| - INSTANT_SUGGESTION_SEARCH,
|
| - string16(),
|
| - OmniboxPopupModel::kNoMatch),
|
| - skip_inline_autocomplete);
|
| + const string16 final_text = view_->GetText() + suggestion;
|
| + view_->OnBeforePossibleChange();
|
| + view_->SetWindowTextAndCaretPos(final_text, final_text.length(), false,
|
| + false);
|
| + view_->OnAfterPossibleChange();
|
| return true;
|
| }
|
|
|
| @@ -327,12 +323,28 @@ void OmniboxEditModel::OnChanged() {
|
| recommended_action,
|
| AutocompleteActionPredictor::LAST_PREDICT_ACTION);
|
|
|
| - if (!DoInstant(current_match)) {
|
| + // Do not perform instant if we're currently reverting or the change is the
|
| + // result of an INSTANT_COMPLETE_REPLACE instant suggestion.
|
| + bool performed_instant = false;
|
| + if (!in_revert_ &&
|
| + (!has_temporary_text_ || !is_temporary_text_set_by_instant_)) {
|
| + size_t start, end;
|
| + view_->GetSelectionBounds(&start, &end);
|
| + string16 user_text = has_temporary_text_ ? current_match.fill_into_edit :
|
| + DisplayTextFromUserText(user_text_);
|
| + performed_instant = omnibox_controller_->DoInstant(
|
| + current_match, user_text, view_->GetText(), start, end,
|
| + user_input_in_progress_, in_escape_handler_,
|
| + view_->DeleteAtEndPressed() || just_deleted_text_,
|
| + KeywordIsSelected());
|
| + }
|
| +
|
| + if (!performed_instant) {
|
| // Hide any suggestions we might be showing.
|
| view_->SetInstantSuggestion(string16());
|
|
|
| // No need to wait any longer for Instant.
|
| - FinalizeInstantQuery(string16(), InstantSuggestion(), false);
|
| + FinalizeInstantQuery(string16(), InstantSuggestion());
|
| }
|
|
|
| switch (recommended_action) {
|
| @@ -370,27 +382,6 @@ void OmniboxEditModel::GetDataForURLExport(GURL* url,
|
| }
|
| }
|
|
|
| -bool OmniboxEditModel::UseVerbatimInstant() {
|
| -#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 view_->DeleteAtEndPressed() || popup_model()->selected_line() != 0 ||
|
| - just_deleted_text_;
|
| -}
|
| -
|
| bool OmniboxEditModel::CurrentTextIsURL() const {
|
| if (view_->toolbar_model()->GetSearchTermsType() !=
|
| ToolbarModel::NO_SEARCH_TERMS)
|
| @@ -502,11 +493,6 @@ void OmniboxEditModel::Revert() {
|
| void OmniboxEditModel::StartAutocomplete(
|
| bool has_selected_text,
|
| bool prevent_inline_autocomplete) const {
|
| - omnibox_controller_->ClearPopupKeywordMode();
|
| -
|
| - bool keyword_is_selected = KeywordIsSelected();
|
| - popup_model()->SetHoveredLine(OmniboxPopupModel::kNoMatch);
|
| -
|
| size_t cursor_position;
|
| if (inline_autocomplete_text_.empty()) {
|
| // Cursor position is equivalent to the current selection's end.
|
| @@ -532,28 +518,15 @@ void OmniboxEditModel::StartAutocomplete(
|
| cursor_position = user_text_.length();
|
| }
|
|
|
| - InstantController* instant = controller_->GetInstant();
|
| - if (instant) {
|
| - instant->OnAutocompleteStart();
|
| - // If the embedded page for InstantExtended is fetching its own suggestions,
|
| - // suppress search suggestions from SearchProvider. We still need
|
| - // SearchProvider to run for FinalizeInstantQuery.
|
| - // TODO(dcblack): Once we are done refactoring the omnibox so we don't need
|
| - // to use FinalizeInstantQuery anymore, we can take out this check and
|
| - // remove this provider from kInstantExtendedOmniboxProviders.
|
| - if (instant->WillFetchCompletions())
|
| - autocomplete_controller()->search_provider()->SuppressSearchSuggestions();
|
| - }
|
| -
|
| - // We don't explicitly clear OmniboxPopupModel::manually_selected_match, as
|
| - // Start ends up invoking OmniboxPopupModel::OnResultChanged which clears it.
|
| - autocomplete_controller()->Start(AutocompleteInput(
|
| - user_text_, cursor_position, string16(), GURL(),
|
| + bool keyword_is_selected = KeywordIsSelected();
|
| + omnibox_controller_->StartAutocomplete(
|
| + user_text_,
|
| + cursor_position,
|
| prevent_inline_autocomplete || just_deleted_text_ ||
|
| (has_selected_text && inline_autocomplete_text_.empty()) ||
|
| - (paste_state_ != NONE), keyword_is_selected,
|
| - keyword_is_selected || allow_exact_keyword_match_,
|
| - AutocompleteInput::ALL_MATCHES));
|
| + (paste_state_ != NONE),
|
| + keyword_is_selected,
|
| + keyword_is_selected || allow_exact_keyword_match_);
|
| }
|
|
|
| void OmniboxEditModel::StopAutocomplete() {
|
| @@ -1372,36 +1345,6 @@ bool OmniboxEditModel::CreatedKeywordSearchByInsertingSpaceInMiddle(
|
| GetKeywordForText(keyword).empty();
|
| }
|
|
|
| -bool OmniboxEditModel::DoInstant(const AutocompleteMatch& match) {
|
| - InstantController* instant = controller_->GetInstant();
|
| - if (!instant || in_revert_)
|
| - return false;
|
| -
|
| - // Don't call Update() if the change is the result of an
|
| - // INSTANT_COMPLETE_REPLACE instant suggestion.
|
| - if (is_temporary_text_set_by_instant_)
|
| - return false;
|
| -
|
| - // The two pieces of text we want to send Instant, viz., what the user has
|
| - // typed, and the full omnibox text including any inline autocompletion.
|
| - string16 user_text = has_temporary_text_ ?
|
| - match.fill_into_edit : DisplayTextFromUserText(user_text_);
|
| - string16 full_text = view_->GetText();
|
| -
|
| - // Remove "?" if we're in forced query mode.
|
| - AutocompleteInput::RemoveForcedQueryStringIfNecessary(
|
| - autocomplete_controller()->input().type(), &user_text);
|
| - AutocompleteInput::RemoveForcedQueryStringIfNecessary(
|
| - autocomplete_controller()->input().type(), &full_text);
|
| -
|
| - size_t start, end;
|
| - view_->GetSelectionBounds(&start, &end);
|
| -
|
| - return instant->Update(match, user_text, full_text, start, end,
|
| - UseVerbatimInstant(), user_input_in_progress_, popup_model()->IsOpen(),
|
| - in_escape_handler_, KeywordIsSelected());
|
| -}
|
| -
|
| // static
|
| bool OmniboxEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) {
|
| switch (c) {
|
|
|