зеркало из https://github.com/mozilla/pjs.git
Moving view selection for event handling into nsViewManager, Adding GrabMouseEvents and GrabKeyEvents
This commit is contained in:
Родитель
8865f7ea88
Коммит
a3d9156246
|
@ -168,7 +168,7 @@ public:
|
|||
* @param event event to dispatch
|
||||
* @result event handling status
|
||||
*/
|
||||
virtual PRBool DispatchEvent(nsIEvent *event) = 0;
|
||||
virtual nsEventStatus DispatchEvent(nsGUIEvent *aEvent) = 0;
|
||||
|
||||
/**
|
||||
* Used to grab/capture all mouse events for a specific view,
|
||||
|
|
|
@ -57,7 +57,7 @@ ScrollBarView :: ~ScrollBarView()
|
|||
|
||||
nsEventStatus ScrollBarView :: HandleEvent(nsGUIEvent *aEvent, PRUint32 aEventFlags)
|
||||
{
|
||||
nsEventStatus retval;
|
||||
nsEventStatus retval = nsEventStatus_eIgnore;
|
||||
|
||||
switch (aEvent->message)
|
||||
{
|
||||
|
@ -73,7 +73,6 @@ nsEventStatus ScrollBarView :: HandleEvent(nsGUIEvent *aEvent, PRUint32 aEventFl
|
|||
break;
|
||||
|
||||
default:
|
||||
retval = nsEventStatus_eIgnore;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,116 +44,13 @@ nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent)
|
|||
{
|
||||
//printf(" %d %d %d (%d,%d) \n", aEvent->widget, aEvent->widgetSupports,
|
||||
// aEvent->message, aEvent->point.x, aEvent->point.y);
|
||||
nsIView* view = nsView::GetViewFor(aEvent->widget);
|
||||
nsEventStatus result = nsEventStatus_eIgnore;
|
||||
|
||||
if (nsnull != view)
|
||||
{
|
||||
switch(aEvent->message)
|
||||
{
|
||||
case NS_SIZE:
|
||||
{
|
||||
nscoord width = ((nsSizeEvent*)aEvent)->windowSize->width;
|
||||
nscoord height = ((nsSizeEvent*)aEvent)->windowSize->height;
|
||||
|
||||
// Inform the view manager that the root window has been resized
|
||||
nsIViewManager* vm = view->GetViewManager();
|
||||
nsIPresContext* presContext = vm->GetPresContext();
|
||||
|
||||
// The root view may not be set if this is the resize associated with
|
||||
// window creation
|
||||
|
||||
nsIView* rootView = vm->GetRootView();
|
||||
|
||||
if (view == rootView)
|
||||
{
|
||||
// Convert from pixels to twips
|
||||
float p2t = presContext->GetPixelsToTwips();
|
||||
nsIScrollableView *scrollView;
|
||||
|
||||
//XXX hey look, a hack! :) i'm not proud of it, but it does
|
||||
//work. the purpose is to prevent resizes of the view if the
|
||||
//clip size (assumed to be the size of this window) is the same
|
||||
//as the new size we get here. MMP
|
||||
|
||||
if (NS_OK == rootView->QueryInterface(kIScrollableViewIID, (void **)&scrollView))
|
||||
{
|
||||
nscoord sizex, sizey;
|
||||
float t2p = presContext->GetTwipsToPixels();
|
||||
|
||||
scrollView->GetClipSize(&sizex, &sizey);
|
||||
|
||||
if ((width == NSTwipsToIntPixels(sizex, t2p)) &&
|
||||
(height == NSTwipsToIntPixels(sizey, t2p)))
|
||||
{
|
||||
NS_RELEASE(presContext);
|
||||
NS_RELEASE(vm);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
vm->SetWindowDimensions(NSIntPixelsToTwips(width, p2t),
|
||||
NSIntPixelsToTwips(height, p2t));
|
||||
result = nsEventStatus_eConsumeNoDefault;
|
||||
}
|
||||
|
||||
NS_RELEASE(presContext);
|
||||
NS_RELEASE(vm);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case NS_PAINT:
|
||||
{
|
||||
nsIViewManager *vm = view->GetViewManager();
|
||||
nsIPresContext *px = vm->GetPresContext();
|
||||
float convert = px->GetPixelsToTwips();
|
||||
nsRect trect = *((nsPaintEvent*)aEvent)->rect;
|
||||
nsIDeviceContext *dx = px->GetDeviceContext();
|
||||
|
||||
trect *= convert;
|
||||
|
||||
//printf("damage repair...\n");
|
||||
|
||||
vm->UpdateView(view, trect,
|
||||
NS_VMREFRESH_SCREEN_RECT |
|
||||
NS_VMREFRESH_IMMEDIATE |
|
||||
NS_VMREFRESH_AUTO_DOUBLE_BUFFER);
|
||||
|
||||
NS_RELEASE(dx);
|
||||
NS_RELEASE(px);
|
||||
NS_RELEASE(vm);
|
||||
|
||||
result = nsEventStatus_eConsumeNoDefault;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case NS_DESTROY:
|
||||
result = nsEventStatus_eConsumeNoDefault;
|
||||
break;
|
||||
|
||||
default:
|
||||
nsIViewManager *vm = view->GetViewManager();
|
||||
nsIPresContext *cx = vm->GetPresContext();
|
||||
|
||||
// pass on to view somewhere else to deal with
|
||||
|
||||
aEvent->point.x = NSIntPixelsToTwips(aEvent->point.x, cx->GetPixelsToTwips());
|
||||
aEvent->point.y = NSIntPixelsToTwips(aEvent->point.y, cx->GetPixelsToTwips());
|
||||
|
||||
result = view->HandleEvent(aEvent, NS_VIEW_FLAG_CHECK_CHILDREN |
|
||||
NS_VIEW_FLAG_CHECK_PARENT |
|
||||
NS_VIEW_FLAG_CHECK_SIBLINGS);
|
||||
|
||||
aEvent->point.x = NSTwipsToIntPixels(aEvent->point.x, cx->GetTwipsToPixels());
|
||||
aEvent->point.y = NSTwipsToIntPixels(aEvent->point.y, cx->GetTwipsToPixels());
|
||||
|
||||
NS_RELEASE(cx);
|
||||
NS_RELEASE(vm);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
nsIView* view = nsView::GetViewFor(aEvent->widget);
|
||||
if (nsnull != view) {
|
||||
nsIViewManager* vm = view->GetViewManager();
|
||||
result = vm->DispatchEvent(aEvent);
|
||||
NS_RELEASE(vm);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -590,9 +487,7 @@ nsEventStatus nsView :: HandleEvent(nsGUIEvent *event, PRUint32 aEventFlags)
|
|||
nsEventStatus retval = nsEventStatus_eIgnore;
|
||||
|
||||
//see if any of this view's children can process the event
|
||||
if ((aEventFlags & NS_VIEW_FLAG_CHECK_CHILDREN) &&
|
||||
(retval == nsEventStatus_eIgnore))
|
||||
{
|
||||
if (retval == nsEventStatus_eIgnore) {
|
||||
PRInt32 numkids = GetChildCount();
|
||||
nsRect trect;
|
||||
nscoord x, y;
|
||||
|
@ -604,7 +499,7 @@ nsEventStatus nsView :: HandleEvent(nsGUIEvent *event, PRUint32 aEventFlags)
|
|||
{
|
||||
nsIView *pKid = GetChild(cnt);
|
||||
nscoord lx, ly;
|
||||
|
||||
|
||||
pKid->GetBounds(trect);
|
||||
|
||||
lx = x - trect.x;
|
||||
|
@ -631,7 +526,7 @@ nsEventStatus nsView :: HandleEvent(nsGUIEvent *event, PRUint32 aEventFlags)
|
|||
}
|
||||
|
||||
//if the view's children didn't take the event, check the view itself.
|
||||
if ((retval == nsEventStatus_eIgnore) && (nsnull != mFrame))
|
||||
if (retval == nsEventStatus_eIgnore && nsnull != mFrame)
|
||||
{
|
||||
nsIPresContext *cx = mViewManager->GetPresContext();
|
||||
nscoord xoff, yoff;
|
||||
|
@ -649,44 +544,6 @@ nsEventStatus nsView :: HandleEvent(nsGUIEvent *event, PRUint32 aEventFlags)
|
|||
NS_RELEASE(cx);
|
||||
}
|
||||
|
||||
//see if any of this views siblings can process this event
|
||||
//we only go from the next sibling since this is a z-ordered
|
||||
//list
|
||||
|
||||
if ((aEventFlags & NS_VIEW_FLAG_CHECK_SIBLINGS) &&
|
||||
(retval == nsEventStatus_eIgnore))
|
||||
{
|
||||
nsIView *pNext = GetNextSibling();
|
||||
|
||||
while (pNext)
|
||||
{
|
||||
retval = pNext->HandleEvent(event, NS_VIEW_FLAG_CHECK_CHILDREN);
|
||||
|
||||
if (retval != PR_FALSE)
|
||||
break;
|
||||
|
||||
pNext = pNext->GetNextSibling();
|
||||
}
|
||||
}
|
||||
|
||||
//no-one has a clue what to do with this... so ask the
|
||||
//parents. kind of mimics life, huh?
|
||||
|
||||
if ((aEventFlags & NS_VIEW_FLAG_CHECK_PARENT) && (retval == nsEventStatus_eIgnore))
|
||||
{
|
||||
nsIView *pParent = GetParent();
|
||||
|
||||
while (pParent)
|
||||
{
|
||||
retval = pParent->HandleEvent(event, NS_VIEW_FLAG_CHECK_SIBLINGS);
|
||||
|
||||
if (retval == nsEventStatus_eIgnore)
|
||||
break;
|
||||
|
||||
pParent = pParent->GetParent();
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
#include "nsGfxCIID.h"
|
||||
#include "nsIScrollableView.h"
|
||||
#include "nsIRegion.h"
|
||||
#include "nsView.h"
|
||||
|
||||
static NS_DEFINE_IID(kIScrollableViewIID, NS_ISCROLLABLEVIEW_IID);
|
||||
|
||||
static const PRBool gsDebug = PR_FALSE;
|
||||
|
||||
|
@ -145,6 +148,9 @@ nsresult nsViewManager::Init(nsIPresContext* aPresContext)
|
|||
|
||||
mRefreshEnabled = PR_TRUE;
|
||||
|
||||
mMouseGrabber = nsnull;
|
||||
mKeyGrabber = nsnull;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -239,9 +245,7 @@ void nsViewManager :: GetWindowOffsets(nscoord *xoffset, nscoord *yoffset)
|
|||
{
|
||||
nsIScrollableView *scroller;
|
||||
|
||||
static NS_DEFINE_IID(kscroller, NS_ISCROLLABLEVIEW_IID);
|
||||
|
||||
if (NS_OK == mRootView->QueryInterface(kscroller, (void **)&scroller))
|
||||
if (NS_OK == mRootView->QueryInterface(kIScrollableViewIID, (void **)&scroller))
|
||||
{
|
||||
scroller->GetVisibleOffset(xoffset, yoffset);
|
||||
}
|
||||
|
@ -258,9 +262,7 @@ void nsViewManager :: SetWindowOffsets(nscoord xoffset, nscoord yoffset)
|
|||
{
|
||||
nsIScrollableView *scroller;
|
||||
|
||||
static NS_DEFINE_IID(kscroller, NS_ISCROLLABLEVIEW_IID);
|
||||
|
||||
if (NS_OK == mRootView->QueryInterface(kscroller, (void **)&scroller))
|
||||
if (NS_OK == mRootView->QueryInterface(kIScrollableViewIID, (void **)&scroller))
|
||||
{
|
||||
scroller->SetVisibleOffset(xoffset, yoffset);
|
||||
}
|
||||
|
@ -273,9 +275,7 @@ void nsViewManager :: ResetScrolling(void)
|
|||
{
|
||||
nsIScrollableView *scroller;
|
||||
|
||||
static NS_DEFINE_IID(kscroller, NS_ISCROLLABLEVIEW_IID);
|
||||
|
||||
if (NS_OK == mRootView->QueryInterface(kscroller, (void **)&scroller))
|
||||
if (NS_OK == mRootView->QueryInterface(kIScrollableViewIID, (void **)&scroller))
|
||||
{
|
||||
scroller->ComputeContainerSize();
|
||||
}
|
||||
|
@ -592,29 +592,146 @@ void nsViewManager :: UpdateView(nsIView *aView, const nsRect &aRect, PRUint32 a
|
|||
}
|
||||
}
|
||||
|
||||
PRBool nsViewManager :: DispatchEvent(nsIEvent *event)
|
||||
nsEventStatus nsViewManager :: DispatchEvent(nsGUIEvent *aEvent)
|
||||
{
|
||||
return PR_TRUE;
|
||||
nsEventStatus result = nsEventStatus_eIgnore;
|
||||
|
||||
switch(aEvent->message)
|
||||
{
|
||||
case NS_SIZE:
|
||||
{
|
||||
nsIView* view = nsView::GetViewFor(aEvent->widget);
|
||||
if (nsnull != view) {
|
||||
|
||||
nscoord width = ((nsSizeEvent*)aEvent)->windowSize->width;
|
||||
nscoord height = ((nsSizeEvent*)aEvent)->windowSize->height;
|
||||
|
||||
// The root view may not be set if this is the resize associated with
|
||||
// window creation
|
||||
|
||||
if (view == mRootView)
|
||||
{
|
||||
// Convert from pixels to twips
|
||||
float p2t = mContext->GetPixelsToTwips();
|
||||
nsIScrollableView *scrollView;
|
||||
|
||||
//XXX hey look, a hack! :) i'm not proud of it, but it does
|
||||
//work. the purpose is to prevent resizes of the view if the
|
||||
//clip size (assumed to be the size of this window) is the same
|
||||
//as the new size we get here. MMP
|
||||
|
||||
if (NS_OK == mRootView->QueryInterface(kIScrollableViewIID, (void **)&scrollView))
|
||||
{
|
||||
nscoord sizex, sizey;
|
||||
float t2p = mContext->GetTwipsToPixels();
|
||||
|
||||
scrollView->GetClipSize(&sizex, &sizey);
|
||||
|
||||
if ((width == NSTwipsToIntPixels(sizex, t2p)) &&
|
||||
(height == NSTwipsToIntPixels(sizey, t2p)))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SetWindowDimensions(NSIntPixelsToTwips(width, p2t),
|
||||
NSIntPixelsToTwips(height, p2t));
|
||||
result = nsEventStatus_eConsumeNoDefault;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case NS_PAINT:
|
||||
{
|
||||
nsIView* view = nsView::GetViewFor(aEvent->widget);
|
||||
if (nsnull != view) {
|
||||
|
||||
float convert = mContext->GetPixelsToTwips();
|
||||
nsRect trect = *((nsPaintEvent*)aEvent)->rect;
|
||||
nsIDeviceContext *dx = mContext->GetDeviceContext();
|
||||
|
||||
trect *= convert;
|
||||
|
||||
//printf("damage repair...\n");
|
||||
|
||||
UpdateView(view, trect,
|
||||
NS_VMREFRESH_SCREEN_RECT |
|
||||
NS_VMREFRESH_IMMEDIATE |
|
||||
NS_VMREFRESH_AUTO_DOUBLE_BUFFER);
|
||||
|
||||
NS_RELEASE(dx);
|
||||
|
||||
result = nsEventStatus_eConsumeNoDefault;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case NS_DESTROY:
|
||||
result = nsEventStatus_eConsumeNoDefault;
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
nsIView* view;
|
||||
|
||||
if (nsnull != mMouseGrabber && NS_IS_MOUSE_EVENT(aEvent)) {
|
||||
view = mMouseGrabber;
|
||||
}
|
||||
else if (nsnull != mKeyGrabber && NS_IS_KEY_EVENT(aEvent)) {
|
||||
view = mKeyGrabber;
|
||||
}
|
||||
else {
|
||||
view = nsView::GetViewFor(aEvent->widget);
|
||||
}
|
||||
|
||||
if (nsnull != view) {
|
||||
nsIViewManager *vm = view->GetViewManager();
|
||||
nsIPresContext *cx = vm->GetPresContext();
|
||||
|
||||
// pass on to view somewhere else to deal with
|
||||
|
||||
aEvent->point.x = NSIntPixelsToTwips(aEvent->point.x, cx->GetPixelsToTwips());
|
||||
aEvent->point.y = NSIntPixelsToTwips(aEvent->point.y, cx->GetPixelsToTwips());
|
||||
|
||||
|
||||
result = view->HandleEvent(aEvent, NS_VIEW_FLAG_CHECK_CHILDREN |
|
||||
NS_VIEW_FLAG_CHECK_PARENT |
|
||||
NS_VIEW_FLAG_CHECK_SIBLINGS);
|
||||
|
||||
aEvent->point.x = NSTwipsToIntPixels(aEvent->point.x, cx->GetTwipsToPixels());
|
||||
aEvent->point.y = NSTwipsToIntPixels(aEvent->point.y, cx->GetTwipsToPixels());
|
||||
|
||||
NS_RELEASE(cx);
|
||||
NS_RELEASE(vm);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
PRBool nsViewManager :: GrabMouseEvents(nsIView *aView)
|
||||
{
|
||||
mMouseGrabber = aView;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsViewManager :: GrabKeyEvents(nsIView *aView)
|
||||
{
|
||||
mKeyGrabber = aView;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
nsIView * nsViewManager :: GetMouseEventGrabber()
|
||||
{
|
||||
return nsnull;
|
||||
return mMouseGrabber;
|
||||
}
|
||||
|
||||
nsIView * nsViewManager :: GetKeyEventGrabber()
|
||||
{
|
||||
return nsnull;
|
||||
return mKeyGrabber;
|
||||
}
|
||||
|
||||
void nsViewManager :: InsertChild(nsIView *parent, nsIView *child, nsIView *sibling,
|
||||
|
@ -940,9 +1057,7 @@ void nsViewManager :: ShowQuality(PRBool aShow)
|
|||
{
|
||||
nsIScrollableView *scroller;
|
||||
|
||||
static NS_DEFINE_IID(kscroller, NS_ISCROLLABLEVIEW_IID);
|
||||
|
||||
if (NS_OK == mRootView->QueryInterface(kscroller, (void **)&scroller))
|
||||
if (NS_OK == mRootView->QueryInterface(kIScrollableViewIID, (void **)&scroller))
|
||||
{
|
||||
scroller->ShowQuality(aShow);
|
||||
}
|
||||
|
@ -953,9 +1068,7 @@ PRBool nsViewManager :: GetShowQuality(void)
|
|||
nsIScrollableView *scroller;
|
||||
PRBool retval = PR_FALSE;
|
||||
|
||||
static NS_DEFINE_IID(kscroller, NS_ISCROLLABLEVIEW_IID);
|
||||
|
||||
if (NS_OK == mRootView->QueryInterface(kscroller, (void **)&scroller))
|
||||
if (NS_OK == mRootView->QueryInterface(kIScrollableViewIID, (void **)&scroller))
|
||||
{
|
||||
retval = scroller->GetShowQuality();
|
||||
}
|
||||
|
@ -967,9 +1080,7 @@ void nsViewManager :: SetQuality(nsContentQuality aQuality)
|
|||
{
|
||||
nsIScrollableView *scroller;
|
||||
|
||||
static NS_DEFINE_IID(kscroller, NS_ISCROLLABLEVIEW_IID);
|
||||
|
||||
if (NS_OK == mRootView->QueryInterface(kscroller, (void **)&scroller))
|
||||
if (NS_OK == mRootView->QueryInterface(kIScrollableViewIID, (void **)&scroller))
|
||||
{
|
||||
scroller->SetQuality(aQuality);
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public:
|
|||
PRUint32 aUpdateFlags);
|
||||
virtual void UpdateView(nsIView *aView, const nsRect &aRect, PRUint32 aUpdateFlags);
|
||||
|
||||
virtual PRBool DispatchEvent(nsIEvent *event);
|
||||
virtual nsEventStatus DispatchEvent(nsGUIEvent *aEvent);
|
||||
|
||||
virtual PRBool GrabMouseEvents(nsIView *aView);
|
||||
virtual PRBool GrabKeyEvents(nsIView *aView);
|
||||
|
@ -132,6 +132,8 @@ private:
|
|||
nsIRegion *mDirtyRegion;
|
||||
PRInt32 mTransCnt;
|
||||
PRBool mRefreshEnabled;
|
||||
nsIView *mMouseGrabber;
|
||||
nsIView *mKeyGrabber;
|
||||
|
||||
static PRUint32 mVMCount; //number of viewmanagers
|
||||
static nsDrawingSurface mDrawingSurface; //single drawing surface
|
||||
|
|
Загрузка…
Ссылка в новой задаче