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

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

Issue 18223002: InstantExtended: Remove overlay control code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 7 years, 5 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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_edit_model.h" 5 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 omnibox_controller_->InvalidateCurrentMatch(); 232 omnibox_controller_->InvalidateCurrentMatch();
233 paste_state_ = NONE; 233 paste_state_ = NONE;
234 has_temporary_text_ = false; 234 has_temporary_text_ = false;
235 is_temporary_text_set_by_instant_ = false; 235 is_temporary_text_set_by_instant_ = false;
236 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch; 236 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch;
237 is_instant_temporary_text_a_search_query_ = false; 237 is_instant_temporary_text_a_search_query_ = false;
238 } 238 }
239 239
240 void OmniboxEditModel::SetInstantSuggestion( 240 void OmniboxEditModel::SetInstantSuggestion(
241 const InstantSuggestion& suggestion) { 241 const InstantSuggestion& suggestion) {
242 // Should only get called for the HTML popup.
243 #if defined(HTML_INSTANT_EXTENDED_POPUP)
244 omnibox_controller_->SetInstantSuggestion(suggestion);
245 #endif
246 } 242 }
247 243
248 bool OmniboxEditModel::CommitSuggestedText() { 244 bool OmniboxEditModel::CommitSuggestedText() {
249 const string16 suggestion = view_->GetInstantSuggestion(); 245 const string16 suggestion = view_->GetInstantSuggestion();
250 if (suggestion.empty()) 246 if (suggestion.empty())
251 return false; 247 return false;
252 248
253 // Assume that the gray text we are committing is a search suggestion. 249 // Assume that the gray text we are committing is a search suggestion.
254 const string16 final_text = view_->GetText() + suggestion; 250 const string16 final_text = view_->GetText() + suggestion;
255 view_->OnBeforePossibleChange(); 251 view_->OnBeforePossibleChange();
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 700
705 // Track whether the destination URL sends us to a search results page 701 // Track whether the destination URL sends us to a search results page
706 // using the default search provider. 702 // using the default search provider.
707 TemplateURL* default_provider = 703 TemplateURL* default_provider =
708 TemplateURLServiceFactory::GetForProfile(profile_)-> 704 TemplateURLServiceFactory::GetForProfile(profile_)->
709 GetDefaultSearchProvider(); 705 GetDefaultSearchProvider();
710 if (default_provider && default_provider->IsSearchURL(destination_url)) 706 if (default_provider && default_provider->IsSearchURL(destination_url))
711 content::RecordAction(UserMetricsAction( 707 content::RecordAction(UserMetricsAction(
712 "OmniboxDestinationURLMatchesDefaultSearchProvider")); 708 "OmniboxDestinationURLMatchesDefaultSearchProvider"));
713 709
714 #if defined(HTML_INSTANT_EXTENDED_POPUP)
715 // If running with instant, notify the instant controller that a navigation
716 // is about to take place if we are navigating to a URL. This can be
717 // determined by inspecting the transition type. To ensure that this is only
718 // done on Enter key press, check that the disposition is CURRENT_TAB. This
719 // is the same heuristic used by BrowserInstantController::OpenInstant
720 if (match.transition == content::PAGE_TRANSITION_TYPED &&
721 disposition == CURRENT_TAB) {
722 InstantController* instant = GetInstantController();
723 if (instant)
724 instant->OmniboxNavigateToURL();
725 }
726 #endif
727
728 // This calls RevertAll again. 710 // This calls RevertAll again.
729 base::AutoReset<bool> tmp(&in_revert_, true); 711 base::AutoReset<bool> tmp(&in_revert_, true);
730 controller_->OnAutocompleteAccept(destination_url, disposition, 712 controller_->OnAutocompleteAccept(destination_url, disposition,
731 match.transition, alternate_nav_url); 713 match.transition, alternate_nav_url);
732 } 714 }
733 715
734 if (match.starred) 716 if (match.starred)
735 bookmark_utils::RecordBookmarkLaunch(bookmark_utils::LAUNCH_OMNIBOX); 717 bookmark_utils::RecordBookmarkLaunch(bookmark_utils::LAUNCH_OMNIBOX);
736 } 718 }
737 719
(...skipping 26 matching lines...) Expand all
764 746
765 return true; 747 return true;
766 } 748 }
767 749
768 void OmniboxEditModel::AcceptTemporaryTextAsUserText() { 750 void OmniboxEditModel::AcceptTemporaryTextAsUserText() {
769 InternalSetUserText(UserTextFromDisplayText(view_->GetText())); 751 InternalSetUserText(UserTextFromDisplayText(view_->GetText()));
770 has_temporary_text_ = false; 752 has_temporary_text_ = false;
771 is_temporary_text_set_by_instant_ = false; 753 is_temporary_text_set_by_instant_ = false;
772 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch; 754 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch;
773 is_instant_temporary_text_a_search_query_ = false; 755 is_instant_temporary_text_a_search_query_ = false;
774 OnPopupBoundsChanged(gfx::Rect());
775 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_, 756 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_,
776 popup_model()->IsOpen(), user_text_.empty()); 757 popup_model()->IsOpen(), user_text_.empty());
777 } 758 }
778 759
779 void OmniboxEditModel::ClearKeyword(const string16& visible_text) { 760 void OmniboxEditModel::ClearKeyword(const string16& visible_text) {
780 autocomplete_controller()->Stop(false); 761 autocomplete_controller()->Stop(false);
781 omnibox_controller_->ClearPopupKeywordMode(); 762 omnibox_controller_->ClearPopupKeywordMode();
782 763
783 const string16 window_text(keyword_ + visible_text); 764 const string16 window_text(keyword_ + visible_text);
784 765
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 // TODO(pkasting): We should, in fact, force this particular query to open 888 // TODO(pkasting): We should, in fact, force this particular query to open
908 // the popup immediately. 889 // the popup immediately.
909 if (!user_input_in_progress_) 890 if (!user_input_in_progress_)
910 InternalSetUserText(permanent_text_); 891 InternalSetUserText(permanent_text_);
911 view_->UpdatePopup(); 892 view_->UpdatePopup();
912 } else { 893 } else {
913 // TODO(pkasting): The popup is working on a query but is not open. We 894 // TODO(pkasting): The popup is working on a query but is not open. We
914 // should force it to open immediately. 895 // should force it to open immediately.
915 } 896 }
916 } else { 897 } else {
917 #if defined(HTML_INSTANT_EXTENDED_POPUP) 898 // The popup is open, so the user should be able to interact with it
918 InstantController* instant = GetInstantController(); 899 // normally.
919 if (instant && instant->OnUpOrDownKeyPressed(count)) { 900 popup_model()->Move(count);
920 // If Instant handles the key press, it's showing a list of suggestions
921 // that it's stepping through. In that case, our popup model is
922 // irrelevant, so don't process the key press ourselves. However, do stop
923 // the autocomplete system from changing the results.
924 autocomplete_controller()->Stop(false);
925 } else
926 #endif
927 {
928 // The popup is open, so the user should be able to interact with it
929 // normally.
930 popup_model()->Move(count);
931 }
932 } 901 }
933 } 902 }
934 903
935 void OmniboxEditModel::OnPopupDataChanged( 904 void OmniboxEditModel::OnPopupDataChanged(
936 const string16& text, 905 const string16& text,
937 GURL* destination_for_temporary_text_change, 906 GURL* destination_for_temporary_text_change,
938 const string16& keyword, 907 const string16& keyword,
939 bool is_keyword_hint) { 908 bool is_keyword_hint) {
940 // The popup changed its data, the match in the controller is no longer valid. 909 // The popup changed its data, the match in the controller is no longer valid.
941 omnibox_controller_->InvalidateCurrentMatch(); 910 omnibox_controller_->InvalidateCurrentMatch();
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 // explicitly set up a match that will reload here. 1170 // explicitly set up a match that will reload here.
1202 1171
1203 // It's important that we fetch the current visible URL to reload instead of 1172 // It's important that we fetch the current visible URL to reload instead of
1204 // just getting a "search what you typed" URL from 1173 // just getting a "search what you typed" URL from
1205 // SearchProvider::CreateSearchSuggestion(), since the user may be in a 1174 // SearchProvider::CreateSearchSuggestion(), since the user may be in a
1206 // non-default search mode such as image search. 1175 // non-default search mode such as image search.
1207 match->type = AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED; 1176 match->type = AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED;
1208 match->destination_url = 1177 match->destination_url =
1209 delegate_->GetNavigationController().GetVisibleEntry()->GetURL(); 1178 delegate_->GetNavigationController().GetVisibleEntry()->GetURL();
1210 match->transition = content::PAGE_TRANSITION_RELOAD; 1179 match->transition = content::PAGE_TRANSITION_RELOAD;
1211 #if defined(HTML_INSTANT_EXTENDED_POPUP) 1180 #if defined(HTML_INSTANT_EXTENDED_POPUP)
Peter Kasting 2013/06/28 18:47:55 Should this be nuked?
Jered 2013/06/28 19:09:55 Done.
1212 } else if (is_temporary_text_set_by_instant_) { 1181 } else if (is_temporary_text_set_by_instant_) {
1213 // If there's temporary text and it has been set by Instant, we won't find 1182 // If there's temporary text and it has been set by Instant, we won't find
1214 // it in the popup model, so create the match based on the type Instant told 1183 // it in the popup model, so create the match based on the type Instant told
1215 // us (SWYT for queries and UWYT for URLs). We do this instead of 1184 // us (SWYT for queries and UWYT for URLs). We do this instead of
1216 // classifying the text ourselves because the text may look like a URL, but 1185 // classifying the text ourselves because the text may look like a URL, but
1217 // Instant may expect it to be a search (e.g.: a query for "amazon.com"). 1186 // Instant may expect it to be a search (e.g.: a query for "amazon.com").
1218 if (selected_instant_autocomplete_match_index_ != 1187 if (selected_instant_autocomplete_match_index_ !=
1219 OmniboxPopupModel::kNoMatch) { 1188 OmniboxPopupModel::kNoMatch) {
1220 // Great, we know the exact match struct. Just use that. 1189 // Great, we know the exact match struct. Just use that.
1221 const AutocompleteResult& result = this->result(); 1190 const AutocompleteResult& result = this->result();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify( 1250 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(
1282 UserTextFromDisplayText(view_->GetText()), KeywordIsSelected(), true, 1251 UserTextFromDisplayText(view_->GetText()), KeywordIsSelected(), true,
1283 match, alternate_nav_url); 1252 match, alternate_nav_url);
1284 } 1253 }
1285 } 1254 }
1286 1255
1287 void OmniboxEditModel::RevertTemporaryText(bool revert_popup) { 1256 void OmniboxEditModel::RevertTemporaryText(bool revert_popup) {
1288 // The user typed something, then selected a different item. Restore the 1257 // The user typed something, then selected a different item. Restore the
1289 // text they typed and change back to the default item. 1258 // text they typed and change back to the default item.
1290 // NOTE: This purposefully does not reset paste_state_. 1259 // NOTE: This purposefully does not reset paste_state_.
1291 #if defined(HTML_INSTANT_EXTENDED_POPUP)
1292 bool notify_instant = is_temporary_text_set_by_instant_;
1293 #endif
1294 just_deleted_text_ = false; 1260 just_deleted_text_ = false;
1295 has_temporary_text_ = false; 1261 has_temporary_text_ = false;
1296 is_temporary_text_set_by_instant_ = false; 1262 is_temporary_text_set_by_instant_ = false;
1297 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch; 1263 selected_instant_autocomplete_match_index_ = OmniboxPopupModel::kNoMatch;
1298 is_instant_temporary_text_a_search_query_ = false; 1264 is_instant_temporary_text_a_search_query_ = false;
1299 1265
1300 #if defined(HTML_INSTANT_EXTENDED_POPUP)
1301 InstantController* instant = GetInstantController();
1302 if (instant && notify_instant) {
1303 // Normally, popup_model()->ResetToDefaultMatch() will cause the view text
1304 // to be updated. In Instant Extended mode however, the popup_model() is
1305 // not used, so it won't do anything. So, update the view ourselves. Even
1306 // if Instant is not in extended mode (i.e., it's enabled in non-extended
1307 // mode, or disabled altogether), this is okay to do, since the call to
1308 // popup_model()->ResetToDefaultMatch() will just override whatever we do
1309 // here.
1310 //
1311 // The two "false" arguments make sure that our shenanigans don't cause any
1312 // previously saved selection to be erased nor OnChanged() to be called.
1313 view_->OnTemporaryTextMaybeChanged(user_text_ + inline_autocomplete_text_,
1314 false, false);
1315 AutocompleteResult::const_iterator match(result().default_match());
1316 instant->OnCancel(match != result().end() ? *match : AutocompleteMatch(),
1317 user_text_,
1318 user_text_ + inline_autocomplete_text_);
1319 }
1320 #endif
1321 if (revert_popup) 1266 if (revert_popup)
1322 popup_model()->ResetToDefaultMatch(); 1267 popup_model()->ResetToDefaultMatch();
1323 view_->OnRevertTemporaryText(); 1268 view_->OnRevertTemporaryText();
1324 } 1269 }
1325 1270
1326 bool OmniboxEditModel::MaybeAcceptKeywordBySpace(const string16& new_text) { 1271 bool OmniboxEditModel::MaybeAcceptKeywordBySpace(const string16& new_text) {
1327 size_t keyword_length = new_text.length() - 1; 1272 size_t keyword_length = new_text.length() - 1;
1328 return (paste_state_ == NONE) && is_keyword_hint_ && !keyword_.empty() && 1273 return (paste_state_ == NONE) && is_keyword_hint_ && !keyword_.empty() &&
1329 inline_autocomplete_text_.empty() && 1274 inline_autocomplete_text_.empty() &&
1330 (keyword_.length() == keyword_length) && 1275 (keyword_.length() == keyword_length) &&
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 instant->OmniboxFocusChanged(state, reason, NULL); 1353 instant->OmniboxFocusChanged(state, reason, NULL);
1409 1354
1410 // Update state and notify view if the omnibox has focus and the caret 1355 // Update state and notify view if the omnibox has focus and the caret
1411 // visibility changed. 1356 // visibility changed.
1412 const bool was_caret_visible = is_caret_visible(); 1357 const bool was_caret_visible = is_caret_visible();
1413 focus_state_ = state; 1358 focus_state_ = state;
1414 if (focus_state_ != OMNIBOX_FOCUS_NONE && 1359 if (focus_state_ != OMNIBOX_FOCUS_NONE &&
1415 is_caret_visible() != was_caret_visible) 1360 is_caret_visible() != was_caret_visible)
1416 view_->ApplyCaretVisibility(); 1361 view_->ApplyCaretVisibility();
1417 } 1362 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698