Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Unified Diff: chrome/browser/ui/omnibox/omnibox_controller.cc

Issue 15003002: Omnibox refactor. Move StartAutocomplete and DoInstant to controller. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reverted dummy test. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/omnibox/omnibox_controller.cc
diff --git a/chrome/browser/ui/omnibox/omnibox_controller.cc b/chrome/browser/ui/omnibox/omnibox_controller.cc
index 48171c6e33cb168f70985c6a6d2160ebd7358a4e..c8ba1c68b2f6abcb39464590fb93ced64a275c94 100644
--- a/chrome/browser/ui/omnibox/omnibox_controller.cc
+++ b/chrome/browser/ui/omnibox/omnibox_controller.cc
@@ -7,6 +7,7 @@
#include "base/metrics/histogram.h"
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
+#include "chrome/browser/autocomplete/search_provider.h"
#include "chrome/browser/net/predictor.h"
#include "chrome/browser/predictors/autocomplete_action_predictor.h"
#include "chrome/browser/prerender/prerender_field_trial.h"
@@ -26,9 +27,11 @@ using predictors::AutocompleteActionPredictor;
OmniboxController::OmniboxController(OmniboxEditModel* omnibox_edit_model,
- Profile* profile)
+ Profile* profile,
+ InstantController* instant_controller)
: omnibox_edit_model_(omnibox_edit_model),
- profile_(profile) {
+ profile_(profile),
+ instant_controller_(instant_controller) {
autocomplete_controller_.reset(new AutocompleteController(profile, this,
chrome::IsInstantExtendedAPIEnabled() ?
AutocompleteClassifier::kInstantExtendedOmniboxProviders :
@@ -38,6 +41,35 @@ OmniboxController::OmniboxController(OmniboxEditModel* omnibox_edit_model,
OmniboxController::~OmniboxController() {
}
+void OmniboxController::StartAutocomplete(
+ string16 user_text,
+ size_t cursor_position,
+ bool prevent_inline_autocomplete,
+ bool prefer_keyword,
+ bool allow_exact_keyword_match) const {
+ ClearPopupKeywordMode();
+ popup_->SetHoveredLine(OmniboxPopupModel::kNoMatch);
+
+ if (instant_controller_) {
+ instant_controller_->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_controller_->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(),
+ prevent_inline_autocomplete, prefer_keyword, allow_exact_keyword_match,
+ AutocompleteInput::ALL_MATCHES));
+}
+
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.
@@ -79,10 +111,8 @@ void OmniboxController::OnResultChanged(bool default_match_changed) {
// The popup size may have changed, let instant know.
OnPopupBoundsChanged(popup_->view()->GetTargetBounds());
- InstantController* instant =
- omnibox_edit_model_->controller()->GetInstant();
- if (instant && !omnibox_edit_model_->in_revert()) {
- instant->HandleAutocompleteResults(
+ if (instant_controller_ && !omnibox_edit_model_->in_revert()) {
+ instant_controller_->HandleAutocompleteResults(
*autocomplete_controller()->providers(),
autocomplete_controller()->result());
}
@@ -95,6 +125,30 @@ void OmniboxController::OnResultChanged(bool default_match_changed) {
}
}
+bool OmniboxController::DoInstant(const AutocompleteMatch& match,
+ string16 user_text,
+ string16 full_text,
+ size_t selection_start,
+ size_t selection_end,
+ bool user_input_in_progress,
+ bool in_escape_handler,
+ bool just_deleted_text,
+ bool keyword_is_selected) {
+ if (!instant_controller_)
+ return false;
+
+ // Remove "?" if we're in forced query mode.
+ AutocompleteInput::RemoveForcedQueryStringIfNecessary(
+ autocomplete_controller_->input().type(), &user_text);
+ AutocompleteInput::RemoveForcedQueryStringIfNecessary(
+ autocomplete_controller_->input().type(), &full_text);
+
+ return instant_controller_->Update(
+ match, user_text, full_text, selection_start, selection_end,
+ UseVerbatimInstant(just_deleted_text), user_input_in_progress,
+ popup_->IsOpen(), in_escape_handler, keyword_is_selected);
+}
+
void OmniboxController::ClearPopupKeywordMode() const {
if (popup_->IsOpen() &&
popup_->selected_line_state() == OmniboxPopupModel::KEYWORD)
@@ -118,7 +172,26 @@ void OmniboxController::DoPreconnect(const AutocompleteMatch& match) {
}
void OmniboxController::OnPopupBoundsChanged(const gfx::Rect& bounds) {
- InstantController* instant = omnibox_edit_model_->controller()->GetInstant();
- if (instant)
- instant->SetPopupBounds(bounds);
+ if (instant_controller_)
+ instant_controller_->SetPopupBounds(bounds);
+}
+
+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;
}

Powered by Google App Engine
This is Rietveld 408576698