Fixing bugs 154906 and 149670, and lots of other drag and drop bugs. Drags from the proxy icon are now droppable in the Finder, in the content area, and on tabs, and do the right thing. Single bookmarks are also draggable to the Finder. Page links can also now be dragged onto tabs.

This commit is contained in:
sfraser%netscape.com 2002-07-06 06:44:14 +00:00
Родитель 479f9d7dcc
Коммит 25c2c01a40
18 изменённых файлов: 324 добавлений и 174 удалений

Просмотреть файл

@ -111,6 +111,7 @@ class BookmarksService;
- (nsIContent*)contentNode;
- (void)setContentNode: (nsIContent*)aContentNode;
- (NSString*)url;
- (NSNumber*)contentID;
- (id)copyWithZone:(NSZone *)aZone;

Просмотреть файл

@ -587,10 +587,28 @@
if (count > 0) {
// Create Pasteboard Data
NSMutableArray *draggedID = [NSMutableArray arrayWithCapacity: count];
for (int i = 0; i < count; i++)
[draggedID addObject: [[toDrag objectAtIndex: i] contentID]];
[pboard declareTypes: [NSArray arrayWithObject: @"MozBookmarkType"] owner: self];
[pboard setPropertyList: draggedID forType: @"MozBookmarkType"];
if (count == 1) {
// if we have just one item, we add some more flavours
[pboard declareTypes: [NSArray arrayWithObjects:
@"MozBookmarkType", NSURLPboardType, NSStringPboardType, nil] owner: self];
[pboard setPropertyList: draggedID forType: @"MozBookmarkType"];
NSString* itemURL = [[toDrag objectAtIndex: 0] url];
[pboard setString:itemURL forType: NSStringPboardType];
[[NSURL URLWithString:itemURL] writeToPasteboard: pboard];
// maybe construct the @"MozURLType" type here also
}
else {
// multiple bookmarks. Array sof strings or NSURLs seem to
// confuse receivers. Not sure what the correct way is.
[pboard declareTypes: [NSArray arrayWithObject: @"MozBookmarkType"] owner: self];
[pboard setPropertyList: draggedID forType: @"MozBookmarkType"];
}
return YES;
}
@ -784,6 +802,15 @@
return [NSString stringWithFormat:@"<BookmarkItem, name = \"%@\">", info];
}
- (NSString *)url
{
nsCOMPtr<nsIContent> item = [self contentNode];
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(item));
nsAutoString href;
element->GetAttribute(NS_LITERAL_STRING("name"), href);
return [NSString stringWithCharacters: href.get() length: href.Length()];
}
-(void)setContentNode: (nsIContent*)aContentNode
{
mContentNode = aContentNode;

Просмотреть файл

@ -981,8 +981,8 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
baseWin->Create();
// register the view as a drop site for text, files, and urls.
[self registerForDraggedTypes:
[NSArray arrayWithObjects:NSStringPboardType, NSURLPboardType, NSFilenamesPboardType, nil]];
[self registerForDraggedTypes: [NSArray arrayWithObjects:
@"MozURLType", NSStringPboardType, NSURLPboardType, NSFilenamesPboardType, nil]];
}
return self;
}
@ -1595,9 +1595,8 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
nsCOMPtr<nsIEventSink> sink;
[self findEventSink:getter_AddRefs(sink) forPoint:[sender draggingLocation]
inWindow:[sender draggingDestinationWindow]];
NS_ASSERTION(sink, "Couldn't get event sink for view");
mDragHelper->Enter ( [sender draggingSequenceNumber], sink );
if (sink)
mDragHelper->Enter ( [sender draggingSequenceNumber], sink );
}
return NSDragOperationCopy;
@ -1609,9 +1608,8 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
nsCOMPtr<nsIEventSink> sink;
[self findEventSink:getter_AddRefs(sink) forPoint:[sender draggingLocation]
inWindow:[sender draggingDestinationWindow]];
NS_ASSERTION(sink, "Couldn't get event sink for view");
mDragHelper->Leave ( [sender draggingSequenceNumber], sink );
if (sink)
mDragHelper->Leave( [sender draggingSequenceNumber], sink );
NS_RELEASE(mDragHelper);
}
}
@ -1623,9 +1621,8 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
nsCOMPtr<nsIEventSink> sink;
[self findEventSink:getter_AddRefs(sink) forPoint:[sender draggingLocation]
inWindow:[sender draggingDestinationWindow]];
NS_ASSERTION(sink, "Couldn't get event sink for view");
mDragHelper->Tracking ( [sender draggingSequenceNumber], sink, &dropAllowed );
if (sink)
mDragHelper->Tracking([sender draggingSequenceNumber], sink, &dropAllowed);
}
return dropAllowed ? NSDragOperationCopy : NSDragOperationNone;
@ -1639,16 +1636,16 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
PRBool dragAccepted = PR_FALSE;
if ( mDragHelper ) {
nsCOMPtr<nsIEventSink> sink;
[self findEventSink:getter_AddRefs(sink) forPoint:[sender draggingLocation]
inWindow:[sender draggingDestinationWindow]];
NS_ASSERTION(sink, "Couldn't get event sink for view");
mDragHelper->Drop ( [sender draggingSequenceNumber], sink, &dragAccepted );
if (sink)
mDragHelper->Drop([sender draggingSequenceNumber], sink, &dragAccepted);
}
return dragAccepted;
return dragAccepted ? YES : NO;
}
@ -1675,4 +1672,3 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
}
@end

Просмотреть файл

@ -34,7 +34,10 @@
//////////////////////////
@interface CHExtendedTabView (Private)
- (void)showOrHideTabsAsAppropriate;
- (void)handleDropOnTab:(NSTabViewItem*)overTabViewItem overContent:(BOOL)overContentArea withURL:(NSString*)url;
@end
@implementation CHExtendedTabView
@ -54,7 +57,8 @@
- (void)awakeFromNib
{
[self showOrHideTabsAsAppropriate];
[self registerForDraggedTypes:[NSArray arrayWithObjects:@"MozURLType", @"MozBookmarkType", nil]];
[self registerForDraggedTypes:[NSArray arrayWithObjects:
@"MozURLType", @"MozBookmarkType", NSStringPboardType, NSFilenamesPboardType, nil]];
}
/******************************************/
@ -127,6 +131,17 @@
// }
}
- (void)handleDropOnTab:(NSTabViewItem*)overTabViewItem overContent:(BOOL)overContentArea withURL:(NSString*)url
{
if (overTabViewItem) {
[[[overTabViewItem view] getBrowserView] loadURI: url flags: NSLoadFlagsNone];
} else if (overContentArea) {
[[[[self selectedTabViewItem] view] getBrowserView] loadURI: url flags: NSLoadFlagsNone];
} else
[self addTabForURL:url];
}
// NSDraggingDestination ///////////
- (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender
@ -146,54 +161,62 @@
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSArray* contentIds;
NSTabViewItem* overTabViewItem = nil;
BOOL overContentArea = NO;
// determine if we are over a tab or the content area
NSPoint localPoint = [self convertPoint: [sender draggingLocation] fromView: nil];
overTabViewItem = [self tabViewItemAtPoint: localPoint];
overContentArea = NSPointInRect(localPoint, [self contentRect]);
NSPoint localPoint = [self convertPoint: [sender draggingLocation] fromView: nil];
NSTabViewItem* overTabViewItem = [self tabViewItemAtPoint: localPoint];
BOOL overContentArea = NSPointInRect(localPoint, [self contentRect]);
// check for recognized drag types
contentIds = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"];
if (contentIds) {
// drag type is chimera bookmarks
for (unsigned int i = 0; i < [contentIds count]; ++i) {
BookmarkItem* item = [BookmarksService::gDictionary objectForKey: [contentIds objectAtIndex:i]];
nsCOMPtr<nsIDOMElement> bookmarkElt = do_QueryInterface([item contentNode]);
nsCOMPtr<nsIAtom> tagName;
[item contentNode]->GetTag(*getter_AddRefs(tagName));
nsAutoString href;
bookmarkElt->GetAttribute(NS_LITERAL_STRING("href"), href);
NSString* url = [NSString stringWithCharacters: href.get() length: nsCRT::strlen(href.get())];
nsAutoString group;
bookmarkElt->GetAttribute(NS_LITERAL_STRING("group"), group);
if (!group.IsEmpty()) {
BookmarksService::OpenBookmarkGroup(self, bookmarkElt);
} else {
if (overTabViewItem) {
[[[overTabViewItem view] getBrowserView] loadURI: url
flags: NSLoadFlagsNone];
} else if (overContentArea) {
[[[[self selectedTabViewItem] view] getBrowserView] loadURI: url
flags: NSLoadFlagsNone];
} else
[self addTabForURL:url];
}
NSArray* pasteBoardTypes = [[sender draggingPasteboard] types];
if ([pasteBoardTypes containsObject: @"MozBookmarkType"])
{
NSArray* contentIds = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"];
if (contentIds) {
// drag type is chimera bookmarks
for (unsigned int i = 0; i < [contentIds count]; ++i) {
BookmarkItem* item = [BookmarksService::gDictionary objectForKey: [contentIds objectAtIndex:i]];
nsCOMPtr<nsIDOMElement> bookmarkElt = do_QueryInterface([item contentNode]);
nsCOMPtr<nsIAtom> tagName;
[item contentNode]->GetTag(*getter_AddRefs(tagName));
nsAutoString href;
bookmarkElt->GetAttribute(NS_LITERAL_STRING("href"), href);
NSString* url = [NSString stringWithCharacters: href.get() length: nsCRT::strlen(href.get())];
nsAutoString group;
bookmarkElt->GetAttribute(NS_LITERAL_STRING("group"), group);
if (!group.IsEmpty()) {
BookmarksService::OpenBookmarkGroup(self, bookmarkElt);
} else {
[self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:url];
}
} // for each item
}
} else {
// add bookmark for chimera url type
}
else if ([pasteBoardTypes containsObject: @"MozURLType"])
{
// drag type is MozURLType
NSDictionary* data = [[sender draggingPasteboard] propertyListForType: @"MozURLType"];
if (overTabViewItem || overContentArea) {
[[[overTabViewItem view] getBrowserView] loadURI:[data objectForKey:@"url"]
flags: NSLoadFlagsNone];
} else
[self addTabForURL:[data objectForKey:@"url"]];
if (data) {
NSString* urlString = [data objectForKey:@"url"];
[self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:urlString];
}
}
else if ([pasteBoardTypes containsObject: NSStringPboardType])
{
NSString* urlString = [[sender draggingPasteboard] propertyListForType: NSStringPboardType];
[self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:urlString];
}
else if ([pasteBoardTypes containsObject: NSURLPboardType])
{
NSURL* urlData = [NSURL URLFromPasteboard:[sender draggingPasteboard]];
[self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:[urlData absoluteString]];
}
else if ([pasteBoardTypes containsObject: NSFilenamesPboardType])
{
NSString* urlString = [[sender draggingPasteboard] propertyListForType: NSFilenamesPboardType];
[self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:urlString];
}
return YES;

Просмотреть файл

@ -58,8 +58,8 @@
NSString* title;
nsAutoString hrefStr, titleStr;
BookmarksService::GetTitleAndHrefForBrowserView([[[[self window] windowController] getBrowserWrapper] getBrowserView],
titleStr, hrefStr);
BookmarksService::GetTitleAndHrefForBrowserView(
[[[[self window] windowController] getBrowserWrapper] getBrowserView], titleStr, hrefStr);
url = [NSString stringWithCharacters: hrefStr.get() length: nsCRT::strlen(hrefStr.get())];
title = [NSString stringWithCharacters: titleStr.get() length: nsCRT::strlen(titleStr.get())];
@ -69,8 +69,10 @@
data = [NSDictionary dictionaryWithObjects:dataVals forKeys:dataKeys];
pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
[pboard declareTypes:[NSArray arrayWithObject:@"MozURLType"] owner:self];
[pboard declareTypes:[NSArray arrayWithObjects:@"MozURLType", NSURLPboardType, NSStringPboardType, nil] owner:self];
[pboard setPropertyList:data forType: @"MozURLType"];
[[NSURL URLWithString:url] writeToPasteboard: pboard];
[pboard setString:url forType: NSStringPboardType];
[self dragImage: [MainController createImageForDragging:[self image] title:title]
at: NSMakePoint(0,0) offset: NSMakeSize(0,0)

Просмотреть файл

@ -111,6 +111,7 @@ class BookmarksService;
- (nsIContent*)contentNode;
- (void)setContentNode: (nsIContent*)aContentNode;
- (NSString*)url;
- (NSNumber*)contentID;
- (id)copyWithZone:(NSZone *)aZone;

Просмотреть файл

@ -587,10 +587,28 @@
if (count > 0) {
// Create Pasteboard Data
NSMutableArray *draggedID = [NSMutableArray arrayWithCapacity: count];
for (int i = 0; i < count; i++)
[draggedID addObject: [[toDrag objectAtIndex: i] contentID]];
[pboard declareTypes: [NSArray arrayWithObject: @"MozBookmarkType"] owner: self];
[pboard setPropertyList: draggedID forType: @"MozBookmarkType"];
if (count == 1) {
// if we have just one item, we add some more flavours
[pboard declareTypes: [NSArray arrayWithObjects:
@"MozBookmarkType", NSURLPboardType, NSStringPboardType, nil] owner: self];
[pboard setPropertyList: draggedID forType: @"MozBookmarkType"];
NSString* itemURL = [[toDrag objectAtIndex: 0] url];
[pboard setString:itemURL forType: NSStringPboardType];
[[NSURL URLWithString:itemURL] writeToPasteboard: pboard];
// maybe construct the @"MozURLType" type here also
}
else {
// multiple bookmarks. Array sof strings or NSURLs seem to
// confuse receivers. Not sure what the correct way is.
[pboard declareTypes: [NSArray arrayWithObject: @"MozBookmarkType"] owner: self];
[pboard setPropertyList: draggedID forType: @"MozBookmarkType"];
}
return YES;
}
@ -784,6 +802,15 @@
return [NSString stringWithFormat:@"<BookmarkItem, name = \"%@\">", info];
}
- (NSString *)url
{
nsCOMPtr<nsIContent> item = [self contentNode];
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(item));
nsAutoString href;
element->GetAttribute(NS_LITERAL_STRING("name"), href);
return [NSString stringWithCharacters: href.get() length: href.Length()];
}
-(void)setContentNode: (nsIContent*)aContentNode
{
mContentNode = aContentNode;

Просмотреть файл

@ -58,8 +58,8 @@
NSString* title;
nsAutoString hrefStr, titleStr;
BookmarksService::GetTitleAndHrefForBrowserView([[[[self window] windowController] getBrowserWrapper] getBrowserView],
titleStr, hrefStr);
BookmarksService::GetTitleAndHrefForBrowserView(
[[[[self window] windowController] getBrowserWrapper] getBrowserView], titleStr, hrefStr);
url = [NSString stringWithCharacters: hrefStr.get() length: nsCRT::strlen(hrefStr.get())];
title = [NSString stringWithCharacters: titleStr.get() length: nsCRT::strlen(titleStr.get())];
@ -69,8 +69,10 @@
data = [NSDictionary dictionaryWithObjects:dataVals forKeys:dataKeys];
pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
[pboard declareTypes:[NSArray arrayWithObject:@"MozURLType"] owner:self];
[pboard declareTypes:[NSArray arrayWithObjects:@"MozURLType", NSURLPboardType, NSStringPboardType, nil] owner:self];
[pboard setPropertyList:data forType: @"MozURLType"];
[[NSURL URLWithString:url] writeToPasteboard: pboard];
[pboard setString:url forType: NSStringPboardType];
[self dragImage: [MainController createImageForDragging:[self image] title:title]
at: NSMakePoint(0,0) offset: NSMakeSize(0,0)

Просмотреть файл

@ -981,8 +981,8 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
baseWin->Create();
// register the view as a drop site for text, files, and urls.
[self registerForDraggedTypes:
[NSArray arrayWithObjects:NSStringPboardType, NSURLPboardType, NSFilenamesPboardType, nil]];
[self registerForDraggedTypes: [NSArray arrayWithObjects:
@"MozURLType", NSStringPboardType, NSURLPboardType, NSFilenamesPboardType, nil]];
}
return self;
}
@ -1595,9 +1595,8 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
nsCOMPtr<nsIEventSink> sink;
[self findEventSink:getter_AddRefs(sink) forPoint:[sender draggingLocation]
inWindow:[sender draggingDestinationWindow]];
NS_ASSERTION(sink, "Couldn't get event sink for view");
mDragHelper->Enter ( [sender draggingSequenceNumber], sink );
if (sink)
mDragHelper->Enter ( [sender draggingSequenceNumber], sink );
}
return NSDragOperationCopy;
@ -1609,9 +1608,8 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
nsCOMPtr<nsIEventSink> sink;
[self findEventSink:getter_AddRefs(sink) forPoint:[sender draggingLocation]
inWindow:[sender draggingDestinationWindow]];
NS_ASSERTION(sink, "Couldn't get event sink for view");
mDragHelper->Leave ( [sender draggingSequenceNumber], sink );
if (sink)
mDragHelper->Leave( [sender draggingSequenceNumber], sink );
NS_RELEASE(mDragHelper);
}
}
@ -1623,9 +1621,8 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
nsCOMPtr<nsIEventSink> sink;
[self findEventSink:getter_AddRefs(sink) forPoint:[sender draggingLocation]
inWindow:[sender draggingDestinationWindow]];
NS_ASSERTION(sink, "Couldn't get event sink for view");
mDragHelper->Tracking ( [sender draggingSequenceNumber], sink, &dropAllowed );
if (sink)
mDragHelper->Tracking([sender draggingSequenceNumber], sink, &dropAllowed);
}
return dropAllowed ? NSDragOperationCopy : NSDragOperationNone;
@ -1639,16 +1636,16 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
PRBool dragAccepted = PR_FALSE;
if ( mDragHelper ) {
nsCOMPtr<nsIEventSink> sink;
[self findEventSink:getter_AddRefs(sink) forPoint:[sender draggingLocation]
inWindow:[sender draggingDestinationWindow]];
NS_ASSERTION(sink, "Couldn't get event sink for view");
mDragHelper->Drop ( [sender draggingSequenceNumber], sink, &dragAccepted );
if (sink)
mDragHelper->Drop([sender draggingSequenceNumber], sink, &dragAccepted);
}
return dragAccepted;
return dragAccepted ? YES : NO;
}
@ -1675,4 +1672,3 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
}
@end

Просмотреть файл

@ -111,6 +111,7 @@ class BookmarksService;
- (nsIContent*)contentNode;
- (void)setContentNode: (nsIContent*)aContentNode;
- (NSString*)url;
- (NSNumber*)contentID;
- (id)copyWithZone:(NSZone *)aZone;

Просмотреть файл

@ -587,10 +587,28 @@
if (count > 0) {
// Create Pasteboard Data
NSMutableArray *draggedID = [NSMutableArray arrayWithCapacity: count];
for (int i = 0; i < count; i++)
[draggedID addObject: [[toDrag objectAtIndex: i] contentID]];
[pboard declareTypes: [NSArray arrayWithObject: @"MozBookmarkType"] owner: self];
[pboard setPropertyList: draggedID forType: @"MozBookmarkType"];
if (count == 1) {
// if we have just one item, we add some more flavours
[pboard declareTypes: [NSArray arrayWithObjects:
@"MozBookmarkType", NSURLPboardType, NSStringPboardType, nil] owner: self];
[pboard setPropertyList: draggedID forType: @"MozBookmarkType"];
NSString* itemURL = [[toDrag objectAtIndex: 0] url];
[pboard setString:itemURL forType: NSStringPboardType];
[[NSURL URLWithString:itemURL] writeToPasteboard: pboard];
// maybe construct the @"MozURLType" type here also
}
else {
// multiple bookmarks. Array sof strings or NSURLs seem to
// confuse receivers. Not sure what the correct way is.
[pboard declareTypes: [NSArray arrayWithObject: @"MozBookmarkType"] owner: self];
[pboard setPropertyList: draggedID forType: @"MozBookmarkType"];
}
return YES;
}
@ -784,6 +802,15 @@
return [NSString stringWithFormat:@"<BookmarkItem, name = \"%@\">", info];
}
- (NSString *)url
{
nsCOMPtr<nsIContent> item = [self contentNode];
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(item));
nsAutoString href;
element->GetAttribute(NS_LITERAL_STRING("name"), href);
return [NSString stringWithCharacters: href.get() length: href.Length()];
}
-(void)setContentNode: (nsIContent*)aContentNode
{
mContentNode = aContentNode;

Просмотреть файл

@ -981,8 +981,8 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
baseWin->Create();
// register the view as a drop site for text, files, and urls.
[self registerForDraggedTypes:
[NSArray arrayWithObjects:NSStringPboardType, NSURLPboardType, NSFilenamesPboardType, nil]];
[self registerForDraggedTypes: [NSArray arrayWithObjects:
@"MozURLType", NSStringPboardType, NSURLPboardType, NSFilenamesPboardType, nil]];
}
return self;
}
@ -1595,9 +1595,8 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
nsCOMPtr<nsIEventSink> sink;
[self findEventSink:getter_AddRefs(sink) forPoint:[sender draggingLocation]
inWindow:[sender draggingDestinationWindow]];
NS_ASSERTION(sink, "Couldn't get event sink for view");
mDragHelper->Enter ( [sender draggingSequenceNumber], sink );
if (sink)
mDragHelper->Enter ( [sender draggingSequenceNumber], sink );
}
return NSDragOperationCopy;
@ -1609,9 +1608,8 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
nsCOMPtr<nsIEventSink> sink;
[self findEventSink:getter_AddRefs(sink) forPoint:[sender draggingLocation]
inWindow:[sender draggingDestinationWindow]];
NS_ASSERTION(sink, "Couldn't get event sink for view");
mDragHelper->Leave ( [sender draggingSequenceNumber], sink );
if (sink)
mDragHelper->Leave( [sender draggingSequenceNumber], sink );
NS_RELEASE(mDragHelper);
}
}
@ -1623,9 +1621,8 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
nsCOMPtr<nsIEventSink> sink;
[self findEventSink:getter_AddRefs(sink) forPoint:[sender draggingLocation]
inWindow:[sender draggingDestinationWindow]];
NS_ASSERTION(sink, "Couldn't get event sink for view");
mDragHelper->Tracking ( [sender draggingSequenceNumber], sink, &dropAllowed );
if (sink)
mDragHelper->Tracking([sender draggingSequenceNumber], sink, &dropAllowed);
}
return dropAllowed ? NSDragOperationCopy : NSDragOperationNone;
@ -1639,16 +1636,16 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
PRBool dragAccepted = PR_FALSE;
if ( mDragHelper ) {
nsCOMPtr<nsIEventSink> sink;
[self findEventSink:getter_AddRefs(sink) forPoint:[sender draggingLocation]
inWindow:[sender draggingDestinationWindow]];
NS_ASSERTION(sink, "Couldn't get event sink for view");
mDragHelper->Drop ( [sender draggingSequenceNumber], sink, &dragAccepted );
if (sink)
mDragHelper->Drop([sender draggingSequenceNumber], sink, &dragAccepted);
}
return dragAccepted;
return dragAccepted ? YES : NO;
}
@ -1675,4 +1672,3 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
}
@end

Просмотреть файл

@ -34,7 +34,10 @@
//////////////////////////
@interface CHExtendedTabView (Private)
- (void)showOrHideTabsAsAppropriate;
- (void)handleDropOnTab:(NSTabViewItem*)overTabViewItem overContent:(BOOL)overContentArea withURL:(NSString*)url;
@end
@implementation CHExtendedTabView
@ -54,7 +57,8 @@
- (void)awakeFromNib
{
[self showOrHideTabsAsAppropriate];
[self registerForDraggedTypes:[NSArray arrayWithObjects:@"MozURLType", @"MozBookmarkType", nil]];
[self registerForDraggedTypes:[NSArray arrayWithObjects:
@"MozURLType", @"MozBookmarkType", NSStringPboardType, NSFilenamesPboardType, nil]];
}
/******************************************/
@ -127,6 +131,17 @@
// }
}
- (void)handleDropOnTab:(NSTabViewItem*)overTabViewItem overContent:(BOOL)overContentArea withURL:(NSString*)url
{
if (overTabViewItem) {
[[[overTabViewItem view] getBrowserView] loadURI: url flags: NSLoadFlagsNone];
} else if (overContentArea) {
[[[[self selectedTabViewItem] view] getBrowserView] loadURI: url flags: NSLoadFlagsNone];
} else
[self addTabForURL:url];
}
// NSDraggingDestination ///////////
- (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender
@ -146,54 +161,62 @@
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSArray* contentIds;
NSTabViewItem* overTabViewItem = nil;
BOOL overContentArea = NO;
// determine if we are over a tab or the content area
NSPoint localPoint = [self convertPoint: [sender draggingLocation] fromView: nil];
overTabViewItem = [self tabViewItemAtPoint: localPoint];
overContentArea = NSPointInRect(localPoint, [self contentRect]);
NSPoint localPoint = [self convertPoint: [sender draggingLocation] fromView: nil];
NSTabViewItem* overTabViewItem = [self tabViewItemAtPoint: localPoint];
BOOL overContentArea = NSPointInRect(localPoint, [self contentRect]);
// check for recognized drag types
contentIds = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"];
if (contentIds) {
// drag type is chimera bookmarks
for (unsigned int i = 0; i < [contentIds count]; ++i) {
BookmarkItem* item = [BookmarksService::gDictionary objectForKey: [contentIds objectAtIndex:i]];
nsCOMPtr<nsIDOMElement> bookmarkElt = do_QueryInterface([item contentNode]);
nsCOMPtr<nsIAtom> tagName;
[item contentNode]->GetTag(*getter_AddRefs(tagName));
nsAutoString href;
bookmarkElt->GetAttribute(NS_LITERAL_STRING("href"), href);
NSString* url = [NSString stringWithCharacters: href.get() length: nsCRT::strlen(href.get())];
nsAutoString group;
bookmarkElt->GetAttribute(NS_LITERAL_STRING("group"), group);
if (!group.IsEmpty()) {
BookmarksService::OpenBookmarkGroup(self, bookmarkElt);
} else {
if (overTabViewItem) {
[[[overTabViewItem view] getBrowserView] loadURI: url
flags: NSLoadFlagsNone];
} else if (overContentArea) {
[[[[self selectedTabViewItem] view] getBrowserView] loadURI: url
flags: NSLoadFlagsNone];
} else
[self addTabForURL:url];
}
NSArray* pasteBoardTypes = [[sender draggingPasteboard] types];
if ([pasteBoardTypes containsObject: @"MozBookmarkType"])
{
NSArray* contentIds = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"];
if (contentIds) {
// drag type is chimera bookmarks
for (unsigned int i = 0; i < [contentIds count]; ++i) {
BookmarkItem* item = [BookmarksService::gDictionary objectForKey: [contentIds objectAtIndex:i]];
nsCOMPtr<nsIDOMElement> bookmarkElt = do_QueryInterface([item contentNode]);
nsCOMPtr<nsIAtom> tagName;
[item contentNode]->GetTag(*getter_AddRefs(tagName));
nsAutoString href;
bookmarkElt->GetAttribute(NS_LITERAL_STRING("href"), href);
NSString* url = [NSString stringWithCharacters: href.get() length: nsCRT::strlen(href.get())];
nsAutoString group;
bookmarkElt->GetAttribute(NS_LITERAL_STRING("group"), group);
if (!group.IsEmpty()) {
BookmarksService::OpenBookmarkGroup(self, bookmarkElt);
} else {
[self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:url];
}
} // for each item
}
} else {
// add bookmark for chimera url type
}
else if ([pasteBoardTypes containsObject: @"MozURLType"])
{
// drag type is MozURLType
NSDictionary* data = [[sender draggingPasteboard] propertyListForType: @"MozURLType"];
if (overTabViewItem || overContentArea) {
[[[overTabViewItem view] getBrowserView] loadURI:[data objectForKey:@"url"]
flags: NSLoadFlagsNone];
} else
[self addTabForURL:[data objectForKey:@"url"]];
if (data) {
NSString* urlString = [data objectForKey:@"url"];
[self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:urlString];
}
}
else if ([pasteBoardTypes containsObject: NSStringPboardType])
{
NSString* urlString = [[sender draggingPasteboard] propertyListForType: NSStringPboardType];
[self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:urlString];
}
else if ([pasteBoardTypes containsObject: NSURLPboardType])
{
NSURL* urlData = [NSURL URLFromPasteboard:[sender draggingPasteboard]];
[self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:[urlData absoluteString]];
}
else if ([pasteBoardTypes containsObject: NSFilenamesPboardType])
{
NSString* urlString = [[sender draggingPasteboard] propertyListForType: NSFilenamesPboardType];
[self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:urlString];
}
return YES;

Просмотреть файл

@ -58,8 +58,8 @@
NSString* title;
nsAutoString hrefStr, titleStr;
BookmarksService::GetTitleAndHrefForBrowserView([[[[self window] windowController] getBrowserWrapper] getBrowserView],
titleStr, hrefStr);
BookmarksService::GetTitleAndHrefForBrowserView(
[[[[self window] windowController] getBrowserWrapper] getBrowserView], titleStr, hrefStr);
url = [NSString stringWithCharacters: hrefStr.get() length: nsCRT::strlen(hrefStr.get())];
title = [NSString stringWithCharacters: titleStr.get() length: nsCRT::strlen(titleStr.get())];
@ -69,8 +69,10 @@
data = [NSDictionary dictionaryWithObjects:dataVals forKeys:dataKeys];
pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
[pboard declareTypes:[NSArray arrayWithObject:@"MozURLType"] owner:self];
[pboard declareTypes:[NSArray arrayWithObjects:@"MozURLType", NSURLPboardType, NSStringPboardType, nil] owner:self];
[pboard setPropertyList:data forType: @"MozURLType"];
[[NSURL URLWithString:url] writeToPasteboard: pboard];
[pboard setString:url forType: NSStringPboardType];
[self dragImage: [MainController createImageForDragging:[self image] title:title]
at: NSMakePoint(0,0) offset: NSMakeSize(0,0)

Просмотреть файл

@ -111,6 +111,7 @@ class BookmarksService;
- (nsIContent*)contentNode;
- (void)setContentNode: (nsIContent*)aContentNode;
- (NSString*)url;
- (NSNumber*)contentID;
- (id)copyWithZone:(NSZone *)aZone;

Просмотреть файл

@ -587,10 +587,28 @@
if (count > 0) {
// Create Pasteboard Data
NSMutableArray *draggedID = [NSMutableArray arrayWithCapacity: count];
for (int i = 0; i < count; i++)
[draggedID addObject: [[toDrag objectAtIndex: i] contentID]];
[pboard declareTypes: [NSArray arrayWithObject: @"MozBookmarkType"] owner: self];
[pboard setPropertyList: draggedID forType: @"MozBookmarkType"];
if (count == 1) {
// if we have just one item, we add some more flavours
[pboard declareTypes: [NSArray arrayWithObjects:
@"MozBookmarkType", NSURLPboardType, NSStringPboardType, nil] owner: self];
[pboard setPropertyList: draggedID forType: @"MozBookmarkType"];
NSString* itemURL = [[toDrag objectAtIndex: 0] url];
[pboard setString:itemURL forType: NSStringPboardType];
[[NSURL URLWithString:itemURL] writeToPasteboard: pboard];
// maybe construct the @"MozURLType" type here also
}
else {
// multiple bookmarks. Array sof strings or NSURLs seem to
// confuse receivers. Not sure what the correct way is.
[pboard declareTypes: [NSArray arrayWithObject: @"MozBookmarkType"] owner: self];
[pboard setPropertyList: draggedID forType: @"MozBookmarkType"];
}
return YES;
}
@ -784,6 +802,15 @@
return [NSString stringWithFormat:@"<BookmarkItem, name = \"%@\">", info];
}
- (NSString *)url
{
nsCOMPtr<nsIContent> item = [self contentNode];
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(item));
nsAutoString href;
element->GetAttribute(NS_LITERAL_STRING("name"), href);
return [NSString stringWithCharacters: href.get() length: href.Length()];
}
-(void)setContentNode: (nsIContent*)aContentNode
{
mContentNode = aContentNode;

Просмотреть файл

@ -58,8 +58,8 @@
NSString* title;
nsAutoString hrefStr, titleStr;
BookmarksService::GetTitleAndHrefForBrowserView([[[[self window] windowController] getBrowserWrapper] getBrowserView],
titleStr, hrefStr);
BookmarksService::GetTitleAndHrefForBrowserView(
[[[[self window] windowController] getBrowserWrapper] getBrowserView], titleStr, hrefStr);
url = [NSString stringWithCharacters: hrefStr.get() length: nsCRT::strlen(hrefStr.get())];
title = [NSString stringWithCharacters: titleStr.get() length: nsCRT::strlen(titleStr.get())];
@ -69,8 +69,10 @@
data = [NSDictionary dictionaryWithObjects:dataVals forKeys:dataKeys];
pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
[pboard declareTypes:[NSArray arrayWithObject:@"MozURLType"] owner:self];
[pboard declareTypes:[NSArray arrayWithObjects:@"MozURLType", NSURLPboardType, NSStringPboardType, nil] owner:self];
[pboard setPropertyList:data forType: @"MozURLType"];
[[NSURL URLWithString:url] writeToPasteboard: pboard];
[pboard setString:url forType: NSStringPboardType];
[self dragImage: [MainController createImageForDragging:[self image] title:title]
at: NSMakePoint(0,0) offset: NSMakeSize(0,0)

Просмотреть файл

@ -981,8 +981,8 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
baseWin->Create();
// register the view as a drop site for text, files, and urls.
[self registerForDraggedTypes:
[NSArray arrayWithObjects:NSStringPboardType, NSURLPboardType, NSFilenamesPboardType, nil]];
[self registerForDraggedTypes: [NSArray arrayWithObjects:
@"MozURLType", NSStringPboardType, NSURLPboardType, NSFilenamesPboardType, nil]];
}
return self;
}
@ -1595,9 +1595,8 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
nsCOMPtr<nsIEventSink> sink;
[self findEventSink:getter_AddRefs(sink) forPoint:[sender draggingLocation]
inWindow:[sender draggingDestinationWindow]];
NS_ASSERTION(sink, "Couldn't get event sink for view");
mDragHelper->Enter ( [sender draggingSequenceNumber], sink );
if (sink)
mDragHelper->Enter ( [sender draggingSequenceNumber], sink );
}
return NSDragOperationCopy;
@ -1609,9 +1608,8 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
nsCOMPtr<nsIEventSink> sink;
[self findEventSink:getter_AddRefs(sink) forPoint:[sender draggingLocation]
inWindow:[sender draggingDestinationWindow]];
NS_ASSERTION(sink, "Couldn't get event sink for view");
mDragHelper->Leave ( [sender draggingSequenceNumber], sink );
if (sink)
mDragHelper->Leave( [sender draggingSequenceNumber], sink );
NS_RELEASE(mDragHelper);
}
}
@ -1623,9 +1621,8 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
nsCOMPtr<nsIEventSink> sink;
[self findEventSink:getter_AddRefs(sink) forPoint:[sender draggingLocation]
inWindow:[sender draggingDestinationWindow]];
NS_ASSERTION(sink, "Couldn't get event sink for view");
mDragHelper->Tracking ( [sender draggingSequenceNumber], sink, &dropAllowed );
if (sink)
mDragHelper->Tracking([sender draggingSequenceNumber], sink, &dropAllowed);
}
return dropAllowed ? NSDragOperationCopy : NSDragOperationNone;
@ -1639,16 +1636,16 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
PRBool dragAccepted = PR_FALSE;
if ( mDragHelper ) {
nsCOMPtr<nsIEventSink> sink;
[self findEventSink:getter_AddRefs(sink) forPoint:[sender draggingLocation]
inWindow:[sender draggingDestinationWindow]];
NS_ASSERTION(sink, "Couldn't get event sink for view");
mDragHelper->Drop ( [sender draggingSequenceNumber], sink, &dragAccepted );
if (sink)
mDragHelper->Drop([sender draggingSequenceNumber], sink, &dragAccepted);
}
return dragAccepted;
return dragAccepted ? YES : NO;
}
@ -1675,4 +1672,3 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq
}
@end