diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-24 02:01:08 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-24 02:01:08 +0000 |
commit | cb26fb7252e6839b7465de9ce0aec64f321a4851 (patch) | |
tree | 287fa98b14126ce7e32a0d1c138125e36135da67 /chrome/browser/cocoa/bookmark_bar_view.mm | |
parent | 0790ab29d8b09d8c737ecd976822f794223b2847 (diff) | |
download | chromium_src-cb26fb7252e6839b7465de9ce0aec64f321a4851.zip chromium_src-cb26fb7252e6839b7465de9ce0aec64f321a4851.tar.gz chromium_src-cb26fb7252e6839b7465de9ce0aec64f321a4851.tar.bz2 |
[Mac] Make bookmark bar primitive drag destination.
Credits for the bookmark bar fix to dmac; stolen from http://codereview.chromium.org/267082 .
BUG=18289
TEST=Drag a link or bookmarklet from the web to the bookmark bar. It should be added at the end of the bar.
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=29906
Reverted: http://src.chromium.org/viewvc/chrome?view=rev&revision=29908
Review URL: http://codereview.chromium.org/336001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29990 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/bookmark_bar_view.mm')
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_view.mm | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/bookmark_bar_view.mm b/chrome/browser/cocoa/bookmark_bar_view.mm index a991e71..d62b755 100644 --- a/chrome/browser/cocoa/bookmark_bar_view.mm +++ b/chrome/browser/cocoa/bookmark_bar_view.mm @@ -3,7 +3,10 @@ // found in the LICENSE file. #import "chrome/browser/cocoa/bookmark_bar_view.h" + +#import "chrome/browser/cocoa/bookmark_bar_controller.h" #import "third_party/GTM/AppKit/GTMTheme.h" +#import "third_party/mozilla/include/NSPasteboard+Utils.h" @interface BookmarkBarView (Private) - (void)themeDidChangeNotification:(NSNotification*)aNotification; @@ -14,6 +17,8 @@ - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; + // This probably isn't strictly necessary, but can't hurt. + [self unregisterDraggedTypes]; [super dealloc]; } @@ -23,6 +28,11 @@ selector:@selector(themeDidChangeNotification:) name:kGTMThemeDidChangeNotification object:nil]; + + DCHECK(controller_ && "Expected this to be hooked up via Interface Builder"); + NSArray* types = [NSArray arrayWithObjects:NSStringPboardType, + NSHTMLPboardType, NSURLPboardType, nil]; + [self registerForDraggedTypes:types]; } - (void)viewDidMoveToWindow { @@ -51,4 +61,42 @@ return noItemTextfield_; } +// NSDraggingDestination methods + +- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)info { + if ([[info draggingPasteboard] containsURLData]) + return NSDragOperationCopy; + return NSDragOperationNone; +} + +- (BOOL)wantsPeriodicDraggingUpdates { + // TODO(port): This should probably return |YES| and the controller should + // slide the existing bookmark buttons interactively to the side to make + // room for the about-to-be-dropped bookmark. + return NO; +} + +- (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info { + if ([[info draggingPasteboard] containsURLData]) + return NSDragOperationCopy; + return NSDragOperationNone; +} + +- (BOOL)prepareForDragOperation:(id<NSDraggingInfo>)info { + return YES; +} + +- (BOOL)performDragOperation:(id<NSDraggingInfo>)info { + NSPasteboard* pboard = [info draggingPasteboard]; + DCHECK([pboard containsURLData]); + + NSArray* urls = nil; + NSArray* titles = nil; + [pboard getURLs:&urls andTitles:&titles]; + + return [controller_ addURLs:urls + withTitles:titles + at:[info draggingLocation]]; +} + @end // @implementation BookmarkBarView |