Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2307)

Unified Diff: chrome/browser/ui/omnibox/omnibox_view.cc

Issue 20501002: Adds paste function to searchbox api and handles paste event on fakebox (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_view.h ('k') | chrome/browser/ui/omnibox/omnibox_view_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/omnibox/omnibox_view.cc
diff --git a/chrome/browser/ui/omnibox/omnibox_view.cc b/chrome/browser/ui/omnibox/omnibox_view.cc
index 50cc536f375c86913c17a507b34d81278d5c4ea0..9d8f50fbdc1ce88a201173a957c56abd637ad3fc 100644
--- a/chrome/browser/ui/omnibox/omnibox_view.cc
+++ b/chrome/browser/ui/omnibox/omnibox_view.cc
@@ -24,6 +24,26 @@ string16 OmniboxView::StripJavascriptSchemas(const string16& text) {
}
// static
+string16 OmniboxView::SanitizeTextForPaste(const string16& text) {
+ // Check for non-newline whitespace; if found, collapse whitespace runs down
+ // to single spaces.
+ // TODO(shess): It may also make sense to ignore leading or
+ // trailing whitespace when making this determination.
+ for (size_t i = 0; i < text.size(); ++i) {
+ if (IsWhitespace(text[i]) && text[i] != '\n' && text[i] != '\r') {
+ const string16 collapsed = CollapseWhitespace(text, false);
+ // If the user is pasting all-whitespace, paste a single space
+ // rather than nothing, since pasting nothing feels broken.
+ return collapsed.empty() ?
+ ASCIIToUTF16(" ") : StripJavascriptSchemas(collapsed);
+ }
+ }
+
+ // Otherwise, all whitespace is newlines; remove it entirely.
+ return StripJavascriptSchemas(CollapseWhitespace(text, true));
+}
+
+// static
string16 OmniboxView::GetClipboardText() {
// Try text format.
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
@@ -31,26 +51,7 @@ string16 OmniboxView::GetClipboardText() {
ui::Clipboard::BUFFER_STANDARD)) {
string16 text;
clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &text);
-
- // If the input contains non-newline whitespace, treat it as
- // search data and convert newlines to spaces. For instance, a
- // street address.
- // TODO(shess): It may also make sense to ignore leading or
- // trailing whitespace when making this determination.
- for (size_t i = 0; i < text.size(); ++i) {
- if (IsWhitespace(text[i]) && text[i] != '\n' && text[i] != '\r') {
- const string16 collapsed = CollapseWhitespace(text, false);
- // If the user is pasting all-whitespace, paste a single space
- // rather than nothing, since pasting nothing feels broken.
- return collapsed.empty() ?
- ASCIIToUTF16(" ") : StripJavascriptSchemas(collapsed);
- }
- }
-
- // Otherwise, the only whitespace in |text| is newlines. Remove
- // these entirely, because users are most likely pasting URLs
- // split into multiple lines by terminals, email programs, etc.
- return StripJavascriptSchemas(CollapseWhitespace(text, true));
+ return SanitizeTextForPaste(text);
}
// Try bookmark format.
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_view.h ('k') | chrome/browser/ui/omnibox/omnibox_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698