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