Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1225)

Side by Side Diff: content/browser/web_contents/web_drag_source_mac.mm

Issue 2509933002: Drag-and-drop: Target drag messages (the sequel). (Closed)
Patch Set: Addressed comments. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 if (dragStartRWH_) {
dcheng 2016/11/17 19:59:02 Let's centralize the null checking in WebCOntents.
paulmeyer 2016/11/17 20:46:43 Done.
275 contents_->GetRenderViewHost()); 277 contents_->SystemDragEnded(dragStartRWH_.get());
276 if (rvh) { 278
277 // Convert |screenPoint| to view coordinates and flip it. 279 // Convert |screenPoint| to view coordinates and flip it.
278 NSPoint localPoint = NSZeroPoint; 280 NSPoint localPoint = NSZeroPoint;
279 if ([contentsView_ window]) 281 if ([contentsView_ window])
280 localPoint = [self convertScreenPoint:screenPoint]; 282 localPoint = [self convertScreenPoint:screenPoint];
281 NSRect viewFrame = [contentsView_ frame]; 283 NSRect viewFrame = [contentsView_ frame];
282 localPoint.y = viewFrame.size.height - localPoint.y; 284 localPoint.y = viewFrame.size.height - localPoint.y;
283 // Flip |screenPoint|. 285 // Flip |screenPoint|.
284 NSRect screenFrame = [[[contentsView_ window] screen] frame]; 286 NSRect screenFrame = [[[contentsView_ window] screen] frame];
285 screenPoint.y = screenFrame.size.height - screenPoint.y; 287 screenPoint.y = screenFrame.size.height - screenPoint.y;
286 288
287 // If AppKit returns a copy and move operation, mask off the move bit 289 // If AppKit returns a copy and move operation, mask off the move bit
288 // because WebCore does not understand what it means to do both, which 290 // because WebCore does not understand what it means to do both, which
289 // results in an assertion failure/renderer crash. 291 // results in an assertion failure/renderer crash.
290 if (operation == (NSDragOperationMove | NSDragOperationCopy)) 292 if (operation == (NSDragOperationMove | NSDragOperationCopy))
291 operation &= ~NSDragOperationMove; 293 operation &= ~NSDragOperationMove;
292 294
293 contents_->DragSourceEndedAt(localPoint.x, localPoint.y, screenPoint.x, 295 // TODO(paulmeyer): In the OOPIF case, should |localPoint| be converted to
294 screenPoint.y, static_cast<blink::WebDragOperation>(operation)); 296 // the coordinates local to |dragStartRWH_|?
297 contents_->DragSourceEndedAt(
298 localPoint.x, localPoint.y, screenPoint.x, screenPoint.y,
299 static_cast<blink::WebDragOperation>(operation),
300 dragStartRWH_.get());
295 } 301 }
296 302
297 // Make sure the pasteboard owner isn't us. 303 // Make sure the pasteboard owner isn't us.
298 [pasteboard_ declareTypes:[NSArray array] owner:nil]; 304 [pasteboard_ declareTypes:[NSArray array] owner:nil];
299 } 305 }
300 306
301 - (NSString*)dragPromisedFileTo:(NSString*)path { 307 - (NSString*)dragPromisedFileTo:(NSString*)path {
302 // Be extra paranoid; avoid crashing. 308 // Be extra paranoid; avoid crashing.
303 if (!dropData_) { 309 if (!dropData_) {
304 NOTREACHED() << "No drag-and-drop data available for promised file."; 310 NOTREACHED() << "No drag-and-drop data available for promised file.";
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 - (NSImage*)dragImage { 470 - (NSImage*)dragImage {
465 if (dragImage_) 471 if (dragImage_)
466 return dragImage_; 472 return dragImage_;
467 473
468 // Default to returning a generic image. 474 // Default to returning a generic image.
469 return content::GetContentClient()->GetNativeImageNamed( 475 return content::GetContentClient()->GetNativeImageNamed(
470 IDR_DEFAULT_FAVICON).ToNSImage(); 476 IDR_DEFAULT_FAVICON).ToNSImage();
471 } 477 }
472 478
473 @end // @implementation WebDragSource (Private) 479 @end // @implementation WebDragSource (Private)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698