OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/autocomplete/autocomplete_edit.h" | 5 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/histogram.h" | 10 #include "base/histogram.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 GetInfoForCurrentText(&match, NULL); | 163 GetInfoForCurrentText(&match, NULL); |
164 *url = match.destination_url; | 164 *url = match.destination_url; |
165 if (*url == URLFixerUpper::FixupURL(WideToUTF8(permanent_text_), | 165 if (*url == URLFixerUpper::FixupURL(WideToUTF8(permanent_text_), |
166 std::string())) { | 166 std::string())) { |
167 *title = controller_->GetTitle(); | 167 *title = controller_->GetTitle(); |
168 *favicon = controller_->GetFavIcon(); | 168 *favicon = controller_->GetFavIcon(); |
169 } | 169 } |
170 } | 170 } |
171 | 171 |
172 std::wstring AutocompleteEditModel::GetDesiredTLD() const { | 172 std::wstring AutocompleteEditModel::GetDesiredTLD() const { |
173 return (control_key_state_ == DOWN_WITHOUT_CHANGE) ? | 173 // Tricky corner case: The user has typed "foo" and currently sees an inline |
174 // autocomplete suggestion of "foo.net". He now presses ctrl-a (e.g. to | |
175 // select all, on Windows). If we treat the ctrl press as potentially for the | |
176 // sake of ctrl-enter, then we risk "www.foo.com" being promoted as the best | |
177 // match. This would make the autocompleted text disappear, leaving our user | |
178 // feeling very confused when the wrong text gets highlighted. | |
179 // | |
180 // Thus, we only treat the user as pressing ctrl-enter when the user presses | |
181 // ctrl without any fragile state built up in the omnibox: | |
182 // * the contents of the omnibox have not changed since the keypress, | |
183 // * there is no autocompleted text visible, and | |
184 // * the user is not typing a keyword query. | |
185 return (control_key_state_ == DOWN_WITHOUT_CHANGE && | |
186 inline_autocomplete_text_.empty() && | |
187 !KeywordIsSelected())? | |
Peter Kasting
2010/08/25 01:35:07
Nit: Put as many conditions on one line as possibl
| |
174 std::wstring(L"com") : std::wstring(); | 188 std::wstring(L"com") : std::wstring(); |
175 } | 189 } |
176 | 190 |
177 bool AutocompleteEditModel::CurrentTextIsURL() const { | 191 bool AutocompleteEditModel::CurrentTextIsURL() const { |
178 // If !user_input_in_progress_, the permanent text is showing, which should | 192 // If !user_input_in_progress_, the permanent text is showing, which should |
179 // always be a URL, so no further checking is needed. By avoiding checking in | 193 // always be a URL, so no further checking is needed. By avoiding checking in |
180 // this case, we avoid calling into the autocomplete providers, and thus | 194 // this case, we avoid calling into the autocomplete providers, and thus |
181 // initializing the history system, as long as possible, which speeds startup. | 195 // initializing the history system, as long as possible, which speeds startup. |
182 if (!user_input_in_progress_) | 196 if (!user_input_in_progress_) |
183 return true; | 197 return true; |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
698 | 712 |
699 OnPopupDataChanged(inline_autocomplete_text, NULL, keyword, is_keyword_hint); | 713 OnPopupDataChanged(inline_autocomplete_text, NULL, keyword, is_keyword_hint); |
700 } | 714 } |
701 | 715 |
702 void AutocompleteEditModel::InternalSetUserText(const std::wstring& text) { | 716 void AutocompleteEditModel::InternalSetUserText(const std::wstring& text) { |
703 user_text_ = text; | 717 user_text_ = text; |
704 just_deleted_text_ = false; | 718 just_deleted_text_ = false; |
705 inline_autocomplete_text_.clear(); | 719 inline_autocomplete_text_.clear(); |
706 } | 720 } |
707 | 721 |
722 bool AutocompleteEditModel::KeywordIsSelected() const { | |
723 return ((keyword_ui_state_ != NO_KEYWORD) && !is_keyword_hint_ && | |
724 !keyword_.empty()); | |
725 } | |
726 | |
708 std::wstring AutocompleteEditModel::DisplayTextFromUserText( | 727 std::wstring AutocompleteEditModel::DisplayTextFromUserText( |
709 const std::wstring& text) const { | 728 const std::wstring& text) const { |
710 return ((keyword_ui_state_ == NO_KEYWORD) || is_keyword_hint_ || | 729 return KeywordIsSelected() ? |
711 keyword_.empty()) ? | 730 KeywordProvider::SplitReplacementStringFromInput(text) : text; |
712 text : KeywordProvider::SplitReplacementStringFromInput(text); | |
713 } | 731 } |
714 | 732 |
715 std::wstring AutocompleteEditModel::UserTextFromDisplayText( | 733 std::wstring AutocompleteEditModel::UserTextFromDisplayText( |
716 const std::wstring& text) const { | 734 const std::wstring& text) const { |
717 return ((keyword_ui_state_ == NO_KEYWORD) || is_keyword_hint_ || | 735 return KeywordIsSelected() ? |
Peter Kasting
2010/08/25 01:35:07
Nit: This will all fit on one line.
| |
718 keyword_.empty()) ? | 736 (keyword_ + L" " + text) : text; |
719 text : (keyword_ + L" " + text); | |
720 } | 737 } |
721 | 738 |
722 void AutocompleteEditModel::GetInfoForCurrentText( | 739 void AutocompleteEditModel::GetInfoForCurrentText( |
723 AutocompleteMatch* match, | 740 AutocompleteMatch* match, |
724 GURL* alternate_nav_url) const { | 741 GURL* alternate_nav_url) const { |
725 if (popup_->IsOpen() || query_in_progress()) { | 742 if (popup_->IsOpen() || query_in_progress()) { |
726 popup_->InfoForCurrentSelection(match, alternate_nav_url); | 743 popup_->InfoForCurrentSelection(match, alternate_nav_url); |
727 } else { | 744 } else { |
728 profile_->GetAutocompleteClassifier()->Classify( | 745 profile_->GetAutocompleteClassifier()->Classify( |
729 UserTextFromDisplayText(view_->GetText()), GetDesiredTLD(), match, | 746 UserTextFromDisplayText(view_->GetText()), GetDesiredTLD(), match, |
730 alternate_nav_url); | 747 alternate_nav_url); |
731 } | 748 } |
732 } | 749 } |
OLD | NEW |