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

Side by Side Diff: chrome/browser/cocoa/web_drag_source.mm

Issue 174364: Plumb the DragOperation through all the layers between the platform DnD code ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/cocoa/web_drag_source.h ('k') | chrome/browser/cocoa/web_drop_target.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome/browser/cocoa/web_drag_source.h" 5 #import "chrome/browser/cocoa/web_drag_source.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/sys_string_conversions.h" 9 #include "base/sys_string_conversions.h"
10 #include "base/task.h" 10 #include "base/task.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 - (void)fillPasteboard; 115 - (void)fillPasteboard;
116 - (NSImage*)dragImage; 116 - (NSImage*)dragImage;
117 117
118 @end // @interface WebDragSource(Private) 118 @end // @interface WebDragSource(Private)
119 119
120 120
121 @implementation WebDragSource 121 @implementation WebDragSource
122 122
123 - (id)initWithContentsView:(TabContentsViewCocoa*)contentsView 123 - (id)initWithContentsView:(TabContentsViewCocoa*)contentsView
124 dropData:(const WebDropData*)dropData 124 dropData:(const WebDropData*)dropData
125 pasteboard:(NSPasteboard*)pboard { 125 pasteboard:(NSPasteboard*)pboard
126 dragOperationMask:(NSDragOperation)dragOperationMask {
126 if ((self = [super init])) { 127 if ((self = [super init])) {
127 contentsView_ = contentsView; 128 contentsView_ = contentsView;
128 DCHECK(contentsView_); 129 DCHECK(contentsView_);
129 130
130 dropData_.reset(new WebDropData(*dropData)); 131 dropData_.reset(new WebDropData(*dropData));
131 DCHECK(dropData_.get()); 132 DCHECK(dropData_.get());
132 133
133 pasteboard_.reset([pboard retain]); 134 pasteboard_.reset([pboard retain]);
134 DCHECK(pasteboard_.get()); 135 DCHECK(pasteboard_.get());
135 136
137 dragOperationMask_ = dragOperationMask;
138
136 [self fillPasteboard]; 139 [self fillPasteboard];
137 } 140 }
138 141
139 return self; 142 return self;
140 } 143 }
141 144
145 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal {
146 return dragOperationMask_;
147 }
148
142 - (void)lazyWriteToPasteboard:(NSPasteboard*)pboard forType:(NSString*)type { 149 - (void)lazyWriteToPasteboard:(NSPasteboard*)pboard forType:(NSString*)type {
143 // Be extra paranoid; avoid crashing. 150 // Be extra paranoid; avoid crashing.
144 if (!dropData_.get()) { 151 if (!dropData_.get()) {
145 NOTREACHED() << "No drag-and-drop data available for lazy write."; 152 NOTREACHED() << "No drag-and-drop data available for lazy write.";
146 return; 153 return;
147 } 154 }
148 155
149 // HTML. 156 // HTML.
150 if ([type isEqualToString:NSHTMLPboardType]) { 157 if ([type isEqualToString:NSHTMLPboardType]) {
151 DCHECK(!dropData_->text_html.empty()); 158 DCHECK(!dropData_->text_html.empty());
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 [contentsView_ dragImage:[self dragImage] 226 [contentsView_ dragImage:[self dragImage]
220 at:position 227 at:position
221 offset:NSZeroSize 228 offset:NSZeroSize
222 event:dragEvent 229 event:dragEvent
223 pasteboard:pasteboard_ 230 pasteboard:pasteboard_
224 source:contentsView_ 231 source:contentsView_
225 slideBack:YES]; 232 slideBack:YES];
226 } 233 }
227 234
228 - (void)endDragAt:(NSPoint)screenPoint 235 - (void)endDragAt:(NSPoint)screenPoint
229 isCancelled:(BOOL)cancelled { 236 operation:(NSDragOperation)operation {
230 RenderViewHost* rvh = [contentsView_ tabContents]->render_view_host(); 237 RenderViewHost* rvh = [contentsView_ tabContents]->render_view_host();
231 if (rvh) { 238 if (rvh) {
232 rvh->DragSourceSystemDragEnded(); 239 rvh->DragSourceSystemDragEnded();
233 240
234 // Convert |screenPoint| to view coordinates and flip it. 241 // Convert |screenPoint| to view coordinates and flip it.
235 NSPoint localPoint = [contentsView_ convertPointFromBase:screenPoint]; 242 NSPoint localPoint = [contentsView_ convertPointFromBase:screenPoint];
236 NSRect viewFrame = [contentsView_ frame]; 243 NSRect viewFrame = [contentsView_ frame];
237 localPoint.y = viewFrame.size.height - localPoint.y; 244 localPoint.y = viewFrame.size.height - localPoint.y;
238 // Flip |screenPoint|. 245 // Flip |screenPoint|.
239 NSRect screenFrame = [[[contentsView_ window] screen] frame]; 246 NSRect screenFrame = [[[contentsView_ window] screen] frame];
240 screenPoint.y = screenFrame.size.height - screenPoint.y; 247 screenPoint.y = screenFrame.size.height - screenPoint.y;
241 248
242 if (cancelled) { 249 rvh->DragSourceEndedAt(localPoint.x, localPoint.y,
243 rvh->DragSourceCancelledAt(localPoint.x, localPoint.y, 250 screenPoint.x, screenPoint.y,
244 screenPoint.x, screenPoint.y); 251 static_cast<WebKit::WebDragOperation>(operation));
245 } else {
246 rvh->DragSourceEndedAt(localPoint.x, localPoint.y,
247 screenPoint.x, screenPoint.y);
248 }
249 } 252 }
250 253
251 // Make sure the pasteboard owner isn't us. 254 // Make sure the pasteboard owner isn't us.
252 [pasteboard_ declareTypes:[NSArray array] owner:nil]; 255 [pasteboard_ declareTypes:[NSArray array] owner:nil];
253 } 256 }
254 257
255 - (void)moveDragTo:(NSPoint)screenPoint { 258 - (void)moveDragTo:(NSPoint)screenPoint {
256 RenderViewHost* rvh = [contentsView_ tabContents]->render_view_host(); 259 RenderViewHost* rvh = [contentsView_ tabContents]->render_view_host();
257 if (rvh) { 260 if (rvh) {
258 // Convert |screenPoint| to view coordinates and flip it. 261 // Convert |screenPoint| to view coordinates and flip it.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 if (!dropData_->plain_text.empty()) 354 if (!dropData_->plain_text.empty())
352 [pasteboard_ addTypes:[NSArray arrayWithObject:NSStringPboardType] 355 [pasteboard_ addTypes:[NSArray arrayWithObject:NSStringPboardType]
353 owner:contentsView_]; 356 owner:contentsView_];
354 } 357 }
355 358
356 - (NSImage*)dragImage { 359 - (NSImage*)dragImage {
357 return MakeDragImage(dropData_.get()); 360 return MakeDragImage(dropData_.get());
358 } 361 }
359 362
360 @end // @implementation WebDragSource (Private) 363 @end // @implementation WebDragSource (Private)
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/web_drag_source.h ('k') | chrome/browser/cocoa/web_drop_target.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698