| 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/ui/cocoa/omnibox/omnibox_view_mac.h" | 5 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
| 6 | 6 |
| 7 #include <Carbon/Carbon.h> // kVK_Return | 7 #include <Carbon/Carbon.h> // kVK_Return |
| 8 | 8 |
| 9 #include "app/mac/nsimage_cache.h" | 9 #include "app/mac/nsimage_cache.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 ui::Clipboard::BUFFER_STANDARD)) { | 1063 ui::Clipboard::BUFFER_STANDARD)) { |
| 1064 string16 text16; | 1064 string16 text16; |
| 1065 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &text16); | 1065 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &text16); |
| 1066 | 1066 |
| 1067 // Note: Unlike in the find popup and textfield view, here we completely | 1067 // Note: Unlike in the find popup and textfield view, here we completely |
| 1068 // remove whitespace strings containing newlines. We assume users are | 1068 // remove whitespace strings containing newlines. We assume users are |
| 1069 // most likely pasting in URLs that may have been split into multiple | 1069 // most likely pasting in URLs that may have been split into multiple |
| 1070 // lines in terminals, email programs, etc., and so linebreaks indicate | 1070 // lines in terminals, email programs, etc., and so linebreaks indicate |
| 1071 // completely bogus whitespace that would just cause the input to be | 1071 // completely bogus whitespace that would just cause the input to be |
| 1072 // invalid. | 1072 // invalid. |
| 1073 return CollapseWhitespace(text16, true); | 1073 return CollapseWhitespace(StripJavascriptSchemas(text16), true); |
| 1074 } | 1074 } |
| 1075 | 1075 |
| 1076 // Try bookmark format. | 1076 // Try bookmark format. |
| 1077 // | 1077 // |
| 1078 // It is tempting to try bookmark format first, but the URL we get out of a | 1078 // It is tempting to try bookmark format first, but the URL we get out of a |
| 1079 // bookmark has been cannonicalized via GURL. This means if a user copies | 1079 // bookmark has been cannonicalized via GURL. This means if a user copies |
| 1080 // and pastes from the URL bar to itself, the text will get fixed up and | 1080 // and pastes from the URL bar to itself, the text will get fixed up and |
| 1081 // cannonicalized, which is not what the user expects. By pasting in this | 1081 // cannonicalized, which is not what the user expects. By pasting in this |
| 1082 // order, we are sure to paste what the user copied. | 1082 // order, we are sure to paste what the user copied. |
| 1083 if (clipboard->IsFormatAvailable(ui::Clipboard::GetUrlWFormatType(), | 1083 if (clipboard->IsFormatAvailable(ui::Clipboard::GetUrlWFormatType(), |
| 1084 ui::Clipboard::BUFFER_STANDARD)) { | 1084 ui::Clipboard::BUFFER_STANDARD)) { |
| 1085 std::string url_str; | 1085 std::string url_str; |
| 1086 clipboard->ReadBookmark(NULL, &url_str); | 1086 clipboard->ReadBookmark(NULL, &url_str); |
| 1087 // pass resulting url string through GURL to normalize | 1087 // pass resulting url string through GURL to normalize |
| 1088 GURL url(url_str); | 1088 GURL url(url_str); |
| 1089 if (url.is_valid()) { | 1089 if (url.is_valid()) |
| 1090 return UTF8ToUTF16(url.spec()); | 1090 return StripJavascriptSchemas(UTF8ToUTF16(url.spec())); |
| 1091 } | |
| 1092 } | 1091 } |
| 1093 | 1092 |
| 1094 return string16(); | 1093 return string16(); |
| 1095 } | 1094 } |
| 1096 | 1095 |
| 1097 // static | 1096 // static |
| 1098 NSFont* OmniboxViewMac::GetFieldFont() { | 1097 NSFont* OmniboxViewMac::GetFieldFont() { |
| 1099 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1098 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 1100 return rb.GetFont(ResourceBundle::BaseFont).GetNativeFont(); | 1099 return rb.GetFont(ResourceBundle::BaseFont).GetNativeFont(); |
| 1101 } | 1100 } |
| 1102 | 1101 |
| 1103 NSUInteger OmniboxViewMac::GetTextLength() const { | 1102 NSUInteger OmniboxViewMac::GetTextLength() const { |
| 1104 return ([field_ currentEditor] ? | 1103 return ([field_ currentEditor] ? |
| 1105 [[[field_ currentEditor] string] length] : | 1104 [[[field_ currentEditor] string] length] : |
| 1106 [[field_ stringValue] length]) - suggest_text_length_; | 1105 [[field_ stringValue] length]) - suggest_text_length_; |
| 1107 } | 1106 } |
| 1108 | 1107 |
| 1109 void OmniboxViewMac::PlaceCaretAt(NSUInteger pos) { | 1108 void OmniboxViewMac::PlaceCaretAt(NSUInteger pos) { |
| 1110 DCHECK(pos <= GetTextLength()); | 1109 DCHECK(pos <= GetTextLength()); |
| 1111 SetSelectedRange(NSMakeRange(pos, pos)); | 1110 SetSelectedRange(NSMakeRange(pos, pos)); |
| 1112 } | 1111 } |
| 1113 | 1112 |
| 1114 bool OmniboxViewMac::IsCaretAtEnd() const { | 1113 bool OmniboxViewMac::IsCaretAtEnd() const { |
| 1115 const NSRange selection = GetSelectedRange(); | 1114 const NSRange selection = GetSelectedRange(); |
| 1116 return selection.length == 0 && selection.location == GetTextLength(); | 1115 return selection.length == 0 && selection.location == GetTextLength(); |
| 1117 } | 1116 } |
| OLD | NEW |