| 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 #import "content/browser/web_contents/web_drag_source_mac.h" | 5 #import "content/browser/web_contents/web_drag_source_mac.h" |
| 6 | 6 |
| 7 #include <sys/param.h> | 7 #include <sys/param.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/files/file.h" | 12 #include "base/files/file.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/mac/foundation_util.h" | 14 #include "base/mac/foundation_util.h" |
| 15 #include "base/pickle.h" | 15 #include "base/pickle.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/sys_string_conversions.h" | 17 #include "base/strings/sys_string_conversions.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
| 20 #include "base/threading/thread_restrictions.h" | 20 #include "base/threading/thread_restrictions.h" |
| 21 #include "content/browser/browser_thread_impl.h" | 21 #include "content/browser/browser_thread_impl.h" |
| 22 #include "content/browser/download/drag_download_file.h" | 22 #include "content/browser/download/drag_download_file.h" |
| 23 #include "content/browser/download/drag_download_util.h" | 23 #include "content/browser/download/drag_download_util.h" |
| 24 #include "content/browser/renderer_host/render_view_host_impl.h" | 24 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 25 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 25 #include "content/browser/web_contents/web_contents_impl.h" | 26 #include "content/browser/web_contents/web_contents_impl.h" |
| 26 #include "content/public/browser/content_browser_client.h" | 27 #include "content/public/browser/content_browser_client.h" |
| 27 #include "content/public/common/content_client.h" | 28 #include "content/public/common/content_client.h" |
| 28 #include "content/public/common/drop_data.h" | 29 #include "content/public/common/drop_data.h" |
| 29 #include "net/base/escape.h" | 30 #include "net/base/escape.h" |
| 30 #include "net/base/filename_util.h" | 31 #include "net/base/filename_util.h" |
| 31 #include "net/base/mime_util.h" | 32 #include "net/base/mime_util.h" |
| 32 #include "ui/base/clipboard/custom_data_helper.h" | 33 #include "ui/base/clipboard/custom_data_helper.h" |
| 33 #include "ui/base/cocoa/cocoa_base_utils.h" | 34 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 34 #include "ui/base/dragdrop/cocoa_dnd_util.h" | 35 #include "ui/base/dragdrop/cocoa_dnd_util.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 - (NSImage*)dragImage; | 103 - (NSImage*)dragImage; |
| 103 | 104 |
| 104 @end // @interface WebDragSource(Private) | 105 @end // @interface WebDragSource(Private) |
| 105 | 106 |
| 106 | 107 |
| 107 @implementation WebDragSource | 108 @implementation WebDragSource |
| 108 | 109 |
| 109 - (id)initWithContents:(content::WebContentsImpl*)contents | 110 - (id)initWithContents:(content::WebContentsImpl*)contents |
| 110 view:(NSView*)contentsView | 111 view:(NSView*)contentsView |
| 111 dropData:(const DropData*)dropData | 112 dropData:(const DropData*)dropData |
| 113 sourceRWH:(content::RenderWidgetHostImpl*)sourceRWH |
| 112 image:(NSImage*)image | 114 image:(NSImage*)image |
| 113 offset:(NSPoint)offset | 115 offset:(NSPoint)offset |
| 114 pasteboard:(NSPasteboard*)pboard | 116 pasteboard:(NSPasteboard*)pboard |
| 115 dragOperationMask:(NSDragOperation)dragOperationMask { | 117 dragOperationMask:(NSDragOperation)dragOperationMask { |
| 116 if ((self = [super init])) { | 118 if ((self = [super init])) { |
| 117 contents_ = contents; | 119 contents_ = contents; |
| 118 DCHECK(contents_); | 120 DCHECK(contents_); |
| 119 | 121 |
| 120 contentsView_ = contentsView; | 122 contentsView_ = contentsView; |
| 121 DCHECK(contentsView_); | 123 DCHECK(contentsView_); |
| 122 | 124 |
| 123 dropData_.reset(new DropData(*dropData)); | 125 dropData_.reset(new DropData(*dropData)); |
| 124 DCHECK(dropData_.get()); | 126 DCHECK(dropData_.get()); |
| 125 | 127 |
| 128 dragStartRWH_ = sourceRWH->GetWeakPtr(); |
| 126 dragImage_.reset([image retain]); | 129 dragImage_.reset([image retain]); |
| 127 imageOffset_ = offset; | 130 imageOffset_ = offset; |
| 128 | 131 |
| 129 pasteboard_.reset([pboard retain]); | 132 pasteboard_.reset([pboard retain]); |
| 130 DCHECK(pasteboard_.get()); | 133 DCHECK(pasteboard_.get()); |
| 131 | 134 |
| 132 dragOperationMask_ = dragOperationMask; | 135 dragOperationMask_ = dragOperationMask; |
| 133 | 136 |
| 134 [self fillPasteboard]; | 137 [self fillPasteboard]; |
| 135 } | 138 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 event:dragEvent | 265 event:dragEvent |
| 263 pasteboard:pasteboard_ | 266 pasteboard:pasteboard_ |
| 264 source:contentsView_ | 267 source:contentsView_ |
| 265 slideBack:YES]; | 268 slideBack:YES]; |
| 266 } | 269 } |
| 267 | 270 |
| 268 - (void)endDragAt:(NSPoint)screenPoint | 271 - (void)endDragAt:(NSPoint)screenPoint |
| 269 operation:(NSDragOperation)operation { | 272 operation:(NSDragOperation)operation { |
| 270 if (!contents_ || !contentsView_) | 273 if (!contents_ || !contentsView_) |
| 271 return; | 274 return; |
| 272 contents_->SystemDragEnded(); | |
| 273 | 275 |
| 274 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 276 contents_->SystemDragEnded(dragStartRWH_.get()); |
| 275 contents_->GetRenderViewHost()); | |
| 276 if (rvh) { | |
| 277 // Convert |screenPoint| to view coordinates and flip it. | |
| 278 NSPoint localPoint = NSZeroPoint; | |
| 279 if ([contentsView_ window]) | |
| 280 localPoint = [self convertScreenPoint:screenPoint]; | |
| 281 NSRect viewFrame = [contentsView_ frame]; | |
| 282 localPoint.y = viewFrame.size.height - localPoint.y; | |
| 283 // Flip |screenPoint|. | |
| 284 NSRect screenFrame = [[[contentsView_ window] screen] frame]; | |
| 285 screenPoint.y = screenFrame.size.height - screenPoint.y; | |
| 286 | 277 |
| 287 // If AppKit returns a copy and move operation, mask off the move bit | 278 // Convert |screenPoint| to view coordinates and flip it. |
| 288 // because WebCore does not understand what it means to do both, which | 279 NSPoint localPoint = NSZeroPoint; |
| 289 // results in an assertion failure/renderer crash. | 280 if ([contentsView_ window]) |
| 290 if (operation == (NSDragOperationMove | NSDragOperationCopy)) | 281 localPoint = [self convertScreenPoint:screenPoint]; |
| 291 operation &= ~NSDragOperationMove; | 282 NSRect viewFrame = [contentsView_ frame]; |
| 283 localPoint.y = viewFrame.size.height - localPoint.y; |
| 284 // Flip |screenPoint|. |
| 285 NSRect screenFrame = [[[contentsView_ window] screen] frame]; |
| 286 screenPoint.y = screenFrame.size.height - screenPoint.y; |
| 292 | 287 |
| 293 contents_->DragSourceEndedAt(localPoint.x, localPoint.y, screenPoint.x, | 288 // If AppKit returns a copy and move operation, mask off the move bit |
| 294 screenPoint.y, static_cast<blink::WebDragOperation>(operation)); | 289 // because WebCore does not understand what it means to do both, which |
| 295 } | 290 // results in an assertion failure/renderer crash. |
| 291 if (operation == (NSDragOperationMove | NSDragOperationCopy)) |
| 292 operation &= ~NSDragOperationMove; |
| 293 |
| 294 // TODO(paulmeyer): In the OOPIF case, should |localPoint| be converted to |
| 295 // the coordinates local to |dragStartRWH_|? |
| 296 contents_->DragSourceEndedAt( |
| 297 localPoint.x, localPoint.y, screenPoint.x, screenPoint.y, |
| 298 static_cast<blink::WebDragOperation>(operation), |
| 299 dragStartRWH_.get()); |
| 296 | 300 |
| 297 // Make sure the pasteboard owner isn't us. | 301 // Make sure the pasteboard owner isn't us. |
| 298 [pasteboard_ declareTypes:[NSArray array] owner:nil]; | 302 [pasteboard_ declareTypes:[NSArray array] owner:nil]; |
| 299 } | 303 } |
| 300 | 304 |
| 301 - (NSString*)dragPromisedFileTo:(NSString*)path { | 305 - (NSString*)dragPromisedFileTo:(NSString*)path { |
| 302 // Be extra paranoid; avoid crashing. | 306 // Be extra paranoid; avoid crashing. |
| 303 if (!dropData_) { | 307 if (!dropData_) { |
| 304 NOTREACHED() << "No drag-and-drop data available for promised file."; | 308 NOTREACHED() << "No drag-and-drop data available for promised file."; |
| 305 return nil; | 309 return nil; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 - (NSImage*)dragImage { | 468 - (NSImage*)dragImage { |
| 465 if (dragImage_) | 469 if (dragImage_) |
| 466 return dragImage_; | 470 return dragImage_; |
| 467 | 471 |
| 468 // Default to returning a generic image. | 472 // Default to returning a generic image. |
| 469 return content::GetContentClient()->GetNativeImageNamed( | 473 return content::GetContentClient()->GetNativeImageNamed( |
| 470 IDR_DEFAULT_FAVICON).ToNSImage(); | 474 IDR_DEFAULT_FAVICON).ToNSImage(); |
| 471 } | 475 } |
| 472 | 476 |
| 473 @end // @implementation WebDragSource (Private) | 477 @end // @implementation WebDragSource (Private) |
| OLD | NEW |