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" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 122 |
123 NSPasteboard* pb = GetPasteboard(); | 123 NSPasteboard* pb = GetPasteboard(); |
124 [pb addTypes:[NSArray arrayWithObject:NSFilenamesPboardType] owner:nil]; | 124 [pb addTypes:[NSArray arrayWithObject:NSFilenamesPboardType] owner:nil]; |
125 [pb setPropertyList:fileList forType:NSFilenamesPboardType]; | 125 [pb setPropertyList:fileList forType:NSFilenamesPboardType]; |
126 } | 126 } |
127 | 127 |
128 // Write an extra flavor that signifies WebKit was the last to modify the | 128 // Write an extra flavor that signifies WebKit was the last to modify the |
129 // pasteboard. This flavor has no data. | 129 // pasteboard. This flavor has no data. |
130 void Clipboard::WriteWebSmartPaste() { | 130 void Clipboard::WriteWebSmartPaste() { |
131 NSPasteboard* pb = GetPasteboard(); | 131 NSPasteboard* pb = GetPasteboard(); |
132 [pb addTypes:[NSArray arrayWithObject:GetWebKitSmartPasteFormatType()] owner:n
il]; | 132 NSString* format = base::SysUTF8ToNSString(GetWebKitSmartPasteFormatType()); |
133 [pb setData:nil forType:GetWebKitSmartPasteFormatType()]; | 133 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; |
| 134 [pb setData:nil forType:format]; |
134 } | 135 } |
135 | 136 |
136 bool Clipboard::IsFormatAvailable(NSString* format) const { | 137 bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format) const { |
| 138 NSString* format_ns = base::SysUTF8ToNSString(format); |
| 139 |
137 NSPasteboard* pb = GetPasteboard(); | 140 NSPasteboard* pb = GetPasteboard(); |
138 NSArray* types = [pb types]; | 141 NSArray* types = [pb types]; |
139 | 142 |
140 return [types containsObject:format]; | 143 return [types containsObject:format_ns]; |
141 } | 144 } |
142 | 145 |
143 void Clipboard::ReadText(string16* result) const { | 146 void Clipboard::ReadText(string16* result) const { |
144 NSPasteboard* pb = GetPasteboard(); | 147 NSPasteboard* pb = GetPasteboard(); |
145 NSString* contents = [pb stringForType:NSStringPboardType]; | 148 NSString* contents = [pb stringForType:NSStringPboardType]; |
146 | 149 |
147 UTF8ToUTF16([contents UTF8String], | 150 UTF8ToUTF16([contents UTF8String], |
148 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], | 151 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], |
149 result); | 152 result); |
150 } | 153 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 NSArray* fileList = [pb propertyListForType:NSFilenamesPboardType]; | 226 NSArray* fileList = [pb propertyListForType:NSFilenamesPboardType]; |
224 | 227 |
225 for (unsigned int i = 0; i < [fileList count]; ++i) { | 228 for (unsigned int i = 0; i < [fileList count]; ++i) { |
226 std::string file = [[fileList objectAtIndex:i] UTF8String]; | 229 std::string file = [[fileList objectAtIndex:i] UTF8String]; |
227 files->push_back(FilePath(file)); | 230 files->push_back(FilePath(file)); |
228 } | 231 } |
229 } | 232 } |
230 | 233 |
231 // static | 234 // static |
232 Clipboard::FormatType Clipboard::GetUrlFormatType() { | 235 Clipboard::FormatType Clipboard::GetUrlFormatType() { |
233 return NSURLPboardType; | 236 static const std::string type = base::SysNSStringToUTF8(NSURLPboardType); |
| 237 return type; |
234 } | 238 } |
235 | 239 |
236 // static | 240 // static |
237 Clipboard::FormatType Clipboard::GetUrlWFormatType() { | 241 Clipboard::FormatType Clipboard::GetUrlWFormatType() { |
238 return NSURLPboardType; | 242 static const std::string type = base::SysNSStringToUTF8(NSURLPboardType); |
| 243 return type; |
239 } | 244 } |
240 | 245 |
241 // static | 246 // static |
242 Clipboard::FormatType Clipboard::GetPlainTextFormatType() { | 247 Clipboard::FormatType Clipboard::GetPlainTextFormatType() { |
243 return NSStringPboardType; | 248 static const std::string type = base::SysNSStringToUTF8(NSStringPboardType); |
| 249 return type; |
244 } | 250 } |
245 | 251 |
246 // static | 252 // static |
247 Clipboard::FormatType Clipboard::GetPlainTextWFormatType() { | 253 Clipboard::FormatType Clipboard::GetPlainTextWFormatType() { |
248 return NSStringPboardType; | 254 static const std::string type = base::SysNSStringToUTF8(NSStringPboardType); |
| 255 return type; |
249 } | 256 } |
250 | 257 |
251 // static | 258 // static |
252 Clipboard::FormatType Clipboard::GetFilenameFormatType() { | 259 Clipboard::FormatType Clipboard::GetFilenameFormatType() { |
253 return NSFilenamesPboardType; | 260 static const std::string type = |
| 261 base::SysNSStringToUTF8(NSFilenamesPboardType); |
| 262 return type; |
254 } | 263 } |
255 | 264 |
256 // static | 265 // static |
257 Clipboard::FormatType Clipboard::GetFilenameWFormatType() { | 266 Clipboard::FormatType Clipboard::GetFilenameWFormatType() { |
258 return NSFilenamesPboardType; | 267 static const std::string type = |
| 268 base::SysNSStringToUTF8(NSFilenamesPboardType); |
| 269 return type; |
259 } | 270 } |
260 | 271 |
261 // static | 272 // static |
262 Clipboard::FormatType Clipboard::GetHtmlFormatType() { | 273 Clipboard::FormatType Clipboard::GetHtmlFormatType() { |
263 return NSHTMLPboardType; | 274 static const std::string type = base::SysNSStringToUTF8(NSHTMLPboardType); |
| 275 return type; |
264 } | 276 } |
265 | 277 |
266 // static | 278 // static |
267 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { | 279 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { |
268 return kWebSmartPastePboardType; | 280 static const std::string type = |
| 281 base::SysNSStringToUTF8(kWebSmartPastePboardType); |
| 282 return type; |
269 } | 283 } |
OLD | NEW |