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