| 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" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 // Save off the RVH so we can tell if it changes during a drag. If it does, | 127 // Save off the RVH so we can tell if it changes during a drag. If it does, |
| 128 // we need to send a new enter message in draggingUpdated:. | 128 // we need to send a new enter message in draggingUpdated:. |
| 129 currentRVH_ = webContents_->GetRenderViewHost(); | 129 currentRVH_ = webContents_->GetRenderViewHost(); |
| 130 | 130 |
| 131 // Create the appropriate mouse locations for WebCore. The draggingLocation | 131 // Create the appropriate mouse locations for WebCore. The draggingLocation |
| 132 // is in window coordinates. Both need to be flipped. | 132 // is in window coordinates. Both need to be flipped. |
| 133 NSPoint windowPoint = [info draggingLocation]; | 133 NSPoint windowPoint = [info draggingLocation]; |
| 134 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; | 134 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; |
| 135 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; | 135 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; |
| 136 gfx::Point transformedPt; | 136 gfx::Point transformedPt; |
| 137 if (!webContents_->GetRenderWidgetHostView()) { |
| 138 // TODO(ekaramad, paulmeyer): Find a better way than toggling |canceled_|. |
| 139 // This could happen when the renderer process for the top-level RWH crashes |
| 140 // (see https://crbug.com/670645). |
| 141 canceled_ = true; |
| 142 return NSDragOperationNone; |
| 143 } |
| 137 currentRWHForDrag_ = | 144 currentRWHForDrag_ = |
| 138 [self GetRenderWidgetHostAtPoint:viewPoint transformedPt:&transformedPt] | 145 [self GetRenderWidgetHostAtPoint:viewPoint transformedPt:&transformedPt] |
| 139 ->GetWeakPtr(); | 146 ->GetWeakPtr(); |
| 140 | 147 |
| 141 // Fill out a DropData from pasteboard. | 148 // Fill out a DropData from pasteboard. |
| 142 std::unique_ptr<DropData> dropData; | 149 std::unique_ptr<DropData> dropData; |
| 143 dropData.reset(new DropData()); | 150 dropData.reset(new DropData()); |
| 144 [self populateDropData:dropData.get() | 151 [self populateDropData:dropData.get() |
| 145 fromPasteboard:[info draggingPasteboard]]; | 152 fromPasteboard:[info draggingPasteboard]]; |
| 146 // TODO(paulmeyer): Data may be pulled from the pasteboard multiple times per | 153 // TODO(paulmeyer): Data may be pulled from the pasteboard multiple times per |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 if (delegate_) | 201 if (delegate_) |
| 195 delegate_->OnDragLeave(); | 202 delegate_->OnDragLeave(); |
| 196 | 203 |
| 197 if (currentRWHForDrag_) { | 204 if (currentRWHForDrag_) { |
| 198 currentRWHForDrag_->DragTargetDragLeave(); | 205 currentRWHForDrag_->DragTargetDragLeave(); |
| 199 currentRWHForDrag_.reset(); | 206 currentRWHForDrag_.reset(); |
| 200 } | 207 } |
| 201 dropData_.reset(); | 208 dropData_.reset(); |
| 202 } | 209 } |
| 203 | 210 |
| 204 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info | 211 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info view:(NSView*)view { |
| 205 view:(NSView*)view { | 212 if (canceled_) { |
| 213 // TODO(ekaramad,paulmeyer): We probably shouldn't be checking for |
| 214 // |canceled_| twice in this method. |
| 215 return NSDragOperationNone; |
| 216 } |
| 217 |
| 206 // Create the appropriate mouse locations for WebCore. The draggingLocation | 218 // Create the appropriate mouse locations for WebCore. The draggingLocation |
| 207 // is in window coordinates. Both need to be flipped. | 219 // is in window coordinates. Both need to be flipped. |
| 208 NSPoint windowPoint = [info draggingLocation]; | 220 NSPoint windowPoint = [info draggingLocation]; |
| 209 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; | 221 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; |
| 210 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; | 222 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; |
| 211 gfx::Point transformedPt; | 223 gfx::Point transformedPt; |
| 212 content::RenderWidgetHostImpl* targetRWH = | 224 content::RenderWidgetHostImpl* targetRWH = |
| 213 [self GetRenderWidgetHostAtPoint:viewPoint transformedPt:&transformedPt]; | 225 [self GetRenderWidgetHostAtPoint:viewPoint transformedPt:&transformedPt]; |
| 214 | 226 |
| 215 // TODO(paulmeyer): The dragging delegates may now by invoked multiple times | 227 // TODO(paulmeyer): The dragging delegates may now by invoked multiple times |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 // Get custom MIME data. | 366 // Get custom MIME data. |
| 355 if ([types containsObject:ui::kWebCustomDataPboardType]) { | 367 if ([types containsObject:ui::kWebCustomDataPboardType]) { |
| 356 NSData* customData = [pboard dataForType:ui::kWebCustomDataPboardType]; | 368 NSData* customData = [pboard dataForType:ui::kWebCustomDataPboardType]; |
| 357 ui::ReadCustomDataIntoMap([customData bytes], | 369 ui::ReadCustomDataIntoMap([customData bytes], |
| 358 [customData length], | 370 [customData length], |
| 359 &data->custom_data); | 371 &data->custom_data); |
| 360 } | 372 } |
| 361 } | 373 } |
| 362 | 374 |
| 363 @end | 375 @end |
| OLD | NEW |