зеркало из https://github.com/mozilla/pjs.git
Fix for bug 160312: avoid crashes when dragging bookmark folders from the sidebar onto themselves in the bookmarks toolbar.
This commit is contained in:
Родитель
85bd093913
Коммит
92d3202cb3
|
@ -1251,14 +1251,17 @@ BookmarksService::PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray*
|
|||
}
|
||||
|
||||
// remove it from the tree
|
||||
if (draggedParent)
|
||||
draggedParent->RemoveChildAt(existingIndex, PR_TRUE);
|
||||
BookmarkRemoved(draggedParent, draggedNode, false);
|
||||
|
||||
// insert into new position
|
||||
if (proposedParent)
|
||||
proposedParent->InsertChildAt(draggedNode, index, PR_TRUE, PR_TRUE);
|
||||
BookmarkAdded(proposedParent, draggedNode, false);
|
||||
if (draggedNode != proposedParent) // paranoia. This should never happen
|
||||
{
|
||||
if (draggedParent)
|
||||
draggedParent->RemoveChildAt(existingIndex, PR_TRUE);
|
||||
BookmarkRemoved(draggedParent, draggedNode, false);
|
||||
|
||||
// insert into new position
|
||||
if (proposedParent)
|
||||
proposedParent->InsertChildAt(draggedNode, index, PR_TRUE, PR_TRUE);
|
||||
BookmarkAdded(proposedParent, draggedNode, false);
|
||||
}
|
||||
}
|
||||
|
||||
FlushBookmarks();
|
||||
|
|
|
@ -308,10 +308,47 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (BOOL)dropDestinationValid:(NSPasteboard*)draggingPasteboard
|
||||
{
|
||||
NSArray* types = [draggingPasteboard types];
|
||||
|
||||
if ([types containsObject: @"MozBookmarkType"])
|
||||
{
|
||||
NSArray *draggedIDs = [draggingPasteboard propertyListForType: @"MozBookmarkType"];
|
||||
|
||||
nsCOMPtr<nsIContent> destinationContent;
|
||||
int index = 0;
|
||||
|
||||
if (mDragInsertionPosition == BookmarksService::CHInsertInto) // drop onto folder
|
||||
{
|
||||
nsCOMPtr<nsIDOMElement> parentElt = [mDragInsertionButton element];
|
||||
destinationContent = do_QueryInterface(parentElt);
|
||||
index = 0;
|
||||
}
|
||||
else if (mDragInsertionPosition == BookmarksService::CHInsertBefore ||
|
||||
mDragInsertionPosition == BookmarksService::CHInsertAfter) // drop onto toolbar
|
||||
{
|
||||
nsCOMPtr<nsIDOMElement> toolbarRoot = BookmarksService::gToolbarRoot;
|
||||
destinationContent = do_QueryInterface(toolbarRoot);
|
||||
index = [mButtons indexOfObject: mDragInsertionButton];
|
||||
}
|
||||
|
||||
BookmarkItem* toolbarFolderItem = BookmarksService::GetWrapperFor(destinationContent);
|
||||
if (!BookmarksService::IsBookmarkDropValid(toolbarFolderItem, index, draggedIDs)) {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
// NSDraggingDestination ///////////
|
||||
|
||||
- (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender
|
||||
{
|
||||
if (![self dropDestinationValid:[sender draggingPasteboard]])
|
||||
return NSDragOperationNone;
|
||||
|
||||
return NSDragOperationGeneric;
|
||||
}
|
||||
|
||||
|
@ -329,6 +366,9 @@
|
|||
if (mDragInsertionPosition)
|
||||
[self setNeedsDisplayInRect:[self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]];
|
||||
|
||||
if (![self dropDestinationValid:[sender draggingPasteboard]])
|
||||
return NSDragOperationNone;
|
||||
|
||||
[self setButtonInsertionPoint:[sender draggingLocation]];
|
||||
|
||||
if (mDragInsertionPosition)
|
||||
|
|
|
@ -1251,14 +1251,17 @@ BookmarksService::PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray*
|
|||
}
|
||||
|
||||
// remove it from the tree
|
||||
if (draggedParent)
|
||||
draggedParent->RemoveChildAt(existingIndex, PR_TRUE);
|
||||
BookmarkRemoved(draggedParent, draggedNode, false);
|
||||
|
||||
// insert into new position
|
||||
if (proposedParent)
|
||||
proposedParent->InsertChildAt(draggedNode, index, PR_TRUE, PR_TRUE);
|
||||
BookmarkAdded(proposedParent, draggedNode, false);
|
||||
if (draggedNode != proposedParent) // paranoia. This should never happen
|
||||
{
|
||||
if (draggedParent)
|
||||
draggedParent->RemoveChildAt(existingIndex, PR_TRUE);
|
||||
BookmarkRemoved(draggedParent, draggedNode, false);
|
||||
|
||||
// insert into new position
|
||||
if (proposedParent)
|
||||
proposedParent->InsertChildAt(draggedNode, index, PR_TRUE, PR_TRUE);
|
||||
BookmarkAdded(proposedParent, draggedNode, false);
|
||||
}
|
||||
}
|
||||
|
||||
FlushBookmarks();
|
||||
|
|
|
@ -308,10 +308,47 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (BOOL)dropDestinationValid:(NSPasteboard*)draggingPasteboard
|
||||
{
|
||||
NSArray* types = [draggingPasteboard types];
|
||||
|
||||
if ([types containsObject: @"MozBookmarkType"])
|
||||
{
|
||||
NSArray *draggedIDs = [draggingPasteboard propertyListForType: @"MozBookmarkType"];
|
||||
|
||||
nsCOMPtr<nsIContent> destinationContent;
|
||||
int index = 0;
|
||||
|
||||
if (mDragInsertionPosition == BookmarksService::CHInsertInto) // drop onto folder
|
||||
{
|
||||
nsCOMPtr<nsIDOMElement> parentElt = [mDragInsertionButton element];
|
||||
destinationContent = do_QueryInterface(parentElt);
|
||||
index = 0;
|
||||
}
|
||||
else if (mDragInsertionPosition == BookmarksService::CHInsertBefore ||
|
||||
mDragInsertionPosition == BookmarksService::CHInsertAfter) // drop onto toolbar
|
||||
{
|
||||
nsCOMPtr<nsIDOMElement> toolbarRoot = BookmarksService::gToolbarRoot;
|
||||
destinationContent = do_QueryInterface(toolbarRoot);
|
||||
index = [mButtons indexOfObject: mDragInsertionButton];
|
||||
}
|
||||
|
||||
BookmarkItem* toolbarFolderItem = BookmarksService::GetWrapperFor(destinationContent);
|
||||
if (!BookmarksService::IsBookmarkDropValid(toolbarFolderItem, index, draggedIDs)) {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
// NSDraggingDestination ///////////
|
||||
|
||||
- (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender
|
||||
{
|
||||
if (![self dropDestinationValid:[sender draggingPasteboard]])
|
||||
return NSDragOperationNone;
|
||||
|
||||
return NSDragOperationGeneric;
|
||||
}
|
||||
|
||||
|
@ -329,6 +366,9 @@
|
|||
if (mDragInsertionPosition)
|
||||
[self setNeedsDisplayInRect:[self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]];
|
||||
|
||||
if (![self dropDestinationValid:[sender draggingPasteboard]])
|
||||
return NSDragOperationNone;
|
||||
|
||||
[self setButtonInsertionPoint:[sender draggingLocation]];
|
||||
|
||||
if (mDragInsertionPosition)
|
||||
|
|
|
@ -1251,14 +1251,17 @@ BookmarksService::PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray*
|
|||
}
|
||||
|
||||
// remove it from the tree
|
||||
if (draggedParent)
|
||||
draggedParent->RemoveChildAt(existingIndex, PR_TRUE);
|
||||
BookmarkRemoved(draggedParent, draggedNode, false);
|
||||
|
||||
// insert into new position
|
||||
if (proposedParent)
|
||||
proposedParent->InsertChildAt(draggedNode, index, PR_TRUE, PR_TRUE);
|
||||
BookmarkAdded(proposedParent, draggedNode, false);
|
||||
if (draggedNode != proposedParent) // paranoia. This should never happen
|
||||
{
|
||||
if (draggedParent)
|
||||
draggedParent->RemoveChildAt(existingIndex, PR_TRUE);
|
||||
BookmarkRemoved(draggedParent, draggedNode, false);
|
||||
|
||||
// insert into new position
|
||||
if (proposedParent)
|
||||
proposedParent->InsertChildAt(draggedNode, index, PR_TRUE, PR_TRUE);
|
||||
BookmarkAdded(proposedParent, draggedNode, false);
|
||||
}
|
||||
}
|
||||
|
||||
FlushBookmarks();
|
||||
|
|
|
@ -308,10 +308,47 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (BOOL)dropDestinationValid:(NSPasteboard*)draggingPasteboard
|
||||
{
|
||||
NSArray* types = [draggingPasteboard types];
|
||||
|
||||
if ([types containsObject: @"MozBookmarkType"])
|
||||
{
|
||||
NSArray *draggedIDs = [draggingPasteboard propertyListForType: @"MozBookmarkType"];
|
||||
|
||||
nsCOMPtr<nsIContent> destinationContent;
|
||||
int index = 0;
|
||||
|
||||
if (mDragInsertionPosition == BookmarksService::CHInsertInto) // drop onto folder
|
||||
{
|
||||
nsCOMPtr<nsIDOMElement> parentElt = [mDragInsertionButton element];
|
||||
destinationContent = do_QueryInterface(parentElt);
|
||||
index = 0;
|
||||
}
|
||||
else if (mDragInsertionPosition == BookmarksService::CHInsertBefore ||
|
||||
mDragInsertionPosition == BookmarksService::CHInsertAfter) // drop onto toolbar
|
||||
{
|
||||
nsCOMPtr<nsIDOMElement> toolbarRoot = BookmarksService::gToolbarRoot;
|
||||
destinationContent = do_QueryInterface(toolbarRoot);
|
||||
index = [mButtons indexOfObject: mDragInsertionButton];
|
||||
}
|
||||
|
||||
BookmarkItem* toolbarFolderItem = BookmarksService::GetWrapperFor(destinationContent);
|
||||
if (!BookmarksService::IsBookmarkDropValid(toolbarFolderItem, index, draggedIDs)) {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
// NSDraggingDestination ///////////
|
||||
|
||||
- (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender
|
||||
{
|
||||
if (![self dropDestinationValid:[sender draggingPasteboard]])
|
||||
return NSDragOperationNone;
|
||||
|
||||
return NSDragOperationGeneric;
|
||||
}
|
||||
|
||||
|
@ -329,6 +366,9 @@
|
|||
if (mDragInsertionPosition)
|
||||
[self setNeedsDisplayInRect:[self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]];
|
||||
|
||||
if (![self dropDestinationValid:[sender draggingPasteboard]])
|
||||
return NSDragOperationNone;
|
||||
|
||||
[self setButtonInsertionPoint:[sender draggingLocation]];
|
||||
|
||||
if (mDragInsertionPosition)
|
||||
|
|
|
@ -1251,14 +1251,17 @@ BookmarksService::PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray*
|
|||
}
|
||||
|
||||
// remove it from the tree
|
||||
if (draggedParent)
|
||||
draggedParent->RemoveChildAt(existingIndex, PR_TRUE);
|
||||
BookmarkRemoved(draggedParent, draggedNode, false);
|
||||
|
||||
// insert into new position
|
||||
if (proposedParent)
|
||||
proposedParent->InsertChildAt(draggedNode, index, PR_TRUE, PR_TRUE);
|
||||
BookmarkAdded(proposedParent, draggedNode, false);
|
||||
if (draggedNode != proposedParent) // paranoia. This should never happen
|
||||
{
|
||||
if (draggedParent)
|
||||
draggedParent->RemoveChildAt(existingIndex, PR_TRUE);
|
||||
BookmarkRemoved(draggedParent, draggedNode, false);
|
||||
|
||||
// insert into new position
|
||||
if (proposedParent)
|
||||
proposedParent->InsertChildAt(draggedNode, index, PR_TRUE, PR_TRUE);
|
||||
BookmarkAdded(proposedParent, draggedNode, false);
|
||||
}
|
||||
}
|
||||
|
||||
FlushBookmarks();
|
||||
|
|
|
@ -308,10 +308,47 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (BOOL)dropDestinationValid:(NSPasteboard*)draggingPasteboard
|
||||
{
|
||||
NSArray* types = [draggingPasteboard types];
|
||||
|
||||
if ([types containsObject: @"MozBookmarkType"])
|
||||
{
|
||||
NSArray *draggedIDs = [draggingPasteboard propertyListForType: @"MozBookmarkType"];
|
||||
|
||||
nsCOMPtr<nsIContent> destinationContent;
|
||||
int index = 0;
|
||||
|
||||
if (mDragInsertionPosition == BookmarksService::CHInsertInto) // drop onto folder
|
||||
{
|
||||
nsCOMPtr<nsIDOMElement> parentElt = [mDragInsertionButton element];
|
||||
destinationContent = do_QueryInterface(parentElt);
|
||||
index = 0;
|
||||
}
|
||||
else if (mDragInsertionPosition == BookmarksService::CHInsertBefore ||
|
||||
mDragInsertionPosition == BookmarksService::CHInsertAfter) // drop onto toolbar
|
||||
{
|
||||
nsCOMPtr<nsIDOMElement> toolbarRoot = BookmarksService::gToolbarRoot;
|
||||
destinationContent = do_QueryInterface(toolbarRoot);
|
||||
index = [mButtons indexOfObject: mDragInsertionButton];
|
||||
}
|
||||
|
||||
BookmarkItem* toolbarFolderItem = BookmarksService::GetWrapperFor(destinationContent);
|
||||
if (!BookmarksService::IsBookmarkDropValid(toolbarFolderItem, index, draggedIDs)) {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
// NSDraggingDestination ///////////
|
||||
|
||||
- (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender
|
||||
{
|
||||
if (![self dropDestinationValid:[sender draggingPasteboard]])
|
||||
return NSDragOperationNone;
|
||||
|
||||
return NSDragOperationGeneric;
|
||||
}
|
||||
|
||||
|
@ -329,6 +366,9 @@
|
|||
if (mDragInsertionPosition)
|
||||
[self setNeedsDisplayInRect:[self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]];
|
||||
|
||||
if (![self dropDestinationValid:[sender draggingPasteboard]])
|
||||
return NSDragOperationNone;
|
||||
|
||||
[self setButtonInsertionPoint:[sender draggingLocation]];
|
||||
|
||||
if (mDragInsertionPosition)
|
||||
|
|
Загрузка…
Ссылка в новой задаче