diff options
author | mrossetti@chromium.org <mrossetti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-18 17:11:02 +0000 |
---|---|---|
committer | mrossetti@chromium.org <mrossetti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-18 17:11:02 +0000 |
commit | 4ac884b18f10f3ae3a5daafbfa25f4545dd401ce (patch) | |
tree | daca6e7903d29ccf169723a88265574f1fa90d29 /chrome/browser/cocoa/bookmark_bar_folder_controller.mm | |
parent | b808eb6f0f47a7c4ad15dd8ec115404ce14b47b6 (diff) | |
download | chromium_src-4ac884b18f10f3ae3a5daafbfa25f4545dd401ce.zip chromium_src-4ac884b18f10f3ae3a5daafbfa25f4545dd401ce.tar.gz chromium_src-4ac884b18f10f3ae3a5daafbfa25f4545dd401ce.tar.bz2 |
Implement drag from bookmark manager to bookmark bar or a folder thereof. Implement drag of other bookmark and URL sources such as from the Desktop or a text selection.
BUG=39884,44228
TEST=Note: For all drag operations verify that the appropriate drop indicator is presented while dragging. When dragging onto a bookmark bar folder the folder button should be highlighted and, after a short delay, open into a menu. When dragging between folders or on top of a non-folder bookmark an insertion bar (vertical when in the bookmark bar, horizontal when in a folder menu) should be presented. For 'copy' moves the drag image should be adorned with a plus sign in a green circle. A non-copy move should show no such tag.
1) Drag a non-folder bookmark from the bookmark manager to the bookmark bar such that it falls on a non-folder bookmark. Verify that the bookmark is moved to be on the bar just before the bookmark upon which is was dropped.
2) Drag a folder bookmark from the manager to the bookmark bar such that it falls on a non-folder bookmark. Verify that the folder (as a folder) is moved to be on the bar just before the bookmark upon which is was dropped.
3) Drag a bookmark from the manager to a folder on the bookmark bar. Verify that the bookmark is added to the folder at the end and removed from the old location in the manager.
4) Drag a bookmark from the manager to a folder on the bookmark bar and wait for the folder to open and then drag to within the folder. Verify that dropping places the bookmark and removes it from the old location in the manager.
5) Drag a bookmark from the bar to the manager and verify that the manager now shows the dragged bookmark. (Note that this should be a 'move' but is currently a 'copy'. See http://crbug.com/44039.)
6) Drag a bookmark clipping from the Finder Desktop to the bookmark bar. Verify that it is added to the bar as a new bookmark.
7) Drag a bookmark clipping from the Finder Desktop to a folder on the bookmark bar and drop it within the folder menu. Verify that it is added to the folder as a new bookmark.
8) Create a URL in TextEdit or Stickies, select it and drag to the bookmark bar. Verify that it is added to the bar.
9) Create a URL in TextEdit or Stickies, select it and drag to a folder on the bookmark bar and drop it within the folder menu. Verify that it is added to the folder.
Review URL: http://codereview.chromium.org/2066001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47523 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/bookmark_bar_folder_controller.mm')
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_folder_controller.mm | 111 |
1 files changed, 99 insertions, 12 deletions
diff --git a/chrome/browser/cocoa/bookmark_bar_folder_controller.mm b/chrome/browser/cocoa/bookmark_bar_folder_controller.mm index bc9a75a..ddb79c6 100644 --- a/chrome/browser/cocoa/bookmark_bar_folder_controller.mm +++ b/chrome/browser/cocoa/bookmark_bar_folder_controller.mm @@ -63,6 +63,15 @@ const CGFloat kScrollWindowVerticalMargin = 0.0; // Show or hide the scroll arrows at the top/bottom of the window. - (void)showOrHideScrollArrows; +// |point| is in the base coordinate system of the destination window; +// it comes from an id<NSDraggingInfo>. |copy| is YES if a copy is to be +// made and inserted into the new location while leaving the bookmark in +// the old location, otherwise move the bookmark by removing from its old +// location and inserting into the new location. +- (BOOL)dragBookmark:(const BookmarkNode*)sourceNode + to:(NSPoint)point + copy:(BOOL)copy; + @end @interface BookmarkButton (BookmarkBarFolderMenuHighlighting) @@ -942,10 +951,7 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { // difference is accomodation for the "empty" button (which may not // exist in the future). // http://crbug.com/35966 -- (int)indexForDragOfButton:(BookmarkButton*)sourceButton - toPoint:(NSPoint)point { - DCHECK([sourceButton isKindOfClass:[BookmarkButton class]]); - +- (int)indexForDragToPoint:(NSPoint)point { // Identify which buttons we are between. For now, assume a button // location is at the center point of its view, and that an exact // match means "place before". @@ -986,6 +992,52 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { [[parentButton_ cell] startingChildIndex]); } +// More code which essentially duplicates that of BookmarkBarController. +// TODO(mrossetti,jrg): http://crbug.com/35966 +- (BOOL)addURLs:(NSArray*)urls withTitles:(NSArray*)titles at:(NSPoint)point { + DCHECK([urls count] == [titles count]); + BOOL nodesWereAdded = NO; + // Figure out where these new bookmarks nodes are to be added. + BookmarkButton* button = [self buttonForDroppingOnAtPoint:point]; + BookmarkModel* bookmarkModel = [self bookmarkModel]; + const BookmarkNode* destParent = NULL; + int destIndex = 0; + if ([button isFolder]) { + destParent = [button bookmarkNode]; + // Drop it at the end. + destIndex = [button bookmarkNode]->GetChildCount(); + } else { + // Else we're dropping somewhere in the folder, so find the right spot. + destParent = [parentButton_ bookmarkNode]; + destIndex = [self indexForDragToPoint:point]; + // Be careful if the number of buttons != number of nodes. + destIndex += [[parentButton_ cell] startingChildIndex]; + } + + // Create and add the new bookmark nodes. + size_t urlCount = [urls count]; + for (size_t i = 0; i < urlCount; ++i) { + // URLs come in several forms (see NSPasteboard+Utils.mm). + GURL gurl; + const char* string = [[urls objectAtIndex:i] UTF8String]; + if (string) + gurl = GURL(string); + if (!gurl.is_valid() && string) { + gurl = GURL([[NSString stringWithFormat:@"file://%s", string] + UTF8String]); + } + DCHECK(gurl.is_valid()); + if (gurl.is_valid()) { + bookmarkModel->AddURL(destParent, + destIndex++, + base::SysNSStringToWide([titles objectAtIndex:i]), + gurl); + nodesWereAdded = YES; + } + } + return nodesWereAdded; +} + - (BookmarkModel*)bookmarkModel { return [barController_ bookmarkModel]; } @@ -996,8 +1048,15 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { to:(NSPoint)point copy:(BOOL)copy { DCHECK([sourceButton isKindOfClass:[BookmarkButton class]]); - const BookmarkNode* sourceNode = [sourceButton bookmarkNode]; + return [self dragBookmark:sourceNode to:point copy:copy]; +} + +// TODO(jrg): Yet more code dup. +// http://crbug.com/35966 +- (BOOL)dragBookmark:(const BookmarkNode*)sourceNode + to:(NSPoint)point + copy:(BOOL)copy { DCHECK(sourceNode); // Drop destination. @@ -1014,7 +1073,7 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { } else { // Else we're dropping somewhere in the folder, so find the right spot. destParent = [parentButton_ bookmarkNode]; - destIndex = [self indexForDragOfButton:sourceButton toPoint:point]; + destIndex = [self indexForDragToPoint:point]; // Be careful if the number of buttons != number of nodes. destIndex += [[parentButton_ cell] startingChildIndex]; } @@ -1034,6 +1093,37 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { return wasCopiedOrMoved; } +// TODO(mrossetti,jrg): Identical to the same function in BookmarkBarController. +// http://crbug.com/35966 +- (std::vector<const BookmarkNode*>)retrieveBookmarkDragDataNodes { + std::vector<const BookmarkNode*> dragDataNodes; + BookmarkDragData dragData; + if(dragData.ReadFromDragClipboard()) { + BookmarkModel* bookmarkModel = [self bookmarkModel]; + Profile* profile = bookmarkModel->profile(); + std::vector<const BookmarkNode*> nodes(dragData.GetNodes(profile)); + dragDataNodes.assign(nodes.begin(), nodes.end()); + } + return dragDataNodes; +} + +// TODO(mrossetti,jrg): Identical to the same function in BookmarkBarController. +// http://crbug.com/35966 +- (BOOL)dragBookmarkData:(id<NSDraggingInfo>)info { + BOOL dragged = NO; + std::vector<const BookmarkNode*> nodes([self retrieveBookmarkDragDataNodes]); + if (nodes.size()) { + BOOL copy = !([info draggingSourceOperationMask] & NSDragOperationMove); + NSPoint dropPoint = [info draggingLocation]; + for (std::vector<const BookmarkNode*>::const_iterator it = nodes.begin(); + it != nodes.end(); ++it) { + const BookmarkNode* sourceNode = *it; + dragged = [self dragBookmark:sourceNode to:dropPoint copy:copy]; + } + } + return dragged; +} + // Return YES if we should show the drop indicator, else NO. // TODO(jrg): ARGH code dup! // http://crbug.com/35966 @@ -1047,10 +1137,9 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { // TODO(jrg): again we have code dup, sort of, with // bookmark_bar_controller.mm, but the axis is changed. // http://crbug.com/35966 -- (CGFloat)indicatorPosForDragOfButton:(BookmarkButton*)sourceButton - toPoint:(NSPoint)point { +- (CGFloat)indicatorPosForDragToPoint:(NSPoint)point { CGFloat y = 0; - int destIndex = [self indexForDragOfButton:sourceButton toPoint:point]; + int destIndex = [self indexForDragToPoint:point]; int numButtons = static_cast<int>([buttons_ count]); // If it's a drop strictly between existing buttons or at the very beginning @@ -1060,9 +1149,7 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { [buttons_ objectAtIndex:static_cast<NSUInteger>(destIndex)]; DCHECK(button); NSRect buttonFrame = [button frame]; - y = buttonFrame.origin.y + - buttonFrame.size.height + - 0.5 * bookmarks::kBookmarkVerticalPadding; + y = NSMaxY(buttonFrame) + 0.5 * bookmarks::kBookmarkVerticalPadding; // If it's a drop at the end (past the last button, if there are any) ... } else if (destIndex == numButtons) { |