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