Chromium Code Reviews| 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 "chrome/browser/ui/cocoa/url_drop_target.h" | 5 #import "chrome/browser/ui/cocoa/url_drop_target.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/cocoa/drag_util.h" | 7 #include "chrome/browser/ui/cocoa/drag_util.h" |
| 8 #import "third_party/mozilla/NSPasteboard+Utils.h" | 8 #import "third_party/mozilla/NSPasteboard+Utils.h" |
| 9 #include "ui/base/clipboard/clipboard_util_mac.h" | 9 #include "ui/base/clipboard/clipboard_util_mac.h" |
| 10 #include "url/gurl.h" | 10 #include "url/gurl.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { | 77 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { |
| 78 [self hideIndicator]; | 78 [self hideIndicator]; |
| 79 | 79 |
| 80 NSPasteboard* pboard = [sender draggingPasteboard]; | 80 NSPasteboard* pboard = [sender draggingPasteboard]; |
| 81 NSArray* supportedTypes = [NSArray arrayWithObjects:NSStringPboardType, nil]; | 81 NSArray* supportedTypes = [NSArray arrayWithObjects:NSStringPboardType, nil]; |
| 82 NSString* bestType = [pboard availableTypeFromArray:supportedTypes]; | 82 NSString* bestType = [pboard availableTypeFromArray:supportedTypes]; |
| 83 | 83 |
| 84 NSPoint dropPoint = | 84 NSPoint dropPoint = |
| 85 [view_ convertPoint:[sender draggingLocation] fromView:nil]; | 85 [view_ convertPoint:[sender draggingLocation] fromView:nil]; |
| 86 // Tell the window controller about the dropped URL(s). | 86 // Tell the window controller about the dropped URL(s). |
| 87 if ([pboard containsURLData]) { | 87 if ([pboard containsURLDataInType]) { |
|
erikchen
2016/05/26 21:01:18
I don't think this is the right approach. If a use
| |
| 88 NSArray* urls = nil; | 88 NSArray* urls = nil; |
| 89 NSArray* titles; // discarded | 89 NSArray* titles; // discarded |
| 90 [pboard getURLs:&urls andTitles:&titles convertingFilenames:YES]; | 90 [pboard getURLsFromType:&urls andTitles:&titles convertingFilenames:YES]; |
| 91 | 91 |
| 92 if ([urls count]) { | 92 if ([urls count]) { |
| 93 [[view_ urlDropController] dropURLs:urls inView:view_ at:dropPoint]; | 93 [[view_ urlDropController] dropURLs:urls inView:view_ at:dropPoint]; |
| 94 return YES; | 94 return YES; |
| 95 } | 95 } |
| 96 } else if (NSString* text = [pboard stringForType:bestType]) { | 96 } else if (NSString* text = [pboard stringForType:bestType]) { |
| 97 // This does not include any URLs, so treat it as plain text if we can | 97 // This does not include any URLs, so treat it as plain text if we can |
| 98 // get NSString. | 98 // get NSString. |
| 99 [[view_ urlDropController] dropText:text inView:view_ at:dropPoint]; | 99 [[view_ urlDropController] dropText:text inView:view_ at:dropPoint]; |
| 100 return YES; | 100 return YES; |
| 101 } | 101 } |
| 102 | 102 |
| 103 return NO; | 103 return NO; |
| 104 } | 104 } |
| 105 | 105 |
| 106 @end // @implementation URLDropTargetHandler | 106 @end // @implementation URLDropTargetHandler |
| 107 | 107 |
| 108 @implementation URLDropTargetHandler(Private) | 108 @implementation URLDropTargetHandler(Private) |
| 109 | 109 |
| 110 - (NSDragOperation)getDragOperation:(id<NSDraggingInfo>)sender { | 110 - (NSDragOperation)getDragOperation:(id<NSDraggingInfo>)sender { |
| 111 NSPasteboard* pboard = [sender draggingPasteboard]; | 111 NSPasteboard* pboard = [sender draggingPasteboard]; |
| 112 NSArray *supportedTypes = [NSArray arrayWithObjects:NSStringPboardType, nil]; | 112 NSArray *supportedTypes = [NSArray arrayWithObjects:NSStringPboardType, nil]; |
| 113 NSString *bestType = [pboard availableTypeFromArray:supportedTypes]; | 113 NSString *bestType = [pboard availableTypeFromArray:supportedTypes]; |
| 114 if (![pboard containsURLData] && ![pboard stringForType:bestType]) | 114 if (![pboard containsURLDataInType] && ![pboard stringForType:bestType]) |
| 115 return NSDragOperationNone; | 115 return NSDragOperationNone; |
| 116 | 116 |
| 117 // Only allow the copy operation. | 117 // Only allow the copy operation. |
| 118 return [sender draggingSourceOperationMask] & NSDragOperationCopy; | 118 return [sender draggingSourceOperationMask] & NSDragOperationCopy; |
| 119 } | 119 } |
| 120 | 120 |
| 121 - (void)hideIndicator { | 121 - (void)hideIndicator { |
| 122 [[view_ urlDropController] hideDropURLsIndicatorInView:view_]; | 122 [[view_ urlDropController] hideDropURLsIndicatorInView:view_]; |
| 123 } | 123 } |
| 124 | 124 |
| 125 @end // @implementation URLDropTargetHandler(Private) | 125 @end // @implementation URLDropTargetHandler(Private) |
| OLD | NEW |