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/property_bag.h" | 9 #include "base/property_bag.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 [editor replaceCharactersInRange:selectedRange withString:s]; | 935 [editor replaceCharactersInRange:selectedRange withString:s]; |
936 [editor didChangeText]; | 936 [editor didChangeText]; |
937 } | 937 } |
938 } | 938 } |
939 | 939 |
940 bool OmniboxViewMac::CanPasteAndGo() { | 940 bool OmniboxViewMac::CanPasteAndGo() { |
941 return model_->CanPasteAndGo(GetClipboardText()); | 941 return model_->CanPasteAndGo(GetClipboardText()); |
942 } | 942 } |
943 | 943 |
944 int OmniboxViewMac::GetPasteActionStringId() { | 944 int OmniboxViewMac::GetPasteActionStringId() { |
945 DCHECK(CanPasteAndGo()); | 945 string16 text(GetClipboardText()); |
946 | 946 DCHECK(model_->CanPasteAndGo(text)); |
947 // Use PASTE_AND_SEARCH as the default fallback (although the DCHECK above | 947 return model_->IsPasteAndSearch(GetClipboardText()) ? |
948 // should never trigger). | 948 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO; |
949 if (!model_->is_paste_and_search()) | |
950 return IDS_PASTE_AND_GO; | |
951 else | |
952 return IDS_PASTE_AND_SEARCH; | |
953 } | 949 } |
954 | 950 |
955 void OmniboxViewMac::OnPasteAndGo() { | 951 void OmniboxViewMac::OnPasteAndGo() { |
956 if (CanPasteAndGo()) | 952 string16 text(GetClipboardText()); |
957 model_->PasteAndGo(); | 953 if (model_->CanPasteAndGo(text)) |
| 954 model_->PasteAndGo(text); |
958 } | 955 } |
959 | 956 |
960 void OmniboxViewMac::OnFrameChanged() { | 957 void OmniboxViewMac::OnFrameChanged() { |
961 // TODO(shess): UpdatePopupAppearance() is called frequently, so it | 958 // TODO(shess): UpdatePopupAppearance() is called frequently, so it |
962 // should be really cheap, but in this case we could probably make | 959 // should be really cheap, but in this case we could probably make |
963 // things even cheaper by refactoring between the popup-placement | 960 // things even cheaper by refactoring between the popup-placement |
964 // code and the matrix-population code. | 961 // code and the matrix-population code. |
965 popup_view_->UpdatePopupAppearance(); | 962 popup_view_->UpdatePopupAppearance(); |
966 model_->PopupBoundsChangedTo(popup_view_->GetTargetBounds()); | 963 model_->PopupBoundsChangedTo(popup_view_->GetTargetBounds()); |
967 | 964 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 | 1041 |
1045 void OmniboxViewMac::PlaceCaretAt(NSUInteger pos) { | 1042 void OmniboxViewMac::PlaceCaretAt(NSUInteger pos) { |
1046 DCHECK(pos <= GetTextLength()); | 1043 DCHECK(pos <= GetTextLength()); |
1047 SetSelectedRange(NSMakeRange(pos, pos)); | 1044 SetSelectedRange(NSMakeRange(pos, pos)); |
1048 } | 1045 } |
1049 | 1046 |
1050 bool OmniboxViewMac::IsCaretAtEnd() const { | 1047 bool OmniboxViewMac::IsCaretAtEnd() const { |
1051 const NSRange selection = GetSelectedRange(); | 1048 const NSRange selection = GetSelectedRange(); |
1052 return selection.length == 0 && selection.location == GetTextLength(); | 1049 return selection.length == 0 && selection.location == GetTextLength(); |
1053 } | 1050 } |
OLD | NEW |