| 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/sys_string_conversions.h" | 9 #include "base/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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 // hear back from the renderer. For now, be optimistic: | 135 // hear back from the renderer. For now, be optimistic: |
| 136 currentOperation_ = NSDragOperationCopy; | 136 currentOperation_ = NSDragOperationCopy; |
| 137 return currentOperation_; | 137 return currentOperation_; |
| 138 } | 138 } |
| 139 | 139 |
| 140 - (void)draggingExited:(id<NSDraggingInfo>)info { | 140 - (void)draggingExited:(id<NSDraggingInfo>)info { |
| 141 DCHECK(currentRVH_); | 141 DCHECK(currentRVH_); |
| 142 if (currentRVH_ != webContents_->GetRenderViewHost()) | 142 if (currentRVH_ != webContents_->GetRenderViewHost()) |
| 143 return; | 143 return; |
| 144 | 144 |
| 145 // Nothing to do in the interstitial case. | 145 if ([self onlyAllowsNavigation]) |
| 146 return; |
| 146 | 147 |
| 147 if (delegate_) | 148 if (delegate_) |
| 148 delegate_->OnDragLeave(); | 149 delegate_->OnDragLeave(); |
| 149 | 150 |
| 150 webContents_->GetRenderViewHost()->DragTargetDragLeave(); | 151 webContents_->GetRenderViewHost()->DragTargetDragLeave(); |
| 151 dropData_.reset(); | 152 dropData_.reset(); |
| 152 } | 153 } |
| 153 | 154 |
| 154 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info | 155 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info |
| 155 view:(NSView*)view { | 156 view:(NSView*)view { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 180 | 181 |
| 181 return currentOperation_; | 182 return currentOperation_; |
| 182 } | 183 } |
| 183 | 184 |
| 184 - (BOOL)performDragOperation:(id<NSDraggingInfo>)info | 185 - (BOOL)performDragOperation:(id<NSDraggingInfo>)info |
| 185 view:(NSView*)view { | 186 view:(NSView*)view { |
| 186 if (currentRVH_ != webContents_->GetRenderViewHost()) | 187 if (currentRVH_ != webContents_->GetRenderViewHost()) |
| 187 [self draggingEntered:info view:view]; | 188 [self draggingEntered:info view:view]; |
| 188 | 189 |
| 189 // Check if we only allow navigation and navigate to a url on the pasteboard. | 190 // Check if we only allow navigation and navigate to a url on the pasteboard. |
| 190 BOOL result = YES; | |
| 191 if ([self onlyAllowsNavigation]) { | 191 if ([self onlyAllowsNavigation]) { |
| 192 NSPasteboard* pboard = [info draggingPasteboard]; | 192 NSPasteboard* pboard = [info draggingPasteboard]; |
| 193 if ([pboard containsURLData]) { | 193 if ([pboard containsURLData]) { |
| 194 GURL url; | 194 GURL url; |
| 195 ui::PopulateURLAndTitleFromPasteboard(&url, NULL, pboard, YES); | 195 ui::PopulateURLAndTitleFromPasteboard(&url, NULL, pboard, YES); |
| 196 webContents_->OpenURL(OpenURLParams( | 196 webContents_->OpenURL(OpenURLParams( |
| 197 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_AUTO_BOOKMARK, | 197 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_AUTO_BOOKMARK, |
| 198 false)); | 198 false)); |
| 199 return YES; |
| 199 } else { | 200 } else { |
| 200 result = NO; | 201 return NO; |
| 201 } | 202 } |
| 202 } else { | |
| 203 if (delegate_) | |
| 204 delegate_->OnDrop(); | |
| 205 } | 203 } |
| 206 | 204 |
| 205 if (delegate_) |
| 206 delegate_->OnDrop(); |
| 207 |
| 207 currentRVH_ = NULL; | 208 currentRVH_ = NULL; |
| 208 | 209 |
| 209 // Create the appropriate mouse locations for WebCore. The draggingLocation | 210 // Create the appropriate mouse locations for WebCore. The draggingLocation |
| 210 // is in window coordinates. Both need to be flipped. | 211 // is in window coordinates. Both need to be flipped. |
| 211 NSPoint windowPoint = [info draggingLocation]; | 212 NSPoint windowPoint = [info draggingLocation]; |
| 212 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; | 213 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; |
| 213 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; | 214 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; |
| 214 webContents_->GetRenderViewHost()->DragTargetDrop( | 215 webContents_->GetRenderViewHost()->DragTargetDrop( |
| 215 gfx::Point(viewPoint.x, viewPoint.y), | 216 gfx::Point(viewPoint.x, viewPoint.y), |
| 216 gfx::Point(screenPoint.x, screenPoint.y), | 217 gfx::Point(screenPoint.x, screenPoint.y), |
| 217 GetModifierFlags()); | 218 GetModifierFlags()); |
| 218 | 219 |
| 219 dropData_.reset(); | 220 dropData_.reset(); |
| 220 | 221 |
| 221 return result; | 222 return YES; |
| 222 } | 223 } |
| 223 | 224 |
| 224 // Given |data|, which should not be nil, fill it in using the contents of the | 225 // Given |data|, which should not be nil, fill it in using the contents of the |
| 225 // given pasteboard. The types handled by this method should be kept in sync | 226 // given pasteboard. The types handled by this method should be kept in sync |
| 226 // with [WebContentsViewCocoa registerDragTypes]. | 227 // with [WebContentsViewCocoa registerDragTypes]. |
| 227 - (void)populateWebDropData:(WebDropData*)data | 228 - (void)populateWebDropData:(WebDropData*)data |
| 228 fromPasteboard:(NSPasteboard*)pboard { | 229 fromPasteboard:(NSPasteboard*)pboard { |
| 229 DCHECK(data); | 230 DCHECK(data); |
| 230 DCHECK(pboard); | 231 DCHECK(pboard); |
| 231 NSArray* types = [pboard types]; | 232 NSArray* types = [pboard types]; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 // Get custom MIME data. | 277 // Get custom MIME data. |
| 277 if ([types containsObject:ui::kWebCustomDataPboardType]) { | 278 if ([types containsObject:ui::kWebCustomDataPboardType]) { |
| 278 NSData* customData = [pboard dataForType:ui::kWebCustomDataPboardType]; | 279 NSData* customData = [pboard dataForType:ui::kWebCustomDataPboardType]; |
| 279 ui::ReadCustomDataIntoMap([customData bytes], | 280 ui::ReadCustomDataIntoMap([customData bytes], |
| 280 [customData length], | 281 [customData length], |
| 281 &data->custom_data); | 282 &data->custom_data); |
| 282 } | 283 } |
| 283 } | 284 } |
| 284 | 285 |
| 285 @end | 286 @end |
| OLD | NEW |