| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "chrome/browser/cocoa/url_drop_target.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #import "third_party/mozilla/include/NSPasteboard+Utils.h" |
| 9 |
| 10 @interface URLDropTargetHandler(Private) |
| 11 |
| 12 // Get the window controller. |
| 13 - (id<URLDropTargetWindowController>)windowController; |
| 14 |
| 15 // Gets the appropriate drag operation given the |NSDraggingInfo|. |
| 16 - (NSDragOperation)getDragOperation:(id<NSDraggingInfo>)sender; |
| 17 |
| 18 // Tell the window controller to hide the drop indicator. |
| 19 - (void)hideIndicator; |
| 20 |
| 21 @end // @interface URLDropTargetHandler(Private) |
| 22 |
| 23 @implementation URLDropTargetHandler |
| 24 |
| 25 - (id)initWithView:(NSView*)view { |
| 26 if ((self = [super init])) { |
| 27 view_ = view; |
| 28 [view_ registerForDraggedTypes: |
| 29 [NSArray arrayWithObjects:kWebURLsWithTitlesPboardType, |
| 30 NSURLPboardType, |
| 31 NSStringPboardType, |
| 32 NSFilenamesPboardType, |
| 33 nil]]; |
| 34 } |
| 35 return self; |
| 36 } |
| 37 |
| 38 // The following four methods implement parts of the |NSDraggingDestination| |
| 39 // protocol, which the owner should "forward" to its |URLDropTargetHandler| |
| 40 // (us). |
| 41 |
| 42 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender { |
| 43 return [self getDragOperation:sender]; |
| 44 } |
| 45 |
| 46 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender { |
| 47 NSDragOperation dragOp = [self getDragOperation:sender]; |
| 48 if (dragOp == NSDragOperationCopy) { |
| 49 // Just tell the window controller to update the indicator. |
| 50 [[self windowController] indicateDropURLsAt:[sender draggingLocation]]; |
| 51 } |
| 52 return dragOp; |
| 53 } |
| 54 |
| 55 - (void)draggingExited:(id<NSDraggingInfo>)sender { |
| 56 [self hideIndicator]; |
| 57 } |
| 58 |
| 59 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { |
| 60 [self hideIndicator]; |
| 61 |
| 62 NSPasteboard* pboard = [sender draggingPasteboard]; |
| 63 if ([pboard containsURLData]) { |
| 64 NSArray* urls = nil; |
| 65 NSArray* titles; // discarded |
| 66 [pboard getURLs:&urls andTitles:&titles]; |
| 67 |
| 68 if ([urls count]) { |
| 69 // Tell the window controller about the dropped URL(s). |
| 70 [[self windowController] dropURLs:urls at:[sender draggingLocation]]; |
| 71 return YES; |
| 72 } |
| 73 } |
| 74 |
| 75 return NO; |
| 76 } |
| 77 |
| 78 @end // @implementation URLDropTargetHandler |
| 79 |
| 80 @implementation URLDropTargetHandler(Private) |
| 81 |
| 82 - (id<URLDropTargetWindowController>)windowController { |
| 83 id<URLDropTargetWindowController> controller = |
| 84 [[view_ window] windowController]; |
| 85 DCHECK([(id)controller conformsToProtocol: |
| 86 @protocol(URLDropTargetWindowController)]); |
| 87 return controller; |
| 88 } |
| 89 |
| 90 - (NSDragOperation)getDragOperation:(id<NSDraggingInfo>)sender { |
| 91 // Only allow the copy operation. |
| 92 return [sender draggingSourceOperationMask] & NSDragOperationCopy; |
| 93 } |
| 94 |
| 95 - (void)hideIndicator { |
| 96 [[self windowController] hideDropURLsIndicator]; |
| 97 } |
| 98 |
| 99 @end // @implementation URLDropTargetHandler(Private) |
| OLD | NEW |