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

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

Issue 2485693003: Drag-and-drop: DragEnter, DragOver, DragLeave, DragDrop (Closed)
Patch Set: Rebased. More fixes. 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_dest_mac.h" 5 #import "content/browser/web_contents/web_drag_dest_mac.h"
6 6
7 #import <Carbon/Carbon.h> 7 #import <Carbon/Carbon.h>
8 8
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "content/browser/renderer_host/render_view_host_impl.h" 10 #include "content/browser/renderer_host/render_view_host_impl.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 view:(NSView*)view { 123 view:(NSView*)view {
124 // Save off the RVH so we can tell if it changes during a drag. If it does, 124 // Save off the RVH so we can tell if it changes during a drag. If it does,
125 // we need to send a new enter message in draggingUpdated:. 125 // we need to send a new enter message in draggingUpdated:.
126 currentRVH_ = webContents_->GetRenderViewHost(); 126 currentRVH_ = webContents_->GetRenderViewHost();
127 127
128 // Fill out a DropData from pasteboard. 128 // Fill out a DropData from pasteboard.
129 std::unique_ptr<DropData> dropData; 129 std::unique_ptr<DropData> dropData;
130 dropData.reset(new DropData()); 130 dropData.reset(new DropData());
131 [self populateDropData:dropData.get() 131 [self populateDropData:dropData.get()
132 fromPasteboard:[info draggingPasteboard]]; 132 fromPasteboard:[info draggingPasteboard]];
133 currentRVH_->FilterDropData(dropData.get()); 133 // TODO(paulmeyer): This will need to target the correct specific
134 // RenderWidgetHost to work with OOPIFs. See crbug.com/647249.
135 currentRVH_->GetWidget()->FilterDropData(dropData.get());
134 136
135 NSDragOperation mask = [info draggingSourceOperationMask]; 137 NSDragOperation mask = [info draggingSourceOperationMask];
136 138
137 // Give the delegate an opportunity to cancel the drag. 139 // Give the delegate an opportunity to cancel the drag.
138 canceled_ = !webContents_->GetDelegate()->CanDragEnter( 140 canceled_ = !webContents_->GetDelegate()->CanDragEnter(
139 webContents_, 141 webContents_,
140 *dropData, 142 *dropData,
141 static_cast<WebDragOperationsMask>(mask)); 143 static_cast<WebDragOperationsMask>(mask));
142 if (canceled_) 144 if (canceled_)
143 return NSDragOperationNone; 145 return NSDragOperationNone;
144 146
145 if ([self onlyAllowsNavigation]) { 147 if ([self onlyAllowsNavigation]) {
146 if ([[info draggingPasteboard] containsURLDataConvertingTextToURL:YES]) 148 if ([[info draggingPasteboard] containsURLDataConvertingTextToURL:YES])
147 return NSDragOperationCopy; 149 return NSDragOperationCopy;
148 return NSDragOperationNone; 150 return NSDragOperationNone;
149 } 151 }
150 152
151 if (delegate_) { 153 if (delegate_) {
152 delegate_->DragInitialize(webContents_); 154 delegate_->DragInitialize(webContents_);
153 delegate_->OnDragEnter(); 155 delegate_->OnDragEnter();
154 } 156 }
155 157
156 dropData_.swap(dropData); 158 dropData_.swap(dropData);
157 159
158 // Create the appropriate mouse locations for WebCore. The draggingLocation 160 // Create the appropriate mouse locations for WebCore. The draggingLocation
159 // is in window coordinates. Both need to be flipped. 161 // is in window coordinates. Both need to be flipped.
160 NSPoint windowPoint = [info draggingLocation]; 162 NSPoint windowPoint = [info draggingLocation];
161 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; 163 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view];
162 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; 164 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view];
163 webContents_->GetRenderViewHost()->DragTargetDragEnter( 165 // TODO(paulmeyer): This will need to target the correct specific
166 // RenderWidgetHost to work with OOPIFs. See crbug.com/647249.
167 webContents_->GetRenderViewHost()->GetWidget()->DragTargetDragEnter(
164 *dropData_, 168 *dropData_,
165 gfx::Point(viewPoint.x, viewPoint.y), 169 gfx::Point(viewPoint.x, viewPoint.y),
166 gfx::Point(screenPoint.x, screenPoint.y), 170 gfx::Point(screenPoint.x, screenPoint.y),
167 static_cast<WebDragOperationsMask>(mask), 171 static_cast<WebDragOperationsMask>(mask),
168 GetModifierFlags()); 172 GetModifierFlags());
169 173
170 // We won't know the true operation (whether the drag is allowed) until we 174 // We won't know the true operation (whether the drag is allowed) until we
171 // hear back from the renderer. For now, be optimistic: 175 // hear back from the renderer. For now, be optimistic:
172 currentOperation_ = NSDragOperationCopy; 176 currentOperation_ = NSDragOperationCopy;
173 return currentOperation_; 177 return currentOperation_;
174 } 178 }
175 179
176 - (void)draggingExited:(id<NSDraggingInfo>)info { 180 - (void)draggingExited:(id<NSDraggingInfo>)info {
177 DCHECK(currentRVH_); 181 DCHECK(currentRVH_);
178 if (currentRVH_ != webContents_->GetRenderViewHost()) 182 if (currentRVH_ != webContents_->GetRenderViewHost())
179 return; 183 return;
180 184
181 if (canceled_) 185 if (canceled_)
182 return; 186 return;
183 187
184 if ([self onlyAllowsNavigation]) 188 if ([self onlyAllowsNavigation])
185 return; 189 return;
186 190
187 if (delegate_) 191 if (delegate_)
188 delegate_->OnDragLeave(); 192 delegate_->OnDragLeave();
189 193
190 webContents_->GetRenderViewHost()->DragTargetDragLeave(); 194 // TODO(paulmeyer): This will need to target the correct specific
195 // RenderWidgetHost to work with OOPIFs. See crbug.com/647249.
196 webContents_->GetRenderViewHost()->GetWidget()->DragTargetDragLeave();
191 dropData_.reset(); 197 dropData_.reset();
192 } 198 }
193 199
194 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info 200 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info
195 view:(NSView*)view { 201 view:(NSView*)view {
196 DCHECK(currentRVH_); 202 DCHECK(currentRVH_);
197 if (currentRVH_ != webContents_->GetRenderViewHost()) 203 if (currentRVH_ != webContents_->GetRenderViewHost())
198 [self draggingEntered:info view:view]; 204 [self draggingEntered:info view:view];
199 205
200 if (canceled_) 206 if (canceled_)
201 return NSDragOperationNone; 207 return NSDragOperationNone;
202 208
203 if ([self onlyAllowsNavigation]) { 209 if ([self onlyAllowsNavigation]) {
204 if ([[info draggingPasteboard] containsURLDataConvertingTextToURL:YES]) 210 if ([[info draggingPasteboard] containsURLDataConvertingTextToURL:YES])
205 return NSDragOperationCopy; 211 return NSDragOperationCopy;
206 return NSDragOperationNone; 212 return NSDragOperationNone;
207 } 213 }
208 214
209 // Create the appropriate mouse locations for WebCore. The draggingLocation 215 // Create the appropriate mouse locations for WebCore. The draggingLocation
210 // is in window coordinates. 216 // is in window coordinates.
211 NSPoint windowPoint = [info draggingLocation]; 217 NSPoint windowPoint = [info draggingLocation];
212 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; 218 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view];
213 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; 219 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view];
214 NSDragOperation mask = [info draggingSourceOperationMask]; 220 NSDragOperation mask = [info draggingSourceOperationMask];
215 webContents_->GetRenderViewHost()->DragTargetDragOver( 221 // TODO(paulmeyer): This will need to target the correct specific
222 // RenderWidgetHost to work with OOPIFs. See crbug.com/647249.
223 webContents_->GetRenderViewHost()->GetWidget()->DragTargetDragOver(
216 gfx::Point(viewPoint.x, viewPoint.y), 224 gfx::Point(viewPoint.x, viewPoint.y),
217 gfx::Point(screenPoint.x, screenPoint.y), 225 gfx::Point(screenPoint.x, screenPoint.y),
218 static_cast<WebDragOperationsMask>(mask), 226 static_cast<WebDragOperationsMask>(mask),
219 GetModifierFlags()); 227 GetModifierFlags());
220 228
221 if (delegate_) 229 if (delegate_)
222 delegate_->OnDragOver(); 230 delegate_->OnDragOver();
223 231
224 return currentOperation_; 232 return currentOperation_;
225 } 233 }
(...skipping 21 matching lines...) Expand all
247 if (delegate_) 255 if (delegate_)
248 delegate_->OnDrop(); 256 delegate_->OnDrop();
249 257
250 currentRVH_ = NULL; 258 currentRVH_ = NULL;
251 259
252 // Create the appropriate mouse locations for WebCore. The draggingLocation 260 // Create the appropriate mouse locations for WebCore. The draggingLocation
253 // is in window coordinates. Both need to be flipped. 261 // is in window coordinates. Both need to be flipped.
254 NSPoint windowPoint = [info draggingLocation]; 262 NSPoint windowPoint = [info draggingLocation];
255 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; 263 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view];
256 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; 264 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view];
257 webContents_->GetRenderViewHost()->DragTargetDrop( 265 // TODO(paulmeyer): This will need to target the correct specific
266 // RenderWidgetHost to work with OOPIFs. See crbug.com/647249.
267 webContents_->GetRenderViewHost()->GetWidget()->DragTargetDrop(
258 *dropData_, gfx::Point(viewPoint.x, viewPoint.y), 268 *dropData_, gfx::Point(viewPoint.x, viewPoint.y),
259 gfx::Point(screenPoint.x, screenPoint.y), GetModifierFlags()); 269 gfx::Point(screenPoint.x, screenPoint.y), GetModifierFlags());
260 270
261 dropData_.reset(); 271 dropData_.reset();
262 272
263 return YES; 273 return YES;
264 } 274 }
265 275
266 // Given |data|, which should not be nil, fill it in using the contents of the 276 // Given |data|, which should not be nil, fill it in using the contents of the
267 // given pasteboard. The types handled by this method should be kept in sync 277 // given pasteboard. The types handled by this method should be kept in sync
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 // Get custom MIME data. 333 // Get custom MIME data.
324 if ([types containsObject:ui::kWebCustomDataPboardType]) { 334 if ([types containsObject:ui::kWebCustomDataPboardType]) {
325 NSData* customData = [pboard dataForType:ui::kWebCustomDataPboardType]; 335 NSData* customData = [pboard dataForType:ui::kWebCustomDataPboardType];
326 ui::ReadCustomDataIntoMap([customData bytes], 336 ui::ReadCustomDataIntoMap([customData bytes],
327 [customData length], 337 [customData length],
328 &data->custom_data); 338 &data->custom_data);
329 } 339 }
330 } 340 }
331 341
332 @end 342 @end
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_view_aura.cc ('k') | content/public/browser/render_view_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698