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" |
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/mac/scoped_nsobject.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/strings/sys_string_conversions.h" | 16 #include "base/strings/sys_string_conversions.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/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 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, | 178 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, |
179 data_provider, | 179 data_provider, |
180 NULL, | 180 NULL, |
181 false, | 181 false, |
182 kCGRenderingIntentDefault)); | 182 kCGRenderingIntentDefault)); |
183 // Aggressively free storage since image buffers can potentially be very | 183 // Aggressively free storage since image buffers can potentially be very |
184 // large. | 184 // large. |
185 data_provider.reset(); | 185 data_provider.reset(); |
186 data.reset(); | 186 data.reset(); |
187 | 187 |
188 scoped_nsobject<NSBitmapImageRep> bitmap( | 188 base::scoped_nsobject<NSBitmapImageRep> bitmap( |
189 [[NSBitmapImageRep alloc] initWithCGImage:cgimage]); | 189 [[NSBitmapImageRep alloc] initWithCGImage:cgimage]); |
190 cgimage.reset(); | 190 cgimage.reset(); |
191 | 191 |
192 scoped_nsobject<NSImage> image([[NSImage alloc] init]); | 192 base::scoped_nsobject<NSImage> image([[NSImage alloc] init]); |
193 [image addRepresentation:bitmap]; | 193 [image addRepresentation:bitmap]; |
194 | 194 |
195 // An API to ask the NSImage to write itself to the clipboard comes in 10.6 :( | 195 // An API to ask the NSImage to write itself to the clipboard comes in 10.6 :( |
196 // For now, spit out the image as a TIFF. | 196 // For now, spit out the image as a TIFF. |
197 NSPasteboard* pb = GetPasteboard(); | 197 NSPasteboard* pb = GetPasteboard(); |
198 [pb addTypes:[NSArray arrayWithObject:NSTIFFPboardType] owner:nil]; | 198 [pb addTypes:[NSArray arrayWithObject:NSTIFFPboardType] owner:nil]; |
199 NSData *tiff_data = [image TIFFRepresentation]; | 199 NSData *tiff_data = [image TIFFRepresentation]; |
200 LOG_IF(ERROR, tiff_data == NULL) << "Failed to allocate image for clipboard"; | 200 LOG_IF(ERROR, tiff_data == NULL) << "Failed to allocate image for clipboard"; |
201 if (tiff_data) { | 201 if (tiff_data) { |
202 [pb setData:tiff_data forType:NSTIFFPboardType]; | 202 [pb setData:tiff_data forType:NSTIFFPboardType]; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 DCHECK(CalledOnValidThread()); | 336 DCHECK(CalledOnValidThread()); |
337 DCHECK_EQ(buffer, BUFFER_STANDARD); | 337 DCHECK_EQ(buffer, BUFFER_STANDARD); |
338 | 338 |
339 return ReadData(GetRtfFormatType(), result); | 339 return ReadData(GetRtfFormatType(), result); |
340 } | 340 } |
341 | 341 |
342 SkBitmap Clipboard::ReadImage(Buffer buffer) const { | 342 SkBitmap Clipboard::ReadImage(Buffer buffer) const { |
343 DCHECK(CalledOnValidThread()); | 343 DCHECK(CalledOnValidThread()); |
344 DCHECK_EQ(buffer, BUFFER_STANDARD); | 344 DCHECK_EQ(buffer, BUFFER_STANDARD); |
345 | 345 |
346 scoped_nsobject<NSImage> image( | 346 base::scoped_nsobject<NSImage> image( |
347 [[NSImage alloc] initWithPasteboard:GetPasteboard()]); | 347 [[NSImage alloc] initWithPasteboard:GetPasteboard()]); |
348 if (!image.get()) | 348 if (!image.get()) |
349 return SkBitmap(); | 349 return SkBitmap(); |
350 | 350 |
351 gfx::ScopedNSGraphicsContextSaveGState scoped_state; | 351 gfx::ScopedNSGraphicsContextSaveGState scoped_state; |
352 [image setFlipped:YES]; | 352 [image setFlipped:YES]; |
353 int width = [image size].width; | 353 int width = [image size].width; |
354 int height = [image size].height; | 354 int height = [image size].height; |
355 | 355 |
356 gfx::Canvas canvas(gfx::Size(width, height), ui::SCALE_FACTOR_100P, false); | 356 gfx::Canvas canvas(gfx::Size(width, height), ui::SCALE_FACTOR_100P, false); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 return type; | 479 return type; |
480 } | 480 } |
481 | 481 |
482 // static | 482 // static |
483 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { | 483 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { |
484 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kPepperCustomDataPboardType)); | 484 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kPepperCustomDataPboardType)); |
485 return type; | 485 return type; |
486 } | 486 } |
487 | 487 |
488 } // namespace ui | 488 } // namespace ui |
OLD | NEW |