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 "ui/base/clipboard/clipboard.h" | 5 #include "ui/base/clipboard/clipboard.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 if ([[pb types] containsObject:kWebCustomDataPboardType]) { | 286 if ([[pb types] containsObject:kWebCustomDataPboardType]) { |
287 NSData* data = [pb dataForType:kWebCustomDataPboardType]; | 287 NSData* data = [pb dataForType:kWebCustomDataPboardType]; |
288 if ([data length]) | 288 if ([data length]) |
289 ReadCustomDataTypes([data bytes], [data length], types); | 289 ReadCustomDataTypes([data bytes], [data length], types); |
290 } | 290 } |
291 } | 291 } |
292 | 292 |
293 void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const { | 293 void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const { |
294 DCHECK(CalledOnValidThread()); | 294 DCHECK(CalledOnValidThread()); |
295 DCHECK_EQ(buffer, BUFFER_STANDARD); | 295 DCHECK_EQ(buffer, BUFFER_STANDARD); |
| 296 ReportAction(buffer, READ_TEXT); |
296 NSPasteboard* pb = GetPasteboard(); | 297 NSPasteboard* pb = GetPasteboard(); |
297 NSString* contents = [pb stringForType:NSStringPboardType]; | 298 NSString* contents = [pb stringForType:NSStringPboardType]; |
298 | 299 |
299 UTF8ToUTF16([contents UTF8String], | 300 UTF8ToUTF16([contents UTF8String], |
300 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], | 301 [contents lengthOfBytesUsingEncoding:NSUTF8StringEncoding], |
301 result); | 302 result); |
302 } | 303 } |
303 | 304 |
304 void Clipboard::ReadAsciiText(Clipboard::Buffer buffer, | 305 void Clipboard::ReadAsciiText(Clipboard::Buffer buffer, |
305 std::string* result) const { | 306 std::string* result) const { |
306 DCHECK(CalledOnValidThread()); | 307 DCHECK(CalledOnValidThread()); |
307 DCHECK_EQ(buffer, BUFFER_STANDARD); | 308 DCHECK_EQ(buffer, BUFFER_STANDARD); |
| 309 ReportAction(buffer, READ_TEXT); |
308 NSPasteboard* pb = GetPasteboard(); | 310 NSPasteboard* pb = GetPasteboard(); |
309 NSString* contents = [pb stringForType:NSStringPboardType]; | 311 NSString* contents = [pb stringForType:NSStringPboardType]; |
310 | 312 |
311 if (!contents) | 313 if (!contents) |
312 result->clear(); | 314 result->clear(); |
313 else | 315 else |
314 result->assign([contents UTF8String]); | 316 result->assign([contents UTF8String]); |
315 } | 317 } |
316 | 318 |
317 void Clipboard::ReadHTML(Clipboard::Buffer buffer, string16* markup, | 319 void Clipboard::ReadHTML(Clipboard::Buffer buffer, string16* markup, |
(...skipping 23 matching lines...) Expand all Loading... |
341 } | 343 } |
342 | 344 |
343 *fragment_start = 0; | 345 *fragment_start = 0; |
344 DCHECK(markup->length() <= kuint32max); | 346 DCHECK(markup->length() <= kuint32max); |
345 *fragment_end = static_cast<uint32>(markup->length()); | 347 *fragment_end = static_cast<uint32>(markup->length()); |
346 } | 348 } |
347 | 349 |
348 void Clipboard::ReadRTF(Buffer buffer, std::string* result) const { | 350 void Clipboard::ReadRTF(Buffer buffer, std::string* result) const { |
349 DCHECK(CalledOnValidThread()); | 351 DCHECK(CalledOnValidThread()); |
350 DCHECK_EQ(buffer, BUFFER_STANDARD); | 352 DCHECK_EQ(buffer, BUFFER_STANDARD); |
| 353 ReportAction(buffer, READ_TEXT); |
351 | 354 |
352 return ReadData(GetRtfFormatType(), result); | 355 return ReadData(GetRtfFormatType(), result); |
353 } | 356 } |
354 | 357 |
355 SkBitmap Clipboard::ReadImage(Buffer buffer) const { | 358 SkBitmap Clipboard::ReadImage(Buffer buffer) const { |
356 DCHECK(CalledOnValidThread()); | 359 DCHECK(CalledOnValidThread()); |
357 DCHECK_EQ(buffer, BUFFER_STANDARD); | 360 DCHECK_EQ(buffer, BUFFER_STANDARD); |
358 | 361 |
359 scoped_nsobject<NSImage> image( | 362 scoped_nsobject<NSImage> image( |
360 [[NSImage alloc] initWithPasteboard:GetPasteboard()]); | 363 [[NSImage alloc] initWithPasteboard:GetPasteboard()]); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 return type; | 508 return type; |
506 } | 509 } |
507 | 510 |
508 // static | 511 // static |
509 const Clipboard::FormatType& Clipboard::GetSourceTagFormatType() { | 512 const Clipboard::FormatType& Clipboard::GetSourceTagFormatType() { |
510 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kSourceTagPboardType)); | 513 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kSourceTagPboardType)); |
511 return type; | 514 return type; |
512 } | 515 } |
513 | 516 |
514 } // namespace ui | 517 } // namespace ui |
OLD | NEW |