| 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_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" |
| 11 #include "content/browser/renderer_host/render_widget_host_impl.h" | 11 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 12 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" | 12 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" |
| 13 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 13 #include "content/browser/web_contents/web_contents_impl.h" | 14 #include "content/browser/web_contents/web_contents_impl.h" |
| 14 #include "content/public/browser/web_contents_delegate.h" | 15 #include "content/public/browser/web_contents_delegate.h" |
| 15 #include "content/public/browser/web_drag_dest_delegate.h" | 16 #include "content/public/browser/web_drag_dest_delegate.h" |
| 16 #include "content/public/common/child_process_host.h" | 17 #include "content/public/common/child_process_host.h" |
| 17 #include "content/public/common/drop_data.h" | 18 #include "content/public/common/drop_data.h" |
| 18 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 19 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 19 #import "third_party/mozilla/NSPasteboard+Utils.h" | 20 #import "third_party/mozilla/NSPasteboard+Utils.h" |
| 20 #include "ui/base/clipboard/custom_data_helper.h" | 21 #include "ui/base/clipboard/custom_data_helper.h" |
| 21 #include "ui/base/cocoa/cocoa_base_utils.h" | 22 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 22 #import "ui/base/dragdrop/cocoa_dnd_util.h" | 23 #import "ui/base/dragdrop/cocoa_dnd_util.h" |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 if (canceled_) | 209 if (canceled_) |
| 209 return; | 210 return; |
| 210 | 211 |
| 211 if ([self onlyAllowsNavigation]) | 212 if ([self onlyAllowsNavigation]) |
| 212 return; | 213 return; |
| 213 | 214 |
| 214 if (delegate_) | 215 if (delegate_) |
| 215 delegate_->OnDragLeave(); | 216 delegate_->OnDragLeave(); |
| 216 | 217 |
| 217 if (currentRWHForDrag_) { | 218 if (currentRWHForDrag_) { |
| 218 currentRWHForDrag_->DragTargetDragLeave(); | 219 currentRWHForDrag_->DragTargetDragLeave(gfx::Point(), gfx::Point()); |
| 219 currentRWHForDrag_.reset(); | 220 currentRWHForDrag_.reset(); |
| 220 } | 221 } |
| 221 dropData_.reset(); | 222 dropData_.reset(); |
| 222 } | 223 } |
| 223 | 224 |
| 224 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info view:(NSView*)view { | 225 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info view:(NSView*)view { |
| 225 if (canceled_) { | 226 if (canceled_) { |
| 226 // TODO(ekaramad,paulmeyer): We probably shouldn't be checking for | 227 // TODO(ekaramad,paulmeyer): We probably shouldn't be checking for |
| 227 // |canceled_| twice in this method. | 228 // |canceled_| twice in this method. |
| 228 return NSDragOperationNone; | 229 return NSDragOperationNone; |
| 229 } | 230 } |
| 230 | 231 |
| 231 // Create the appropriate mouse locations for WebCore. The draggingLocation | 232 // Create the appropriate mouse locations for WebCore. The draggingLocation |
| 232 // is in window coordinates. Both need to be flipped. | 233 // is in window coordinates. Both need to be flipped. |
| 233 NSPoint windowPoint = [info draggingLocation]; | 234 NSPoint windowPoint = [info draggingLocation]; |
| 234 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; | 235 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; |
| 235 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; | 236 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; |
| 236 gfx::Point transformedPt; | 237 gfx::Point transformedPt; |
| 237 content::RenderWidgetHostImpl* targetRWH = | 238 content::RenderWidgetHostImpl* targetRWH = |
| 238 [self GetRenderWidgetHostAtPoint:viewPoint transformedPt:&transformedPt]; | 239 [self GetRenderWidgetHostAtPoint:viewPoint transformedPt:&transformedPt]; |
| 239 | 240 |
| 240 if (![self isValidDragTarget:targetRWH]) | 241 if (![self isValidDragTarget:targetRWH]) |
| 241 return NSDragOperationNone; | 242 return NSDragOperationNone; |
| 242 | 243 |
| 243 // TODO(paulmeyer): The dragging delegates may now by invoked multiple times | 244 // TODO(paulmeyer): The dragging delegates may now by invoked multiple times |
| 244 // per drag, even without the drag ever leaving the window. | 245 // per drag, even without the drag ever leaving the window. |
| 245 if (targetRWH != currentRWHForDrag_.get()) { | 246 if (targetRWH != currentRWHForDrag_.get()) { |
| 246 if (currentRWHForDrag_) | 247 if (currentRWHForDrag_) { |
| 247 currentRWHForDrag_->DragTargetDragLeave(); | 248 gfx::Point transformedLeavePoint = gfx::Point(viewPoint.x, viewPoint.y); |
| 249 gfx::Point transformedScreenPoint = |
| 250 gfx::Point(screenPoint.x, screenPoint.y); |
| 251 content::RenderWidgetHostViewBase* rootView = |
| 252 static_cast<content::RenderWidgetHostViewBase*>( |
| 253 webContents_->GetRenderWidgetHostView()); |
| 254 content::RenderWidgetHostViewBase* currentDragView = |
| 255 static_cast<content::RenderWidgetHostViewBase*>( |
| 256 currentRWHForDrag_->GetView()); |
| 257 rootView->TransformPointToCoordSpaceForView( |
| 258 transformedLeavePoint, currentDragView, &transformedLeavePoint); |
| 259 rootView->TransformPointToCoordSpaceForView( |
| 260 transformedScreenPoint, currentDragView, &transformedScreenPoint); |
| 261 currentRWHForDrag_->DragTargetDragLeave(transformedLeavePoint, |
| 262 transformedScreenPoint); |
| 263 } |
| 248 [self draggingEntered:info view:view]; | 264 [self draggingEntered:info view:view]; |
| 249 } | 265 } |
| 250 | 266 |
| 251 if (canceled_) | 267 if (canceled_) |
| 252 return NSDragOperationNone; | 268 return NSDragOperationNone; |
| 253 | 269 |
| 254 if ([self onlyAllowsNavigation]) { | 270 if ([self onlyAllowsNavigation]) { |
| 255 if ([[info draggingPasteboard] containsURLDataConvertingTextToURL:YES]) | 271 if ([[info draggingPasteboard] containsURLDataConvertingTextToURL:YES]) |
| 256 return NSDragOperationCopy; | 272 return NSDragOperationCopy; |
| 257 return NSDragOperationNone; | 273 return NSDragOperationNone; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 277 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; | 293 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; |
| 278 gfx::Point transformedPt; | 294 gfx::Point transformedPt; |
| 279 content::RenderWidgetHostImpl* targetRWH = | 295 content::RenderWidgetHostImpl* targetRWH = |
| 280 [self GetRenderWidgetHostAtPoint:viewPoint transformedPt:&transformedPt]; | 296 [self GetRenderWidgetHostAtPoint:viewPoint transformedPt:&transformedPt]; |
| 281 | 297 |
| 282 if (![self isValidDragTarget:targetRWH]) | 298 if (![self isValidDragTarget:targetRWH]) |
| 283 return NO; | 299 return NO; |
| 284 | 300 |
| 285 if (targetRWH != currentRWHForDrag_.get()) { | 301 if (targetRWH != currentRWHForDrag_.get()) { |
| 286 if (currentRWHForDrag_) | 302 if (currentRWHForDrag_) |
| 287 currentRWHForDrag_->DragTargetDragLeave(); | 303 currentRWHForDrag_->DragTargetDragLeave( |
| 304 transformedPt, gfx::Point(screenPoint.x, screenPoint.y)); |
| 288 [self draggingEntered:info view:view]; | 305 [self draggingEntered:info view:view]; |
| 289 } | 306 } |
| 290 | 307 |
| 291 // Check if we only allow navigation and navigate to a url on the pasteboard. | 308 // Check if we only allow navigation and navigate to a url on the pasteboard. |
| 292 if ([self onlyAllowsNavigation]) { | 309 if ([self onlyAllowsNavigation]) { |
| 293 NSPasteboard* pboard = [info draggingPasteboard]; | 310 NSPasteboard* pboard = [info draggingPasteboard]; |
| 294 if ([pboard containsURLDataConvertingTextToURL:YES]) { | 311 if ([pboard containsURLDataConvertingTextToURL:YES]) { |
| 295 GURL url; | 312 GURL url; |
| 296 ui::PopulateURLAndTitleFromPasteboard(&url, NULL, pboard, YES); | 313 ui::PopulateURLAndTitleFromPasteboard(&url, NULL, pboard, YES); |
| 297 webContents_->OpenURL( | 314 webContents_->OpenURL( |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 // Get custom MIME data. | 413 // Get custom MIME data. |
| 397 if ([types containsObject:ui::kWebCustomDataPboardType]) { | 414 if ([types containsObject:ui::kWebCustomDataPboardType]) { |
| 398 NSData* customData = [pboard dataForType:ui::kWebCustomDataPboardType]; | 415 NSData* customData = [pboard dataForType:ui::kWebCustomDataPboardType]; |
| 399 ui::ReadCustomDataIntoMap([customData bytes], | 416 ui::ReadCustomDataIntoMap([customData bytes], |
| 400 [customData length], | 417 [customData length], |
| 401 &data->custom_data); | 418 &data->custom_data); |
| 402 } | 419 } |
| 403 } | 420 } |
| 404 | 421 |
| 405 @end | 422 @end |
| OLD | NEW |