| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/dragdrop/os_exchange_data_provider_mac.h" | 5 #include "ui/base/dragdrop/os_exchange_data_provider_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" |
| 10 #include "base/pickle.h" | 11 #include "base/pickle.h" |
| 11 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 #import "third_party/mozilla/NSPasteboard+Utils.h" | 14 #import "third_party/mozilla/NSPasteboard+Utils.h" |
| 14 #import "ui/base/clipboard/clipboard_util_mac.h" | 15 #import "ui/base/clipboard/clipboard_util_mac.h" |
| 16 #import "ui/base/dragdrop/cocoa_dnd_util.h" |
| 15 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 16 | 18 |
| 17 namespace ui { | 19 namespace ui { |
| 18 | 20 |
| 19 OSExchangeDataProviderMac::OSExchangeDataProviderMac() | 21 OSExchangeDataProviderMac::OSExchangeDataProviderMac() |
| 20 : pasteboard_(new ui::UniquePasteboard) {} | 22 : pasteboard_(new ui::UniquePasteboard) {} |
| 21 | 23 |
| 22 OSExchangeDataProviderMac::OSExchangeDataProviderMac( | 24 OSExchangeDataProviderMac::OSExchangeDataProviderMac( |
| 23 scoped_refptr<ui::UniquePasteboard> pb) | 25 scoped_refptr<ui::UniquePasteboard> pb) |
| 24 : pasteboard_(pb) {} | 26 : pasteboard_(pb) {} |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 164 |
| 163 bool OSExchangeDataProviderMac::HasFile() const { | 165 bool OSExchangeDataProviderMac::HasFile() const { |
| 164 return [[pasteboard_->get() types] containsObject:NSFilenamesPboardType]; | 166 return [[pasteboard_->get() types] containsObject:NSFilenamesPboardType]; |
| 165 } | 167 } |
| 166 | 168 |
| 167 bool OSExchangeDataProviderMac::HasCustomFormat( | 169 bool OSExchangeDataProviderMac::HasCustomFormat( |
| 168 const Clipboard::FormatType& format) const { | 170 const Clipboard::FormatType& format) const { |
| 169 return [[pasteboard_->get() types] containsObject:format.ToNSString()]; | 171 return [[pasteboard_->get() types] containsObject:format.ToNSString()]; |
| 170 } | 172 } |
| 171 | 173 |
| 174 void OSExchangeDataProviderMac::SetDragImage( |
| 175 const gfx::ImageSkia& image, |
| 176 const gfx::Vector2d& cursor_offset) { |
| 177 drag_image_ = image; |
| 178 cursor_offset_ = cursor_offset; |
| 179 } |
| 180 |
| 181 const gfx::ImageSkia& OSExchangeDataProviderMac::GetDragImage() const { |
| 182 return drag_image_; |
| 183 } |
| 184 |
| 185 const gfx::Vector2d& OSExchangeDataProviderMac::GetDragImageOffset() const { |
| 186 return cursor_offset_; |
| 187 } |
| 188 |
| 189 NSData* OSExchangeDataProviderMac::GetNSDataForType(NSString* type) const { |
| 190 return [pasteboard_->get() dataForType:type]; |
| 191 } |
| 192 |
| 193 NSArray* OSExchangeDataProviderMac::GetPasteboardTypes() const { |
| 194 return [pasteboard_->get() types]; |
| 195 } |
| 196 |
| 197 std::unique_ptr<OSExchangeData> |
| 198 OSExchangeDataProviderMac::CreateDataFromPasteboard(NSPasteboard* pasteboard) { |
| 199 OSExchangeDataProviderMac* provider = new OSExchangeDataProviderMac(); |
| 200 |
| 201 for (NSPasteboardItem* item in [pasteboard pasteboardItems]) |
| 202 ClipboardUtil::AddDataToPasteboard(provider->pasteboard_->get(), item); |
| 203 |
| 204 return base::WrapUnique(new OSExchangeData(provider)); |
| 205 } |
| 206 |
| 207 NSArray* OSExchangeDataProviderMac::SupportedPasteboardTypes() { |
| 208 return @[ |
| 209 ui::ClipboardUtil::UTIForWebURLsAndTitles(), NSURLPboardType, |
| 210 NSPasteboardTypeString, NSFilenamesPboardType |
| 211 ]; |
| 212 } |
| 213 |
| 172 /////////////////////////////////////////////////////////////////////////////// | 214 /////////////////////////////////////////////////////////////////////////////// |
| 173 // OSExchangeData, public: | 215 // OSExchangeData, public: |
| 174 | 216 |
| 175 // static | 217 // static |
| 176 OSExchangeData::Provider* OSExchangeData::CreateProvider() { | 218 OSExchangeData::Provider* OSExchangeData::CreateProvider() { |
| 177 return new OSExchangeDataProviderMac; | 219 return new OSExchangeDataProviderMac; |
| 178 } | 220 } |
| 179 | 221 |
| 180 } // namespace ui | 222 } // namespace ui |
| OLD | NEW |