diff options
author | mrossetti@chromium.org <mrossetti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-10 01:37:07 +0000 |
---|---|---|
committer | mrossetti@chromium.org <mrossetti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-10 01:37:07 +0000 |
commit | a54d402c3bf0a74aff9e4fa04f86b8818c6ebe3a (patch) | |
tree | a9bda009f5fba50cf09d4b7edc8f9763c22f8f63 /chrome/browser/cocoa/bookmark_bar_controller.mm | |
parent | 61dd7efa16c8f62d07588aaca7163ad3052bb99e (diff) | |
download | chromium_src-a54d402c3bf0a74aff9e4fa04f86b8818c6ebe3a.zip chromium_src-a54d402c3bf0a74aff9e4fa04f86b8818c6ebe3a.tar.gz chromium_src-a54d402c3bf0a74aff9e4fa04f86b8818c6ebe3a.tar.bz2 |
Mac: Allow dragging bookmarks to trash
This patch allows users to delete bookmarks by dragging them to the trash icon on the Mac OS dock.
Note: Original patch http://codereview.chromium.org/3342023 proposed by fnepal@gmail.com.
BUG=54727
TEST=Dragged bookmarks to trash. Verified that the bookmark was deleted. Verified that the poof animation was draw centered over the mouse cursor. Verified that the same thing worked for bookmarks inside folders.
Review URL: http://codereview.chromium.org/3333026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59030 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/bookmark_bar_controller.mm')
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_controller.mm | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/chrome/browser/cocoa/bookmark_bar_controller.mm b/chrome/browser/cocoa/bookmark_bar_controller.mm index 7bd2988..f3a59d6 100644 --- a/chrome/browser/cocoa/bookmark_bar_controller.mm +++ b/chrome/browser/cocoa/bookmark_bar_controller.mm @@ -506,6 +506,15 @@ const NSTimeInterval kBookmarkBarAnimationDuration = 0.12; [self closeAllBookmarkFolders]; } +- (BOOL)canEditBookmark:(const BookmarkNode*)node { + // Don't allow edit/delete of the bar node, or of "Other Bookmarks" + if ((node == nil) || + (node == bookmarkModel_->other_node()) || + (node == bookmarkModel_->GetBookmarkBarNode())) + return NO; + return YES; +} + #pragma mark Actions - (IBAction)openBookmark:(id)sender { @@ -905,10 +914,7 @@ const NSTimeInterval kBookmarkBarAnimationDuration = 0.12; (action == @selector(deleteBookmark:)) || (action == @selector(cutBookmark:)) || (action == @selector(copyBookmark:))) { - // Don't allow edit/delete of the bar node, or of "Other Bookmarks" - if ((node == nil) || - (node == bookmarkModel_->other_node()) || - (node == bookmarkModel_->GetBookmarkBarNode())) { + if (![self canEditBookmark:node]) { return NO; } } @@ -1422,7 +1428,7 @@ const NSTimeInterval kBookmarkBarAnimationDuration = 0.12; return [offTheSideButton_ isHidden]; } -- (NSButton*)otherBookmarksButton { +- (BookmarkButton*)otherBookmarksButton { return otherBookmarksButton_.get(); } @@ -2004,6 +2010,21 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { return [[self view] window]; } +- (BOOL)canDragBookmarkButtonToTrash:(BookmarkButton*)button { + return [self canEditBookmark:[button bookmarkNode]]; +} + +- (void)didDragBookmarkToTrash:(BookmarkButton*)button { + // TODO(mrossetti): Refactor BookmarkBarFolder common code. + // http://crbug.com/35966 + const BookmarkNode* node = [button bookmarkNode]; + if (node) { + const BookmarkNode* parent = node->GetParent(); + bookmarkModel_->Remove(parent, + parent->IndexOfChild(node)); + } +} + #pragma mark BookmarkButtonControllerProtocol // Close all bookmark folders. "Folder" here is the fake menu for @@ -2378,10 +2399,7 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { // If we are deleting a button whose folder is currently open, close it! [self closeAllBookmarkFolders]; } - NSRect poofFrame = [oldButton bounds]; - NSPoint poofPoint = NSMakePoint(NSMidX(poofFrame), NSMidY(poofFrame)); - poofPoint = [oldButton convertPoint:poofPoint toView:nil]; - poofPoint = [[oldButton window] convertBaseToScreen:poofPoint]; + NSPoint poofPoint = [oldButton screenLocationForRemoveAnimation]; NSRect oldFrame = [oldButton frame]; [oldButton setDelegate:nil]; [oldButton removeFromSuperview]; |