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

Side by Side Diff: chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm

Issue 10915069: Add Copy URL option to Omnibox context menu when URL is replaced by Instant Extended. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 (!ShouldEnableCopyURL()) {
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(ShouldEnableCopyURL());
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
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? Currently this is defined on
895 // the AutocompleteTextFieldObserver but the logic is shared between all
896 // platforms. Some refactor might be necessary to simplify this. Or at least
897 // this method could call the OmniboxView version.
898 bool OmniboxViewMac::ShouldEnableCopyURL() {
899 return !model()->user_input_in_progress() &&
900 toolbar_model()->WouldReplaceSearchURLWithSearchTerms();
901 }
902
875 bool OmniboxViewMac::CanPasteAndGo() { 903 bool OmniboxViewMac::CanPasteAndGo() {
876 return model()->CanPasteAndGo(GetClipboardText()); 904 return model()->CanPasteAndGo(GetClipboardText());
877 } 905 }
878 906
879 int OmniboxViewMac::GetPasteActionStringId() { 907 int OmniboxViewMac::GetPasteActionStringId() {
880 string16 text(GetClipboardText()); 908 string16 text(GetClipboardText());
881 DCHECK(model()->CanPasteAndGo(text)); 909 DCHECK(model()->CanPasteAndGo(text));
882 return model()->IsPasteAndSearch(GetClipboardText()) ? 910 return model()->IsPasteAndSearch(GetClipboardText()) ?
883 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO; 911 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO;
884 } 912 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 NSUInteger OmniboxViewMac::GetTextLength() const { 1007 NSUInteger OmniboxViewMac::GetTextLength() const {
980 return ([field_ currentEditor] ? 1008 return ([field_ currentEditor] ?
981 [[[field_ currentEditor] string] length] : 1009 [[[field_ currentEditor] string] length] :
982 [[field_ stringValue] length]) - suggest_text_length_; 1010 [[field_ stringValue] length]) - suggest_text_length_;
983 } 1011 }
984 1012
985 bool OmniboxViewMac::IsCaretAtEnd() const { 1013 bool OmniboxViewMac::IsCaretAtEnd() const {
986 const NSRange selection = GetSelectedRange(); 1014 const NSRange selection = GetSelectedRange();
987 return selection.length == 0 && selection.location == GetTextLength(); 1015 return selection.length == 0 && selection.location == GetTextLength();
988 } 1016 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h ('k') | chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698