This commit is contained in:
pinkerton%netscape.com 1999-08-19 19:48:45 +00:00
Родитель e6c785c88e
Коммит 277d3d704c
6 изменённых файлов: 240 добавлений и 2 удалений

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

@ -1014,6 +1014,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
case NS_DRAGDROP_OVER:
case NS_DRAGDROP_EXIT:
case NS_DRAGDROP_DROP:
case NS_DRAGDROP_GESTURE:
if (nsnull != mDragListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent);
@ -1042,6 +1043,9 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
case NS_DRAGDROP_DROP:
ret = dragListener->DragDrop(*aDOMEvent);
break;
case NS_DRAGDROP_GESTURE:
ret = dragListener->DragGesture(*aDOMEvent);
break;
} // switch
NS_RELEASE(dragListener);
}

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

@ -40,6 +40,8 @@
#include "nsIScrollableView.h"
#include "nsIDOMSelection.h"
#include "nsIFrameSelection.h"
#include "nsIDeviceContext.h"
static NS_DEFINE_IID(kIEventStateManagerIID, NS_IEVENTSTATEMANAGER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
@ -54,7 +56,9 @@ static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
static NS_DEFINE_IID(kIFocusableContentIID, NS_IFOCUSABLECONTENT_IID);
static NS_DEFINE_IID(kIScrollableViewIID, NS_ISCROLLABLEVIEW_IID);
nsEventStateManager::nsEventStateManager() {
nsEventStateManager::nsEventStateManager()
: mGestureDownPoint(0,0)
{
mLastMouseOverFrame = nsnull;
mLastDragOverFrame = nsnull;
mCurrentTarget = nsnull;
@ -63,6 +67,10 @@ nsEventStateManager::nsEventStateManager() {
mLastMiddleMouseDownContent = nsnull;
mLastRightMouseDownContent = nsnull;
// init d&d gesture state machine variables
mIsTrackingDragGesture = PR_FALSE;
mGestureDownFrame = nsnull;
mActiveContent = nsnull;
mHoverContent = nsnull;
mDragOverContent = nsnull;
@ -107,7 +115,14 @@ nsEventStateManager::PreHandleEvent(nsIPresContext& aPresContext,
aStatus = nsEventStatus_eIgnore;
switch (aEvent->message) {
case NS_MOUSE_LEFT_BUTTON_DOWN:
BeginTrackingDragGesture ( aEvent, aTargetFrame );
break;
case NS_MOUSE_LEFT_BUTTON_UP:
StopTrackingDragGesture();
break;
case NS_MOUSE_MOVE:
GenerateDragGesture(aPresContext, aEvent);
UpdateCursor(aPresContext, aEvent->point, aTargetFrame, aStatus);
GenerateMouseEnterExit(aPresContext, aEvent);
break;
@ -212,6 +227,95 @@ nsEventStateManager::PreHandleEvent(nsIPresContext& aPresContext,
return NS_OK;
}
//
// BeginTrackingDragGesture
//
// Record that the mouse has gone down and that we should move to TRACKING state
// of d&d gesture tracker.
//
void
nsEventStateManager :: BeginTrackingDragGesture ( nsGUIEvent* inDownEvent, nsIFrame* inDownFrame )
{
mIsTrackingDragGesture = PR_TRUE;
mGestureDownPoint = inDownEvent->point;
mGestureDownFrame = inDownFrame;
}
//
// StopTrackingDragGesture
//
// Record that the mouse has gone back up so that we should leave the TRACKING
// state of d&d gesture tracker and return to the START state.
//
void
nsEventStateManager :: StopTrackingDragGesture ( )
{
mIsTrackingDragGesture = PR_FALSE;
mGestureDownPoint = nsPoint(0,0);
mGestureDownFrame = nsnull;
}
//
// GenerateDragGesture
//
// If we're in the TRACKING state of the d&d gesture tracker, check the current position
// of the mouse in relation to the old one. If we've moved a sufficient amount from
// the mouse down, then fire off a drag gesture event.
//
// Note that when the mouse enters a new child window with its own view, the event's
// coordinates will be in relation to the origin of the inner child window, which could
// either be very different from that of the mouse coords of the mouse down and trigger
// a drag too early, or very similiar which might not trigger a drag.
//
// Do we need to do anything about this? Let's wait and see.
//
void
nsEventStateManager :: GenerateDragGesture ( nsIPresContext& aPresContext, nsGUIEvent *aEvent )
{
if ( IsTrackingDragGesture() ) {
// figure out the delta in twips, since that is how it is in the event.
// Do we need to do this conversion every time? Will the pres context really change on
// us or can we cache it?
long twipDeltaToStartDrag = 0;
const long pixelDeltaToStartDrag = 5;
nsCOMPtr<nsIDeviceContext> devContext;
aPresContext.GetDeviceContext ( getter_AddRefs(devContext) );
if ( devContext ) {
float pixelsToTwips = 0.0;
devContext->GetDevUnitsToTwips(pixelsToTwips);
twipDeltaToStartDrag = pixelDeltaToStartDrag * pixelsToTwips;
}
// fire drag gesture if mouse has moved enough
if ( abs(aEvent->point.x - mGestureDownPoint.x) > twipDeltaToStartDrag ||
abs(aEvent->point.y - mGestureDownPoint.y) > twipDeltaToStartDrag ) {
nsEventStatus status = nsEventStatus_eIgnore;
nsMouseEvent event;
event.eventStructType = NS_DRAGDROP_EVENT;
event.message = NS_DRAGDROP_GESTURE;
event.widget = aEvent->widget;
event.clickCount = 0;
event.point = aEvent->point;
event.refPoint = aEvent->refPoint;
// dispatch to the DOM
nsCOMPtr<nsIContent> lastContent;
mGestureDownFrame->GetContent(getter_AddRefs(lastContent));
if ( lastContent )
lastContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);
// dispatch to the frame
mGestureDownFrame->HandleEvent(aPresContext, &event, status);
StopTrackingDragGesture();
}
}
} // GenerateDragGesture
NS_IMETHODIMP
nsEventStateManager::PostHandleEvent(nsIPresContext& aPresContext,
nsGUIEvent *aEvent,

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

@ -71,11 +71,22 @@ protected:
NS_IMETHOD SendFocusBlur(nsIContent *aContent);
nsIScrollableView* GetNearestScrollingView(nsIView* aView);
// routines for the d&d gesture tracking state machine
void BeginTrackingDragGesture ( nsGUIEvent* inDownEvent, nsIFrame* inDownFrame ) ;
void StopTrackingDragGesture ( ) ;
void GenerateDragGesture ( nsIPresContext& aPresContext, nsGUIEvent *aEvent ) ;
PRBool IsTrackingDragGesture ( ) const { return mIsTrackingDragGesture; }
//Any frames here must be checked for validity in ClearFrameRefs
nsIFrame* mCurrentTarget;
nsIContent* mCurrentTargetContent;
nsIFrame* mLastMouseOverFrame;
nsIFrame* mLastDragOverFrame;
// member variables for the d&d gesture state machine
PRBool mIsTrackingDragGesture;
nsPoint mGestureDownPoint;
nsIFrame* mGestureDownFrame;
nsIContent* mLastLeftMouseDownContent;
nsIContent* mLastMiddleMouseDownContent;

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

@ -1014,6 +1014,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
case NS_DRAGDROP_OVER:
case NS_DRAGDROP_EXIT:
case NS_DRAGDROP_DROP:
case NS_DRAGDROP_GESTURE:
if (nsnull != mDragListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent);
@ -1042,6 +1043,9 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
case NS_DRAGDROP_DROP:
ret = dragListener->DragDrop(*aDOMEvent);
break;
case NS_DRAGDROP_GESTURE:
ret = dragListener->DragGesture(*aDOMEvent);
break;
} // switch
NS_RELEASE(dragListener);
}

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

@ -40,6 +40,8 @@
#include "nsIScrollableView.h"
#include "nsIDOMSelection.h"
#include "nsIFrameSelection.h"
#include "nsIDeviceContext.h"
static NS_DEFINE_IID(kIEventStateManagerIID, NS_IEVENTSTATEMANAGER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
@ -54,7 +56,9 @@ static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
static NS_DEFINE_IID(kIFocusableContentIID, NS_IFOCUSABLECONTENT_IID);
static NS_DEFINE_IID(kIScrollableViewIID, NS_ISCROLLABLEVIEW_IID);
nsEventStateManager::nsEventStateManager() {
nsEventStateManager::nsEventStateManager()
: mGestureDownPoint(0,0)
{
mLastMouseOverFrame = nsnull;
mLastDragOverFrame = nsnull;
mCurrentTarget = nsnull;
@ -63,6 +67,10 @@ nsEventStateManager::nsEventStateManager() {
mLastMiddleMouseDownContent = nsnull;
mLastRightMouseDownContent = nsnull;
// init d&d gesture state machine variables
mIsTrackingDragGesture = PR_FALSE;
mGestureDownFrame = nsnull;
mActiveContent = nsnull;
mHoverContent = nsnull;
mDragOverContent = nsnull;
@ -107,7 +115,14 @@ nsEventStateManager::PreHandleEvent(nsIPresContext& aPresContext,
aStatus = nsEventStatus_eIgnore;
switch (aEvent->message) {
case NS_MOUSE_LEFT_BUTTON_DOWN:
BeginTrackingDragGesture ( aEvent, aTargetFrame );
break;
case NS_MOUSE_LEFT_BUTTON_UP:
StopTrackingDragGesture();
break;
case NS_MOUSE_MOVE:
GenerateDragGesture(aPresContext, aEvent);
UpdateCursor(aPresContext, aEvent->point, aTargetFrame, aStatus);
GenerateMouseEnterExit(aPresContext, aEvent);
break;
@ -212,6 +227,95 @@ nsEventStateManager::PreHandleEvent(nsIPresContext& aPresContext,
return NS_OK;
}
//
// BeginTrackingDragGesture
//
// Record that the mouse has gone down and that we should move to TRACKING state
// of d&d gesture tracker.
//
void
nsEventStateManager :: BeginTrackingDragGesture ( nsGUIEvent* inDownEvent, nsIFrame* inDownFrame )
{
mIsTrackingDragGesture = PR_TRUE;
mGestureDownPoint = inDownEvent->point;
mGestureDownFrame = inDownFrame;
}
//
// StopTrackingDragGesture
//
// Record that the mouse has gone back up so that we should leave the TRACKING
// state of d&d gesture tracker and return to the START state.
//
void
nsEventStateManager :: StopTrackingDragGesture ( )
{
mIsTrackingDragGesture = PR_FALSE;
mGestureDownPoint = nsPoint(0,0);
mGestureDownFrame = nsnull;
}
//
// GenerateDragGesture
//
// If we're in the TRACKING state of the d&d gesture tracker, check the current position
// of the mouse in relation to the old one. If we've moved a sufficient amount from
// the mouse down, then fire off a drag gesture event.
//
// Note that when the mouse enters a new child window with its own view, the event's
// coordinates will be in relation to the origin of the inner child window, which could
// either be very different from that of the mouse coords of the mouse down and trigger
// a drag too early, or very similiar which might not trigger a drag.
//
// Do we need to do anything about this? Let's wait and see.
//
void
nsEventStateManager :: GenerateDragGesture ( nsIPresContext& aPresContext, nsGUIEvent *aEvent )
{
if ( IsTrackingDragGesture() ) {
// figure out the delta in twips, since that is how it is in the event.
// Do we need to do this conversion every time? Will the pres context really change on
// us or can we cache it?
long twipDeltaToStartDrag = 0;
const long pixelDeltaToStartDrag = 5;
nsCOMPtr<nsIDeviceContext> devContext;
aPresContext.GetDeviceContext ( getter_AddRefs(devContext) );
if ( devContext ) {
float pixelsToTwips = 0.0;
devContext->GetDevUnitsToTwips(pixelsToTwips);
twipDeltaToStartDrag = pixelDeltaToStartDrag * pixelsToTwips;
}
// fire drag gesture if mouse has moved enough
if ( abs(aEvent->point.x - mGestureDownPoint.x) > twipDeltaToStartDrag ||
abs(aEvent->point.y - mGestureDownPoint.y) > twipDeltaToStartDrag ) {
nsEventStatus status = nsEventStatus_eIgnore;
nsMouseEvent event;
event.eventStructType = NS_DRAGDROP_EVENT;
event.message = NS_DRAGDROP_GESTURE;
event.widget = aEvent->widget;
event.clickCount = 0;
event.point = aEvent->point;
event.refPoint = aEvent->refPoint;
// dispatch to the DOM
nsCOMPtr<nsIContent> lastContent;
mGestureDownFrame->GetContent(getter_AddRefs(lastContent));
if ( lastContent )
lastContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);
// dispatch to the frame
mGestureDownFrame->HandleEvent(aPresContext, &event, status);
StopTrackingDragGesture();
}
}
} // GenerateDragGesture
NS_IMETHODIMP
nsEventStateManager::PostHandleEvent(nsIPresContext& aPresContext,
nsGUIEvent *aEvent,

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

@ -71,11 +71,22 @@ protected:
NS_IMETHOD SendFocusBlur(nsIContent *aContent);
nsIScrollableView* GetNearestScrollingView(nsIView* aView);
// routines for the d&d gesture tracking state machine
void BeginTrackingDragGesture ( nsGUIEvent* inDownEvent, nsIFrame* inDownFrame ) ;
void StopTrackingDragGesture ( ) ;
void GenerateDragGesture ( nsIPresContext& aPresContext, nsGUIEvent *aEvent ) ;
PRBool IsTrackingDragGesture ( ) const { return mIsTrackingDragGesture; }
//Any frames here must be checked for validity in ClearFrameRefs
nsIFrame* mCurrentTarget;
nsIContent* mCurrentTargetContent;
nsIFrame* mLastMouseOverFrame;
nsIFrame* mLastDragOverFrame;
// member variables for the d&d gesture state machine
PRBool mIsTrackingDragGesture;
nsPoint mGestureDownPoint;
nsIFrame* mGestureDownFrame;
nsIContent* mLastLeftMouseDownContent;
nsIContent* mLastMiddleMouseDownContent;