OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/clipboard.h" | 5 #include "base/clipboard.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 // Would be nice if this were in UTCoreTypes.h, but it isn't | 15 // Would be nice if this were in UTCoreTypes.h, but it isn't |
16 const NSString* kUTTypeURLName = @"public.url-name"; | 16 const NSString* kUTTypeURLName = @"public.url-name"; |
17 | 17 |
| 18 // Tells us if WebKit was the last to write to the pasteboard. There's no |
| 19 // actual data associated with this type. |
| 20 const NSString *kWebSmartPastePboardType = @"NeXT smart paste pasteboard type"; |
| 21 |
18 NSPasteboard* GetPasteboard() { | 22 NSPasteboard* GetPasteboard() { |
19 // The pasteboard should not be nil in a UI session, but this handy DCHECK | 23 // The pasteboard should not be nil in a UI session, but this handy DCHECK |
20 // can help track down problems if someone tries using clipboard code outside | 24 // can help track down problems if someone tries using clipboard code outside |
21 // of a UI session. | 25 // of a UI session. |
22 NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; | 26 NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; |
23 DCHECK(pasteboard); | 27 DCHECK(pasteboard); |
24 return pasteboard; | 28 return pasteboard; |
25 } | 29 } |
26 | 30 |
27 } // namespace | 31 } // namespace |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 current_filename_offset = i + 1; | 118 current_filename_offset = i + 1; |
115 continue; | 119 continue; |
116 } | 120 } |
117 } | 121 } |
118 | 122 |
119 NSPasteboard* pb = GetPasteboard(); | 123 NSPasteboard* pb = GetPasteboard(); |
120 [pb addTypes:[NSArray arrayWithObject:NSFilenamesPboardType] owner:nil]; | 124 [pb addTypes:[NSArray arrayWithObject:NSFilenamesPboardType] owner:nil]; |
121 [pb setPropertyList:fileList forType:NSFilenamesPboardType]; | 125 [pb setPropertyList:fileList forType:NSFilenamesPboardType]; |
122 } | 126 } |
123 | 127 |
| 128 // Write an extra flavor that signifies WebKit was the last to modify the |
| 129 // pasteboard. This flavor has no data. |
| 130 void Clipboard::WriteWebSmartPaste() { |
| 131 NSPasteboard* pb = GetPasteboard(); |
| 132 [pb addTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil]; |
| 133 [pb setData:nil forType:GetWebKitSmartPasteFormatType()]; |
| 134 } |
| 135 |
124 bool Clipboard::IsFormatAvailable(NSString* format) const { | 136 bool Clipboard::IsFormatAvailable(NSString* format) const { |
125 NSPasteboard* pb = GetPasteboard(); | 137 NSPasteboard* pb = GetPasteboard(); |
126 NSArray* types = [pb types]; | 138 NSArray* types = [pb types]; |
127 | 139 |
128 return [types containsObject:format]; | 140 return [types containsObject:format]; |
129 } | 141 } |
130 | 142 |
131 void Clipboard::ReadText(std::wstring* result) const { | 143 void Clipboard::ReadText(std::wstring* result) const { |
132 NSPasteboard* pb = GetPasteboard(); | 144 NSPasteboard* pb = GetPasteboard(); |
133 NSString* contents = [pb stringForType:NSStringPboardType]; | 145 NSString* contents = [pb stringForType:NSStringPboardType]; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 | 255 |
244 // static | 256 // static |
245 Clipboard::FormatType Clipboard::GetFilenameWFormatType() { | 257 Clipboard::FormatType Clipboard::GetFilenameWFormatType() { |
246 return NSFilenamesPboardType; | 258 return NSFilenamesPboardType; |
247 } | 259 } |
248 | 260 |
249 // static | 261 // static |
250 Clipboard::FormatType Clipboard::GetHtmlFormatType() { | 262 Clipboard::FormatType Clipboard::GetHtmlFormatType() { |
251 return NSHTMLPboardType; | 263 return NSHTMLPboardType; |
252 } | 264 } |
| 265 |
| 266 // static |
| 267 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { |
| 268 return kWebSmartPastePboardType; |
| 269 } |
OLD | NEW |