| 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_mac.h" | 5 #include "ui/base/clipboard/clipboard_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 #include <stdint.h> |
| 8 | 9 |
| 9 #include "base/basictypes.h" | 10 #include <limits> |
| 11 |
| 10 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 11 #include "base/logging.h" | 13 #include "base/logging.h" |
| 12 #include "base/mac/mac_util.h" | 14 #include "base/mac/mac_util.h" |
| 13 #include "base/mac/scoped_cftyperef.h" | 15 #include "base/mac/scoped_cftyperef.h" |
| 14 #include "base/mac/scoped_nsobject.h" | 16 #include "base/mac/scoped_nsobject.h" |
| 15 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 16 #include "base/strings/sys_string_conversions.h" | 18 #include "base/strings/sys_string_conversions.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 18 #include "skia/ext/skia_utils_mac.h" | 20 #include "skia/ext/skia_utils_mac.h" |
| 19 #import "third_party/mozilla/NSPasteboard+Utils.h" | 21 #import "third_party/mozilla/NSPasteboard+Utils.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 | 178 |
| 177 // ClipboardMac implementation. | 179 // ClipboardMac implementation. |
| 178 ClipboardMac::ClipboardMac() { | 180 ClipboardMac::ClipboardMac() { |
| 179 DCHECK(CalledOnValidThread()); | 181 DCHECK(CalledOnValidThread()); |
| 180 } | 182 } |
| 181 | 183 |
| 182 ClipboardMac::~ClipboardMac() { | 184 ClipboardMac::~ClipboardMac() { |
| 183 DCHECK(CalledOnValidThread()); | 185 DCHECK(CalledOnValidThread()); |
| 184 } | 186 } |
| 185 | 187 |
| 186 uint64 ClipboardMac::GetSequenceNumber(ClipboardType type) const { | 188 uint64_t ClipboardMac::GetSequenceNumber(ClipboardType type) const { |
| 187 DCHECK(CalledOnValidThread()); | 189 DCHECK(CalledOnValidThread()); |
| 188 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); | 190 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); |
| 189 | 191 |
| 190 NSPasteboard* pb = GetPasteboard(); | 192 NSPasteboard* pb = GetPasteboard(); |
| 191 return [pb changeCount]; | 193 return [pb changeCount]; |
| 192 } | 194 } |
| 193 | 195 |
| 194 bool ClipboardMac::IsFormatAvailable(const FormatType& format, | 196 bool ClipboardMac::IsFormatAvailable(const FormatType& format, |
| 195 ClipboardType type) const { | 197 ClipboardType type) const { |
| 196 DCHECK(CalledOnValidThread()); | 198 DCHECK(CalledOnValidThread()); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 259 |
| 258 if (!contents) | 260 if (!contents) |
| 259 result->clear(); | 261 result->clear(); |
| 260 else | 262 else |
| 261 result->assign([contents UTF8String]); | 263 result->assign([contents UTF8String]); |
| 262 } | 264 } |
| 263 | 265 |
| 264 void ClipboardMac::ReadHTML(ClipboardType type, | 266 void ClipboardMac::ReadHTML(ClipboardType type, |
| 265 base::string16* markup, | 267 base::string16* markup, |
| 266 std::string* src_url, | 268 std::string* src_url, |
| 267 uint32* fragment_start, | 269 uint32_t* fragment_start, |
| 268 uint32* fragment_end) const { | 270 uint32_t* fragment_end) const { |
| 269 DCHECK(CalledOnValidThread()); | 271 DCHECK(CalledOnValidThread()); |
| 270 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); | 272 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); |
| 271 | 273 |
| 272 // TODO(avi): src_url? | 274 // TODO(avi): src_url? |
| 273 markup->clear(); | 275 markup->clear(); |
| 274 if (src_url) | 276 if (src_url) |
| 275 src_url->clear(); | 277 src_url->clear(); |
| 276 | 278 |
| 277 NSPasteboard* pb = GetPasteboard(); | 279 NSPasteboard* pb = GetPasteboard(); |
| 278 NSArray* supportedTypes = [NSArray arrayWithObjects:NSHTMLPboardType, | 280 NSArray* supportedTypes = [NSArray arrayWithObjects:NSHTMLPboardType, |
| 279 NSRTFPboardType, | 281 NSRTFPboardType, |
| 280 NSStringPboardType, | 282 NSStringPboardType, |
| 281 nil]; | 283 nil]; |
| 282 NSString* bestType = [pb availableTypeFromArray:supportedTypes]; | 284 NSString* bestType = [pb availableTypeFromArray:supportedTypes]; |
| 283 if (bestType) { | 285 if (bestType) { |
| 284 NSString* contents = [pb stringForType:bestType]; | 286 NSString* contents = [pb stringForType:bestType]; |
| 285 if ([bestType isEqualToString:NSRTFPboardType]) | 287 if ([bestType isEqualToString:NSRTFPboardType]) |
| 286 contents = [pb htmlFromRtf]; | 288 contents = [pb htmlFromRtf]; |
| 287 *markup = base::SysNSStringToUTF16(contents); | 289 *markup = base::SysNSStringToUTF16(contents); |
| 288 } | 290 } |
| 289 | 291 |
| 290 *fragment_start = 0; | 292 *fragment_start = 0; |
| 291 DCHECK(markup->length() <= kuint32max); | 293 DCHECK(markup->length() <= std::numeric_limits<uint32_t>::max()); |
| 292 *fragment_end = static_cast<uint32>(markup->length()); | 294 *fragment_end = static_cast<uint32_t>(markup->length()); |
| 293 } | 295 } |
| 294 | 296 |
| 295 void ClipboardMac::ReadRTF(ClipboardType type, std::string* result) const { | 297 void ClipboardMac::ReadRTF(ClipboardType type, std::string* result) const { |
| 296 DCHECK(CalledOnValidThread()); | 298 DCHECK(CalledOnValidThread()); |
| 297 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); | 299 DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); |
| 298 | 300 |
| 299 return ReadData(GetRtfFormatType(), result); | 301 return ReadData(GetRtfFormatType(), result); |
| 300 } | 302 } |
| 301 | 303 |
| 302 SkBitmap ClipboardMac::ReadImage(ClipboardType type) const { | 304 SkBitmap ClipboardMac::ReadImage(ClipboardType type) const { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 // Write an extra flavor that signifies WebKit was the last to modify the | 465 // Write an extra flavor that signifies WebKit was the last to modify the |
| 464 // pasteboard. This flavor has no data. | 466 // pasteboard. This flavor has no data. |
| 465 void ClipboardMac::WriteWebSmartPaste() { | 467 void ClipboardMac::WriteWebSmartPaste() { |
| 466 NSPasteboard* pb = GetPasteboard(); | 468 NSPasteboard* pb = GetPasteboard(); |
| 467 NSString* format = GetWebKitSmartPasteFormatType().ToNSString(); | 469 NSString* format = GetWebKitSmartPasteFormatType().ToNSString(); |
| 468 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; | 470 [pb addTypes:[NSArray arrayWithObject:format] owner:nil]; |
| 469 [pb setData:nil forType:format]; | 471 [pb setData:nil forType:format]; |
| 470 } | 472 } |
| 471 | 473 |
| 472 } // namespace ui | 474 } // namespace ui |
| OLD | NEW |