diff options
author | snej@chromium.org <snej@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-05 23:09:30 +0000 |
---|---|---|
committer | snej@chromium.org <snej@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-05 23:09:30 +0000 |
commit | 080bf942acf0599e0d1811f07f5cef304cf355c4 (patch) | |
tree | 1e9104f67bd1c1ecf75b53f4c0003b02493979cf /chrome/browser/cocoa/bookmark_tree_controller_pasteboard.mm | |
parent | 0f28580a84220d218288bfdec6bb689b2e1b8d29 (diff) | |
download | chromium_src-080bf942acf0599e0d1811f07f5cef304cf355c4.zip chromium_src-080bf942acf0599e0d1811f07f5cef304cf355c4.tar.gz chromium_src-080bf942acf0599e0d1811f07f5cef304cf355c4.tar.bz2 |
Add additional pasteboard tests to BookmarkTreeControllerTest.
Split up one method in BookmarkTreeController to improve testability.
BUG=13149
TEST=BookmarkTreeControllerTest.MoveNodes
Review URL: http://codereview.chromium.org/523069
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35573 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/bookmark_tree_controller_pasteboard.mm')
-rw-r--r-- | chrome/browser/cocoa/bookmark_tree_controller_pasteboard.mm | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/chrome/browser/cocoa/bookmark_tree_controller_pasteboard.mm b/chrome/browser/cocoa/bookmark_tree_controller_pasteboard.mm index e617b4c..4ae5bab 100644 --- a/chrome/browser/cocoa/bookmark_tree_controller_pasteboard.mm +++ b/chrome/browser/cocoa/bookmark_tree_controller_pasteboard.mm @@ -111,13 +111,13 @@ static void flattenNode(const BookmarkNode* node, for (id item in items) { draggedNodes_.push_back([self nodeFromItem:item]); } - [pb addTypes:[NSArray arrayWithObject: kCustomPboardType] owner: self]; + [pb addTypes:[NSArray arrayWithObject:kCustomPboardType] owner:self]; [pb setData:[NSData data] forType:kCustomPboardType]; } // Add single URL: if ([urls count] == 1) { - [pb addTypes:[NSArray arrayWithObject: NSURLPboardType] owner: self]; + [pb addTypes:[NSArray arrayWithObject:NSURLPboardType] owner:self]; NSString* firstURLStr = [urls objectAtIndex:0]; [pb setString:firstURLStr forType:NSURLPboardType]; } @@ -339,34 +339,43 @@ static NSDictionary* makeBookmarkPlistEntry(NSString* name, NSString* urlStr) { return NSDragOperationCopy; } -// Actually handles the drop. -- (BOOL)outlineView:(NSOutlineView*)outlineView - acceptDrop:(id <NSDraggingInfo>)info - item:(id)item - childIndex:(NSInteger)childIndex -{ - NSPasteboard* pb = [info draggingPasteboard]; - +// Determine the parent to insert into and the child index to insert at. +- (const BookmarkNode*)nodeForDropOnItem:(id)item + proposedIndex:(NSInteger*)childIndex { const BookmarkNode* targetNode = [self nodeFromItem:item]; - - // Determine the parent to insert into and the child index to insert at. if (!targetNode->is_folder()) { // If our target is a leaf, and we are dropping on it. - if (childIndex == NSOutlineViewDropOnItemIndex) { - return NO; + if (*childIndex == NSOutlineViewDropOnItemIndex) { + return NULL; } else { // We will be dropping on the item's parent at the target index // of this child, plus one. const BookmarkNode* oldTargetNode = targetNode; targetNode = targetNode->GetParent(); - childIndex = targetNode->IndexOfChild(oldTargetNode) + 1; + *childIndex = targetNode->IndexOfChild(oldTargetNode) + 1; } } else { - if (childIndex == NSOutlineViewDropOnItemIndex) { + if (*childIndex == NSOutlineViewDropOnItemIndex) { // Insert it at the end, if we were dropping on it - childIndex = targetNode->GetChildCount(); + *childIndex = targetNode->GetChildCount(); } } + return targetNode; +} + +// Actually handles the drop. +- (BOOL)outlineView:(NSOutlineView*)outlineView + acceptDrop:(id <NSDraggingInfo>)info + item:(id)item + childIndex:(NSInteger)childIndex +{ + NSPasteboard* pb = [info draggingPasteboard]; + + // Determine the parent to insert into and the child index to insert at. + const BookmarkNode* targetNode = [self nodeForDropOnItem:item + proposedIndex:&childIndex]; + if (!targetNode) + return NO; if ([info draggingSource] == outlineView && [[pb types] containsObject:kCustomPboardType]) { @@ -394,7 +403,7 @@ static NSDictionary* makeBookmarkPlistEntry(NSString* name, NSString* urlStr) { } - (BOOL)pasteFromPasteboard:(NSPasteboard*)pb { - NSArray* plist = [self readPropertyListFromPasteboard: pb]; + NSArray* plist = [self readPropertyListFromPasteboard:pb]; if (!plist) return NO; |