| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_view_mac.h" | 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" |
| 6 | 6 |
| 7 #include <Carbon/Carbon.h> // kVK_Return | 7 #include <Carbon/Carbon.h> // kVK_Return |
| 8 | 8 |
| 9 #include "app/clipboard/clipboard.h" | 9 #include "app/clipboard/clipboard.h" |
| 10 #include "app/clipboard/scoped_clipboard_writer.h" | 10 #include "app/clipboard/scoped_clipboard_writer.h" |
| (...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 | 760 |
| 761 void AutocompleteEditViewMac::OnDidResignKey() { | 761 void AutocompleteEditViewMac::OnDidResignKey() { |
| 762 ClosePopup(); | 762 ClosePopup(); |
| 763 } | 763 } |
| 764 | 764 |
| 765 void AutocompleteEditViewMac::OnCopy() { | 765 void AutocompleteEditViewMac::OnCopy() { |
| 766 const NSRange selection = GetSelectedRange(); | 766 const NSRange selection = GetSelectedRange(); |
| 767 if (selection.length == 0) | 767 if (selection.length == 0) |
| 768 return; | 768 return; |
| 769 | 769 |
| 770 const std::wstring& text = GetText(); | 770 std::wstring text = base::SysNSStringToWide( |
| 771 const string16 text16 = WideToUTF16(text); | 771 [[field_ stringValue] substringWithRange:selection]); |
| 772 | 772 |
| 773 GURL url; |
| 774 bool write_url = false; |
| 775 model_->AdjustTextForCopy(selection.location, IsSelectAll(), &text, &url, |
| 776 &write_url); |
| 777 string16 text16 = WideToUTF16(text); |
| 773 ScopedClipboardWriter scw(g_browser_process->clipboard()); | 778 ScopedClipboardWriter scw(g_browser_process->clipboard()); |
| 774 // If the entire contents are being copied and it looks like an URL, | 779 scw.WriteText(text16); |
| 775 // copy as a hyperlink. | 780 if (write_url) { |
| 776 if (IsSelectAll()) { | 781 scw.WriteBookmark(text16, url.spec()); |
| 777 GURL url; | 782 // This line, cargo cult copied from the Windows and GTK |
| 778 if (model_->GetURLForText(text, &url)) { | 783 // versions (perhaps), breaks paste of an URL into Powerpoint |
| 779 if ((url.SchemeIs("http") || url.SchemeIs("https")) && | 784 // 2008. http://crbug.com/41842 |
| 780 !model_->user_input_in_progress()) | 785 // scw.WriteHyperlink(EscapeForHTML(WideToUTF8(text)), url.spec()); |
| 781 scw.WriteText(UTF8ToUTF16(url.spec())); | |
| 782 else | |
| 783 scw.WriteText(text16); | |
| 784 scw.WriteBookmark(text16, url.spec()); | |
| 785 | |
| 786 // This line, cargo cult copied from the Windows and GTK | |
| 787 // versions (perhaps), breaks paste of an URL into Powerpoint | |
| 788 // 2008. http://crbug.com/41842 | |
| 789 // scw.WriteHyperlink(EscapeForHTML(WideToUTF8(text)), url.spec()); | |
| 790 return; | |
| 791 } | |
| 792 } | 786 } |
| 793 | |
| 794 scw.WriteText(text16.substr(selection.location, selection.length)); | |
| 795 } | 787 } |
| 796 | 788 |
| 797 void AutocompleteEditViewMac::OnPaste() { | 789 void AutocompleteEditViewMac::OnPaste() { |
| 798 // This code currently expects |field_| to be focussed. | 790 // This code currently expects |field_| to be focussed. |
| 799 DCHECK([field_ currentEditor]); | 791 DCHECK([field_ currentEditor]); |
| 800 | 792 |
| 801 std::wstring text = GetClipboardText(g_browser_process->clipboard()); | 793 std::wstring text = GetClipboardText(g_browser_process->clipboard()); |
| 802 if (text.empty()) { | 794 if (text.empty()) { |
| 803 return; | 795 return; |
| 804 } | 796 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 clipboard->ReadBookmark(NULL, &url_str); | 920 clipboard->ReadBookmark(NULL, &url_str); |
| 929 // pass resulting url string through GURL to normalize | 921 // pass resulting url string through GURL to normalize |
| 930 GURL url(url_str); | 922 GURL url(url_str); |
| 931 if (url.is_valid()) { | 923 if (url.is_valid()) { |
| 932 return UTF8ToWide(url.spec()); | 924 return UTF8ToWide(url.spec()); |
| 933 } | 925 } |
| 934 } | 926 } |
| 935 | 927 |
| 936 return std::wstring(); | 928 return std::wstring(); |
| 937 } | 929 } |
| OLD | NEW |