| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 void AutocompleteEditModel::AdjustTextForCopy(int sel_min, | 378 void AutocompleteEditModel::AdjustTextForCopy(int sel_min, |
| 379 bool is_all_selected, | 379 bool is_all_selected, |
| 380 string16* text, | 380 string16* text, |
| 381 GURL* url, | 381 GURL* url, |
| 382 bool* write_url) { | 382 bool* write_url) { |
| 383 *write_url = false; | 383 *write_url = false; |
| 384 | 384 |
| 385 if (sel_min != 0) | 385 if (sel_min != 0) |
| 386 return; | 386 return; |
| 387 | 387 |
| 388 // We can't use CurrentTextIsURL() or GetDataForURLExport() because right now | |
| 389 // the user is probably holding down control to cause the copy, which will | |
| 390 // screw up our calculation of the desired_tld. | |
| 391 if (!GetURLForText(*text, url)) | |
| 392 return; // Can't be parsed as a url, no need to adjust text. | |
| 393 | |
| 394 if (!user_input_in_progress() && is_all_selected) { | 388 if (!user_input_in_progress() && is_all_selected) { |
| 395 // The user selected all the text and has not edited it. Use the url as the | 389 // The user selected all the text and has not edited it. Use the url as the |
| 396 // text so that if the scheme was stripped it's added back, and the url | 390 // text so that if the scheme was stripped it's added back, and the url |
| 397 // is unescaped (we escape parts of the url for display). | 391 // is unescaped (we escape parts of the url for display). |
| 392 *url = PermanentURL(); |
| 398 *text = UTF8ToUTF16(url->spec()); | 393 *text = UTF8ToUTF16(url->spec()); |
| 399 *write_url = true; | 394 *write_url = true; |
| 400 return; | 395 return; |
| 401 } | 396 } |
| 402 | 397 |
| 398 // We can't use CurrentTextIsURL() or GetDataForURLExport() because right now |
| 399 // the user is probably holding down control to cause the copy, which will |
| 400 // screw up our calculation of the desired_tld. |
| 401 AutocompleteMatch match; |
| 402 profile_->GetAutocompleteClassifier()->Classify(*text, string16(), |
| 403 KeywordIsSelected(), true, &match, NULL); |
| 404 if (match.transition != PageTransition::TYPED) |
| 405 return; |
| 406 *url = match.destination_url; |
| 407 |
| 403 // Prefix the text with 'http://' if the text doesn't start with 'http://', | 408 // Prefix the text with 'http://' if the text doesn't start with 'http://', |
| 404 // the text parses as a url with a scheme of http, the user selected the | 409 // the text parses as a url with a scheme of http, the user selected the |
| 405 // entire host, and the user hasn't edited the host or manually removed the | 410 // entire host, and the user hasn't edited the host or manually removed the |
| 406 // scheme. | 411 // scheme. |
| 407 GURL perm_url; | 412 GURL perm_url(PermanentURL()); |
| 408 if (GetURLForText(permanent_text_, &perm_url) && | 413 if (perm_url.SchemeIs(chrome::kHttpScheme) && |
| 409 perm_url.SchemeIs(chrome::kHttpScheme) && | 414 url->SchemeIs(chrome::kHttpScheme) && perm_url.host() == url->host()) { |
| 410 url->SchemeIs(chrome::kHttpScheme) && | |
| 411 perm_url.host() == url->host()) { | |
| 412 *write_url = true; | 415 *write_url = true; |
| 413 | |
| 414 string16 http = ASCIIToUTF16(chrome::kHttpScheme) + | 416 string16 http = ASCIIToUTF16(chrome::kHttpScheme) + |
| 415 ASCIIToUTF16(chrome::kStandardSchemeSeparator); | 417 ASCIIToUTF16(chrome::kStandardSchemeSeparator); |
| 416 if (text->compare(0, http.length(), http) != 0) | 418 if (text->compare(0, http.length(), http) != 0) |
| 417 *text = http + *text; | 419 *text = http + *text; |
| 418 } | 420 } |
| 419 } | 421 } |
| 420 | 422 |
| 421 void AutocompleteEditModel::SetInputInProgress(bool in_progress) { | 423 void AutocompleteEditModel::SetInputInProgress(bool in_progress) { |
| 422 if (user_input_in_progress_ == in_progress) | 424 if (user_input_in_progress_ == in_progress) |
| 423 return; | 425 return; |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 GURL* alternate_nav_url) const { | 968 GURL* alternate_nav_url) const { |
| 967 if (popup_->IsOpen() || query_in_progress()) { | 969 if (popup_->IsOpen() || query_in_progress()) { |
| 968 InfoForCurrentSelection(match, alternate_nav_url); | 970 InfoForCurrentSelection(match, alternate_nav_url); |
| 969 } else { | 971 } else { |
| 970 profile_->GetAutocompleteClassifier()->Classify( | 972 profile_->GetAutocompleteClassifier()->Classify( |
| 971 UserTextFromDisplayText(view_->GetText()), GetDesiredTLD(), | 973 UserTextFromDisplayText(view_->GetText()), GetDesiredTLD(), |
| 972 KeywordIsSelected(), true, match, alternate_nav_url); | 974 KeywordIsSelected(), true, match, alternate_nav_url); |
| 973 } | 975 } |
| 974 } | 976 } |
| 975 | 977 |
| 976 bool AutocompleteEditModel::GetURLForText(const string16& text, | |
| 977 GURL* url) const { | |
| 978 GURL parsed_url; | |
| 979 const AutocompleteInput::Type type = AutocompleteInput::Parse( | |
| 980 UserTextFromDisplayText(text), string16(), NULL, NULL, &parsed_url); | |
| 981 if (type != AutocompleteInput::URL) | |
| 982 return false; | |
| 983 | |
| 984 *url = parsed_url; | |
| 985 return true; | |
| 986 } | |
| 987 | |
| 988 void AutocompleteEditModel::RevertTemporaryText(bool revert_popup) { | 978 void AutocompleteEditModel::RevertTemporaryText(bool revert_popup) { |
| 989 // The user typed something, then selected a different item. Restore the | 979 // The user typed something, then selected a different item. Restore the |
| 990 // text they typed and change back to the default item. | 980 // text they typed and change back to the default item. |
| 991 // NOTE: This purposefully does not reset paste_state_. | 981 // NOTE: This purposefully does not reset paste_state_. |
| 992 just_deleted_text_ = false; | 982 just_deleted_text_ = false; |
| 993 has_temporary_text_ = false; | 983 has_temporary_text_ = false; |
| 994 if (revert_popup) | 984 if (revert_popup) |
| 995 popup_->ResetToDefaultMatch(); | 985 popup_->ResetToDefaultMatch(); |
| 996 view_->OnRevertTemporaryText(); | 986 view_->OnRevertTemporaryText(); |
| 997 } | 987 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 // static | 1084 // static |
| 1095 bool AutocompleteEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { | 1085 bool AutocompleteEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { |
| 1096 switch (c) { | 1086 switch (c) { |
| 1097 case 0x0020: // Space | 1087 case 0x0020: // Space |
| 1098 case 0x3000: // Ideographic Space | 1088 case 0x3000: // Ideographic Space |
| 1099 return true; | 1089 return true; |
| 1100 default: | 1090 default: |
| 1101 return false; | 1091 return false; |
| 1102 } | 1092 } |
| 1103 } | 1093 } |
| OLD | NEW |