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 |
19 namespace { | |
20 | |
21 // The MIME type for the clipboard format for OSExchangeData. | |
22 const std::string kClipboardFormatString = "chromium/x-os-exchange-data"; | |
tapted
2016/05/31 11:49:57
I don't really understand this bit -- what's the u
spqchan
2016/05/31 23:06:12
Ah, good point. I switched to kWebCustomDataPboard
| |
23 | |
24 } // namespace | |
25 | |
17 namespace ui { | 26 namespace ui { |
18 | 27 |
19 OSExchangeDataProviderMac::OSExchangeDataProviderMac() | 28 OSExchangeDataProviderMac::OSExchangeDataProviderMac() |
20 : pasteboard_(new ui::UniquePasteboard) {} | 29 : pasteboard_(new ui::UniquePasteboard) {} |
21 | 30 |
22 OSExchangeDataProviderMac::OSExchangeDataProviderMac( | 31 OSExchangeDataProviderMac::OSExchangeDataProviderMac( |
23 scoped_refptr<ui::UniquePasteboard> pb) | 32 scoped_refptr<ui::UniquePasteboard> pb) |
24 : pasteboard_(pb) {} | 33 : pasteboard_(pb) {} |
25 | 34 |
26 OSExchangeDataProviderMac::~OSExchangeDataProviderMac() { | 35 OSExchangeDataProviderMac::~OSExchangeDataProviderMac() { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 | 171 |
163 bool OSExchangeDataProviderMac::HasFile() const { | 172 bool OSExchangeDataProviderMac::HasFile() const { |
164 return [[pasteboard_->get() types] containsObject:NSFilenamesPboardType]; | 173 return [[pasteboard_->get() types] containsObject:NSFilenamesPboardType]; |
165 } | 174 } |
166 | 175 |
167 bool OSExchangeDataProviderMac::HasCustomFormat( | 176 bool OSExchangeDataProviderMac::HasCustomFormat( |
168 const Clipboard::FormatType& format) const { | 177 const Clipboard::FormatType& format) const { |
169 return [[pasteboard_->get() types] containsObject:format.ToNSString()]; | 178 return [[pasteboard_->get() types] containsObject:format.ToNSString()]; |
170 } | 179 } |
171 | 180 |
181 void OSExchangeDataProviderMac::SetDragImage( | |
182 const gfx::ImageSkia& image, | |
183 const gfx::Vector2d& cursor_offset) { | |
184 drag_image_ = image; | |
185 cursor_offset_ = cursor_offset; | |
186 } | |
187 | |
188 const gfx::ImageSkia& OSExchangeDataProviderMac::GetDragImage() const { | |
189 return drag_image_; | |
190 } | |
191 | |
192 const gfx::Vector2d& OSExchangeDataProviderMac::GetDragImageOffset() const { | |
193 return cursor_offset_; | |
194 } | |
195 | |
196 NSData* OSExchangeDataProviderMac::GetNSDataForType(NSString* type) const { | |
197 return [pasteboard_->get() dataForType:type]; | |
198 } | |
199 | |
200 std::unique_ptr<OSExchangeData> | |
201 OSExchangeDataProviderMac::CreateDataFromPasteboard(NSPasteboard* pasteboard) { | |
202 OSExchangeDataProviderMac* provider = new OSExchangeDataProviderMac(); | |
203 | |
204 for (NSPasteboardItem* item in [pasteboard pasteboardItems]) | |
205 ClipboardUtil::AddDataToPasteboard(provider->pasteboard_->get(), item); | |
206 | |
207 return base::WrapUnique(new OSExchangeData(provider)); | |
208 } | |
209 | |
210 NSArray* OSExchangeDataProviderMac::SupportedPasteboardTypes() { | |
211 return @[ | |
212 base::SysUTF8ToNSString(kClipboardFormatString), | |
213 ui::ClipboardUtil::UTIForWebURLsAndTitles(), NSURLPboardType, | |
214 NSPasteboardTypeString, NSFilenamesPboardType | |
215 ]; | |
216 } | |
217 | |
172 /////////////////////////////////////////////////////////////////////////////// | 218 /////////////////////////////////////////////////////////////////////////////// |
173 // OSExchangeData, public: | 219 // OSExchangeData, public: |
174 | 220 |
175 // static | 221 // static |
176 OSExchangeData::Provider* OSExchangeData::CreateProvider() { | 222 OSExchangeData::Provider* OSExchangeData::CreateProvider() { |
177 return new OSExchangeDataProviderMac; | 223 return new OSExchangeDataProviderMac; |
178 } | 224 } |
179 | 225 |
180 } // namespace ui | 226 } // namespace ui |
OLD | NEW |