mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-11 16:32:59 +00:00
infrastructure to handle dragdrop. Not part of build
This commit is contained in:
parent
1938b600bf
commit
cd310bf362
@ -62,6 +62,7 @@ CPPSRCS = \
|
||||
nsClipboard.cpp \
|
||||
nsDeleteObserver.cpp \
|
||||
nsDragService.cpp \
|
||||
nsDragHelperService.cpp \
|
||||
nsFilePicker.cpp \
|
||||
nsLookAndFeel.cpp \
|
||||
nsMacResources.cpp \
|
||||
@ -87,6 +88,7 @@ CMMSRCS = \
|
||||
XPIDLSRCS += \
|
||||
nsIChangeManager.idl \
|
||||
nsIMenuCommandDispatcher.idl \
|
||||
nsIDragHelperService.idl \
|
||||
$(NULL)
|
||||
|
||||
GARBAGE += $(GFX_LCPPSRCS)
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "nsISupports.h"
|
||||
#include "nsBaseWidget.h"
|
||||
#include "nsDeleteObserver.h"
|
||||
#include "nsIEventSink.h"
|
||||
|
||||
#include "nsIWidget.h"
|
||||
#include "nsIKBStateControl.h"
|
||||
@ -65,7 +66,6 @@ struct nsPluginPort;
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
class nsChildView;
|
||||
class nsIEventSink;
|
||||
|
||||
|
||||
@interface ChildView : NSQuickDrawView<mozView>
|
||||
@ -93,6 +93,8 @@ class nsIEventSink;
|
||||
- (void) convert:(NSEvent*)aKeyEvent message:(PRUint32)aMessage
|
||||
isChar:(PRBool*)outIsChar
|
||||
toGeckoEvent:(nsKeyEvent*)outGeckoEvent;
|
||||
- (void) convert:(NSPoint)inPoint message:(PRInt32)inMsg
|
||||
modifiers:(unsigned int)inMods toGeckoEvent:(nsInputEvent*)outGeckoEvent;
|
||||
|
||||
-(NSMenu*)getContextMenu;
|
||||
|
||||
@ -106,7 +108,7 @@ class nsIEventSink;
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
class nsChildView : public nsBaseWidget, public nsDeleteObserved, public nsIKBStateControl
|
||||
class nsChildView : public nsBaseWidget, public nsDeleteObserved, public nsIKBStateControl, public nsIEventSink
|
||||
{
|
||||
private:
|
||||
typedef nsBaseWidget Inherited;
|
||||
@ -116,7 +118,8 @@ public:
|
||||
virtual ~nsChildView();
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
NS_DECL_NSIEVENTSINK
|
||||
|
||||
// nsIWidget interface
|
||||
NS_IMETHOD Create(nsIWidget *aParent,
|
||||
const nsRect &aRect,
|
||||
|
@ -171,7 +171,7 @@ nsChildView::~nsChildView()
|
||||
delete mPluginPort;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED1(nsChildView, nsBaseWidget, nsIKBStateControl);
|
||||
NS_IMPL_ISUPPORTS_INHERITED2(nsChildView, nsBaseWidget, nsIKBStateControl, nsIEventSink);
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
@ -1677,6 +1677,88 @@ nsChildView::GetQuickDrawPort()
|
||||
#pragma mark -
|
||||
|
||||
|
||||
//
|
||||
// DispatchEvent
|
||||
//
|
||||
// Handle an event coming into us and send it to gecko.
|
||||
//
|
||||
NS_IMETHODIMP
|
||||
nsChildView::DispatchEvent ( void* anEvent, PRBool *_retval )
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// DragEvent
|
||||
//
|
||||
// The drag manager has let us know that something related to a drag has
|
||||
// occurred in this window. It could be any number of things, ranging from
|
||||
// a drop, to a drag enter/leave, or a drag over event. The actual event
|
||||
// is passed in |aMessage| and is passed along to our event hanlder so Gecko
|
||||
// knows about it.
|
||||
//
|
||||
NS_IMETHODIMP
|
||||
nsChildView::DragEvent(PRUint32 aMessage, PRInt16 aMouseGlobalX, PRInt16 aMouseGlobalY,
|
||||
PRUint16 aKeyModifiers, PRBool *_retval)
|
||||
{
|
||||
printf("--------- dragEvent\n");
|
||||
nsMouseEvent geckoEvent;
|
||||
geckoEvent.eventStructType = NS_DRAGDROP_EVENT;
|
||||
NSPoint pt; pt.x = aMouseGlobalX; pt.y = aMouseGlobalY;
|
||||
[mView convert:pt message:aMessage modifiers:0 toGeckoEvent:&geckoEvent];
|
||||
|
||||
printf("mouse location is %d %d\n", geckoEvent.point.x, geckoEvent.point.y);
|
||||
DispatchMouseEvent(geckoEvent);
|
||||
|
||||
#if 0
|
||||
nsMouseEvent geckoEvent;
|
||||
geckoEvent.eventStructType = NS_MOUSE_EVENT;
|
||||
[mView convert:theEvent message:aMessage toGeckoEvent:&geckoEvent];
|
||||
|
||||
*_retval = PR_FALSE;
|
||||
Point globalPoint = {aMouseGlobalY, aMouseGlobalX}; // QD Point stored as v, h
|
||||
if (mMacEventHandler.get())
|
||||
*_retval = mMacEventHandler->DragEvent(aMessage, globalPoint, aKeyModifiers);
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Scroll
|
||||
//
|
||||
// Someone wants us to scroll in the current window, probably as the result
|
||||
// of a scrollWheel event or external scrollbars. Pass along to the
|
||||
// eventhandler.
|
||||
//
|
||||
NS_IMETHODIMP
|
||||
nsChildView::Scroll ( PRBool aVertical, PRInt16 aNumLines, PRInt16 aMouseLocalX,
|
||||
PRInt16 aMouseLocalY, PRBool *_retval )
|
||||
{
|
||||
#if 0
|
||||
*_retval = PR_FALSE;
|
||||
Point localPoint = {aMouseLocalY, aMouseLocalX};
|
||||
if ( mMacEventHandler.get() )
|
||||
*_retval = mMacEventHandler->Scroll(aVertical ? kEventMouseWheelAxisY : kEventMouseWheelAxisX,
|
||||
aNumLines, localPoint);
|
||||
#endif
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsChildView::Idle()
|
||||
{
|
||||
// do some idle stuff?
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
|
||||
@implementation ChildView
|
||||
|
||||
-(NSMenu*)menuForEvent:(NSEvent*)theEvent
|
||||
@ -1942,17 +2024,23 @@ const PRInt32 kNumLines = 8;
|
||||
//
|
||||
// -convert:message:toGeckoEvent:
|
||||
//
|
||||
// convert from one event system to the other for even dispatching
|
||||
// convert from one event system to the other for event dispatching
|
||||
//
|
||||
- (void) convert:(NSEvent*)inEvent message:(PRInt32)inMsg toGeckoEvent:(nsInputEvent*)outGeckoEvent
|
||||
{
|
||||
outGeckoEvent->nativeMsg = inEvent;
|
||||
[self convert:[inEvent locationInWindow] message:inMsg modifiers:[inEvent modifierFlags]
|
||||
toGeckoEvent:outGeckoEvent];
|
||||
}
|
||||
|
||||
- (void) convert:(NSPoint)inPoint message:(PRInt32)inMsg modifiers:(unsigned int)inMods toGeckoEvent:(nsInputEvent*)outGeckoEvent
|
||||
{
|
||||
outGeckoEvent->message = inMsg;
|
||||
outGeckoEvent->widget = [self widget];
|
||||
outGeckoEvent->nativeMsg = inEvent;
|
||||
outGeckoEvent->time = PR_IntervalNow();
|
||||
|
||||
if (outGeckoEvent->eventStructType != NS_KEY_EVENT) {
|
||||
NSPoint mouseLoc = [inEvent locationInWindow];
|
||||
NSPoint mouseLoc = inPoint;
|
||||
|
||||
// convert point to view coordinate system
|
||||
NSPoint localPoint = [self convertPoint:mouseLoc fromView:nil];
|
||||
@ -1966,12 +2054,11 @@ const PRInt32 kNumLines = 8;
|
||||
}
|
||||
|
||||
// set up modifier keys
|
||||
unsigned int modifiers = [inEvent modifierFlags];
|
||||
outGeckoEvent->isShift = ((modifiers & NSShiftKeyMask) != 0);
|
||||
outGeckoEvent->isControl = ((modifiers & NSControlKeyMask) != 0);
|
||||
outGeckoEvent->isAlt = ((modifiers & NSAlternateKeyMask) != 0);
|
||||
outGeckoEvent->isMeta = ((modifiers & NSCommandKeyMask) != 0);
|
||||
} // convert:toGeckoEvent:
|
||||
outGeckoEvent->isShift = ((inMods & NSShiftKeyMask) != 0);
|
||||
outGeckoEvent->isControl = ((inMods & NSControlKeyMask) != 0);
|
||||
outGeckoEvent->isAlt = ((inMods & NSAlternateKeyMask) != 0);
|
||||
outGeckoEvent->isMeta = ((inMods & NSCommandKeyMask) != 0);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
|
267
widget/src/cocoa/nsDragHelperService.cpp
Normal file
267
widget/src/cocoa/nsDragHelperService.cpp
Normal file
@ -0,0 +1,267 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsDragHelperService.h"
|
||||
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsIDragSessionMac.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
|
||||
#define kDragServiceContractID "@mozilla.org/widget/dragservice;1"
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(nsDragHelperService)
|
||||
NS_IMPL_RELEASE(nsDragHelperService)
|
||||
NS_IMPL_QUERY_INTERFACE1(nsDragHelperService, nsIDragHelperService);
|
||||
|
||||
|
||||
//
|
||||
// nsDragHelperService constructor
|
||||
//
|
||||
nsDragHelperService::nsDragHelperService()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// nsDragHelperService destructor
|
||||
//
|
||||
nsDragHelperService::~nsDragHelperService()
|
||||
{
|
||||
NS_ASSERTION ( !mDragService.get(), "A drag was not correctly ended by shutdown" );
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Enter
|
||||
//
|
||||
// Called when the mouse has entered the rectangle bounding the browser
|
||||
// during a drag. Cache the drag service so we don't have to fetch it
|
||||
// repeatedly, and handles setting up the drag reference and sending an
|
||||
// enter event.
|
||||
//
|
||||
NS_IMETHODIMP
|
||||
nsDragHelperService::Enter ( DragReference inDragRef, nsIEventSink *inSink )
|
||||
{
|
||||
// get our drag service for the duration of the drag.
|
||||
mDragService = do_GetService(kDragServiceContractID);
|
||||
NS_ASSERTION ( mDragService, "Couldn't get a drag service, we're in biiig trouble" );
|
||||
if ( !mDragService || !inSink )
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// tell the session about this drag
|
||||
mDragService->StartDragSession();
|
||||
nsCOMPtr<nsIDragSessionMac> macSession ( do_QueryInterface(mDragService) );
|
||||
if ( macSession )
|
||||
macSession->SetDragReference ( inDragRef );
|
||||
|
||||
// let gecko know that the mouse has entered the window so it
|
||||
// can start tracking and sending enter/exit events to frames.
|
||||
Point mouseLocGlobal;
|
||||
::GetDragMouse ( inDragRef, &mouseLocGlobal, nsnull );
|
||||
PRBool handled = PR_FALSE;
|
||||
inSink->DragEvent ( NS_DRAGDROP_ENTER, mouseLocGlobal.h, mouseLocGlobal.v, 0L, &handled );
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Tracking
|
||||
//
|
||||
// Called while the mouse is inside the rectangle bounding the browser
|
||||
// during a drag. The important thing done here is to clear the |canDrop|
|
||||
// property of the drag session every time through. The event handlers
|
||||
// will reset it if appropriate.
|
||||
//
|
||||
NS_IMETHODIMP
|
||||
nsDragHelperService::Tracking ( DragReference inDragRef, nsIEventSink *inSink, PRBool* outDropAllowed )
|
||||
{
|
||||
NS_ASSERTION ( mDragService, "Couldn't get a drag service, we're in biiig trouble" );
|
||||
if ( !mDragService || !inSink ) {
|
||||
*outDropAllowed = PR_FALSE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
Point mouseLocGlobal;
|
||||
::GetDragMouse ( inDragRef, &mouseLocGlobal, nsnull );
|
||||
short modifiers;
|
||||
::GetDragModifiers ( inDragRef, &modifiers, nsnull, nsnull );
|
||||
|
||||
// set the drag action on the service so the frames know what is going on
|
||||
SetDragActionBasedOnModifiers ( modifiers );
|
||||
|
||||
// clear out the |canDrop| property of the drag session. If it's meant to
|
||||
// be, it will be set again.
|
||||
nsCOMPtr<nsIDragSession> session;
|
||||
mDragService->GetCurrentSession(getter_AddRefs(session));
|
||||
NS_ASSERTION ( session, "If we don't have a drag session, we're fucked" );
|
||||
if ( session )
|
||||
session->SetCanDrop(PR_FALSE);
|
||||
|
||||
// pass into gecko for handling...
|
||||
PRBool handled = PR_FALSE;
|
||||
inSink->DragEvent ( NS_DRAGDROP_OVER, mouseLocGlobal.h, mouseLocGlobal.v, modifiers, &handled );
|
||||
|
||||
// check if gecko has since allowed the drop and return it
|
||||
if ( session )
|
||||
session->GetCanDrop(outDropAllowed);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Leave
|
||||
//
|
||||
// Called when the mouse leaves the rectangle bounding the browser
|
||||
// during a drag. Cleans up the drag service and releases it.
|
||||
//
|
||||
NS_IMETHODIMP
|
||||
nsDragHelperService::Leave ( DragReference inDragRef, nsIEventSink *inSink )
|
||||
{
|
||||
NS_ASSERTION ( mDragService, "Couldn't get a drag service, we're in biiig trouble" );
|
||||
if ( !mDragService || !inSink )
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// tell the drag service that we're done with it.
|
||||
mDragService->EndDragSession();
|
||||
|
||||
// clear out the dragRef in the drag session. We are guaranteed that
|
||||
// this will be called _after_ the drop has been processed (if there
|
||||
// is one), so we're not destroying valuable information if the drop
|
||||
// was in our window.
|
||||
nsCOMPtr<nsIDragSessionMac> macSession ( do_QueryInterface(mDragService) );
|
||||
if ( macSession )
|
||||
macSession->SetDragReference ( 0 );
|
||||
|
||||
// let gecko know that the mouse has left the window so it
|
||||
// can stop tracking and sending enter/exit events to frames.
|
||||
Point mouseLocGlobal;
|
||||
::GetDragMouse ( inDragRef, &mouseLocGlobal, nsnull );
|
||||
PRBool handled = PR_FALSE;
|
||||
inSink->DragEvent ( NS_DRAGDROP_EXIT, mouseLocGlobal.h, mouseLocGlobal.v, 0L, &handled );
|
||||
|
||||
::HideDragHilite ( inDragRef );
|
||||
|
||||
// we're _really_ done with it, so let go of the service.
|
||||
mDragService = nsnull;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Drop
|
||||
//
|
||||
// Called when a drop occurs within the rectangle bounding the browser
|
||||
// during a drag. Cleans up the drag service and releases it.
|
||||
//
|
||||
NS_IMETHODIMP
|
||||
nsDragHelperService::Drop ( DragReference inDragRef, nsIEventSink *inSink, PRBool* outAccepted )
|
||||
{
|
||||
NS_ASSERTION ( mDragService, "Couldn't get a drag service, we're in biiig trouble" );
|
||||
if ( !mDragService || !inSink ) {
|
||||
*outAccepted = PR_FALSE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// We make the assuption that the dragOver handlers have correctly set
|
||||
// the |canDrop| property of the Drag Session. Before we dispatch the event
|
||||
// into Gecko, check that value and either dispatch it or set the result
|
||||
// code to "spring-back" and show the user the drag failed.
|
||||
OSErr result = noErr;
|
||||
nsCOMPtr<nsIDragSession> dragSession;
|
||||
mDragService->GetCurrentSession ( getter_AddRefs(dragSession) );
|
||||
if ( dragSession ) {
|
||||
// if the target has set that it can accept the drag, pass along
|
||||
// to gecko, otherwise set phasers for failure.
|
||||
PRBool canDrop = PR_FALSE;
|
||||
if ( NS_SUCCEEDED(dragSession->GetCanDrop(&canDrop)) )
|
||||
if ( canDrop ) {
|
||||
// pass the drop event along to Gecko
|
||||
Point mouseLocGlobal;
|
||||
::GetDragMouse ( inDragRef, &mouseLocGlobal, nsnull );
|
||||
short modifiers;
|
||||
::GetDragModifiers ( inDragRef, &modifiers, nsnull, nsnull );
|
||||
PRBool handled = PR_FALSE;
|
||||
inSink->DragEvent ( NS_DRAGDROP_DROP, mouseLocGlobal.h, mouseLocGlobal.v, modifiers, &handled );
|
||||
}
|
||||
else
|
||||
result = dragNotAcceptedErr;
|
||||
} // if a valid drag session
|
||||
|
||||
// we don't need the drag session anymore, the user has released the
|
||||
// mouse and the event has already gone to gecko.
|
||||
mDragService->EndDragSession();
|
||||
|
||||
// if there was any kind of error, the drag wasn't accepted
|
||||
*outAccepted = (result == noErr);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// SetDragActionsBasedOnModifiers
|
||||
//
|
||||
// Examines the MacOS modifier keys and sets the appropriate drag action on the
|
||||
// drag session to copy/move/etc
|
||||
//
|
||||
void
|
||||
nsDragHelperService::SetDragActionBasedOnModifiers ( short inModifiers )
|
||||
{
|
||||
nsCOMPtr<nsIDragSession> dragSession;
|
||||
mDragService->GetCurrentSession ( getter_AddRefs(dragSession) );
|
||||
if ( dragSession ) {
|
||||
PRUint32 action = nsIDragService::DRAGDROP_ACTION_MOVE;
|
||||
|
||||
// force copy = option, alias = cmd-option, default is move
|
||||
if ( inModifiers & optionKey ) {
|
||||
if ( inModifiers & cmdKey )
|
||||
action = nsIDragService::DRAGDROP_ACTION_LINK;
|
||||
else
|
||||
action = nsIDragService::DRAGDROP_ACTION_COPY;
|
||||
}
|
||||
|
||||
dragSession->SetDragAction ( action );
|
||||
}
|
||||
|
||||
} // SetDragActionBasedOnModifiers
|
||||
|
86
widget/src/cocoa/nsDragHelperService.h
Normal file
86
widget/src/cocoa/nsDragHelperService.h
Normal file
@ -0,0 +1,86 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsDragHelperService_h__
|
||||
#define nsDragHelperService_h__
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDragService.h"
|
||||
|
||||
#include <Drag.h>
|
||||
|
||||
#include "nsIDragHelperService.h"
|
||||
|
||||
|
||||
//
|
||||
// nsDragHelperService
|
||||
//
|
||||
// Implementation of nsIDragHelperService, a helper for managing
|
||||
// drag and drop mechanics.
|
||||
//
|
||||
|
||||
// {75993200-f3b2-11d5-a384-c7054d07d6fc}
|
||||
#define NS_DRAGHELPERSERVICE_CID \
|
||||
{ 0x75993200, 0xf3b2, 0x11d5, { 0xa3, 0x84, 0xc7, 0x05, 0x4d, 0x07, 0xd6, 0xfc } }
|
||||
|
||||
|
||||
class nsDragHelperService : public nsIDragHelperService
|
||||
{
|
||||
public:
|
||||
nsDragHelperService();
|
||||
virtual ~nsDragHelperService();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDRAGHELPERSERVICE
|
||||
|
||||
protected:
|
||||
|
||||
// handles modifier keys (cmd, option, etc) and sets the appropriate
|
||||
// action (move, copy, etc) based on the given modifiers.
|
||||
void SetDragActionBasedOnModifiers ( short inModifiers ) ;
|
||||
|
||||
// holds our drag service across multiple calls to this callback. The reference to
|
||||
// the service is obtained when the mouse enters the window and is released when
|
||||
// the mouse leaves the window (or there is a drop). This prevents us from having
|
||||
// to re-establish the connection to the service manager 15 times a second when
|
||||
// handling the |kDragTrackingInWindow| message.
|
||||
nsCOMPtr<nsIDragService> mDragService;
|
||||
|
||||
}; // nsDragHelperService
|
||||
|
||||
|
||||
#endif // nsDragHelperService_h__
|
@ -221,7 +221,7 @@ nsDragService :: InvokeDragSession (nsIDOMNode *aDOMNode, nsISupportsArray * aTr
|
||||
if ( result != noErr )
|
||||
return NS_ERROR_FAILURE;
|
||||
mDragRef = theDragRef;
|
||||
#if DEBUG_DD
|
||||
#if 1
|
||||
printf("**** created drag ref %ld\n", theDragRef);
|
||||
#endif
|
||||
|
||||
|
116
widget/src/cocoa/nsIDragHelperService.idl
Normal file
116
widget/src/cocoa/nsIDragHelperService.idl
Normal file
@ -0,0 +1,116 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIEventSink.idl"
|
||||
|
||||
/* THIS IS A PUBLIC EMBEDDING API */
|
||||
|
||||
|
||||
/**
|
||||
* The nsIDragHelperService is a service that wraps the dispatch
|
||||
* of drag events into gecko with the appropriate management of
|
||||
* the nsDragService/nsDragSession. It frees the application from
|
||||
* having to manage details specific to how Gecko processes drag
|
||||
* and drop.
|
||||
*
|
||||
* If the browser takes up the entire window, this is straightforward:
|
||||
* call |enter| when the mouse enters the window, |tracking| while the
|
||||
* mouse moves/hovers inside the window, and |leave| when the mouse
|
||||
* exits the window. Call |drop| when the mouse is released w/in the window.
|
||||
*
|
||||
* If the browser does not take up the entire window, call |enter|
|
||||
* when the mouse enters the rectangle bounding the browser, |tracking|
|
||||
* while it is inside, |leave| when the mouse leaves the rectangle, and
|
||||
* |drop| when the mouse is released w/in the rectangle. Note that the
|
||||
* application is responsible for knowing where in its window the browser
|
||||
* has been placed.
|
||||
*
|
||||
* @status UNDER_REVIEW
|
||||
*/
|
||||
|
||||
native DragReference(DragReference);
|
||||
|
||||
|
||||
[uuid(22ac1757-14c5-45ef-841e-ca6e932b989c)]
|
||||
interface nsIDragHelperService : nsISupports
|
||||
{
|
||||
/**
|
||||
* Call when the mouse has entered the rectangle bounding the browser
|
||||
* during a drag.
|
||||
*
|
||||
* @param inDragRef the native DragReference
|
||||
* @param inSink the event sink to which the event will be dispatched
|
||||
*/
|
||||
void enter ( in DragReference inDragRef, in nsIEventSink inSink ) ;
|
||||
|
||||
/**
|
||||
* Call when the mouse is inside the rectangle bounding the browser
|
||||
* during a drag. The return value indicates if Gecko would accept the
|
||||
* contents of the drag if a drop were to happen with the mouse in the
|
||||
* current position. This can be used for doing some rudimentary drop
|
||||
* feedback.
|
||||
*
|
||||
* @param inDragRef the native DragReference
|
||||
* @param inSink the event sink to which the event will be dispatched
|
||||
*
|
||||
* @result <code>PR_TRUE</code> if the drag would be accepted by Gecko.
|
||||
*
|
||||
*/
|
||||
boolean tracking ( in DragReference inDragRef, in nsIEventSink inSink ) ;
|
||||
|
||||
/**
|
||||
* Call when the mouse has left the rectangle bounding the browser
|
||||
* during a drag.
|
||||
*
|
||||
* @param inDragRef the native DragReference
|
||||
* @param inSink the event sink to which the event will be dispatched
|
||||
*/
|
||||
void leave ( in DragReference inDragRef, in nsIEventSink inSink ) ;
|
||||
|
||||
/**
|
||||
* Call when a drop occurs inside the rectangle bounding the browser.
|
||||
*
|
||||
* @param inDragRef the native DragReference
|
||||
* @param inSink the event sink to which the event will be dispatched
|
||||
*
|
||||
* @result <code>PR_TRUE</code> if the drag was accepted by Gecko.
|
||||
*/
|
||||
boolean drop ( in DragReference inDragRef, in nsIEventSink inSink ) ;
|
||||
|
||||
};
|
@ -20,7 +20,6 @@
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Dan Rosen <dr@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@ -59,6 +58,7 @@
|
||||
#include "nsTransferable.h"
|
||||
#include "nsHTMLFormatConverter.h"
|
||||
#include "nsDragService.h"
|
||||
#include "nsDragHelperService.h"
|
||||
|
||||
#if USE_NATIVE_VERSION
|
||||
# include "nsCheckButton.h"
|
||||
@ -98,6 +98,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragHelperService)
|
||||
#ifdef IBMBIDI
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard)
|
||||
#endif
|
||||
@ -169,6 +170,10 @@ static nsModuleComponentInfo components[] =
|
||||
NS_DRAGSERVICE_CID,
|
||||
"@mozilla.org/widget/dragservice;1",
|
||||
nsDragServiceConstructor },
|
||||
{ "Drag Helper Service",
|
||||
NS_DRAGHELPERSERVICE_CID,
|
||||
"@mozilla.org/widget/draghelperservice;1",
|
||||
nsDragHelperServiceConstructor },
|
||||
#ifdef IBMBIDI
|
||||
{ "Gtk Bidi Keyboard",
|
||||
NS_BIDIKEYBOARD_CID,
|
||||
|
Loading…
Reference in New Issue
Block a user