OLD | NEW |
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 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 return true; | 889 return true; |
890 } | 890 } |
891 | 891 |
892 void OmniboxEditModel::OnControlKeyChanged(bool pressed) { | 892 void OmniboxEditModel::OnControlKeyChanged(bool pressed) { |
893 // TODO(beaudoin): Remove this function entirely and all the code that calls | 893 // TODO(beaudoin): Remove this function entirely and all the code that calls |
894 // it. | 894 // it. |
895 } | 895 } |
896 | 896 |
897 void OmniboxEditModel::OnUpOrDownKeyPressed(int count) { | 897 void OmniboxEditModel::OnUpOrDownKeyPressed(int count) { |
898 // NOTE: This purposefully doesn't trigger any code that resets paste_state_. | 898 // NOTE: This purposefully doesn't trigger any code that resets paste_state_. |
899 if (!popup_model()->IsOpen()) { | 899 if (popup_model()->IsOpen()) { |
900 if (!query_in_progress()) { | |
901 // The popup is neither open nor working on a query already. So, start an | |
902 // autocomplete query for the current text. This also sets | |
903 // user_input_in_progress_ to true, which we want: if the user has started | |
904 // to interact with the popup, changing the permanent_text_ shouldn't | |
905 // change the displayed text. | |
906 // Note: This does not force the popup to open immediately. | |
907 // TODO(pkasting): We should, in fact, force this particular query to open | |
908 // the popup immediately. | |
909 if (!user_input_in_progress_) | |
910 InternalSetUserText(permanent_text_); | |
911 view_->UpdatePopup(); | |
912 } else { | |
913 // TODO(pkasting): The popup is working on a query but is not open. We | |
914 // should force it to open immediately. | |
915 } | |
916 } else { | |
917 #if defined(HTML_INSTANT_EXTENDED_POPUP) | 900 #if defined(HTML_INSTANT_EXTENDED_POPUP) |
918 InstantController* instant = GetInstantController(); | 901 InstantController* instant = GetInstantController(); |
919 if (instant && instant->OnUpOrDownKeyPressed(count)) { | 902 if (instant && instant->OnUpOrDownKeyPressed(count)) { |
920 // If Instant handles the key press, it's showing a list of suggestions | 903 // 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 | 904 // 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 | 905 // irrelevant, so don't process the key press ourselves. However, do stop |
923 // the autocomplete system from changing the results. | 906 // the autocomplete system from changing the results. |
924 autocomplete_controller()->Stop(false); | 907 autocomplete_controller()->Stop(false); |
925 } else | 908 return; |
| 909 } |
926 #endif | 910 #endif |
927 { | 911 |
928 // The popup is open, so the user should be able to interact with it | 912 // The popup is open, so the user should be able to interact with it |
929 // normally. | 913 // normally. |
930 popup_model()->Move(count); | 914 popup_model()->Move(count); |
931 } | 915 return; |
932 } | 916 } |
| 917 |
| 918 if (!query_in_progress()) { |
| 919 // The popup is neither open nor working on a query already. So, start an |
| 920 // autocomplete query for the current text. This also sets |
| 921 // user_input_in_progress_ to true, which we want: if the user has started |
| 922 // to interact with the popup, changing the permanent_text_ shouldn't change |
| 923 // the displayed text. |
| 924 // Note: This does not force the popup to open immediately. |
| 925 // TODO(pkasting): We should, in fact, force this particular query to open |
| 926 // the popup immediately. |
| 927 if (!user_input_in_progress_) |
| 928 InternalSetUserText(permanent_text_); |
| 929 view_->UpdatePopup(); |
| 930 return; |
| 931 } |
| 932 |
| 933 // TODO(pkasting): The popup is working on a query but is not open. We should |
| 934 // force it to open immediately. |
933 } | 935 } |
934 | 936 |
935 void OmniboxEditModel::OnPopupDataChanged( | 937 void OmniboxEditModel::OnPopupDataChanged( |
936 const string16& text, | 938 const string16& text, |
937 GURL* destination_for_temporary_text_change, | 939 GURL* destination_for_temporary_text_change, |
938 const string16& keyword, | 940 const string16& keyword, |
939 bool is_keyword_hint) { | 941 bool is_keyword_hint) { |
940 // The popup changed its data, the match in the controller is no longer valid. | 942 // The popup changed its data, the match in the controller is no longer valid. |
941 omnibox_controller_->InvalidateCurrentMatch(); | 943 omnibox_controller_->InvalidateCurrentMatch(); |
942 | 944 |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1228 // used (to either navigate to the URL or let Instant commit its preview). | 1230 // used (to either navigate to the URL or let Instant commit its preview). |
1229 // The match won't be used for logging, displaying in the dropdown, etc. | 1231 // The match won't be used for logging, displaying in the dropdown, etc. |
1230 // So, it's okay to pass in mostly bogus params (such as relevance = 0). | 1232 // So, it's okay to pass in mostly bogus params (such as relevance = 0). |
1231 // TODO(sreeram): Always using NO_SUGGESTIONS_AVAILABLE is wrong when | 1233 // TODO(sreeram): Always using NO_SUGGESTIONS_AVAILABLE is wrong when |
1232 // Instant is using the local fallback overlay. Fix. | 1234 // Instant is using the local fallback overlay. Fix. |
1233 if (is_instant_temporary_text_a_search_query_) { | 1235 if (is_instant_temporary_text_a_search_query_) { |
1234 const TemplateURL* default_provider = | 1236 const TemplateURL* default_provider = |
1235 TemplateURLServiceFactory::GetForProfile(profile_)-> | 1237 TemplateURLServiceFactory::GetForProfile(profile_)-> |
1236 GetDefaultSearchProvider(); | 1238 GetDefaultSearchProvider(); |
1237 if (default_provider && default_provider->SupportsReplacement()) { | 1239 if (default_provider && default_provider->SupportsReplacement()) { |
1238 *match = SearchProvider::CreateSearchSuggestion(profile_, | 1240 *match = SearchProvider::CreateSearchSuggestion( |
1239 autocomplete_controller()->search_provider(), input, text, text, | 1241 autocomplete_controller()->search_provider(), 0, |
1240 0, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 1242 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, default_provider, |
1241 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, false, | 1243 text, text, input, false, |
1242 default_provider->keyword(), | 1244 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, |
1243 controller_->GetOmniboxBounds().x()); | 1245 controller_->GetOmniboxBounds().x()); |
1244 } else { | 1246 } else { |
1245 // Can't create a new search match. Leave |match| as is, with an | 1247 // Can't create a new search match. Leave |match| as is, with an |
1246 // invalid destination_url. This shouldn't ever happen. For example, | 1248 // invalid destination_url. This shouldn't ever happen. For example, |
1247 // even if a group policy update in the midst of interacting with | 1249 // even if a group policy update in the midst of interacting with |
1248 // Instant leaves us without a valid search provider, Instant | 1250 // Instant leaves us without a valid search provider, Instant |
1249 // should've observed the update and reset | 1251 // should've observed the update and reset |
1250 // |is_temporary_text_set_by_instant_|, so we still shouldn't get | 1252 // |is_temporary_text_set_by_instant_|, so we still shouldn't get |
1251 // here. However, as protection against the unknowns and Instant | 1253 // here. However, as protection against the unknowns and Instant |
1252 // regressions, we simply return an invalid match instead of crashing | 1254 // regressions, we simply return an invalid match instead of crashing |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1408 instant->OmniboxFocusChanged(state, reason, NULL); | 1410 instant->OmniboxFocusChanged(state, reason, NULL); |
1409 | 1411 |
1410 // Update state and notify view if the omnibox has focus and the caret | 1412 // Update state and notify view if the omnibox has focus and the caret |
1411 // visibility changed. | 1413 // visibility changed. |
1412 const bool was_caret_visible = is_caret_visible(); | 1414 const bool was_caret_visible = is_caret_visible(); |
1413 focus_state_ = state; | 1415 focus_state_ = state; |
1414 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1416 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
1415 is_caret_visible() != was_caret_visible) | 1417 is_caret_visible() != was_caret_visible) |
1416 view_->ApplyCaretVisibility(); | 1418 view_->ApplyCaretVisibility(); |
1417 } | 1419 } |
OLD | NEW |