From 3b4eff0837f1091b821637db366fa600c1f23aa8 Mon Sep 17 00:00:00 2001 From: "pinkerton%netscape.com" Date: Tue, 23 Apr 2002 03:57:09 +0000 Subject: [PATCH] Beginnings of dnd support. --- camino/CHBrowserView.h | 6 +++ camino/CHBrowserView.mm | 66 ++++++++++++++++++++++++++ camino/src/embedding/CHBrowserView.h | 6 +++ camino/src/embedding/CHBrowserView.mm | 66 ++++++++++++++++++++++++++ chimera/CHBrowserView.h | 6 +++ chimera/CHBrowserView.mm | 66 ++++++++++++++++++++++++++ chimera/src/embedding/CHBrowserView.h | 6 +++ chimera/src/embedding/CHBrowserView.mm | 66 ++++++++++++++++++++++++++ 8 files changed, 288 insertions(+) diff --git a/camino/CHBrowserView.h b/camino/CHBrowserView.h index 53e388a9c70..ee2bd4268d1 100644 --- a/camino/CHBrowserView.h +++ b/camino/CHBrowserView.h @@ -48,6 +48,9 @@ class nsIWebBrowser; class nsIDOMNode; class nsIDOMEvent; class nsIWebBrowserFind; +class nsIEventSink; +class nsIDragHelperService; + // Protocol implemented by anyone interested in progress // related to a BrowserView. A listener should explicitly @@ -101,6 +104,9 @@ enum { nsIWebBrowser* _webBrowser; nsCocoaBrowserListener* _listener; NSWindow* mWindow; + nsIEventSink* mEventSink; + + nsIDragHelperService* mDragHelper; } // NSView overrides diff --git a/camino/CHBrowserView.mm b/camino/CHBrowserView.mm index 2d0d8fe161a..aaacfa274a9 100644 --- a/camino/CHBrowserView.mm +++ b/camino/CHBrowserView.mm @@ -51,6 +51,7 @@ #include "nsIURI.h" #include "nsIDOMWindow.h" #include "nsWeakReference.h" +#include "nsIWidget.h" // XPCOM and String includes #include "nsCRT.h" @@ -81,6 +82,10 @@ #include "nsNetUtil.h" #include "nsIContextMenuListener.h" +typedef unsigned int DragReference; +#include "nsIDragHelperService.h" + + // Cut/copy/paste #include "nsIClipboardCommands.h" #include "nsIInterfaceRequestorUtils.h" @@ -959,6 +964,17 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, baseWin->InitWindow((NSView*)self, nsnull, 0, 0, frame.size.width, frame.size.height); baseWin->Create(); + + nsCOMPtr topLevel; + baseWin->GetMainWidget(getter_AddRefs(topLevel)); + nsCOMPtr sink = do_QueryInterface(topLevel); + mEventSink = sink.get(); + NS_IF_ADDREF(mEventSink); + NS_ASSERTION(mEventSink, "Couldn't get event sink!"); + + // register the view as a drop site for text, files, and urls. + [self registerForDraggedTypes: + [NSArray arrayWithObjects:NSStringPboardType, NSURLPboardType, NSFilenamesPboardType, nil]]; } return self; } @@ -975,6 +991,7 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, NS_RELEASE(_listener); NS_IF_RELEASE(_webBrowser); + NS_IF_RELEASE(mEventSink); nsCocoaBrowserService::BrowserClosed(); @@ -1411,5 +1428,54 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, } } + +- (unsigned int)draggingEntered:(id )sender +{ + nsCOMPtr helper(do_GetService("@mozilla.org/widget/draghelperservice;1")); + mDragHelper = helper.get(); + NS_IF_ADDREF(mDragHelper); + NS_ASSERTION ( mDragHelper, "Couldn't get a drag service, we're in biiig trouble" ); + + if ( mDragHelper ) + mDragHelper->Enter ( [sender draggingSequenceNumber], mEventSink ); + + return NSDragOperationCopy; +} + +- (void)draggingExited:(id )sender +{ + if ( mDragHelper ) { + mDragHelper->Leave ( [sender draggingSequenceNumber], mEventSink ); + NS_RELEASE(mDragHelper); + } +} + +- (unsigned int)draggingUpdated:(id )sender +{ + PRBool dropAllowed = PR_FALSE; + if ( mDragHelper ) + mDragHelper->Tracking ( [sender draggingSequenceNumber], mEventSink, &dropAllowed ); + + NSLog(@"Drop allowed is %d", dropAllowed); + return dropAllowed ? NSDragOperationCopy : NSDragOperationNone; +} + +- (BOOL)prepareForDragOperation:(id )sender +{ + return YES; +} + +- (BOOL)performDragOperation:(id )sender +{ + NSLog(@"Drag DROP!"); + + PRBool dragAccepted = PR_FALSE; + if ( mDragHelper ) + mDragHelper->Drop ( [sender draggingSequenceNumber], mEventSink, &dragAccepted ); + + return dragAccepted; +} + + @end diff --git a/camino/src/embedding/CHBrowserView.h b/camino/src/embedding/CHBrowserView.h index 53e388a9c70..ee2bd4268d1 100644 --- a/camino/src/embedding/CHBrowserView.h +++ b/camino/src/embedding/CHBrowserView.h @@ -48,6 +48,9 @@ class nsIWebBrowser; class nsIDOMNode; class nsIDOMEvent; class nsIWebBrowserFind; +class nsIEventSink; +class nsIDragHelperService; + // Protocol implemented by anyone interested in progress // related to a BrowserView. A listener should explicitly @@ -101,6 +104,9 @@ enum { nsIWebBrowser* _webBrowser; nsCocoaBrowserListener* _listener; NSWindow* mWindow; + nsIEventSink* mEventSink; + + nsIDragHelperService* mDragHelper; } // NSView overrides diff --git a/camino/src/embedding/CHBrowserView.mm b/camino/src/embedding/CHBrowserView.mm index 2d0d8fe161a..aaacfa274a9 100644 --- a/camino/src/embedding/CHBrowserView.mm +++ b/camino/src/embedding/CHBrowserView.mm @@ -51,6 +51,7 @@ #include "nsIURI.h" #include "nsIDOMWindow.h" #include "nsWeakReference.h" +#include "nsIWidget.h" // XPCOM and String includes #include "nsCRT.h" @@ -81,6 +82,10 @@ #include "nsNetUtil.h" #include "nsIContextMenuListener.h" +typedef unsigned int DragReference; +#include "nsIDragHelperService.h" + + // Cut/copy/paste #include "nsIClipboardCommands.h" #include "nsIInterfaceRequestorUtils.h" @@ -959,6 +964,17 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, baseWin->InitWindow((NSView*)self, nsnull, 0, 0, frame.size.width, frame.size.height); baseWin->Create(); + + nsCOMPtr topLevel; + baseWin->GetMainWidget(getter_AddRefs(topLevel)); + nsCOMPtr sink = do_QueryInterface(topLevel); + mEventSink = sink.get(); + NS_IF_ADDREF(mEventSink); + NS_ASSERTION(mEventSink, "Couldn't get event sink!"); + + // register the view as a drop site for text, files, and urls. + [self registerForDraggedTypes: + [NSArray arrayWithObjects:NSStringPboardType, NSURLPboardType, NSFilenamesPboardType, nil]]; } return self; } @@ -975,6 +991,7 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, NS_RELEASE(_listener); NS_IF_RELEASE(_webBrowser); + NS_IF_RELEASE(mEventSink); nsCocoaBrowserService::BrowserClosed(); @@ -1411,5 +1428,54 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, } } + +- (unsigned int)draggingEntered:(id )sender +{ + nsCOMPtr helper(do_GetService("@mozilla.org/widget/draghelperservice;1")); + mDragHelper = helper.get(); + NS_IF_ADDREF(mDragHelper); + NS_ASSERTION ( mDragHelper, "Couldn't get a drag service, we're in biiig trouble" ); + + if ( mDragHelper ) + mDragHelper->Enter ( [sender draggingSequenceNumber], mEventSink ); + + return NSDragOperationCopy; +} + +- (void)draggingExited:(id )sender +{ + if ( mDragHelper ) { + mDragHelper->Leave ( [sender draggingSequenceNumber], mEventSink ); + NS_RELEASE(mDragHelper); + } +} + +- (unsigned int)draggingUpdated:(id )sender +{ + PRBool dropAllowed = PR_FALSE; + if ( mDragHelper ) + mDragHelper->Tracking ( [sender draggingSequenceNumber], mEventSink, &dropAllowed ); + + NSLog(@"Drop allowed is %d", dropAllowed); + return dropAllowed ? NSDragOperationCopy : NSDragOperationNone; +} + +- (BOOL)prepareForDragOperation:(id )sender +{ + return YES; +} + +- (BOOL)performDragOperation:(id )sender +{ + NSLog(@"Drag DROP!"); + + PRBool dragAccepted = PR_FALSE; + if ( mDragHelper ) + mDragHelper->Drop ( [sender draggingSequenceNumber], mEventSink, &dragAccepted ); + + return dragAccepted; +} + + @end diff --git a/chimera/CHBrowserView.h b/chimera/CHBrowserView.h index 53e388a9c70..ee2bd4268d1 100644 --- a/chimera/CHBrowserView.h +++ b/chimera/CHBrowserView.h @@ -48,6 +48,9 @@ class nsIWebBrowser; class nsIDOMNode; class nsIDOMEvent; class nsIWebBrowserFind; +class nsIEventSink; +class nsIDragHelperService; + // Protocol implemented by anyone interested in progress // related to a BrowserView. A listener should explicitly @@ -101,6 +104,9 @@ enum { nsIWebBrowser* _webBrowser; nsCocoaBrowserListener* _listener; NSWindow* mWindow; + nsIEventSink* mEventSink; + + nsIDragHelperService* mDragHelper; } // NSView overrides diff --git a/chimera/CHBrowserView.mm b/chimera/CHBrowserView.mm index 2d0d8fe161a..aaacfa274a9 100644 --- a/chimera/CHBrowserView.mm +++ b/chimera/CHBrowserView.mm @@ -51,6 +51,7 @@ #include "nsIURI.h" #include "nsIDOMWindow.h" #include "nsWeakReference.h" +#include "nsIWidget.h" // XPCOM and String includes #include "nsCRT.h" @@ -81,6 +82,10 @@ #include "nsNetUtil.h" #include "nsIContextMenuListener.h" +typedef unsigned int DragReference; +#include "nsIDragHelperService.h" + + // Cut/copy/paste #include "nsIClipboardCommands.h" #include "nsIInterfaceRequestorUtils.h" @@ -959,6 +964,17 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, baseWin->InitWindow((NSView*)self, nsnull, 0, 0, frame.size.width, frame.size.height); baseWin->Create(); + + nsCOMPtr topLevel; + baseWin->GetMainWidget(getter_AddRefs(topLevel)); + nsCOMPtr sink = do_QueryInterface(topLevel); + mEventSink = sink.get(); + NS_IF_ADDREF(mEventSink); + NS_ASSERTION(mEventSink, "Couldn't get event sink!"); + + // register the view as a drop site for text, files, and urls. + [self registerForDraggedTypes: + [NSArray arrayWithObjects:NSStringPboardType, NSURLPboardType, NSFilenamesPboardType, nil]]; } return self; } @@ -975,6 +991,7 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, NS_RELEASE(_listener); NS_IF_RELEASE(_webBrowser); + NS_IF_RELEASE(mEventSink); nsCocoaBrowserService::BrowserClosed(); @@ -1411,5 +1428,54 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, } } + +- (unsigned int)draggingEntered:(id )sender +{ + nsCOMPtr helper(do_GetService("@mozilla.org/widget/draghelperservice;1")); + mDragHelper = helper.get(); + NS_IF_ADDREF(mDragHelper); + NS_ASSERTION ( mDragHelper, "Couldn't get a drag service, we're in biiig trouble" ); + + if ( mDragHelper ) + mDragHelper->Enter ( [sender draggingSequenceNumber], mEventSink ); + + return NSDragOperationCopy; +} + +- (void)draggingExited:(id )sender +{ + if ( mDragHelper ) { + mDragHelper->Leave ( [sender draggingSequenceNumber], mEventSink ); + NS_RELEASE(mDragHelper); + } +} + +- (unsigned int)draggingUpdated:(id )sender +{ + PRBool dropAllowed = PR_FALSE; + if ( mDragHelper ) + mDragHelper->Tracking ( [sender draggingSequenceNumber], mEventSink, &dropAllowed ); + + NSLog(@"Drop allowed is %d", dropAllowed); + return dropAllowed ? NSDragOperationCopy : NSDragOperationNone; +} + +- (BOOL)prepareForDragOperation:(id )sender +{ + return YES; +} + +- (BOOL)performDragOperation:(id )sender +{ + NSLog(@"Drag DROP!"); + + PRBool dragAccepted = PR_FALSE; + if ( mDragHelper ) + mDragHelper->Drop ( [sender draggingSequenceNumber], mEventSink, &dragAccepted ); + + return dragAccepted; +} + + @end diff --git a/chimera/src/embedding/CHBrowserView.h b/chimera/src/embedding/CHBrowserView.h index 53e388a9c70..ee2bd4268d1 100644 --- a/chimera/src/embedding/CHBrowserView.h +++ b/chimera/src/embedding/CHBrowserView.h @@ -48,6 +48,9 @@ class nsIWebBrowser; class nsIDOMNode; class nsIDOMEvent; class nsIWebBrowserFind; +class nsIEventSink; +class nsIDragHelperService; + // Protocol implemented by anyone interested in progress // related to a BrowserView. A listener should explicitly @@ -101,6 +104,9 @@ enum { nsIWebBrowser* _webBrowser; nsCocoaBrowserListener* _listener; NSWindow* mWindow; + nsIEventSink* mEventSink; + + nsIDragHelperService* mDragHelper; } // NSView overrides diff --git a/chimera/src/embedding/CHBrowserView.mm b/chimera/src/embedding/CHBrowserView.mm index 2d0d8fe161a..aaacfa274a9 100644 --- a/chimera/src/embedding/CHBrowserView.mm +++ b/chimera/src/embedding/CHBrowserView.mm @@ -51,6 +51,7 @@ #include "nsIURI.h" #include "nsIDOMWindow.h" #include "nsWeakReference.h" +#include "nsIWidget.h" // XPCOM and String includes #include "nsCRT.h" @@ -81,6 +82,10 @@ #include "nsNetUtil.h" #include "nsIContextMenuListener.h" +typedef unsigned int DragReference; +#include "nsIDragHelperService.h" + + // Cut/copy/paste #include "nsIClipboardCommands.h" #include "nsIInterfaceRequestorUtils.h" @@ -959,6 +964,17 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, baseWin->InitWindow((NSView*)self, nsnull, 0, 0, frame.size.width, frame.size.height); baseWin->Create(); + + nsCOMPtr topLevel; + baseWin->GetMainWidget(getter_AddRefs(topLevel)); + nsCOMPtr sink = do_QueryInterface(topLevel); + mEventSink = sink.get(); + NS_IF_ADDREF(mEventSink); + NS_ASSERTION(mEventSink, "Couldn't get event sink!"); + + // register the view as a drop site for text, files, and urls. + [self registerForDraggedTypes: + [NSArray arrayWithObjects:NSStringPboardType, NSURLPboardType, NSFilenamesPboardType, nil]]; } return self; } @@ -975,6 +991,7 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, NS_RELEASE(_listener); NS_IF_RELEASE(_webBrowser); + NS_IF_RELEASE(mEventSink); nsCocoaBrowserService::BrowserClosed(); @@ -1411,5 +1428,54 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, } } + +- (unsigned int)draggingEntered:(id )sender +{ + nsCOMPtr helper(do_GetService("@mozilla.org/widget/draghelperservice;1")); + mDragHelper = helper.get(); + NS_IF_ADDREF(mDragHelper); + NS_ASSERTION ( mDragHelper, "Couldn't get a drag service, we're in biiig trouble" ); + + if ( mDragHelper ) + mDragHelper->Enter ( [sender draggingSequenceNumber], mEventSink ); + + return NSDragOperationCopy; +} + +- (void)draggingExited:(id )sender +{ + if ( mDragHelper ) { + mDragHelper->Leave ( [sender draggingSequenceNumber], mEventSink ); + NS_RELEASE(mDragHelper); + } +} + +- (unsigned int)draggingUpdated:(id )sender +{ + PRBool dropAllowed = PR_FALSE; + if ( mDragHelper ) + mDragHelper->Tracking ( [sender draggingSequenceNumber], mEventSink, &dropAllowed ); + + NSLog(@"Drop allowed is %d", dropAllowed); + return dropAllowed ? NSDragOperationCopy : NSDragOperationNone; +} + +- (BOOL)prepareForDragOperation:(id )sender +{ + return YES; +} + +- (BOOL)performDragOperation:(id )sender +{ + NSLog(@"Drag DROP!"); + + PRBool dragAccepted = PR_FALSE; + if ( mDragHelper ) + mDragHelper->Drop ( [sender draggingSequenceNumber], mEventSink, &dragAccepted ); + + return dragAccepted; +} + + @end