Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: ui/base/clipboard/clipboard_mac.mm

Issue 12298037: Revert 183123 (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1417/src/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/base/clipboard/clipboard_gtk.cc ('k') | ui/base/clipboard/clipboard_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/file_path.h" 10 #include "base/file_path.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/mac/mac_util.h" 12 #include "base/mac/mac_util.h"
13 #include "base/mac/scoped_cftyperef.h" 13 #include "base/mac/scoped_cftyperef.h"
14 #include "base/memory/scoped_nsobject.h" 14 #include "base/memory/scoped_nsobject.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/sys_string_conversions.h" 16 #include "base/sys_string_conversions.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #import "third_party/mozilla/NSPasteboard+Utils.h" 18 #import "third_party/mozilla/NSPasteboard+Utils.h"
19 #include "third_party/skia/include/core/SkBitmap.h" 19 #include "third_party/skia/include/core/SkBitmap.h"
20 #include "ui/base/clipboard/custom_data_helper.h" 20 #include "ui/base/clipboard/custom_data_helper.h"
21 #include "ui/gfx/canvas.h" 21 #include "ui/gfx/canvas.h"
22 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 22 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
23 #include "ui/gfx/size.h" 23 #include "ui/gfx/size.h"
24 24
25 namespace ui { 25 namespace ui {
26 26
27 namespace { 27 namespace {
28 28
29 // Source tag format type.
30 NSString* const kSourceTagPboardType = @"org.chromium.source-tag-data";
31
32 // Would be nice if this were in UTCoreTypes.h, but it isn't 29 // Would be nice if this were in UTCoreTypes.h, but it isn't
33 NSString* const kUTTypeURLName = @"public.url-name"; 30 NSString* const kUTTypeURLName = @"public.url-name";
34 31
35 // Tells us if WebKit was the last to write to the pasteboard. There's no 32 // Tells us if WebKit was the last to write to the pasteboard. There's no
36 // actual data associated with this type. 33 // actual data associated with this type.
37 NSString* const kWebSmartPastePboardType = @"NeXT smart paste pasteboard type"; 34 NSString* const kWebSmartPastePboardType = @"NeXT smart paste pasteboard type";
38 35
39 // Pepper custom data format type. 36 // Pepper custom data format type.
40 NSString* const kPepperCustomDataPboardType = 37 NSString* const kPepperCustomDataPboardType =
41 @"org.chromium.pepper-custom-data"; 38 @"org.chromium.pepper-custom-data";
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 83 }
87 84
88 Clipboard::Clipboard() { 85 Clipboard::Clipboard() {
89 DCHECK(CalledOnValidThread()); 86 DCHECK(CalledOnValidThread());
90 } 87 }
91 88
92 Clipboard::~Clipboard() { 89 Clipboard::~Clipboard() {
93 DCHECK(CalledOnValidThread()); 90 DCHECK(CalledOnValidThread());
94 } 91 }
95 92
96 void Clipboard::WriteObjectsImpl(Buffer buffer, 93 void Clipboard::WriteObjects(Buffer buffer, const ObjectMap& objects) {
97 const ObjectMap& objects,
98 SourceTag tag) {
99 DCHECK(CalledOnValidThread()); 94 DCHECK(CalledOnValidThread());
100 DCHECK_EQ(buffer, BUFFER_STANDARD); 95 DCHECK_EQ(buffer, BUFFER_STANDARD);
101 96
102 NSPasteboard* pb = GetPasteboard(); 97 NSPasteboard* pb = GetPasteboard();
103 [pb declareTypes:[NSArray array] owner:nil]; 98 [pb declareTypes:[NSArray array] owner:nil];
104 99
105 for (ObjectMap::const_iterator iter = objects.begin(); 100 for (ObjectMap::const_iterator iter = objects.begin();
106 iter != objects.end(); ++iter) { 101 iter != objects.end(); ++iter) {
107 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); 102 DispatchObject(static_cast<ObjectType>(iter->first), iter->second);
108 } 103 }
109 WriteSourceTag(tag);
110 } 104 }
111 105
112 void Clipboard::WriteText(const char* text_data, size_t text_len) { 106 void Clipboard::WriteText(const char* text_data, size_t text_len) {
113 std::string text_str(text_data, text_len); 107 std::string text_str(text_data, text_len);
114 NSString *text = base::SysUTF8ToNSString(text_str); 108 NSString *text = base::SysUTF8ToNSString(text_str);
115 NSPasteboard* pb = GetPasteboard(); 109 NSPasteboard* pb = GetPasteboard();
116 [pb addTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil]; 110 [pb addTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
117 [pb setString:text forType:NSStringPboardType]; 111 [pb setString:text forType:NSStringPboardType];
118 } 112 }
119 113
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 205
212 void Clipboard::WriteData(const FormatType& format, 206 void Clipboard::WriteData(const FormatType& format,
213 const char* data_data, 207 const char* data_data,
214 size_t data_len) { 208 size_t data_len) {
215 NSPasteboard* pb = GetPasteboard(); 209 NSPasteboard* pb = GetPasteboard();
216 [pb addTypes:[NSArray arrayWithObject:format.ToNSString()] owner:nil]; 210 [pb addTypes:[NSArray arrayWithObject:format.ToNSString()] owner:nil];
217 [pb setData:[NSData dataWithBytes:data_data length:data_len] 211 [pb setData:[NSData dataWithBytes:data_data length:data_len]
218 forType:format.ToNSString()]; 212 forType:format.ToNSString()];
219 } 213 }
220 214
221 void Clipboard::WriteSourceTag(SourceTag tag) {
222 if (tag != SourceTag()) {
223 ObjectMapParam binary = SourceTag2Binary(tag);
224 WriteData(GetSourceTagFormatType(), &binary[0], binary.size());
225 }
226 }
227
228 // Write an extra flavor that signifies WebKit was the last to modify the 215 // Write an extra flavor that signifies WebKit was the last to modify the
229 // pasteboard. This flavor has no data. 216 // pasteboard. This flavor has no data.
230 void Clipboard::WriteWebSmartPaste() { 217 void Clipboard::WriteWebSmartPaste() {
231 NSPasteboard* pb = GetPasteboard(); 218 NSPasteboard* pb = GetPasteboard();
232 NSString* format = GetWebKitSmartPasteFormatType().ToNSString(); 219 NSString* format = GetWebKitSmartPasteFormatType().ToNSString();
233 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; 220 [pb addTypes:[NSArray arrayWithObject:format] owner:nil];
234 [pb setData:nil forType:format]; 221 [pb setData:nil forType:format];
235 } 222 }
236 223
237 uint64 Clipboard::GetSequenceNumber(Buffer buffer) { 224 uint64 Clipboard::GetSequenceNumber(Buffer buffer) {
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 } 403 }
417 404
418 void Clipboard::ReadData(const FormatType& format, std::string* result) const { 405 void Clipboard::ReadData(const FormatType& format, std::string* result) const {
419 DCHECK(CalledOnValidThread()); 406 DCHECK(CalledOnValidThread());
420 NSPasteboard* pb = GetPasteboard(); 407 NSPasteboard* pb = GetPasteboard();
421 NSData* data = [pb dataForType:format.ToNSString()]; 408 NSData* data = [pb dataForType:format.ToNSString()];
422 if ([data length]) 409 if ([data length])
423 result->assign(static_cast<const char*>([data bytes]), [data length]); 410 result->assign(static_cast<const char*>([data bytes]), [data length]);
424 } 411 }
425 412
426 Clipboard::SourceTag Clipboard::ReadSourceTag(Buffer buffer) const {
427 DCHECK_EQ(buffer, BUFFER_STANDARD);
428 std::string result;
429 ReadData(GetSourceTagFormatType(), &result);
430 return Binary2SourceTag(result);
431 }
432
433 // static 413 // static
434 Clipboard::FormatType Clipboard::GetFormatType( 414 Clipboard::FormatType Clipboard::GetFormatType(
435 const std::string& format_string) { 415 const std::string& format_string) {
436 return FormatType::Deserialize(format_string); 416 return FormatType::Deserialize(format_string);
437 } 417 }
438 418
439 // static 419 // static
440 const Clipboard::FormatType& Clipboard::GetUrlFormatType() { 420 const Clipboard::FormatType& Clipboard::GetUrlFormatType() {
441 CR_DEFINE_STATIC_LOCAL(FormatType, type, (NSURLPboardType)); 421 CR_DEFINE_STATIC_LOCAL(FormatType, type, (NSURLPboardType));
442 return type; 422 return type;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kWebCustomDataPboardType)); 478 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kWebCustomDataPboardType));
499 return type; 479 return type;
500 } 480 }
501 481
502 // static 482 // static
503 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { 483 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() {
504 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kPepperCustomDataPboardType)); 484 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kPepperCustomDataPboardType));
505 return type; 485 return type;
506 } 486 }
507 487
508 // static
509 const Clipboard::FormatType& Clipboard::GetSourceTagFormatType() {
510 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kSourceTagPboardType));
511 return type;
512 }
513
514 } // namespace ui 488 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/clipboard/clipboard_gtk.cc ('k') | ui/base/clipboard/clipboard_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698