diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-27 03:33:59 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-27 03:33:59 +0000 |
commit | 562b222ad53049a87f695e450e8698d3cb2aa1d6 (patch) | |
tree | 7ed368560ed1137f330bf1b3d98df84e95107cc8 /chrome/browser/autocomplete/autocomplete_edit.cc | |
parent | 7ff213014f83fc4066fb80f7c4ca3993d81a6b37 (diff) | |
download | chromium_src-562b222ad53049a87f695e450e8698d3cb2aa1d6.zip chromium_src-562b222ad53049a87f695e450e8698d3cb2aa1d6.tar.gz chromium_src-562b222ad53049a87f695e450e8698d3cb2aa1d6.tar.bz2 |
Tweaks to copy/paste of omnibox on windows:
. Makes copy prefix the text with http if the user hasn't edited the
text, and the scheme is http but the text doesn't include http.
. Makes copying use the url as the text if the user hasn't edited the
text and it's http/https.
. Makes control-insert/shift-insert use our copy/paste.
BUG=41639 41489 41493
TEST=make sure copy/paste from the omnibox work sanely. Seriously
though, see the three bugs for specifics.
Review URL: http://codereview.chromium.org/1761002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45667 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete/autocomplete_edit.cc')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit.cc | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc index 9b0aefb..5d68e59 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.cc +++ b/chrome/browser/autocomplete/autocomplete_edit.cc @@ -7,6 +7,7 @@ #include <string> #include "base/basictypes.h" +#include "base/string_util.h" #include "base/utf_string_conversions.h" #include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/autocomplete/autocomplete_classifier.h" @@ -21,6 +22,7 @@ #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/common/notification_service.h" +#include "chrome/common/url_constants.h" #include "googleurl/src/gurl.h" #include "googleurl/src/url_util.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -165,6 +167,45 @@ bool AutocompleteEditModel::GetURLForText(const std::wstring& text, return true; } +void AutocompleteEditModel::AdjustTextForCopy(int sel_start, + bool is_all_selected, + std::wstring* text, + GURL* url, + bool* write_url) { + *write_url = false; + + if (sel_start != 0) + return; + + // We can't use CurrentTextIsURL() or GetDataForURLExport() because right now + // the user is probably holding down control to cause the copy, which will + // screw up our calculation of the desired_tld. + if (!GetURLForText(*text, url)) + return; // Can't be parsed as a url, no need to adjust text. + + if (!user_input_in_progress() && is_all_selected) { + *text = UTF8ToWide(url->spec()); + *write_url = true; + return; + } + + // Prefix the text with 'http://' if the text doesn't start with 'http://', + // the text parses as a url with a scheme of http, the user selected the + // entire host, and the user hasn't edited the host or manually removed the + // scheme. + if (url->SchemeIs(chrome::kHttpScheme)) { + std::wstring http = ASCIIToWide(chrome::kHttpScheme) + + ASCIIToWide(chrome::kStandardSchemeSeparator); + std::wstring host = UTF8ToWide(url->host()); + if (text->compare(0, http.length(), http) != 0 && + text->length() >= host.length() && + permanent_text_.compare(0, host.length(), host) == 0) { + *text = http + *text; + *write_url = true; + } + } +} + void AutocompleteEditModel::SetInputInProgress(bool in_progress) { if (user_input_in_progress_ == in_progress) return; |