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

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

Issue 2232863002: Remove search::GetSearchTerms since it always returns empty string (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_query_extract
Patch Set: Mac Created 4 years, 4 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
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/mac/foundation_util.h" 9 #include "base/mac/foundation_util.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 } 928 }
929 929
930 void OmniboxViewMac::OnMouseDown(NSInteger button_number) { 930 void OmniboxViewMac::OnMouseDown(NSInteger button_number) {
931 // Restore caret visibility whenever the user clicks in the the omnibox. This 931 // Restore caret visibility whenever the user clicks in the the omnibox. This
932 // is not always covered by OnSetFocus() because when clicking while the 932 // is not always covered by OnSetFocus() because when clicking while the
933 // omnibox has invisible focus does not trigger a new OnSetFocus() call. 933 // omnibox has invisible focus does not trigger a new OnSetFocus() call.
934 if (button_number == 0 || button_number == 1) 934 if (button_number == 0 || button_number == 1)
935 model()->SetCaretVisibility(true); 935 model()->SetCaretVisibility(true);
936 } 936 }
937 937
938 bool OmniboxViewMac::ShouldSelectAllOnMouseDown() {
939 return !controller()->GetToolbarModel()->WouldPerformSearchTermReplacement(
940 false);
941 }
942
943 bool OmniboxViewMac::CanCopy() { 938 bool OmniboxViewMac::CanCopy() {
944 const NSRange selection = GetSelectedRange(); 939 const NSRange selection = GetSelectedRange();
945 return selection.length > 0; 940 return selection.length > 0;
946 } 941 }
947 942
948 base::scoped_nsobject<NSPasteboardItem> OmniboxViewMac::CreatePasteboardItem() { 943 base::scoped_nsobject<NSPasteboardItem> OmniboxViewMac::CreatePasteboardItem() {
949 DCHECK(CanCopy()); 944 DCHECK(CanCopy());
950 945
951 const NSRange selection = GetSelectedRange(); 946 const NSRange selection = GetSelectedRange();
952 base::string16 text = base::SysNSStringToUTF16( 947 base::string16 text = base::SysNSStringToUTF16(
953 [[field_ stringValue] substringWithRange:selection]); 948 [[field_ stringValue] substringWithRange:selection]);
954 949
955 // Copy the URL unless this is the search URL and it's being replaced by the 950 // Copy the URL.
956 // Extended Instant API.
957 GURL url; 951 GURL url;
958 bool write_url = false; 952 bool write_url = false;
959 if (!controller()->GetToolbarModel()->WouldPerformSearchTermReplacement( 953 model()->AdjustTextForCopy(selection.location, IsSelectAll(), &text, &url,
960 false)) { 954 &write_url);
961 model()->AdjustTextForCopy(selection.location, IsSelectAll(), &text, &url,
962 &write_url);
963 }
964 955
965 if (IsSelectAll()) 956 if (IsSelectAll())
966 UMA_HISTOGRAM_COUNTS(OmniboxEditModel::kCutOrCopyAllTextHistogram, 1); 957 UMA_HISTOGRAM_COUNTS(OmniboxEditModel::kCutOrCopyAllTextHistogram, 1);
967 958
968 NSString* nstext = base::SysUTF16ToNSString(text); 959 NSString* nstext = base::SysUTF16ToNSString(text);
969 if (write_url) { 960 if (write_url) {
970 return ui::ClipboardUtil::PasteboardItemFromUrl( 961 return ui::ClipboardUtil::PasteboardItemFromUrl(
971 base::SysUTF8ToNSString(url.spec()), nstext); 962 base::SysUTF8ToNSString(url.spec()), nstext);
972 } else { 963 } else {
973 return ui::ClipboardUtil::PasteboardItemFromString(nstext); 964 return ui::ClipboardUtil::PasteboardItemFromString(nstext);
974 } 965 }
975 } 966 }
976 967
977 void OmniboxViewMac::CopyToPasteboard(NSPasteboard* pboard) { 968 void OmniboxViewMac::CopyToPasteboard(NSPasteboard* pboard) {
978 [pboard clearContents]; 969 [pboard clearContents];
979 base::scoped_nsobject<NSPasteboardItem> item(CreatePasteboardItem()); 970 base::scoped_nsobject<NSPasteboardItem> item(CreatePasteboardItem());
980 [pboard writeObjects:@[ item.get() ]]; 971 [pboard writeObjects:@[ item.get() ]];
981 } 972 }
982 973
983 void OmniboxViewMac::ShowURL() {
984 DCHECK(ShouldEnableShowURL());
985 OmniboxView::ShowURL();
Peter Kasting 2016/08/13 05:03:44 Remember to eventually rip out the other call chai
Marc Treib 2016/08/16 12:00:17 Yup, follow-up on the way!
986 }
987
988 void OmniboxViewMac::OnPaste() { 974 void OmniboxViewMac::OnPaste() {
989 // This code currently expects |field_| to be focused. 975 // This code currently expects |field_| to be focused.
990 DCHECK([field_ currentEditor]); 976 DCHECK([field_ currentEditor]);
991 977
992 base::string16 text = GetClipboardText(); 978 base::string16 text = GetClipboardText();
993 if (text.empty()) { 979 if (text.empty()) {
994 return; 980 return;
995 } 981 }
996 NSString* s = base::SysUTF16ToNSString(text); 982 NSString* s = base::SysUTF16ToNSString(text);
997 983
(...skipping 12 matching lines...) Expand all
1010 // Force a Paste operation to trigger the text_changed code in 996 // Force a Paste operation to trigger the text_changed code in
1011 // OnAfterPossibleChange(), even if identical contents are pasted 997 // OnAfterPossibleChange(), even if identical contents are pasted
1012 // into the text box. 998 // into the text box.
1013 state_before_change_.text.clear(); 999 state_before_change_.text.clear();
1014 1000
1015 [editor replaceCharactersInRange:selectedRange withString:s]; 1001 [editor replaceCharactersInRange:selectedRange withString:s];
1016 [editor didChangeText]; 1002 [editor didChangeText];
1017 } 1003 }
1018 } 1004 }
1019 1005
1020 // TODO(dominich): Move to OmniboxView base class? Currently this is defined on
1021 // the AutocompleteTextFieldObserver but the logic is shared between all
1022 // platforms. Some refactor might be necessary to simplify this. Or at least
1023 // this method could call the OmniboxView version.
1024 bool OmniboxViewMac::ShouldEnableShowURL() {
1025 return controller()->GetToolbarModel()->WouldReplaceURL();
1026 }
1027
1028 bool OmniboxViewMac::CanPasteAndGo() { 1006 bool OmniboxViewMac::CanPasteAndGo() {
1029 return model()->CanPasteAndGo(GetClipboardText()); 1007 return model()->CanPasteAndGo(GetClipboardText());
1030 } 1008 }
1031 1009
1032 int OmniboxViewMac::GetPasteActionStringId() { 1010 int OmniboxViewMac::GetPasteActionStringId() {
1033 base::string16 text(GetClipboardText()); 1011 base::string16 text(GetClipboardText());
1034 DCHECK(model()->CanPasteAndGo(text)); 1012 DCHECK(model()->CanPasteAndGo(text));
1035 return model()->IsPasteAndSearch(text) ? 1013 return model()->IsPasteAndSearch(text) ?
1036 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO; 1014 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO;
1037 } 1015 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1162 display_text); 1140 display_text);
1163 NSDictionary* notification_info = @{ 1141 NSDictionary* notification_info = @{
1164 NSAccessibilityAnnouncementKey : announcement, 1142 NSAccessibilityAnnouncementKey : announcement,
1165 NSAccessibilityPriorityKey : @(NSAccessibilityPriorityHigh) 1143 NSAccessibilityPriorityKey : @(NSAccessibilityPriorityHigh)
1166 }; 1144 };
1167 NSAccessibilityPostNotificationWithUserInfo( 1145 NSAccessibilityPostNotificationWithUserInfo(
1168 [field_ window], 1146 [field_ window],
1169 NSAccessibilityAnnouncementRequestedNotification, 1147 NSAccessibilityAnnouncementRequestedNotification,
1170 notification_info); 1148 notification_info);
1171 } 1149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698