Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| (...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 818 return selection.length > 0; | 818 return selection.length > 0; |
| 819 } | 819 } |
| 820 | 820 |
| 821 void OmniboxViewMac::CopyToPasteboard(NSPasteboard* pb) { | 821 void OmniboxViewMac::CopyToPasteboard(NSPasteboard* pb) { |
| 822 DCHECK(CanCopy()); | 822 DCHECK(CanCopy()); |
| 823 | 823 |
| 824 const NSRange selection = GetSelectedRange(); | 824 const NSRange selection = GetSelectedRange(); |
| 825 string16 text = base::SysNSStringToUTF16( | 825 string16 text = base::SysNSStringToUTF16( |
| 826 [[field_ stringValue] substringWithRange:selection]); | 826 [[field_ stringValue] substringWithRange:selection]); |
| 827 | 827 |
| 828 // Copy the URL unless this is the search URL and it's being replaced by the | |
| 829 // Extended Instant API. | |
| 828 GURL url; | 830 GURL url; |
| 829 bool write_url = false; | 831 bool write_url = false; |
| 830 model()->AdjustTextForCopy(selection.location, IsSelectAll(), &text, &url, | 832 if (!ShouldAddCopyURL()) { |
| 831 &write_url); | 833 model()->AdjustTextForCopy(selection.location, IsSelectAll(), &text, &url, |
| 834 &write_url); | |
| 835 } | |
| 832 | 836 |
| 833 NSString* nstext = base::SysUTF16ToNSString(text); | 837 NSString* nstext = base::SysUTF16ToNSString(text); |
| 834 [pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil]; | 838 [pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil]; |
| 835 [pb setString:nstext forType:NSStringPboardType]; | 839 [pb setString:nstext forType:NSStringPboardType]; |
| 836 | 840 |
| 837 if (write_url) { | 841 if (write_url) { |
| 838 [pb declareURLPasteboardWithAdditionalTypes:[NSArray array] owner:nil]; | 842 [pb declareURLPasteboardWithAdditionalTypes:[NSArray array] owner:nil]; |
| 839 [pb setDataForURL:base::SysUTF8ToNSString(url.spec()) title:nstext]; | 843 [pb setDataForURL:base::SysUTF8ToNSString(url.spec()) title:nstext]; |
| 840 } | 844 } |
| 841 } | 845 } |
| 842 | 846 |
| 847 void OmniboxViewMac::CopyURLToPasteboard(NSPasteboard* pb) { | |
| 848 DCHECK(CanCopy()); | |
| 849 DCHECK(ShouldAddCopyURL()); | |
| 850 | |
| 851 string16 text = toolbar_model()->GetText(false); | |
| 852 GURL url = toolbar_model()->GetURL(); | |
| 853 | |
| 854 NSString* nstext = base::SysUTF16ToNSString(text); | |
| 855 [pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil]; | |
| 856 [pb setString:nstext forType:NSStringPboardType]; | |
| 857 | |
| 858 [pb declareURLPasteboardWithAdditionalTypes:[NSArray array] owner:nil]; | |
| 859 [pb setDataForURL:base::SysUTF8ToNSString(url.spec()) title:nstext]; | |
| 860 } | |
| 861 | |
| 843 void OmniboxViewMac::OnPaste() { | 862 void OmniboxViewMac::OnPaste() { |
| 844 // This code currently expects |field_| to be focussed. | 863 // This code currently expects |field_| to be focussed. |
| 845 DCHECK([field_ currentEditor]); | 864 DCHECK([field_ currentEditor]); |
| 846 | 865 |
| 847 string16 text = GetClipboardText(); | 866 string16 text = GetClipboardText(); |
| 848 if (text.empty()) { | 867 if (text.empty()) { |
| 849 return; | 868 return; |
| 850 } | 869 } |
| 851 NSString* s = base::SysUTF16ToNSString(text); | 870 NSString* s = base::SysUTF16ToNSString(text); |
| 852 | 871 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 865 // Force a Paste operation to trigger the text_changed code in | 884 // Force a Paste operation to trigger the text_changed code in |
| 866 // OnAfterPossibleChange(), even if identical contents are pasted | 885 // OnAfterPossibleChange(), even if identical contents are pasted |
| 867 // into the text box. | 886 // into the text box. |
| 868 text_before_change_.clear(); | 887 text_before_change_.clear(); |
| 869 | 888 |
| 870 [editor replaceCharactersInRange:selectedRange withString:s]; | 889 [editor replaceCharactersInRange:selectedRange withString:s]; |
| 871 [editor didChangeText]; | 890 [editor didChangeText]; |
| 872 } | 891 } |
| 873 } | 892 } |
| 874 | 893 |
| 894 // TODO(dominich): Move to OmniboxView base class? | |
|
Peter Kasting
2012/09/11 21:52:59
Yes (since you use logic identical to this a numbe
dominich
2012/09/12 15:23:09
I explained in an earlier revision that it's not a
| |
| 895 bool OmniboxViewMac::ShouldAddCopyURL() { | |
| 896 return !model()->user_input_in_progress() && | |
| 897 toolbar_model()->WouldReplaceSearchURLWithSearchTerms(); | |
| 898 } | |
| 899 | |
| 875 bool OmniboxViewMac::CanPasteAndGo() { | 900 bool OmniboxViewMac::CanPasteAndGo() { |
| 876 return model()->CanPasteAndGo(GetClipboardText()); | 901 return model()->CanPasteAndGo(GetClipboardText()); |
| 877 } | 902 } |
| 878 | 903 |
| 879 int OmniboxViewMac::GetPasteActionStringId() { | 904 int OmniboxViewMac::GetPasteActionStringId() { |
| 880 string16 text(GetClipboardText()); | 905 string16 text(GetClipboardText()); |
| 881 DCHECK(model()->CanPasteAndGo(text)); | 906 DCHECK(model()->CanPasteAndGo(text)); |
| 882 return model()->IsPasteAndSearch(GetClipboardText()) ? | 907 return model()->IsPasteAndSearch(GetClipboardText()) ? |
| 883 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO; | 908 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO; |
| 884 } | 909 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 979 NSUInteger OmniboxViewMac::GetTextLength() const { | 1004 NSUInteger OmniboxViewMac::GetTextLength() const { |
| 980 return ([field_ currentEditor] ? | 1005 return ([field_ currentEditor] ? |
| 981 [[[field_ currentEditor] string] length] : | 1006 [[[field_ currentEditor] string] length] : |
| 982 [[field_ stringValue] length]) - suggest_text_length_; | 1007 [[field_ stringValue] length]) - suggest_text_length_; |
| 983 } | 1008 } |
| 984 | 1009 |
| 985 bool OmniboxViewMac::IsCaretAtEnd() const { | 1010 bool OmniboxViewMac::IsCaretAtEnd() const { |
| 986 const NSRange selection = GetSelectedRange(); | 1011 const NSRange selection = GetSelectedRange(); |
| 987 return selection.length == 0 && selection.location == GetTextLength(); | 1012 return selection.length == 0 && selection.location == GetTextLength(); |
| 988 } | 1013 } |
| OLD | NEW |