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

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

Issue 8801015: Revert 112986 - Implement Clipboard::ReadData and Clipboard::WriteData for Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/file_path.h" 9 #include "base/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 // For now, spit out the image as a TIFF. 146 // For now, spit out the image as a TIFF.
147 NSPasteboard* pb = GetPasteboard(); 147 NSPasteboard* pb = GetPasteboard();
148 [pb addTypes:[NSArray arrayWithObject:NSTIFFPboardType] owner:nil]; 148 [pb addTypes:[NSArray arrayWithObject:NSTIFFPboardType] owner:nil];
149 NSData *tiff_data = [image TIFFRepresentation]; 149 NSData *tiff_data = [image TIFFRepresentation];
150 LOG_IF(ERROR, tiff_data == NULL) << "Failed to allocate image for clipboard"; 150 LOG_IF(ERROR, tiff_data == NULL) << "Failed to allocate image for clipboard";
151 if (tiff_data) { 151 if (tiff_data) {
152 [pb setData:tiff_data forType:NSTIFFPboardType]; 152 [pb setData:tiff_data forType:NSTIFFPboardType];
153 } 153 }
154 } 154 }
155 155
156 void Clipboard::WriteData(const char* format_name, size_t format_len,
157 const char* data_data, size_t data_len) {
158 NSPasteboard* pb = GetPasteboard();
159 NSString* format = [NSString stringWithUTF8String:format_name];
160 [pb addTypes:[NSArray arrayWithObject:format] owner:nil];
161 [pb setData:[NSData dataWithBytes:data_data length:data_len]
162 forType:format];
163 }
164
165 // Write an extra flavor that signifies WebKit was the last to modify the 156 // Write an extra flavor that signifies WebKit was the last to modify the
166 // pasteboard. This flavor has no data. 157 // pasteboard. This flavor has no data.
167 void Clipboard::WriteWebSmartPaste() { 158 void Clipboard::WriteWebSmartPaste() {
168 NSPasteboard* pb = GetPasteboard(); 159 NSPasteboard* pb = GetPasteboard();
169 NSString* format = base::SysUTF8ToNSString(GetWebKitSmartPasteFormatType()); 160 NSString* format = base::SysUTF8ToNSString(GetWebKitSmartPasteFormatType());
170 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; 161 [pb addTypes:[NSArray arrayWithObject:format] owner:nil];
171 [pb setData:nil forType:format]; 162 [pb setData:nil forType:format];
172 } 163 }
173 164
174 uint64 Clipboard::GetSequenceNumber(Buffer buffer) { 165 uint64 Clipboard::GetSequenceNumber(Buffer buffer) {
175 DCHECK_EQ(buffer, BUFFER_STANDARD); 166 DCHECK_EQ(buffer, BUFFER_STANDARD);
176 167
177 NSPasteboard* pb = GetPasteboard(); 168 NSPasteboard* pb = GetPasteboard();
178 return [pb changeCount]; 169 return [pb changeCount];
179 } 170 }
180 171
181 bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format, 172 bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format,
182 Buffer buffer) const { 173 Clipboard::Buffer buffer) const {
183 DCHECK_EQ(buffer, BUFFER_STANDARD); 174 DCHECK_EQ(buffer, BUFFER_STANDARD);
184 NSString* format_ns = base::SysUTF8ToNSString(format); 175 NSString* format_ns = base::SysUTF8ToNSString(format);
185 176
186 NSPasteboard* pb = GetPasteboard(); 177 NSPasteboard* pb = GetPasteboard();
187 NSArray* types = [pb types]; 178 NSArray* types = [pb types];
188 179
189 // Safari only places RTF on the pasteboard, never HTML. We can convert RTF 180 // Safari only places RTF on the pasteboard, never HTML. We can convert RTF
190 // to HTML, so the presence of either indicates success when looking for HTML. 181 // to HTML, so the presence of either indicates success when looking for HTML.
191 if ([format_ns isEqualToString:NSHTMLPboardType]) { 182 if ([format_ns isEqualToString:NSHTMLPboardType]) {
192 return [types containsObject:NSHTMLPboardType] || 183 return [types containsObject:NSHTMLPboardType] ||
193 [types containsObject:NSRTFPboardType]; 184 [types containsObject:NSRTFPboardType];
194 } 185 }
195 return [types containsObject:format_ns]; 186 return [types containsObject:format_ns];
196 } 187 }
197 188
198 bool Clipboard::IsFormatAvailableByString(const std::string& format,
199 Buffer buffer) const {
200 DCHECK_EQ(buffer, BUFFER_STANDARD);
201 NSString* format_ns = base::SysUTF8ToNSString(format);
202
203 NSPasteboard* pb = GetPasteboard();
204 NSArray* types = [pb types];
205
206 return [types containsObject:format_ns];
207 }
208
209 void Clipboard::ReadAvailableTypes(Clipboard::Buffer buffer, 189 void Clipboard::ReadAvailableTypes(Clipboard::Buffer buffer,
210 std::vector<string16>* types, 190 std::vector<string16>* types,
211 bool* contains_filenames) const { 191 bool* contains_filenames) const {
212 if (!types || !contains_filenames) { 192 if (!types || !contains_filenames) {
213 NOTREACHED(); 193 NOTREACHED();
214 return; 194 return;
215 } 195 }
216 196
217 types->clear(); 197 types->clear();
218 if (IsFormatAvailable(Clipboard::GetPlainTextFormatType(), buffer)) 198 if (IsFormatAvailable(Clipboard::GetPlainTextFormatType(), buffer))
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 335
356 NSPasteboard* pb = GetPasteboard(); 336 NSPasteboard* pb = GetPasteboard();
357 NSArray* fileList = [pb propertyListForType:NSFilenamesPboardType]; 337 NSArray* fileList = [pb propertyListForType:NSFilenamesPboardType];
358 338
359 for (unsigned int i = 0; i < [fileList count]; ++i) { 339 for (unsigned int i = 0; i < [fileList count]; ++i) {
360 std::string file = [[fileList objectAtIndex:i] UTF8String]; 340 std::string file = [[fileList objectAtIndex:i] UTF8String];
361 files->push_back(FilePath(file)); 341 files->push_back(FilePath(file));
362 } 342 }
363 } 343 }
364 344
365 void Clipboard::ReadData(const std::string& format, std::string* result) const {
366 NSPasteboard* pb = GetPasteboard();
367 NSData* data = [pb dataForType:base::SysUTF8ToNSString(format)];
368 if ([data length])
369 result->assign(reinterpret_cast<const char*>([data bytes]), [data length]);
370 }
371
372 // static 345 // static
373 Clipboard::FormatType Clipboard::GetUrlFormatType() { 346 Clipboard::FormatType Clipboard::GetUrlFormatType() {
374 return base::SysNSStringToUTF8(NSURLPboardType); 347 return base::SysNSStringToUTF8(NSURLPboardType);
375 } 348 }
376 349
377 // static 350 // static
378 Clipboard::FormatType Clipboard::GetUrlWFormatType() { 351 Clipboard::FormatType Clipboard::GetUrlWFormatType() {
379 return base::SysNSStringToUTF8(NSURLPboardType); 352 return base::SysNSStringToUTF8(NSURLPboardType);
380 } 353 }
381 354
(...skipping 26 matching lines...) Expand all
408 Clipboard::FormatType Clipboard::GetBitmapFormatType() { 381 Clipboard::FormatType Clipboard::GetBitmapFormatType() {
409 return base::SysNSStringToUTF8(NSTIFFPboardType); 382 return base::SysNSStringToUTF8(NSTIFFPboardType);
410 } 383 }
411 384
412 // static 385 // static
413 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { 386 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() {
414 return base::SysNSStringToUTF8(kWebSmartPastePboardType); 387 return base::SysNSStringToUTF8(kWebSmartPastePboardType);
415 } 388 }
416 389
417 } // namespace ui 390 } // 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