diff --git a/mozilla/camino/BookmarksService.h b/mozilla/camino/BookmarksService.h index 457bfc19212..1d50129fcee 100644 --- a/mozilla/camino/BookmarksService.h +++ b/mozilla/camino/BookmarksService.h @@ -165,6 +165,7 @@ public: static BOOL DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem); static bool IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs); static bool PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs); + static bool PerformProxyDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSDictionary* data); static void DropURL(NSString* title, NSURL* url, BookmarkItem* parent, int index); diff --git a/mozilla/camino/BookmarksService.mm b/mozilla/camino/BookmarksService.mm index 6f4db7859f8..a8eb646e440 100644 --- a/mozilla/camino/BookmarksService.mm +++ b/mozilla/camino/BookmarksService.mm @@ -402,7 +402,10 @@ nsCOMPtr child; content->ChildAt(index, *getter_AddRefs(child)); - return mBookmarks->GetWrapperFor(child); + if ( child ) + return mBookmarks->GetWrapperFor(child); + + return nil; } - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item @@ -592,30 +595,11 @@ NSArray *draggedItems = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"]; BookmarksService::PerformBookmarkDrop(parent, index, draggedItems); return YES; - } else if ([types containsObject: @"MozURLType"]) { - NSDictionary* data = [[info draggingPasteboard] propertyListForType: @"MozURLType"]; - nsCOMPtr parentElt; - parentElt = do_QueryInterface([parent contentNode]); - - PRInt32 childCount = 0; - [item contentNode]->ChildCount(childCount); - - if (index >= childCount) - return NO; - - BookmarkItem* beforeItem; - beforeItem = [[ov dataSource] outlineView:ov child:index ofItem:item]; - - if (!beforeItem) - return NO; - - nsCOMPtr beforeElt; - beforeElt = do_QueryInterface([beforeItem contentNode]); - - nsAutoString url; url.AssignWithConversion([[data objectForKey:@"url"] cString]); - nsAutoString title; title.AssignWithConversion([[data objectForKey:@"title"] cString]); - BookmarksService::AddBookmarkToFolder(url, title, parentElt, beforeElt); - return YES; + } + else if ([types containsObject: @"MozURLType"]) { + NSDictionary* proxy = [[info draggingPasteboard] propertyListForType: @"MozURLType"]; + BookmarkItem* beforeItem = [self outlineView:ov child:index ofItem:item]; + return BookmarksService::PerformProxyDrop(parent, beforeItem, proxy); } return NO; @@ -871,6 +855,9 @@ BookmarksService::GetRootItem() { BookmarkItem* BookmarksService::GetWrapperFor(nsIContent* aContent) { + if ( !aContent ) + return nil; + if (!gDictionary) gDictionary = [[NSMutableDictionary alloc] initWithCapacity: 30]; @@ -1670,7 +1657,8 @@ BookmarksService::CreateIconForBookmark(nsIDOMElement* aElement) // Is searchItem equal to bookmark or bookmark's parent, grandparent, etc? BOOL -BookmarksService::DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem) { +BookmarksService::DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem) +{ nsCOMPtr search = [searchItem contentNode]; nsCOMPtr current = [bookmark contentNode]; nsCOMPtr root; @@ -1735,7 +1723,11 @@ BookmarksService::FilterOutDescendantsForDrag(NSArray* nodes) #endif bool -BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs) { +BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs) +{ + if ( !draggedIDs ) + return NO; + NSMutableArray *draggedItems = [NSMutableArray arrayWithCapacity: [draggedIDs count]]; BOOL toolbarRootMoving = NO; @@ -1775,7 +1767,27 @@ BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, N bool -BookmarksService::PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs) { +BookmarksService::PerformProxyDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSDictionary* data) +{ + if ( !data ) + return NO; + + nsCOMPtr parentElt; + parentElt = do_QueryInterface([parentItem contentNode]); + + nsCOMPtr beforeElt; + beforeElt = do_QueryInterface([beforeItem contentNode]); + + nsAutoString url; url.AssignWithConversion([[data objectForKey:@"url"] cString]); + nsAutoString title; title.AssignWithConversion([[data objectForKey:@"title"] cString]); + BookmarksService::AddBookmarkToFolder(url, title, parentElt, beforeElt); + return YES; +} + + +bool +BookmarksService::PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs) +{ NSEnumerator *enumerator = [draggedIDs reverseObjectEnumerator]; NSNumber *contentID; diff --git a/mozilla/camino/CHBookmarksToolbar.mm b/mozilla/camino/CHBookmarksToolbar.mm index ce52f8d73b9..df33cb10c03 100644 --- a/mozilla/camino/CHBookmarksToolbar.mm +++ b/mozilla/camino/CHBookmarksToolbar.mm @@ -71,7 +71,7 @@ // The personal toolbar is 21 pixels tall. The bottom two pixels // are a separator. [[NSColor colorWithCalibratedWhite: 0.90 alpha: 1.0] set]; - NSRectFill(NSMakeRect(aRect.origin.x, [self bounds].size.height-2, aRect.size.width, [self bounds].size.height)); + //NSRectFill(NSMakeRect(aRect.origin.x, [self bounds].size.height-2, aRect.size.width, [self bounds].size.height)); } // The buttons will paint themselves. Just call our base class method. @@ -103,7 +103,7 @@ } if ([self isShown]) - [self reflowButtons]; + [self reflowButtons]; } -(void)addButton: (nsIDOMElement*)aElt atIndex: (int)aIndex @@ -320,63 +320,22 @@ - (BOOL)prepareForDragOperation:(id )sender { - BookmarkItem* parent; - int index = 0; - NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"]; - - // If we are dropping into a folder - if (mDragInsertionPosition == BookmarksService::CHInsertInto) { - nsCOMPtr parentElt = [mDragInsertionButton element]; - nsCOMPtr parentContent(do_QueryInterface(parentElt)); - parent = BookmarksService::GetWrapperFor(parentContent); - index = 0; - } - - // If we are dropping onto the toolbar directly - else if (mDragInsertionPosition == BookmarksService::CHInsertBefore || - mDragInsertionPosition == BookmarksService::CHInsertAfter) { - nsCOMPtr rootElt = BookmarksService::gToolbarRoot; - nsCOMPtr rootContent(do_QueryInterface(rootElt)); - parent = BookmarksService::GetWrapperFor(rootContent); - index = [mButtons indexOfObject: mDragInsertionButton]; - if (index == NSNotFound) - rootContent->ChildCount(index); - else if (mDragInsertionPosition == BookmarksService::CHInsertAfter) - index++; - } else { - mDragInsertionButton = nil; - mDragInsertionPosition = BookmarksService::CHInsertNone; - [self setNeedsDisplay:YES]; - return NO; - } - - bool valid = BookmarksService::IsBookmarkDropValid(parent, index, draggedItems); - if (!valid) { - mDragInsertionButton = nil; - mDragInsertionPosition = BookmarksService::CHInsertNone; - [self setNeedsDisplay:YES]; - } - - return valid; + return YES; } - (BOOL)performDragOperation:(id )sender { - BookmarkItem* parent; + BookmarkItem* parent = nsnull; int index = 0; - NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"]; - // If we are dropping into a folder - if (mDragInsertionPosition == BookmarksService::CHInsertInto) { + if (mDragInsertionPosition == BookmarksService::CHInsertInto) { // drop onto folder nsCOMPtr parentElt = [mDragInsertionButton element]; nsCOMPtr parentContent(do_QueryInterface(parentElt)); parent = BookmarksService::GetWrapperFor(parentContent); index = 0; } - - // If we are dropping onto the toolbar directly else if (mDragInsertionPosition == BookmarksService::CHInsertBefore || - mDragInsertionPosition == BookmarksService::CHInsertAfter) { + mDragInsertionPosition == BookmarksService::CHInsertAfter) { // drop onto toolbar nsCOMPtr rootElt = BookmarksService::gToolbarRoot; nsCOMPtr rootContent(do_QueryInterface(rootElt)); parent = BookmarksService::GetWrapperFor(rootContent); @@ -392,7 +351,16 @@ return NO; } - BookmarksService::PerformBookmarkDrop(parent, index, draggedItems); + NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"]; + if ( draggedItems ) + BookmarksService::PerformBookmarkDrop(parent, index, draggedItems); + else { + NSDictionary* proxy = [[sender draggingPasteboard] propertyListForType: @"MozURLType"]; + nsCOMPtr beforeContent; + [parent contentNode]->ChildAt(index, *getter_AddRefs(beforeContent)); + BookmarkItem* beforeItem = mBookmarks->GetWrapperFor(beforeContent); // can handle nil content + BookmarksService::PerformProxyDrop(parent, beforeItem, proxy); + } mDragInsertionButton = nil; mDragInsertionPosition = BookmarksService::CHInsertNone; diff --git a/mozilla/camino/src/bookmarks/BookmarksService.h b/mozilla/camino/src/bookmarks/BookmarksService.h index 457bfc19212..1d50129fcee 100644 --- a/mozilla/camino/src/bookmarks/BookmarksService.h +++ b/mozilla/camino/src/bookmarks/BookmarksService.h @@ -165,6 +165,7 @@ public: static BOOL DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem); static bool IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs); static bool PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs); + static bool PerformProxyDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSDictionary* data); static void DropURL(NSString* title, NSURL* url, BookmarkItem* parent, int index); diff --git a/mozilla/camino/src/bookmarks/BookmarksService.mm b/mozilla/camino/src/bookmarks/BookmarksService.mm index 6f4db7859f8..a8eb646e440 100644 --- a/mozilla/camino/src/bookmarks/BookmarksService.mm +++ b/mozilla/camino/src/bookmarks/BookmarksService.mm @@ -402,7 +402,10 @@ nsCOMPtr child; content->ChildAt(index, *getter_AddRefs(child)); - return mBookmarks->GetWrapperFor(child); + if ( child ) + return mBookmarks->GetWrapperFor(child); + + return nil; } - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item @@ -592,30 +595,11 @@ NSArray *draggedItems = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"]; BookmarksService::PerformBookmarkDrop(parent, index, draggedItems); return YES; - } else if ([types containsObject: @"MozURLType"]) { - NSDictionary* data = [[info draggingPasteboard] propertyListForType: @"MozURLType"]; - nsCOMPtr parentElt; - parentElt = do_QueryInterface([parent contentNode]); - - PRInt32 childCount = 0; - [item contentNode]->ChildCount(childCount); - - if (index >= childCount) - return NO; - - BookmarkItem* beforeItem; - beforeItem = [[ov dataSource] outlineView:ov child:index ofItem:item]; - - if (!beforeItem) - return NO; - - nsCOMPtr beforeElt; - beforeElt = do_QueryInterface([beforeItem contentNode]); - - nsAutoString url; url.AssignWithConversion([[data objectForKey:@"url"] cString]); - nsAutoString title; title.AssignWithConversion([[data objectForKey:@"title"] cString]); - BookmarksService::AddBookmarkToFolder(url, title, parentElt, beforeElt); - return YES; + } + else if ([types containsObject: @"MozURLType"]) { + NSDictionary* proxy = [[info draggingPasteboard] propertyListForType: @"MozURLType"]; + BookmarkItem* beforeItem = [self outlineView:ov child:index ofItem:item]; + return BookmarksService::PerformProxyDrop(parent, beforeItem, proxy); } return NO; @@ -871,6 +855,9 @@ BookmarksService::GetRootItem() { BookmarkItem* BookmarksService::GetWrapperFor(nsIContent* aContent) { + if ( !aContent ) + return nil; + if (!gDictionary) gDictionary = [[NSMutableDictionary alloc] initWithCapacity: 30]; @@ -1670,7 +1657,8 @@ BookmarksService::CreateIconForBookmark(nsIDOMElement* aElement) // Is searchItem equal to bookmark or bookmark's parent, grandparent, etc? BOOL -BookmarksService::DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem) { +BookmarksService::DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem) +{ nsCOMPtr search = [searchItem contentNode]; nsCOMPtr current = [bookmark contentNode]; nsCOMPtr root; @@ -1735,7 +1723,11 @@ BookmarksService::FilterOutDescendantsForDrag(NSArray* nodes) #endif bool -BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs) { +BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs) +{ + if ( !draggedIDs ) + return NO; + NSMutableArray *draggedItems = [NSMutableArray arrayWithCapacity: [draggedIDs count]]; BOOL toolbarRootMoving = NO; @@ -1775,7 +1767,27 @@ BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, N bool -BookmarksService::PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs) { +BookmarksService::PerformProxyDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSDictionary* data) +{ + if ( !data ) + return NO; + + nsCOMPtr parentElt; + parentElt = do_QueryInterface([parentItem contentNode]); + + nsCOMPtr beforeElt; + beforeElt = do_QueryInterface([beforeItem contentNode]); + + nsAutoString url; url.AssignWithConversion([[data objectForKey:@"url"] cString]); + nsAutoString title; title.AssignWithConversion([[data objectForKey:@"title"] cString]); + BookmarksService::AddBookmarkToFolder(url, title, parentElt, beforeElt); + return YES; +} + + +bool +BookmarksService::PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs) +{ NSEnumerator *enumerator = [draggedIDs reverseObjectEnumerator]; NSNumber *contentID; diff --git a/mozilla/camino/src/bookmarks/BookmarksToolbar.mm b/mozilla/camino/src/bookmarks/BookmarksToolbar.mm index ce52f8d73b9..df33cb10c03 100644 --- a/mozilla/camino/src/bookmarks/BookmarksToolbar.mm +++ b/mozilla/camino/src/bookmarks/BookmarksToolbar.mm @@ -71,7 +71,7 @@ // The personal toolbar is 21 pixels tall. The bottom two pixels // are a separator. [[NSColor colorWithCalibratedWhite: 0.90 alpha: 1.0] set]; - NSRectFill(NSMakeRect(aRect.origin.x, [self bounds].size.height-2, aRect.size.width, [self bounds].size.height)); + //NSRectFill(NSMakeRect(aRect.origin.x, [self bounds].size.height-2, aRect.size.width, [self bounds].size.height)); } // The buttons will paint themselves. Just call our base class method. @@ -103,7 +103,7 @@ } if ([self isShown]) - [self reflowButtons]; + [self reflowButtons]; } -(void)addButton: (nsIDOMElement*)aElt atIndex: (int)aIndex @@ -320,63 +320,22 @@ - (BOOL)prepareForDragOperation:(id )sender { - BookmarkItem* parent; - int index = 0; - NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"]; - - // If we are dropping into a folder - if (mDragInsertionPosition == BookmarksService::CHInsertInto) { - nsCOMPtr parentElt = [mDragInsertionButton element]; - nsCOMPtr parentContent(do_QueryInterface(parentElt)); - parent = BookmarksService::GetWrapperFor(parentContent); - index = 0; - } - - // If we are dropping onto the toolbar directly - else if (mDragInsertionPosition == BookmarksService::CHInsertBefore || - mDragInsertionPosition == BookmarksService::CHInsertAfter) { - nsCOMPtr rootElt = BookmarksService::gToolbarRoot; - nsCOMPtr rootContent(do_QueryInterface(rootElt)); - parent = BookmarksService::GetWrapperFor(rootContent); - index = [mButtons indexOfObject: mDragInsertionButton]; - if (index == NSNotFound) - rootContent->ChildCount(index); - else if (mDragInsertionPosition == BookmarksService::CHInsertAfter) - index++; - } else { - mDragInsertionButton = nil; - mDragInsertionPosition = BookmarksService::CHInsertNone; - [self setNeedsDisplay:YES]; - return NO; - } - - bool valid = BookmarksService::IsBookmarkDropValid(parent, index, draggedItems); - if (!valid) { - mDragInsertionButton = nil; - mDragInsertionPosition = BookmarksService::CHInsertNone; - [self setNeedsDisplay:YES]; - } - - return valid; + return YES; } - (BOOL)performDragOperation:(id )sender { - BookmarkItem* parent; + BookmarkItem* parent = nsnull; int index = 0; - NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"]; - // If we are dropping into a folder - if (mDragInsertionPosition == BookmarksService::CHInsertInto) { + if (mDragInsertionPosition == BookmarksService::CHInsertInto) { // drop onto folder nsCOMPtr parentElt = [mDragInsertionButton element]; nsCOMPtr parentContent(do_QueryInterface(parentElt)); parent = BookmarksService::GetWrapperFor(parentContent); index = 0; } - - // If we are dropping onto the toolbar directly else if (mDragInsertionPosition == BookmarksService::CHInsertBefore || - mDragInsertionPosition == BookmarksService::CHInsertAfter) { + mDragInsertionPosition == BookmarksService::CHInsertAfter) { // drop onto toolbar nsCOMPtr rootElt = BookmarksService::gToolbarRoot; nsCOMPtr rootContent(do_QueryInterface(rootElt)); parent = BookmarksService::GetWrapperFor(rootContent); @@ -392,7 +351,16 @@ return NO; } - BookmarksService::PerformBookmarkDrop(parent, index, draggedItems); + NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"]; + if ( draggedItems ) + BookmarksService::PerformBookmarkDrop(parent, index, draggedItems); + else { + NSDictionary* proxy = [[sender draggingPasteboard] propertyListForType: @"MozURLType"]; + nsCOMPtr beforeContent; + [parent contentNode]->ChildAt(index, *getter_AddRefs(beforeContent)); + BookmarkItem* beforeItem = mBookmarks->GetWrapperFor(beforeContent); // can handle nil content + BookmarksService::PerformProxyDrop(parent, beforeItem, proxy); + } mDragInsertionButton = nil; mDragInsertionPosition = BookmarksService::CHInsertNone; diff --git a/mozilla/chimera/BookmarksService.h b/mozilla/chimera/BookmarksService.h index 457bfc19212..1d50129fcee 100644 --- a/mozilla/chimera/BookmarksService.h +++ b/mozilla/chimera/BookmarksService.h @@ -165,6 +165,7 @@ public: static BOOL DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem); static bool IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs); static bool PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs); + static bool PerformProxyDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSDictionary* data); static void DropURL(NSString* title, NSURL* url, BookmarkItem* parent, int index); diff --git a/mozilla/chimera/BookmarksService.mm b/mozilla/chimera/BookmarksService.mm index 6f4db7859f8..a8eb646e440 100644 --- a/mozilla/chimera/BookmarksService.mm +++ b/mozilla/chimera/BookmarksService.mm @@ -402,7 +402,10 @@ nsCOMPtr child; content->ChildAt(index, *getter_AddRefs(child)); - return mBookmarks->GetWrapperFor(child); + if ( child ) + return mBookmarks->GetWrapperFor(child); + + return nil; } - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item @@ -592,30 +595,11 @@ NSArray *draggedItems = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"]; BookmarksService::PerformBookmarkDrop(parent, index, draggedItems); return YES; - } else if ([types containsObject: @"MozURLType"]) { - NSDictionary* data = [[info draggingPasteboard] propertyListForType: @"MozURLType"]; - nsCOMPtr parentElt; - parentElt = do_QueryInterface([parent contentNode]); - - PRInt32 childCount = 0; - [item contentNode]->ChildCount(childCount); - - if (index >= childCount) - return NO; - - BookmarkItem* beforeItem; - beforeItem = [[ov dataSource] outlineView:ov child:index ofItem:item]; - - if (!beforeItem) - return NO; - - nsCOMPtr beforeElt; - beforeElt = do_QueryInterface([beforeItem contentNode]); - - nsAutoString url; url.AssignWithConversion([[data objectForKey:@"url"] cString]); - nsAutoString title; title.AssignWithConversion([[data objectForKey:@"title"] cString]); - BookmarksService::AddBookmarkToFolder(url, title, parentElt, beforeElt); - return YES; + } + else if ([types containsObject: @"MozURLType"]) { + NSDictionary* proxy = [[info draggingPasteboard] propertyListForType: @"MozURLType"]; + BookmarkItem* beforeItem = [self outlineView:ov child:index ofItem:item]; + return BookmarksService::PerformProxyDrop(parent, beforeItem, proxy); } return NO; @@ -871,6 +855,9 @@ BookmarksService::GetRootItem() { BookmarkItem* BookmarksService::GetWrapperFor(nsIContent* aContent) { + if ( !aContent ) + return nil; + if (!gDictionary) gDictionary = [[NSMutableDictionary alloc] initWithCapacity: 30]; @@ -1670,7 +1657,8 @@ BookmarksService::CreateIconForBookmark(nsIDOMElement* aElement) // Is searchItem equal to bookmark or bookmark's parent, grandparent, etc? BOOL -BookmarksService::DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem) { +BookmarksService::DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem) +{ nsCOMPtr search = [searchItem contentNode]; nsCOMPtr current = [bookmark contentNode]; nsCOMPtr root; @@ -1735,7 +1723,11 @@ BookmarksService::FilterOutDescendantsForDrag(NSArray* nodes) #endif bool -BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs) { +BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs) +{ + if ( !draggedIDs ) + return NO; + NSMutableArray *draggedItems = [NSMutableArray arrayWithCapacity: [draggedIDs count]]; BOOL toolbarRootMoving = NO; @@ -1775,7 +1767,27 @@ BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, N bool -BookmarksService::PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs) { +BookmarksService::PerformProxyDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSDictionary* data) +{ + if ( !data ) + return NO; + + nsCOMPtr parentElt; + parentElt = do_QueryInterface([parentItem contentNode]); + + nsCOMPtr beforeElt; + beforeElt = do_QueryInterface([beforeItem contentNode]); + + nsAutoString url; url.AssignWithConversion([[data objectForKey:@"url"] cString]); + nsAutoString title; title.AssignWithConversion([[data objectForKey:@"title"] cString]); + BookmarksService::AddBookmarkToFolder(url, title, parentElt, beforeElt); + return YES; +} + + +bool +BookmarksService::PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs) +{ NSEnumerator *enumerator = [draggedIDs reverseObjectEnumerator]; NSNumber *contentID; diff --git a/mozilla/chimera/CHBookmarksToolbar.mm b/mozilla/chimera/CHBookmarksToolbar.mm index ce52f8d73b9..df33cb10c03 100644 --- a/mozilla/chimera/CHBookmarksToolbar.mm +++ b/mozilla/chimera/CHBookmarksToolbar.mm @@ -71,7 +71,7 @@ // The personal toolbar is 21 pixels tall. The bottom two pixels // are a separator. [[NSColor colorWithCalibratedWhite: 0.90 alpha: 1.0] set]; - NSRectFill(NSMakeRect(aRect.origin.x, [self bounds].size.height-2, aRect.size.width, [self bounds].size.height)); + //NSRectFill(NSMakeRect(aRect.origin.x, [self bounds].size.height-2, aRect.size.width, [self bounds].size.height)); } // The buttons will paint themselves. Just call our base class method. @@ -103,7 +103,7 @@ } if ([self isShown]) - [self reflowButtons]; + [self reflowButtons]; } -(void)addButton: (nsIDOMElement*)aElt atIndex: (int)aIndex @@ -320,63 +320,22 @@ - (BOOL)prepareForDragOperation:(id )sender { - BookmarkItem* parent; - int index = 0; - NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"]; - - // If we are dropping into a folder - if (mDragInsertionPosition == BookmarksService::CHInsertInto) { - nsCOMPtr parentElt = [mDragInsertionButton element]; - nsCOMPtr parentContent(do_QueryInterface(parentElt)); - parent = BookmarksService::GetWrapperFor(parentContent); - index = 0; - } - - // If we are dropping onto the toolbar directly - else if (mDragInsertionPosition == BookmarksService::CHInsertBefore || - mDragInsertionPosition == BookmarksService::CHInsertAfter) { - nsCOMPtr rootElt = BookmarksService::gToolbarRoot; - nsCOMPtr rootContent(do_QueryInterface(rootElt)); - parent = BookmarksService::GetWrapperFor(rootContent); - index = [mButtons indexOfObject: mDragInsertionButton]; - if (index == NSNotFound) - rootContent->ChildCount(index); - else if (mDragInsertionPosition == BookmarksService::CHInsertAfter) - index++; - } else { - mDragInsertionButton = nil; - mDragInsertionPosition = BookmarksService::CHInsertNone; - [self setNeedsDisplay:YES]; - return NO; - } - - bool valid = BookmarksService::IsBookmarkDropValid(parent, index, draggedItems); - if (!valid) { - mDragInsertionButton = nil; - mDragInsertionPosition = BookmarksService::CHInsertNone; - [self setNeedsDisplay:YES]; - } - - return valid; + return YES; } - (BOOL)performDragOperation:(id )sender { - BookmarkItem* parent; + BookmarkItem* parent = nsnull; int index = 0; - NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"]; - // If we are dropping into a folder - if (mDragInsertionPosition == BookmarksService::CHInsertInto) { + if (mDragInsertionPosition == BookmarksService::CHInsertInto) { // drop onto folder nsCOMPtr parentElt = [mDragInsertionButton element]; nsCOMPtr parentContent(do_QueryInterface(parentElt)); parent = BookmarksService::GetWrapperFor(parentContent); index = 0; } - - // If we are dropping onto the toolbar directly else if (mDragInsertionPosition == BookmarksService::CHInsertBefore || - mDragInsertionPosition == BookmarksService::CHInsertAfter) { + mDragInsertionPosition == BookmarksService::CHInsertAfter) { // drop onto toolbar nsCOMPtr rootElt = BookmarksService::gToolbarRoot; nsCOMPtr rootContent(do_QueryInterface(rootElt)); parent = BookmarksService::GetWrapperFor(rootContent); @@ -392,7 +351,16 @@ return NO; } - BookmarksService::PerformBookmarkDrop(parent, index, draggedItems); + NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"]; + if ( draggedItems ) + BookmarksService::PerformBookmarkDrop(parent, index, draggedItems); + else { + NSDictionary* proxy = [[sender draggingPasteboard] propertyListForType: @"MozURLType"]; + nsCOMPtr beforeContent; + [parent contentNode]->ChildAt(index, *getter_AddRefs(beforeContent)); + BookmarkItem* beforeItem = mBookmarks->GetWrapperFor(beforeContent); // can handle nil content + BookmarksService::PerformProxyDrop(parent, beforeItem, proxy); + } mDragInsertionButton = nil; mDragInsertionPosition = BookmarksService::CHInsertNone; diff --git a/mozilla/chimera/src/bookmarks/BookmarksService.h b/mozilla/chimera/src/bookmarks/BookmarksService.h index 457bfc19212..1d50129fcee 100644 --- a/mozilla/chimera/src/bookmarks/BookmarksService.h +++ b/mozilla/chimera/src/bookmarks/BookmarksService.h @@ -165,6 +165,7 @@ public: static BOOL DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem); static bool IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs); static bool PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs); + static bool PerformProxyDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSDictionary* data); static void DropURL(NSString* title, NSURL* url, BookmarkItem* parent, int index); diff --git a/mozilla/chimera/src/bookmarks/BookmarksService.mm b/mozilla/chimera/src/bookmarks/BookmarksService.mm index 6f4db7859f8..a8eb646e440 100644 --- a/mozilla/chimera/src/bookmarks/BookmarksService.mm +++ b/mozilla/chimera/src/bookmarks/BookmarksService.mm @@ -402,7 +402,10 @@ nsCOMPtr child; content->ChildAt(index, *getter_AddRefs(child)); - return mBookmarks->GetWrapperFor(child); + if ( child ) + return mBookmarks->GetWrapperFor(child); + + return nil; } - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item @@ -592,30 +595,11 @@ NSArray *draggedItems = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"]; BookmarksService::PerformBookmarkDrop(parent, index, draggedItems); return YES; - } else if ([types containsObject: @"MozURLType"]) { - NSDictionary* data = [[info draggingPasteboard] propertyListForType: @"MozURLType"]; - nsCOMPtr parentElt; - parentElt = do_QueryInterface([parent contentNode]); - - PRInt32 childCount = 0; - [item contentNode]->ChildCount(childCount); - - if (index >= childCount) - return NO; - - BookmarkItem* beforeItem; - beforeItem = [[ov dataSource] outlineView:ov child:index ofItem:item]; - - if (!beforeItem) - return NO; - - nsCOMPtr beforeElt; - beforeElt = do_QueryInterface([beforeItem contentNode]); - - nsAutoString url; url.AssignWithConversion([[data objectForKey:@"url"] cString]); - nsAutoString title; title.AssignWithConversion([[data objectForKey:@"title"] cString]); - BookmarksService::AddBookmarkToFolder(url, title, parentElt, beforeElt); - return YES; + } + else if ([types containsObject: @"MozURLType"]) { + NSDictionary* proxy = [[info draggingPasteboard] propertyListForType: @"MozURLType"]; + BookmarkItem* beforeItem = [self outlineView:ov child:index ofItem:item]; + return BookmarksService::PerformProxyDrop(parent, beforeItem, proxy); } return NO; @@ -871,6 +855,9 @@ BookmarksService::GetRootItem() { BookmarkItem* BookmarksService::GetWrapperFor(nsIContent* aContent) { + if ( !aContent ) + return nil; + if (!gDictionary) gDictionary = [[NSMutableDictionary alloc] initWithCapacity: 30]; @@ -1670,7 +1657,8 @@ BookmarksService::CreateIconForBookmark(nsIDOMElement* aElement) // Is searchItem equal to bookmark or bookmark's parent, grandparent, etc? BOOL -BookmarksService::DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem) { +BookmarksService::DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem) +{ nsCOMPtr search = [searchItem contentNode]; nsCOMPtr current = [bookmark contentNode]; nsCOMPtr root; @@ -1735,7 +1723,11 @@ BookmarksService::FilterOutDescendantsForDrag(NSArray* nodes) #endif bool -BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs) { +BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs) +{ + if ( !draggedIDs ) + return NO; + NSMutableArray *draggedItems = [NSMutableArray arrayWithCapacity: [draggedIDs count]]; BOOL toolbarRootMoving = NO; @@ -1775,7 +1767,27 @@ BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, N bool -BookmarksService::PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs) { +BookmarksService::PerformProxyDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSDictionary* data) +{ + if ( !data ) + return NO; + + nsCOMPtr parentElt; + parentElt = do_QueryInterface([parentItem contentNode]); + + nsCOMPtr beforeElt; + beforeElt = do_QueryInterface([beforeItem contentNode]); + + nsAutoString url; url.AssignWithConversion([[data objectForKey:@"url"] cString]); + nsAutoString title; title.AssignWithConversion([[data objectForKey:@"title"] cString]); + BookmarksService::AddBookmarkToFolder(url, title, parentElt, beforeElt); + return YES; +} + + +bool +BookmarksService::PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs) +{ NSEnumerator *enumerator = [draggedIDs reverseObjectEnumerator]; NSNumber *contentID; diff --git a/mozilla/chimera/src/bookmarks/BookmarksToolbar.mm b/mozilla/chimera/src/bookmarks/BookmarksToolbar.mm index ce52f8d73b9..df33cb10c03 100644 --- a/mozilla/chimera/src/bookmarks/BookmarksToolbar.mm +++ b/mozilla/chimera/src/bookmarks/BookmarksToolbar.mm @@ -71,7 +71,7 @@ // The personal toolbar is 21 pixels tall. The bottom two pixels // are a separator. [[NSColor colorWithCalibratedWhite: 0.90 alpha: 1.0] set]; - NSRectFill(NSMakeRect(aRect.origin.x, [self bounds].size.height-2, aRect.size.width, [self bounds].size.height)); + //NSRectFill(NSMakeRect(aRect.origin.x, [self bounds].size.height-2, aRect.size.width, [self bounds].size.height)); } // The buttons will paint themselves. Just call our base class method. @@ -103,7 +103,7 @@ } if ([self isShown]) - [self reflowButtons]; + [self reflowButtons]; } -(void)addButton: (nsIDOMElement*)aElt atIndex: (int)aIndex @@ -320,63 +320,22 @@ - (BOOL)prepareForDragOperation:(id )sender { - BookmarkItem* parent; - int index = 0; - NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"]; - - // If we are dropping into a folder - if (mDragInsertionPosition == BookmarksService::CHInsertInto) { - nsCOMPtr parentElt = [mDragInsertionButton element]; - nsCOMPtr parentContent(do_QueryInterface(parentElt)); - parent = BookmarksService::GetWrapperFor(parentContent); - index = 0; - } - - // If we are dropping onto the toolbar directly - else if (mDragInsertionPosition == BookmarksService::CHInsertBefore || - mDragInsertionPosition == BookmarksService::CHInsertAfter) { - nsCOMPtr rootElt = BookmarksService::gToolbarRoot; - nsCOMPtr rootContent(do_QueryInterface(rootElt)); - parent = BookmarksService::GetWrapperFor(rootContent); - index = [mButtons indexOfObject: mDragInsertionButton]; - if (index == NSNotFound) - rootContent->ChildCount(index); - else if (mDragInsertionPosition == BookmarksService::CHInsertAfter) - index++; - } else { - mDragInsertionButton = nil; - mDragInsertionPosition = BookmarksService::CHInsertNone; - [self setNeedsDisplay:YES]; - return NO; - } - - bool valid = BookmarksService::IsBookmarkDropValid(parent, index, draggedItems); - if (!valid) { - mDragInsertionButton = nil; - mDragInsertionPosition = BookmarksService::CHInsertNone; - [self setNeedsDisplay:YES]; - } - - return valid; + return YES; } - (BOOL)performDragOperation:(id )sender { - BookmarkItem* parent; + BookmarkItem* parent = nsnull; int index = 0; - NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"]; - // If we are dropping into a folder - if (mDragInsertionPosition == BookmarksService::CHInsertInto) { + if (mDragInsertionPosition == BookmarksService::CHInsertInto) { // drop onto folder nsCOMPtr parentElt = [mDragInsertionButton element]; nsCOMPtr parentContent(do_QueryInterface(parentElt)); parent = BookmarksService::GetWrapperFor(parentContent); index = 0; } - - // If we are dropping onto the toolbar directly else if (mDragInsertionPosition == BookmarksService::CHInsertBefore || - mDragInsertionPosition == BookmarksService::CHInsertAfter) { + mDragInsertionPosition == BookmarksService::CHInsertAfter) { // drop onto toolbar nsCOMPtr rootElt = BookmarksService::gToolbarRoot; nsCOMPtr rootContent(do_QueryInterface(rootElt)); parent = BookmarksService::GetWrapperFor(rootContent); @@ -392,7 +351,16 @@ return NO; } - BookmarksService::PerformBookmarkDrop(parent, index, draggedItems); + NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"]; + if ( draggedItems ) + BookmarksService::PerformBookmarkDrop(parent, index, draggedItems); + else { + NSDictionary* proxy = [[sender draggingPasteboard] propertyListForType: @"MozURLType"]; + nsCOMPtr beforeContent; + [parent contentNode]->ChildAt(index, *getter_AddRefs(beforeContent)); + BookmarkItem* beforeItem = mBookmarks->GetWrapperFor(beforeContent); // can handle nil content + BookmarksService::PerformProxyDrop(parent, beforeItem, proxy); + } mDragInsertionButton = nil; mDragInsertionPosition = BookmarksService::CHInsertNone;