diff --git a/mozilla/layout/xul/base/src/nsToolbarDragListener.cpp b/mozilla/layout/xul/base/src/nsToolbarDragListener.cpp index 9ee50ec48bb..53c5ddbc3db 100644 --- a/mozilla/layout/xul/base/src/nsToolbarDragListener.cpp +++ b/mozilla/layout/xul/base/src/nsToolbarDragListener.cpp @@ -54,9 +54,7 @@ NS_IMPL_RELEASE(nsToolbarDragListener) // Not much to do besides init member variables // nsToolbarDragListener :: nsToolbarDragListener ( nsToolbarFrame* inToolbar, nsIPresContext* inPresContext ) - : mToolbar(inToolbar), mPresContext(inPresContext), mCurrentDropLoc(-1), - mMouseDown(PR_FALSE), mMouseDrag(PR_FALSE) - + : mToolbar(inToolbar), mPresContext(inPresContext), mCurrentDropLoc(-1) { NS_INIT_REFCNT(); } @@ -88,10 +86,6 @@ nsToolbarDragListener::QueryInterface(REFNSIID aIID, void** aInstancePtr) *aInstancePtr = NS_STATIC_CAST(nsIDOMEventListener*, NS_STATIC_CAST(nsIDOMDragListener*, this)); else if (aIID.Equals(nsCOMTypeInfo::GetIID())) *aInstancePtr = NS_STATIC_CAST(nsIDOMDragListener*, this); - else if (aIID.Equals(nsCOMTypeInfo::GetIID())) - *aInstancePtr = NS_STATIC_CAST(nsIDOMMouseMotionListener*, this); - else if (aIID.Equals(nsCOMTypeInfo::GetIID())) - *aInstancePtr = NS_STATIC_CAST(nsIDOMMouseListener*, this); else if (aIID.Equals(nsCOMTypeInfo::GetIID())) *aInstancePtr = NS_STATIC_CAST(nsISupports*, NS_STATIC_CAST(nsIDOMDragListener*, this)); else @@ -140,6 +134,67 @@ nsToolbarDragListener::HandleEvent(nsIDOMEvent* aEvent) } +//////////////////////////////////////////////////////////////////////// +nsresult +nsToolbarDragListener::DragGesture(nsIDOMEvent* aDragEvent) +{ + // XXX At the moment toolbar drags contain "text" + // in the future they will probably contain some form of content + // that will be translated into some RDF form + + nsresult rv = NS_OK; + // Ok now check to see if we are dragging a toolbar item + // or the toolbar itself + nscoord xLoc; + PRBool isLegalChild; + PRBool onChild = IsOnToolbarItem(aDragEvent, xLoc, isLegalChild); + + if (onChild) { + if (isLegalChild) { + + // Start Drag + nsIDragService* dragService; + rv = nsServiceManager::GetService(kCDragServiceCID, + nsIDragService::GetIID(), + (nsISupports **)&dragService); + if (NS_OK == rv) { + // XXX NOTE! + // Here you need to create a special transferable + // for handling RDF nodes (instead of this text transferable) + nsCOMPtr trans; + rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, + nsITransferable::GetIID(), getter_AddRefs(trans)); + if (NS_OK == rv && trans) { + nsString ddFlavor; + nsString dragText; + if (onChild) { + ddFlavor = TOOLBARITEM_MIME; + dragText = "toolbar item"; + } else { + ddFlavor = TOOLBAR_MIME; + dragText = "toolbar"; + } + trans->AddDataFlavor(&ddFlavor); + PRUint32 len = dragText.Length(); + trans->SetTransferData(&ddFlavor, dragText.ToNewCString(), len); // transferable consumes the data + + nsCOMPtr items; + NS_NewISupportsArray(getter_AddRefs(items)); + if ( items ) { + items->AppendElement(trans); + dragService->InvokeDragSession(items, nsnull, nsIDragService::DRAGDROP_ACTION_COPY | nsIDragService::DRAGDROP_ACTION_MOVE); + } + } + nsServiceManager::ReleaseService(kCDragServiceCID, dragService); + } + } else { // when it is isn't a legal child then don't consume + return NS_OK; // don't consume event + } + rv = NS_ERROR_BASE; // consumes the event + } + return rv; +} + //////////////////////////////////////////////////////////////////////// nsresult @@ -444,132 +499,3 @@ nsToolbarDragListener::DragDrop(nsIDOMEvent* aMouseEvent) return NS_ERROR_BASE; // consumes the event } -//////////////////////////////////////////////////////////////////////// -nsresult -nsToolbarDragListener::MouseMove(nsIDOMEvent* aMouseEvent) -{ -//XXX people are complaining that the drag start is too sensitive and it's keeping -//XXX them from clicking on buttons. Pooh. Disable this until I can get a better -//XXX heuristic than 1-pixel mouse move -> drag start. -#define UNTIL_NOT_SO_TWITCHY 1 -#if UNTIL_NOT_SO_TWITCHY - return NS_OK; -#endif - - // XXX At the moment toolbar drags contain "text" - // in the future they will probably contain some form of content - // that will be translated into some RDF form - - nsresult rv = NS_OK; - //printf("nsToolbarDragListener::MouseMove mMouseDown %d mMouseDrag %d\n", mMouseDown, mMouseDrag); - if (mMouseDown && !mMouseDrag) { - // Ok now check to see if we are dragging a toolbar item - // or the toolbar itself - nscoord xLoc; - PRBool isLegalChild; - PRBool onChild = IsOnToolbarItem(aMouseEvent, xLoc, isLegalChild); - - if (onChild) { - if (isLegalChild) { - mMouseDrag = PR_TRUE; - - // Start Drag - nsIDragService* dragService; - rv = nsServiceManager::GetService(kCDragServiceCID, - nsIDragService::GetIID(), - (nsISupports **)&dragService); - if (NS_OK == rv) { - // XXX NOTE! - // Here you need to create a special transferable - // for handling RDF nodes (instead of this text transferable) - nsCOMPtr trans; - rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, - nsITransferable::GetIID(), getter_AddRefs(trans)); - if (NS_OK == rv && trans) { - nsString ddFlavor; - nsString dragText; - if (onChild) { - ddFlavor = TOOLBARITEM_MIME; - dragText = "toolbar item"; - } else { - ddFlavor = TOOLBAR_MIME; - dragText = "toolbar"; - } - trans->AddDataFlavor(&ddFlavor); - PRUint32 len = dragText.Length(); - trans->SetTransferData(&ddFlavor, dragText.ToNewCString(), len); // transferable consumes the data - - nsCOMPtr items; - NS_NewISupportsArray(getter_AddRefs(items)); - if ( items ) { - items->AppendElement(trans); - dragService->InvokeDragSession(items, nsnull, nsIDragService::DRAGDROP_ACTION_COPY | nsIDragService::DRAGDROP_ACTION_MOVE); - mMouseDown = PR_FALSE; - mMouseDrag = PR_FALSE; - } - } - nsServiceManager::ReleaseService(kCDragServiceCID, dragService); - } - } else { // when it is isn't a legal child then don't consume - return NS_OK; // don't consume event - } - rv = NS_ERROR_BASE; // consumes the event - } - } - return rv; -} - -//////////////////////////////////////////////////////////////////////// -nsresult -nsToolbarDragListener::DragMove(nsIDOMEvent* aMouseEvent) -{ - return NS_OK; // means I am NOT consuming event -} - - -//////////////////////////////////////////////////////////////////////// -nsresult -nsToolbarDragListener::MouseDown(nsIDOMEvent* aMouseEvent) -{ - mMouseDown = PR_TRUE; - return NS_OK; // means I am NOT consuming event -} - -//////////////////////////////////////////////////////////////////////// -nsresult -nsToolbarDragListener::MouseUp(nsIDOMEvent* aMouseEvent) -{ - printf("nsToolbarDragListener::MouseUp\n"); - nsresult res = (mMouseDrag?NS_ERROR_BASE:NS_OK); - mMouseDown = PR_FALSE; - mMouseDrag = PR_FALSE; - return res; -} - -//////////////////////////////////////////////////////////////////////// -nsresult -nsToolbarDragListener::MouseClick(nsIDOMEvent* aMouseEvent) -{ - return NS_OK; // means I am NOT consuming event -} - -//////////////////////////////////////////////////////////////////////// -nsresult -nsToolbarDragListener::MouseDblClick(nsIDOMEvent* aMouseEvent) -{ - return NS_OK; // means I am NOT consuming event -} - -//////////////////////////////////////////////////////////////////////// -nsresult -nsToolbarDragListener::MouseOver(nsIDOMEvent* aMouseEvent) -{ - return NS_OK; // means I am NOT consuming event -} - -//////////////////////////////////////////////////////////////////////// -nsresult -nsToolbarDragListener::MouseOut(nsIDOMEvent* aMouseEvent) -{ - return NS_OK; // means I am NOT consuming event -} diff --git a/mozilla/layout/xul/base/src/nsToolbarDragListener.h b/mozilla/layout/xul/base/src/nsToolbarDragListener.h index 7b8914902f8..94f9b38cc03 100644 --- a/mozilla/layout/xul/base/src/nsToolbarDragListener.h +++ b/mozilla/layout/xul/base/src/nsToolbarDragListener.h @@ -21,9 +21,6 @@ #define nsToolbarDragListener_h__ #include "nsIDOMDragListener.h" -#include "nsIDOMMouseMotionListener.h" -#include "nsIDOMMouseListener.h" - #include "nsCoord.h" @@ -32,7 +29,7 @@ class nsIPresContext; class nsIDOMEvent; -class nsToolbarDragListener : public nsIDOMDragListener, public nsIDOMMouseListener, public nsIDOMMouseMotionListener +class nsToolbarDragListener : public nsIDOMDragListener { public: @@ -49,18 +46,7 @@ public: virtual nsresult DragOver(nsIDOMEvent* aDragEvent); virtual nsresult DragExit(nsIDOMEvent* aDragEvent); virtual nsresult DragDrop(nsIDOMEvent* aDragEvent); - - // nsIDOMMouseMotionListener - virtual nsresult MouseMove(nsIDOMEvent* aMouseEvent); - virtual nsresult DragMove(nsIDOMEvent* aMouseEvent); - - // nsIDOMMouseListener - virtual nsresult MouseDown(nsIDOMEvent* aMouseEvent); - virtual nsresult MouseUp(nsIDOMEvent* aMouseEvent); - virtual nsresult MouseClick(nsIDOMEvent* aMouseEvent); - virtual nsresult MouseDblClick(nsIDOMEvent* aMouseEvent); - virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent); - virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent); + virtual nsresult DragGesture(nsIDOMEvent* aDragEvent); protected: @@ -70,9 +56,6 @@ protected: nsIPresContext * mPresContext; // weak reference PRInt32 mCurrentDropLoc; - PRBool mMouseDown; - PRBool mMouseDrag; - }; // class nsToolbarDragListener diff --git a/mozilla/layout/xul/base/src/nsToolbarFrame.cpp b/mozilla/layout/xul/base/src/nsToolbarFrame.cpp index bc3814c67a6..6f40648647d 100644 --- a/mozilla/layout/xul/base/src/nsToolbarFrame.cpp +++ b/mozilla/layout/xul/base/src/nsToolbarFrame.cpp @@ -29,6 +29,7 @@ #include "nsToolbarDragListener.h" #include "nsIDOMEventReceiver.h" +#include "nsIDOMDragListener.h" #include "nsIContent.h" #include "nsIPresContext.h" #include "nsIStyleContext.h" @@ -36,35 +37,36 @@ #define TEMP_HACK_FOR_BUG_11291 1 #if TEMP_HACK_FOR_BUG_11291 -// for temp fix of bug 11291 +// for temp fix of bug 11291. This should really be in JavaScript, I think. #include "nsIDOMNodeList.h" #include "nsIDOMElement.h" -class nsTEMPMouseDownEater : public nsIDOMMouseListener + + +class nsTEMPDragGestureEater : public nsIDOMDragListener { public: // default ctor and dtor - nsTEMPMouseDownEater ( ) ; - virtual ~nsTEMPMouseDownEater() { }; + nsTEMPDragGestureEater ( ) ; + virtual ~nsTEMPDragGestureEater() { }; // interfaces for addref and release and queryinterface NS_DECL_ISUPPORTS // nsIDOMMouseListener virtual nsresult HandleEvent(nsIDOMEvent* aEvent); - virtual nsresult MouseDown(nsIDOMEvent* aMouseEvent); - virtual nsresult MouseUp(nsIDOMEvent* aMouseEvent); - virtual nsresult MouseClick(nsIDOMEvent* aMouseEvent); - virtual nsresult MouseDblClick(nsIDOMEvent* aMouseEvent); - virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent); - virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent); + virtual nsresult DragEnter(nsIDOMEvent* aMouseEvent); + virtual nsresult DragOver(nsIDOMEvent* aMouseEvent); + virtual nsresult DragExit(nsIDOMEvent* aMouseEvent); + virtual nsresult DragDrop(nsIDOMEvent* aMouseEvent); + virtual nsresult DragGesture(nsIDOMEvent* aMouseEvent); -}; // class nsTEMPMouseDownEater +}; // class nsTEMPDragGestureEater -NS_IMPL_ADDREF(nsTEMPMouseDownEater) -NS_IMPL_RELEASE(nsTEMPMouseDownEater) +NS_IMPL_ADDREF(nsTEMPDragGestureEater) +NS_IMPL_RELEASE(nsTEMPDragGestureEater) -nsTEMPMouseDownEater :: nsTEMPMouseDownEater ( ) +nsTEMPDragGestureEater :: nsTEMPDragGestureEater ( ) { NS_INIT_REFCNT(); } @@ -76,17 +78,17 @@ nsTEMPMouseDownEater :: nsTEMPMouseDownEater ( ) // http://www.mozilla.org/projects/xpcom/QI.html // nsresult -nsTEMPMouseDownEater::QueryInterface(REFNSIID aIID, void** aInstancePtr) +nsTEMPDragGestureEater::QueryInterface(REFNSIID aIID, void** aInstancePtr) { if ( !aInstancePtr) return NS_ERROR_NULL_POINTER; if (aIID.Equals(nsCOMTypeInfo::GetIID())) *aInstancePtr = NS_STATIC_CAST(nsIDOMEventListener*, this); - else if (aIID.Equals(nsCOMTypeInfo::GetIID())) - *aInstancePtr = NS_STATIC_CAST(nsIDOMMouseListener*, this); + else if (aIID.Equals(nsCOMTypeInfo::GetIID())) + *aInstancePtr = NS_STATIC_CAST(nsIDOMDragListener*, this); else if (aIID.Equals(nsCOMTypeInfo::GetIID())) - *aInstancePtr = NS_STATIC_CAST(nsISupports*, NS_STATIC_CAST(nsIDOMMouseListener*, this)); + *aInstancePtr = NS_STATIC_CAST(nsISupports*, NS_STATIC_CAST(nsIDOMDragListener*, this)); else *aInstancePtr = 0; @@ -101,47 +103,41 @@ nsTEMPMouseDownEater::QueryInterface(REFNSIID aIID, void** aInstancePtr) } nsresult -nsTEMPMouseDownEater :: HandleEvent(nsIDOMEvent* aEvent) +nsTEMPDragGestureEater :: HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; } nsresult -nsTEMPMouseDownEater::MouseDown(nsIDOMEvent* aMouseEvent) +nsTEMPDragGestureEater::DragGesture(nsIDOMEvent* aMouseEvent) { // we want the text widget to see this event, but not anyone above us that - // might be registered as a listener for mouse clicks. Therefore, don't + // might be registered as a listener for drags. Therefore, don't // allow this event to bubble. aMouseEvent->PreventBubble(); - return NS_OK; // means I am NOT consuming event + return NS_ERROR_BASE; // means I AM consuming event } nsresult -nsTEMPMouseDownEater::MouseUp(nsIDOMEvent* aMouseEvent) +nsTEMPDragGestureEater::DragEnter(nsIDOMEvent* aMouseEvent) { return NS_OK; // means I am NOT consuming event } nsresult -nsTEMPMouseDownEater::MouseClick(nsIDOMEvent* aMouseEvent) +nsTEMPDragGestureEater::DragOver(nsIDOMEvent* aMouseEvent) { return NS_OK; // means I am NOT consuming event } nsresult -nsTEMPMouseDownEater::MouseDblClick(nsIDOMEvent* aMouseEvent) +nsTEMPDragGestureEater::DragExit(nsIDOMEvent* aMouseEvent) { return NS_OK; // means I am NOT consuming event } nsresult -nsTEMPMouseDownEater::MouseOver(nsIDOMEvent* aMouseEvent) -{ - return NS_OK; // means I am NOT consuming event -} - -nsresult -nsTEMPMouseDownEater::MouseOut(nsIDOMEvent* aMouseEvent) +nsTEMPDragGestureEater::DragDrop(nsIDOMEvent* aMouseEvent) { return NS_OK; // means I am NOT consuming event } @@ -196,10 +192,8 @@ nsToolbarFrame :: ~nsToolbarFrame ( ) GetContent(getter_AddRefs(content)); nsCOMPtr reciever(do_QueryInterface(content)); - // NOTE: the last Remove will delete the drag listener + // NOTE: the Remove will delete the drag listener reciever->RemoveEventListenerByIID((nsIDOMDragListener *)mDragListener, nsIDOMDragListener::GetIID()); - reciever->RemoveEventListenerByIID((nsIDOMMouseListener *)mDragListener, nsIDOMMouseListener::GetIID()); - reciever->RemoveEventListenerByIID((nsIDOMMouseMotionListener *)mDragListener, nsIDOMMouseMotionListener::GetIID()); } @@ -225,8 +219,6 @@ nsToolbarFrame::Init ( nsIPresContext& aPresContext, nsIContent* aContent, mDragListener = new nsToolbarDragListener(this, &aPresContext); receiver->AddEventListenerByIID((nsIDOMDragListener *)mDragListener, nsIDOMDragListener::GetIID()); - receiver->AddEventListenerByIID((nsIDOMMouseListener *)mDragListener, nsIDOMMouseListener::GetIID()); - receiver->AddEventListenerByIID((nsIDOMMouseMotionListener *)mDragListener, nsIDOMMouseMotionListener::GetIID()); #if TEMP_HACK_FOR_BUG_11291 // Ok, this is a hack until Ender lands. We need to have a mouse listener on text widgets @@ -245,7 +237,7 @@ nsToolbarFrame::Init ( nsIPresContext& aPresContext, nsIContent* aContent, inputList->Item(i, getter_AddRefs(node)); nsCOMPtr receiver(do_QueryInterface(node)); if ( receiver ) - receiver->AddEventListenerByIID(new nsTEMPMouseDownEater, nsIDOMMouseListener::GetIID()); + receiver->AddEventListenerByIID(new nsTEMPDragGestureEater, nsIDOMDragListener::GetIID()); // yes, i know this will leak. That's ok, i don't care because this code will go away } } @@ -345,17 +337,6 @@ nsToolbarFrame :: HandleEvent ( nsIPresContext& aPresContext, } break; - case NS_DRAGDROP_OVER: - break; - - case NS_DRAGDROP_EXIT: - mMarkerStyle = do_QueryInterface(nsnull); - // remove drop feedback - break; - - case NS_DRAGDROP_DROP: - // do drop coolness stuff - break; } //XXX this needs to change when I am really handling the D&D events diff --git a/mozilla/layout/xul/base/src/nsToolboxFrame.cpp b/mozilla/layout/xul/base/src/nsToolboxFrame.cpp index 24e5f1790fd..af96e7706bc 100644 --- a/mozilla/layout/xul/base/src/nsToolboxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsToolboxFrame.cpp @@ -77,6 +77,11 @@ public: { return mFrame ? mFrame->HandleEvent(aEvent) : NS_OK; } + + virtual nsresult DragGesture(nsIDOMEvent* aEvent) + { + return mFrame ? mFrame->DragGesture(aEvent) : NS_OK; + } // nsIDOMDragListener interface virtual nsresult DragEnter(nsIDOMEvent* aMouseEvent) diff --git a/mozilla/layout/xul/base/src/nsToolboxFrame.h b/mozilla/layout/xul/base/src/nsToolboxFrame.h index 1e88601f842..d363e838abf 100644 --- a/mozilla/layout/xul/base/src/nsToolboxFrame.h +++ b/mozilla/layout/xul/base/src/nsToolboxFrame.h @@ -88,6 +88,7 @@ public: virtual nsresult DragOver(nsIDOMEvent* aDragEvent); virtual nsresult DragExit(nsIDOMEvent* aDragEvent); virtual nsresult DragDrop(nsIDOMEvent* aDragEvent); + virtual nsresult DragGesture(nsIDOMEvent* aDragEvent) { return NS_OK; } /*END implementations of dragevent handler interface*/ protected: