summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-04 23:26:48 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-04 23:26:48 +0000
commit27e20af824af71396399a587fea101f9b2cadffb (patch)
treec830797e959effa0f512373c425af1c37e96c1e5 /chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
parentb6ea741a64dc5cddcfe735d15e68718b0f377363 (diff)
downloadchromium_src-27e20af824af71396399a587fea101f9b2cadffb.zip
chromium_src-27e20af824af71396399a587fea101f9b2cadffb.tar.gz
chromium_src-27e20af824af71396399a587fea101f9b2cadffb.tar.bz2
[Mac] Unify drag and copy from Omnibox.
Previously drags went through the NSText code, which allowed drag of rich text out of the Omnibox. Modify so that both drag and copy use the same core code. Also undo the drag-all-like-location-bar-icon effect from an earlier change. BUG=41414, 43183, 41218 TEST=Compare Copy with drag&drop into TextEdit with various selections. Review URL: http://codereview.chromium.org/1936002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46407 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete/autocomplete_edit_view_mac.mm')
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.mm26
1 files changed, 15 insertions, 11 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
index e0362a9..c499859 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
@@ -23,6 +23,7 @@
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "net/base/escape.h"
+#import "third_party/mozilla/NSPasteboard+Utils.h"
// Focus-handling between |field_| and |model_| is a bit subtle.
// Other platforms detect change of focus, which is inconvenient
@@ -770,11 +771,15 @@ void AutocompleteEditViewMac::OnDidResignKey() {
ClosePopup();
}
-void AutocompleteEditViewMac::OnCopy() {
+bool AutocompleteEditViewMac::CanCopy() {
const NSRange selection = GetSelectedRange();
- if (selection.length == 0)
- return;
+ return selection.length > 0;
+}
+
+void AutocompleteEditViewMac::CopyToPasteboard(NSPasteboard* pb) {
+ DCHECK(CanCopy());
+ const NSRange selection = GetSelectedRange();
std::wstring text = base::SysNSStringToWide(
[[field_ stringValue] substringWithRange:selection]);
@@ -782,15 +787,14 @@ void AutocompleteEditViewMac::OnCopy() {
bool write_url = false;
model_->AdjustTextForCopy(selection.location, IsSelectAll(), &text, &url,
&write_url);
- string16 text16 = WideToUTF16(text);
- ScopedClipboardWriter scw(g_browser_process->clipboard());
- scw.WriteText(text16);
+
+ NSString* nstext = base::SysWideToNSString(text);
+ [pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
+ [pb setString:nstext forType:NSStringPboardType];
+
if (write_url) {
- scw.WriteBookmark(text16, url.spec());
- // This line, cargo cult copied from the Windows and GTK
- // versions (perhaps), breaks paste of an URL into Powerpoint
- // 2008. http://crbug.com/41842
- // scw.WriteHyperlink(EscapeForHTML(WideToUTF8(text)), url.spec());
+ [pb declareURLPasteboardWithAdditionalTypes:[NSArray array] owner:nil];
+ [pb setDataForURL:base::SysUTF8ToNSString(url.spec()) title:nstext];
}
}