| 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/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "components/omnibox/browser/omnibox_edit_controller.h" | 27 #include "components/omnibox/browser/omnibox_edit_controller.h" |
| 28 #include "components/omnibox/browser/omnibox_field_trial.h" | 28 #include "components/omnibox/browser/omnibox_field_trial.h" |
| 29 #include "components/omnibox/browser/omnibox_popup_model.h" | 29 #include "components/omnibox/browser/omnibox_popup_model.h" |
| 30 #include "components/security_state/security_state_model.h" | 30 #include "components/security_state/security_state_model.h" |
| 31 #include "components/toolbar/toolbar_model.h" | 31 #include "components/toolbar/toolbar_model.h" |
| 32 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 33 #include "extensions/common/constants.h" | 33 #include "extensions/common/constants.h" |
| 34 #import "skia/ext/skia_utils_mac.h" | 34 #import "skia/ext/skia_utils_mac.h" |
| 35 #import "third_party/mozilla/NSPasteboard+Utils.h" | 35 #import "third_party/mozilla/NSPasteboard+Utils.h" |
| 36 #include "ui/base/clipboard/clipboard.h" | 36 #include "ui/base/clipboard/clipboard.h" |
| 37 #include "ui/base/clipboard/clipboard_util_mac.h" |
| 37 #import "ui/base/cocoa/cocoa_base_utils.h" | 38 #import "ui/base/cocoa/cocoa_base_utils.h" |
| 38 #include "ui/base/material_design/material_design_controller.h" | 39 #include "ui/base/material_design/material_design_controller.h" |
| 39 #include "ui/base/resource/resource_bundle.h" | 40 #include "ui/base/resource/resource_bundle.h" |
| 40 #include "ui/gfx/color_palette.h" | 41 #include "ui/gfx/color_palette.h" |
| 41 #include "ui/gfx/font.h" | 42 #include "ui/gfx/font.h" |
| 42 #include "ui/gfx/font_list.h" | 43 #include "ui/gfx/font_list.h" |
| 43 #include "ui/gfx/geometry/rect.h" | 44 #include "ui/gfx/geometry/rect.h" |
| 44 | 45 |
| 45 using content::WebContents; | 46 using content::WebContents; |
| 46 | 47 |
| (...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 bool OmniboxViewMac::ShouldSelectAllOnMouseDown() { | 920 bool OmniboxViewMac::ShouldSelectAllOnMouseDown() { |
| 920 return !controller()->GetToolbarModel()->WouldPerformSearchTermReplacement( | 921 return !controller()->GetToolbarModel()->WouldPerformSearchTermReplacement( |
| 921 false); | 922 false); |
| 922 } | 923 } |
| 923 | 924 |
| 924 bool OmniboxViewMac::CanCopy() { | 925 bool OmniboxViewMac::CanCopy() { |
| 925 const NSRange selection = GetSelectedRange(); | 926 const NSRange selection = GetSelectedRange(); |
| 926 return selection.length > 0; | 927 return selection.length > 0; |
| 927 } | 928 } |
| 928 | 929 |
| 929 void OmniboxViewMac::CopyToPasteboard(NSPasteboard* pb) { | 930 base::scoped_nsobject<NSPasteboardItem> OmniboxViewMac::CreatePasteboardItem() { |
| 930 DCHECK(CanCopy()); | 931 DCHECK(CanCopy()); |
| 931 | 932 |
| 932 const NSRange selection = GetSelectedRange(); | 933 const NSRange selection = GetSelectedRange(); |
| 933 base::string16 text = base::SysNSStringToUTF16( | 934 base::string16 text = base::SysNSStringToUTF16( |
| 934 [[field_ stringValue] substringWithRange:selection]); | 935 [[field_ stringValue] substringWithRange:selection]); |
| 935 | 936 |
| 936 // Copy the URL unless this is the search URL and it's being replaced by the | 937 // Copy the URL unless this is the search URL and it's being replaced by the |
| 937 // Extended Instant API. | 938 // Extended Instant API. |
| 938 GURL url; | 939 GURL url; |
| 939 bool write_url = false; | 940 bool write_url = false; |
| 940 if (!controller()->GetToolbarModel()->WouldPerformSearchTermReplacement( | 941 if (!controller()->GetToolbarModel()->WouldPerformSearchTermReplacement( |
| 941 false)) { | 942 false)) { |
| 942 model()->AdjustTextForCopy(selection.location, IsSelectAll(), &text, &url, | 943 model()->AdjustTextForCopy(selection.location, IsSelectAll(), &text, &url, |
| 943 &write_url); | 944 &write_url); |
| 944 } | 945 } |
| 945 | 946 |
| 946 if (IsSelectAll()) | 947 if (IsSelectAll()) |
| 947 UMA_HISTOGRAM_COUNTS(OmniboxEditModel::kCutOrCopyAllTextHistogram, 1); | 948 UMA_HISTOGRAM_COUNTS(OmniboxEditModel::kCutOrCopyAllTextHistogram, 1); |
| 948 | 949 |
| 949 NSString* nstext = base::SysUTF16ToNSString(text); | 950 NSString* nstext = base::SysUTF16ToNSString(text); |
| 950 [pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil]; | 951 if (write_url) { |
| 951 [pb setString:nstext forType:NSStringPboardType]; | 952 return ui::ClipboardUtil::PasteboardItemFromUrl( |
| 953 base::SysUTF8ToNSString(url.spec()), nstext); |
| 954 } else { |
| 955 return ui::ClipboardUtil::PasteboardItemFromString(nstext); |
| 956 } |
| 957 } |
| 952 | 958 |
| 953 if (write_url) { | 959 void OmniboxViewMac::CopyToPasteboard(NSPasteboard* pboard) { |
| 954 [pb declareURLPasteboardWithAdditionalTypes:[NSArray array] owner:nil]; | 960 base::scoped_nsobject<NSPasteboardItem> item(CreatePasteboardItem()); |
| 955 [pb setDataForURL:base::SysUTF8ToNSString(url.spec()) title:nstext]; | 961 [pboard writeObjects:@[ item.get() ]]; |
| 956 } | |
| 957 } | 962 } |
| 958 | 963 |
| 959 void OmniboxViewMac::ShowURL() { | 964 void OmniboxViewMac::ShowURL() { |
| 960 DCHECK(ShouldEnableShowURL()); | 965 DCHECK(ShouldEnableShowURL()); |
| 961 OmniboxView::ShowURL(); | 966 OmniboxView::ShowURL(); |
| 962 } | 967 } |
| 963 | 968 |
| 964 void OmniboxViewMac::OnPaste() { | 969 void OmniboxViewMac::OnPaste() { |
| 965 // This code currently expects |field_| to be focused. | 970 // This code currently expects |field_| to be focused. |
| 966 DCHECK([field_ currentEditor]); | 971 DCHECK([field_ currentEditor]); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 | 1106 |
| 1102 NSUInteger OmniboxViewMac::GetTextLength() const { | 1107 NSUInteger OmniboxViewMac::GetTextLength() const { |
| 1103 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : | 1108 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : |
| 1104 [[field_ stringValue] length]; | 1109 [[field_ stringValue] length]; |
| 1105 } | 1110 } |
| 1106 | 1111 |
| 1107 bool OmniboxViewMac::IsCaretAtEnd() const { | 1112 bool OmniboxViewMac::IsCaretAtEnd() const { |
| 1108 const NSRange selection = GetSelectedRange(); | 1113 const NSRange selection = GetSelectedRange(); |
| 1109 return NSMaxRange(selection) == GetTextLength(); | 1114 return NSMaxRange(selection) == GetTextLength(); |
| 1110 } | 1115 } |
| OLD | NEW |