| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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/cocoa/url_drop_target.h" | 5 #import "chrome/browser/cocoa/url_drop_target.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "third_party/mozilla/include/NSPasteboard+Utils.h" | 8 #import "third_party/mozilla/include/NSPasteboard+Utils.h" |
| 9 | 9 |
| 10 @interface URLDropTargetHandler(Private) | 10 @interface URLDropTargetHandler(Private) |
| 11 | 11 |
| 12 // Get the window controller. | |
| 13 - (id<URLDropTargetWindowController>)windowController; | |
| 14 | |
| 15 // Gets the appropriate drag operation given the |NSDraggingInfo|. | 12 // Gets the appropriate drag operation given the |NSDraggingInfo|. |
| 16 - (NSDragOperation)getDragOperation:(id<NSDraggingInfo>)sender; | 13 - (NSDragOperation)getDragOperation:(id<NSDraggingInfo>)sender; |
| 17 | 14 |
| 18 // Tell the window controller to hide the drop indicator. | 15 // Tell the window controller to hide the drop indicator. |
| 19 - (void)hideIndicator; | 16 - (void)hideIndicator; |
| 20 | 17 |
| 21 @end // @interface URLDropTargetHandler(Private) | 18 @end // @interface URLDropTargetHandler(Private) |
| 22 | 19 |
| 23 @implementation URLDropTargetHandler | 20 @implementation URLDropTargetHandler |
| 24 | 21 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 40 // (us). | 37 // (us). |
| 41 | 38 |
| 42 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender { | 39 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender { |
| 43 return [self getDragOperation:sender]; | 40 return [self getDragOperation:sender]; |
| 44 } | 41 } |
| 45 | 42 |
| 46 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender { | 43 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender { |
| 47 NSDragOperation dragOp = [self getDragOperation:sender]; | 44 NSDragOperation dragOp = [self getDragOperation:sender]; |
| 48 if (dragOp == NSDragOperationCopy) { | 45 if (dragOp == NSDragOperationCopy) { |
| 49 // Just tell the window controller to update the indicator. | 46 // Just tell the window controller to update the indicator. |
| 50 [[self windowController] indicateDropURLsAt:[sender draggingLocation]]; | 47 NSPoint hoverPoint = [view_ convertPointFromBase:[sender draggingLocation]]; |
| 48 [[view_ urlDropController] indicateDropURLsInView:view_ at:hoverPoint]; |
| 51 } | 49 } |
| 52 return dragOp; | 50 return dragOp; |
| 53 } | 51 } |
| 54 | 52 |
| 55 - (void)draggingExited:(id<NSDraggingInfo>)sender { | 53 - (void)draggingExited:(id<NSDraggingInfo>)sender { |
| 56 [self hideIndicator]; | 54 [self hideIndicator]; |
| 57 } | 55 } |
| 58 | 56 |
| 59 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { | 57 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { |
| 60 [self hideIndicator]; | 58 [self hideIndicator]; |
| 61 | 59 |
| 62 NSPasteboard* pboard = [sender draggingPasteboard]; | 60 NSPasteboard* pboard = [sender draggingPasteboard]; |
| 63 if ([pboard containsURLData]) { | 61 if ([pboard containsURLData]) { |
| 64 NSArray* urls = nil; | 62 NSArray* urls = nil; |
| 65 NSArray* titles; // discarded | 63 NSArray* titles; // discarded |
| 66 [pboard getURLs:&urls andTitles:&titles]; | 64 [pboard getURLs:&urls andTitles:&titles]; |
| 67 | 65 |
| 68 if ([urls count]) { | 66 if ([urls count]) { |
| 69 // Tell the window controller about the dropped URL(s). | 67 // Tell the window controller about the dropped URL(s). |
| 70 [[self windowController] dropURLs:urls at:[sender draggingLocation]]; | 68 NSPoint dropPoint = |
| 69 [view_ convertPointFromBase:[sender draggingLocation]]; |
| 70 [[view_ urlDropController] dropURLs:urls inView:view_ at:dropPoint]; |
| 71 return YES; | 71 return YES; |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 return NO; | 75 return NO; |
| 76 } | 76 } |
| 77 | 77 |
| 78 @end // @implementation URLDropTargetHandler | 78 @end // @implementation URLDropTargetHandler |
| 79 | 79 |
| 80 @implementation URLDropTargetHandler(Private) | 80 @implementation URLDropTargetHandler(Private) |
| 81 | 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 { | 82 - (NSDragOperation)getDragOperation:(id<NSDraggingInfo>)sender { |
| 91 // Only allow the copy operation. | 83 // Only allow the copy operation. |
| 92 return [sender draggingSourceOperationMask] & NSDragOperationCopy; | 84 return [sender draggingSourceOperationMask] & NSDragOperationCopy; |
| 93 } | 85 } |
| 94 | 86 |
| 95 - (void)hideIndicator { | 87 - (void)hideIndicator { |
| 96 [[self windowController] hideDropURLsIndicator]; | 88 [[view_ urlDropController] hideDropURLsIndicatorInView:view_]; |
| 97 } | 89 } |
| 98 | 90 |
| 99 @end // @implementation URLDropTargetHandler(Private) | 91 @end // @implementation URLDropTargetHandler(Private) |
| OLD | NEW |