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

Side by Side Diff: chrome/browser/ui/omnibox/omnibox_controller.cc

Issue 14358005: Omnibox refactor, moved OnResultChanged to OmniboxController (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed nit. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/omnibox/omnibox_controller.h" 5 #include "chrome/browser/ui/omnibox/omnibox_controller.h"
6 6
7 #include "base/metrics/histogram.h"
7 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 8 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
8 #include "chrome/browser/autocomplete/autocomplete_controller.h" 9 #include "chrome/browser/autocomplete/autocomplete_controller.h"
10 #include "chrome/browser/autocomplete/autocomplete_match.h"
11 #include "chrome/browser/net/predictor.h"
12 #include "chrome/browser/predictors/autocomplete_action_predictor.h"
13 #include "chrome/browser/prerender/prerender_field_trial.h"
14 #include "chrome/browser/prerender/prerender_manager.h"
15 #include "chrome/browser/prerender/prerender_manager_factory.h"
16 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/search/search.h" 17 #include "chrome/browser/search/search.h"
18 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h"
10 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" 19 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h"
20 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
21 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h"
22 #include "chrome/browser/ui/search/instant_controller.h"
23 #include "extensions/common/constants.h"
24 #include "ui/gfx/rect.h"
25
26 using predictors::AutocompleteActionPredictor;
11 27
12 28
13 OmniboxController::OmniboxController(OmniboxEditModel* omnibox_edit_model, 29 OmniboxController::OmniboxController(OmniboxEditModel* omnibox_edit_model,
14 Profile* profile) 30 Profile* profile)
15 : omnibox_edit_model_(omnibox_edit_model) { 31 : omnibox_edit_model_(omnibox_edit_model),
32 profile_(profile) {
16 autocomplete_controller_.reset(new AutocompleteController(profile, this, 33 autocomplete_controller_.reset(new AutocompleteController(profile, this,
17 chrome::IsInstantExtendedAPIEnabled() ? 34 chrome::IsInstantExtendedAPIEnabled() ?
18 AutocompleteClassifier::kInstantExtendedOmniboxProviders : 35 AutocompleteClassifier::kInstantExtendedOmniboxProviders :
19 AutocompleteClassifier::kDefaultOmniboxProviders)); 36 AutocompleteClassifier::kDefaultOmniboxProviders));
20 } 37 }
21 38
22 OmniboxController::~OmniboxController() { 39 OmniboxController::~OmniboxController() {
23 } 40 }
24 41
25 void OmniboxController::OnResultChanged(bool default_match_changed) { 42 void OmniboxController::OnResultChanged(bool default_match_changed) {
26 omnibox_edit_model_->OnResultChanged(default_match_changed); 43 // TODO(beaudoin): There should be no need to access the popup when using
44 // instant extended, remove this reference.
45 const bool was_open = popup_->IsOpen();
46 if (default_match_changed) {
47 // The default match has changed, we need to let the OmniboxEditModel know
48 // about new inline autocomplete text (blue highlight).
49 string16 inline_autocomplete_text;
50 string16 keyword;
51 bool is_keyword_hint = false;
52 const AutocompleteResult& result = this->result();
53 const AutocompleteResult::const_iterator match(result.default_match());
54 if (match != result.end()) {
55 if ((match->inline_autocomplete_offset != string16::npos) &&
56 (match->inline_autocomplete_offset <
57 match->fill_into_edit.length())) {
58 inline_autocomplete_text =
59 match->fill_into_edit.substr(match->inline_autocomplete_offset);
60 }
61
62 if (!prerender::IsOmniboxEnabled(profile_))
63 DoPreconnect(*match);
64
65 // We could prefetch the alternate nav URL, if any, but because there
66 // can be many of these as a user types an initial series of characters,
67 // the OS DNS cache could suffer eviction problems for minimal gain.
68
69 match->GetKeywordUIState(profile_, &keyword, &is_keyword_hint);
70 }
71
72 popup_->OnResultChanged();
73 omnibox_edit_model_->OnPopupDataChanged(inline_autocomplete_text, NULL,
74 keyword, is_keyword_hint);
75 } else {
76 popup_->OnResultChanged();
77 }
78
79 if (popup_->IsOpen()) {
80 // The popup size may have changed, let instant know.
81 OnPopupBoundsChanged(popup_->view()->GetTargetBounds());
82
83 InstantController* instant =
84 omnibox_edit_model_->controller()->GetInstant();
85 if (instant && !omnibox_edit_model_->in_revert()) {
86 instant->HandleAutocompleteResults(
87 *autocomplete_controller()->providers(),
88 autocomplete_controller()->result());
89 }
90 } else if (was_open) {
91 // Accepts the temporary text as the user text, because it makes little
Peter Kasting 2013/05/22 23:56:54 Nit: Accepts -> Accept
beaudoin 2013/05/23 14:16:41 Done.
92 // sense to have temporary text when the popup is closed.
93 omnibox_edit_model_->AcceptTemporaryTextAsUserText();
94 // The popup has been closed, let instant know.
95 OnPopupBoundsChanged(gfx::Rect());
96 }
27 } 97 }
98
99 void OmniboxController::ClearPopupKeywordMode() const {
100 if (popup_->IsOpen() &&
101 popup_->selected_line_state() == OmniboxPopupModel::KEYWORD)
102 popup_->SetSelectedLineState(OmniboxPopupModel::NORMAL);
103 }
104
105 const AutocompleteResult& OmniboxController::result() const {
106 return autocomplete_controller_->result();
107 }
108
109 void OmniboxController::DoPreconnect(const AutocompleteMatch& match) {
110 if (!match.destination_url.SchemeIs(extensions::kExtensionScheme)) {
111 // Warm up DNS Prefetch cache, or preconnect to a search service.
112 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type,
113 AutocompleteMatchType::NUM_TYPES);
114 if (profile_->GetNetworkPredictor()) {
115 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl(
116 match.destination_url,
117 AutocompleteActionPredictor::IsPreconnectable(match));
118 }
119 // We could prefetch the alternate nav URL, if any, but because there
120 // can be many of these as a user types an initial series of characters,
121 // the OS DNS cache could suffer eviction problems for minimal gain.
122 }
123 }
124
125 void OmniboxController::OnPopupBoundsChanged(const gfx::Rect& bounds) {
126 InstantController* instant = omnibox_edit_model_->controller()->GetInstant();
127 if (instant)
128 instant->SetPopupBounds(bounds);
129 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698