Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4004)

Unified Diff: chrome/browser/cocoa/url_drop_target.mm

Issue 337055: Mac: implement drag-and-drop of URLs to tabs/tab strip. (Closed)
Patch Set: Give another line back. Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/cocoa/url_drop_target.mm
diff --git a/chrome/browser/cocoa/url_drop_target.mm b/chrome/browser/cocoa/url_drop_target.mm
new file mode 100644
index 0000000000000000000000000000000000000000..6a2031d073e601e4a2e5ce68cabf1209e6dad4ab
--- /dev/null
+++ b/chrome/browser/cocoa/url_drop_target.mm
@@ -0,0 +1,99 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/cocoa/url_drop_target.h"
+
+#include "base/logging.h"
+#import "third_party/mozilla/include/NSPasteboard+Utils.h"
+
+@interface URLDropTargetHandler(Private)
+
+// Get the window controller.
+- (id<URLDropTargetWindowController>)windowController;
+
+// Gets the appropriate drag operation given the |NSDraggingInfo|.
+- (NSDragOperation)getDragOperation:(id<NSDraggingInfo>)sender;
+
+// Tell the window controller to hide the drop indicator.
+- (void)hideIndicator;
+
+@end // @interface URLDropTargetHandler(Private)
+
+@implementation URLDropTargetHandler
+
+- (id)initWithView:(NSView*)view {
+ if ((self = [super init])) {
+ view_ = view;
+ [view_ registerForDraggedTypes:
+ [NSArray arrayWithObjects:kWebURLsWithTitlesPboardType,
+ NSURLPboardType,
+ NSStringPboardType,
+ NSFilenamesPboardType,
+ nil]];
+ }
+ return self;
+}
+
+// The following four methods implement parts of the |NSDraggingDestination|
+// protocol, which the owner should "forward" to its |URLDropTargetHandler|
+// (us).
+
+- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
+ return [self getDragOperation:sender];
+}
+
+- (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender {
+ NSDragOperation dragOp = [self getDragOperation:sender];
+ if (dragOp == NSDragOperationCopy) {
+ // Just tell the window controller to update the indicator.
+ [[self windowController] indicateDropURLsAt:[sender draggingLocation]];
+ }
+ return dragOp;
+}
+
+- (void)draggingExited:(id<NSDraggingInfo>)sender {
+ [self hideIndicator];
+}
+
+- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
+ [self hideIndicator];
+
+ NSPasteboard* pboard = [sender draggingPasteboard];
+ if ([pboard containsURLData]) {
+ NSArray* urls = nil;
+ NSArray* titles; // discarded
+ [pboard getURLs:&urls andTitles:&titles];
+
+ if ([urls count]) {
+ // Tell the window controller about the dropped URL(s).
+ [[self windowController] dropURLs:urls at:[sender draggingLocation]];
+ return YES;
+ }
+ }
+
+ return NO;
+}
+
+@end // @implementation URLDropTargetHandler
+
+@implementation URLDropTargetHandler(Private)
+
+- (id<URLDropTargetWindowController>)windowController {
+ id<URLDropTargetWindowController> controller =
+ [[view_ window] windowController];
+ DCHECK([(id)controller conformsToProtocol:
+ @protocol(URLDropTargetWindowController)]);
+ return controller;
+}
+
+- (NSDragOperation)getDragOperation:(id<NSDraggingInfo>)sender {
+ // Only allow the copy operation.
+ return [sender draggingSourceOperationMask] & NSDragOperationCopy;
+}
+
+- (void)hideIndicator {
+ [[self windowController] hideDropURLsIndicator];
+}
+
+@end // @implementation URLDropTargetHandler(Private)

Powered by Google App Engine
This is Rietveld 408576698