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

Side by Side Diff: chrome/browser/cocoa/web_drop_target.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_drop_target.h ('k') | chrome/browser/extensions/extension_host.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_drop_target.h" 5 #import "chrome/browser/cocoa/web_drop_target.h"
6 6
7 #include "base/sys_string_conversions.h" 7 #include "base/sys_string_conversions.h"
8 #include "chrome/browser/renderer_host/render_view_host.h" 8 #include "chrome/browser/renderer_host/render_view_host.h"
9 #include "chrome/browser/tab_contents/tab_contents.h" 9 #include "chrome/browser/tab_contents/tab_contents.h"
10 #import "third_party/mozilla/include/NSPasteboard+Utils.h" 10 #import "third_party/mozilla/include/NSPasteboard+Utils.h"
11 #include "webkit/glue/webdropdata.h" 11 #include "webkit/glue/webdropdata.h"
12 #include "webkit/glue/window_open_disposition.h" 12 #include "webkit/glue/window_open_disposition.h"
13 13
14 using WebKit::WebDragOperationsMask;
15
14 @implementation WebDropTarget 16 @implementation WebDropTarget
15 17
16 // |contents| is the TabContents representing this tab, used to communicate 18 // |contents| is the TabContents representing this tab, used to communicate
17 // drag&drop messages to WebCore and handle navigation on a successful drop 19 // drag&drop messages to WebCore and handle navigation on a successful drop
18 // (if necessary). 20 // (if necessary).
19 - (id)initWithTabContents:(TabContents*)contents { 21 - (id)initWithTabContents:(TabContents*)contents {
20 if ((self = [super init])) { 22 if ((self = [super init])) {
21 tabContents_ = contents; 23 tabContents_ = contents;
22 } 24 }
23 return self; 25 return self;
24 } 26 }
25 27
26 // Call to set whether or not we should allow the drop. Takes effect the 28 // Call to set whether or not we should allow the drop. Takes effect the
27 // next time |-draggingUpdated:| is called. 29 // next time |-draggingUpdated:| is called.
28 - (void)setIsDropTarget:(BOOL)isDropTarget { 30 - (void)setCurrentOperation: (NSDragOperation)operation {
29 isDropTarget_ = isDropTarget; 31 current_operation_ = operation;
30 } 32 }
31 33
32 // Given a point in window coordinates and a view in that window, return a 34 // Given a point in window coordinates and a view in that window, return a
33 // flipped point in the coordinate system of |view|. 35 // flipped point in the coordinate system of |view|.
34 - (NSPoint)flipWindowPointToView:(const NSPoint&)windowPoint 36 - (NSPoint)flipWindowPointToView:(const NSPoint&)windowPoint
35 view:(NSView*)view { 37 view:(NSView*)view {
36 DCHECK(view); 38 DCHECK(view);
37 NSPoint viewPoint = [view convertPoint:windowPoint fromView:nil]; 39 NSPoint viewPoint = [view convertPoint:windowPoint fromView:nil];
38 NSRect viewFrame = [view frame]; 40 NSRect viewFrame = [view frame];
39 viewPoint.y = viewFrame.size.height - viewPoint.y; 41 viewPoint.y = viewFrame.size.height - viewPoint.y;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 80
79 // Fill out a WebDropData from pasteboard. 81 // Fill out a WebDropData from pasteboard.
80 WebDropData data; 82 WebDropData data;
81 [self populateWebDropData:&data fromPasteboard:[info draggingPasteboard]]; 83 [self populateWebDropData:&data fromPasteboard:[info draggingPasteboard]];
82 84
83 // Create the appropriate mouse locations for WebCore. The draggingLocation 85 // Create the appropriate mouse locations for WebCore. The draggingLocation
84 // is in window coordinates. Both need to be flipped. 86 // is in window coordinates. Both need to be flipped.
85 NSPoint windowPoint = [info draggingLocation]; 87 NSPoint windowPoint = [info draggingLocation];
86 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; 88 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view];
87 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; 89 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view];
90 NSDragOperation mask = [info draggingSourceOperationMask];
88 tabContents_->render_view_host()->DragTargetDragEnter(data, 91 tabContents_->render_view_host()->DragTargetDragEnter(data,
89 gfx::Point(viewPoint.x, viewPoint.y), 92 gfx::Point(viewPoint.x, viewPoint.y),
90 gfx::Point(screenPoint.x, screenPoint.y)); 93 gfx::Point(screenPoint.x, screenPoint.y),
94 static_cast<WebDragOperationsMask>(mask));
91 95
92 isDropTarget_ = YES; 96 // We won't know the true operation (whether the drag is allowed) until we
93 97 // hear back from the renderer. For now, be optimistic:
94 return NSDragOperationCopy; 98 current_operation_ = NSDragOperationCopy;
99 return current_operation_;
95 } 100 }
96 101
97 - (void)draggingExited:(id<NSDraggingInfo>)info { 102 - (void)draggingExited:(id<NSDraggingInfo>)info {
98 DCHECK(currentRVH_); 103 DCHECK(currentRVH_);
99 if (currentRVH_ != tabContents_->render_view_host()) 104 if (currentRVH_ != tabContents_->render_view_host())
100 return; 105 return;
101 106
102 // Nothing to do in the interstitial case. 107 // Nothing to do in the interstitial case.
103 108
104 tabContents_->render_view_host()->DragTargetDragLeave(); 109 tabContents_->render_view_host()->DragTargetDragLeave();
105 } 110 }
106 111
107 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info 112 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info
108 view:(NSView*)view { 113 view:(NSView*)view {
109 DCHECK(currentRVH_); 114 DCHECK(currentRVH_);
110 if (currentRVH_ != tabContents_->render_view_host()) 115 if (currentRVH_ != tabContents_->render_view_host())
111 [self draggingEntered:info]; 116 [self draggingEntered:info];
112 117
113 if ([self onlyAllowsNavigation]) { 118 if ([self onlyAllowsNavigation]) {
114 if ([[info draggingPasteboard] containsURLData]) 119 if ([[info draggingPasteboard] containsURLData])
115 return NSDragOperationCopy; 120 return NSDragOperationCopy;
116 return NSDragOperationNone; 121 return NSDragOperationNone;
117 } 122 }
118 123
119 // Create the appropriate mouse locations for WebCore. The draggingLocation 124 // Create the appropriate mouse locations for WebCore. The draggingLocation
120 // is in window coordinates. 125 // is in window coordinates.
121 NSPoint windowPoint = [info draggingLocation]; 126 NSPoint windowPoint = [info draggingLocation];
122 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; 127 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view];
123 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; 128 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view];
129 NSDragOperation mask = [info draggingSourceOperationMask];
124 tabContents_->render_view_host()->DragTargetDragOver( 130 tabContents_->render_view_host()->DragTargetDragOver(
125 gfx::Point(viewPoint.x, viewPoint.y), 131 gfx::Point(viewPoint.x, viewPoint.y),
126 gfx::Point(screenPoint.x, screenPoint.y)); 132 gfx::Point(screenPoint.x, screenPoint.y),
133 static_cast<WebDragOperationsMask>(mask));
127 134
128 if (!isDropTarget_) 135 return current_operation_;
129 return NSDragOperationNone;
130 return NSDragOperationCopy;
131 } 136 }
132 137
133 - (BOOL)performDragOperation:(id<NSDraggingInfo>)info 138 - (BOOL)performDragOperation:(id<NSDraggingInfo>)info
134 view:(NSView*)view { 139 view:(NSView*)view {
135 if (currentRVH_ != tabContents_->render_view_host()) 140 if (currentRVH_ != tabContents_->render_view_host())
136 [self draggingEntered:info]; 141 [self draggingEntered:info];
137 142
138 // Check if we only allow navigation and navigate to a url on the pasteboard. 143 // Check if we only allow navigation and navigate to a url on the pasteboard.
139 if ([self onlyAllowsNavigation]) { 144 if ([self onlyAllowsNavigation]) {
140 NSPasteboard* pboard = [info draggingPasteboard]; 145 NSPasteboard* pboard = [info draggingPasteboard];
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 // Get HTML. 205 // Get HTML.
201 if ([types containsObject:NSHTMLPboardType]) { 206 if ([types containsObject:NSHTMLPboardType]) {
202 data->text_html = 207 data->text_html =
203 base::SysNSStringToUTF16([pboard stringForType:NSHTMLPboardType]); 208 base::SysNSStringToUTF16([pboard stringForType:NSHTMLPboardType]);
204 } 209 }
205 210
206 // TODO(pinkerton): Get files and file contents. 211 // TODO(pinkerton): Get files and file contents.
207 } 212 }
208 213
209 @end 214 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/web_drop_target.h ('k') | chrome/browser/extensions/extension_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698