From a158b164ef4f5c47a21bc2051d81f3afc64198d4 Mon Sep 17 00:00:00 2001 From: "joki%netscape.com" Date: Fri, 30 Apr 1999 19:38:39 +0000 Subject: [PATCH] Adding scrolling fixes to fix bug #3999, A: chofmann git-svn-id: svn://10.0.0.236/trunk@29867 18797224-902f-48f8-a5cc-f745e15eee43 --- .../events/public/nsIEventStateManager.h | 4 +- .../events/src/nsEventStateManager.cpp | 39 +++++- .../content/events/src/nsEventStateManager.h | 5 +- .../editor/base/nsEditorEventListeners.cpp | 11 +- .../libeditor/text/nsEditorEventListeners.cpp | 11 +- mozilla/layout/base/nsPresShell.cpp | 2 +- .../events/public/nsIEventStateManager.h | 4 +- .../layout/events/src/nsEventStateManager.cpp | 39 +++++- .../layout/events/src/nsEventStateManager.h | 5 +- mozilla/layout/html/base/src/nsPresShell.cpp | 2 +- mozilla/view/src/nsScrollingView.cpp | 125 ------------------ mozilla/view/src/nsScrollingView.h | 1 - 12 files changed, 110 insertions(+), 138 deletions(-) diff --git a/mozilla/content/events/public/nsIEventStateManager.h b/mozilla/content/events/public/nsIEventStateManager.h index 49bcd385193..ce5cfe66628 100644 --- a/mozilla/content/events/public/nsIEventStateManager.h +++ b/mozilla/content/events/public/nsIEventStateManager.h @@ -27,6 +27,7 @@ class nsIContent; class nsIPresContext; class nsIDOMEvent; class nsIFrame; +class nsIView; /* * Event listener manager interface. @@ -48,7 +49,8 @@ public: NS_IMETHOD PostHandleEvent(nsIPresContext& aPresContext, nsGUIEvent *aEvent, nsIFrame* aTargetFrame, - nsEventStatus& aStatus) = 0; + nsEventStatus& aStatus, + nsIView* aView) = 0; NS_IMETHOD SetPresContext(nsIPresContext* aPresContext) = 0; NS_IMETHOD ClearFrameRefs(nsIFrame* aFrame) = 0; diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index a42c2aae5cc..2a3b9c69bd9 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -37,6 +37,7 @@ #include "nsINameSpaceManager.h" // for kNameSpaceID_HTML #include "nsIWebShell.h" #include "nsIFocusableContent.h" +#include "nsIScrollableView.h" static NS_DEFINE_IID(kIEventStateManagerIID, NS_IEVENTSTATEMANAGER_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); @@ -49,6 +50,7 @@ static NS_DEFINE_IID(kIDOMHTMLObjectElementIID, NS_IDOMHTMLOBJECTELEMENT_IID); static NS_DEFINE_IID(kIDOMHTMLButtonElementIID, NS_IDOMHTMLBUTTONELEMENT_IID); 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() { mLastMouseOverFrame = nsnull; @@ -114,7 +116,8 @@ NS_IMETHODIMP nsEventStateManager::PostHandleEvent(nsIPresContext& aPresContext, nsGUIEvent *aEvent, nsIFrame* aTargetFrame, - nsEventStatus& aStatus) + nsEventStatus& aStatus, + nsIView* aView) { mCurrentTarget = aTargetFrame; nsresult ret = NS_OK; @@ -139,6 +142,7 @@ nsEventStateManager::PostHandleEvent(nsIPresContext& aPresContext, if (nsnull != aEvent->widget) { aEvent->widget->SetFocus(); } + SetContentState(nsnull, NS_EVENT_STATE_FOCUS); } } @@ -166,9 +170,24 @@ nsEventStateManager::PostHandleEvent(nsIPresContext& aPresContext, break; case NS_VK_PAGE_DOWN: case NS_VK_PAGE_UP: + case NS_VK_SPACE: + if (!mCurrentFocus) { + nsIScrollableView* sv = GetNearestScrollingView(aView); + if (sv) { + nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent; + sv->ScrollByPages((keyEvent->keyCode != NS_VK_PAGE_UP) ? 1 : -1); + } + } break; case NS_VK_DOWN: case NS_VK_UP: + if (!mCurrentFocus) { + nsIScrollableView* sv = GetNearestScrollingView(aView); + if (sv) { + nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent; + sv->ScrollByLines((keyEvent->keyCode == NS_VK_DOWN) ? 1 : -1); + } + } break; } } @@ -196,6 +215,24 @@ nsEventStateManager::ClearFrameRefs(nsIFrame* aFrame) return NS_OK; } +nsIScrollableView* +nsEventStateManager::GetNearestScrollingView(nsIView* aView) +{ + nsIScrollableView* sv; + if (NS_OK == aView->QueryInterface(kIScrollableViewIID, (void**)&sv)) { + return sv; + } + + nsIView* parent; + aView->GetParent(parent); + + if (nsnull != parent) { + return GetNearestScrollingView(parent); + } + + return nsnull; +} + void nsEventStateManager::UpdateCursor(nsIPresContext& aPresContext, nsPoint& aPoint, nsIFrame* aTargetFrame, nsEventStatus& aStatus) diff --git a/mozilla/content/events/src/nsEventStateManager.h b/mozilla/content/events/src/nsEventStateManager.h index 04545b0d59f..defaeaeae96 100644 --- a/mozilla/content/events/src/nsEventStateManager.h +++ b/mozilla/content/events/src/nsEventStateManager.h @@ -22,6 +22,7 @@ #include "nsIEventStateManager.h" #include "nsGUIEvent.h" class nsIDocument; +class nsIScrollableView; /* * Event listener manager @@ -43,7 +44,8 @@ public: NS_IMETHOD PostHandleEvent(nsIPresContext& aPresContext, nsGUIEvent *aEvent, nsIFrame* aTargetFrame, - nsEventStatus& aStatus); + nsEventStatus& aStatus, + nsIView* aView); NS_IMETHOD SetPresContext(nsIPresContext* aPresContext); NS_IMETHOD ClearFrameRefs(nsIFrame* aFrame); @@ -63,6 +65,7 @@ protected: nsIContent* GetNextTabbableContent(nsIContent* aParent, nsIContent* aChild, nsIContent* aTop, PRBool foward); PRInt32 GetNextTabIndex(nsIContent* aParent, PRBool foward); NS_IMETHOD SendFocusBlur(nsIContent *aContent); + nsIScrollableView* GetNearestScrollingView(nsIView* aView); //Any frames here must be checked for validity in ClearFrameRefs nsIFrame* mCurrentTarget; diff --git a/mozilla/editor/base/nsEditorEventListeners.cpp b/mozilla/editor/base/nsEditorEventListeners.cpp index cfc99de869a..a8a714674bf 100644 --- a/mozilla/editor/base/nsEditorEventListeners.cpp +++ b/mozilla/editor/base/nsEditorEventListeners.cpp @@ -188,16 +188,23 @@ nsTextEditorKeyListener::KeyDown(nsIDOMEvent* aKeyEvent) case nsIDOMEvent::VK_DOWN: // these have already been handled in nsRangeList. Why are we getting them // again here (Mac)? In switch to avoid putting in bogus chars. + + //return NS_OK to allow page scrolling. + return NS_OK; break; case nsIDOMEvent::VK_HOME: case nsIDOMEvent::VK_END: - case nsIDOMEvent::VK_PAGE_UP: - case nsIDOMEvent::VK_PAGE_DOWN: // who handles these? #if DEBUG printf("Key not handled\n"); #endif + break; + + case nsIDOMEvent::VK_PAGE_UP: + case nsIDOMEvent::VK_PAGE_DOWN: + //return NS_OK to allow page scrolling. + return NS_OK; break; default: diff --git a/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp b/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp index cfc99de869a..a8a714674bf 100644 --- a/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp +++ b/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp @@ -188,16 +188,23 @@ nsTextEditorKeyListener::KeyDown(nsIDOMEvent* aKeyEvent) case nsIDOMEvent::VK_DOWN: // these have already been handled in nsRangeList. Why are we getting them // again here (Mac)? In switch to avoid putting in bogus chars. + + //return NS_OK to allow page scrolling. + return NS_OK; break; case nsIDOMEvent::VK_HOME: case nsIDOMEvent::VK_END: - case nsIDOMEvent::VK_PAGE_UP: - case nsIDOMEvent::VK_PAGE_DOWN: // who handles these? #if DEBUG printf("Key not handled\n"); #endif + break; + + case nsIDOMEvent::VK_PAGE_UP: + case nsIDOMEvent::VK_PAGE_DOWN: + //return NS_OK to allow page scrolling. + return NS_OK; break; default: diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index ef3bb1a4df8..7ff6ef121fd 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -2005,7 +2005,7 @@ PresShell::HandleEvent(nsIView *aView, //4. Give event to event manager for post event state changes and generation of synthetic events. if (nsnull != mCurrentEventFrame && NS_OK == rv) { - rv = manager->PostHandleEvent(*mPresContext, aEvent, mCurrentEventFrame, aEventStatus); + rv = manager->PostHandleEvent(*mPresContext, aEvent, mCurrentEventFrame, aEventStatus, aView); } } } diff --git a/mozilla/layout/events/public/nsIEventStateManager.h b/mozilla/layout/events/public/nsIEventStateManager.h index 49bcd385193..ce5cfe66628 100644 --- a/mozilla/layout/events/public/nsIEventStateManager.h +++ b/mozilla/layout/events/public/nsIEventStateManager.h @@ -27,6 +27,7 @@ class nsIContent; class nsIPresContext; class nsIDOMEvent; class nsIFrame; +class nsIView; /* * Event listener manager interface. @@ -48,7 +49,8 @@ public: NS_IMETHOD PostHandleEvent(nsIPresContext& aPresContext, nsGUIEvent *aEvent, nsIFrame* aTargetFrame, - nsEventStatus& aStatus) = 0; + nsEventStatus& aStatus, + nsIView* aView) = 0; NS_IMETHOD SetPresContext(nsIPresContext* aPresContext) = 0; NS_IMETHOD ClearFrameRefs(nsIFrame* aFrame) = 0; diff --git a/mozilla/layout/events/src/nsEventStateManager.cpp b/mozilla/layout/events/src/nsEventStateManager.cpp index a42c2aae5cc..2a3b9c69bd9 100644 --- a/mozilla/layout/events/src/nsEventStateManager.cpp +++ b/mozilla/layout/events/src/nsEventStateManager.cpp @@ -37,6 +37,7 @@ #include "nsINameSpaceManager.h" // for kNameSpaceID_HTML #include "nsIWebShell.h" #include "nsIFocusableContent.h" +#include "nsIScrollableView.h" static NS_DEFINE_IID(kIEventStateManagerIID, NS_IEVENTSTATEMANAGER_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); @@ -49,6 +50,7 @@ static NS_DEFINE_IID(kIDOMHTMLObjectElementIID, NS_IDOMHTMLOBJECTELEMENT_IID); static NS_DEFINE_IID(kIDOMHTMLButtonElementIID, NS_IDOMHTMLBUTTONELEMENT_IID); 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() { mLastMouseOverFrame = nsnull; @@ -114,7 +116,8 @@ NS_IMETHODIMP nsEventStateManager::PostHandleEvent(nsIPresContext& aPresContext, nsGUIEvent *aEvent, nsIFrame* aTargetFrame, - nsEventStatus& aStatus) + nsEventStatus& aStatus, + nsIView* aView) { mCurrentTarget = aTargetFrame; nsresult ret = NS_OK; @@ -139,6 +142,7 @@ nsEventStateManager::PostHandleEvent(nsIPresContext& aPresContext, if (nsnull != aEvent->widget) { aEvent->widget->SetFocus(); } + SetContentState(nsnull, NS_EVENT_STATE_FOCUS); } } @@ -166,9 +170,24 @@ nsEventStateManager::PostHandleEvent(nsIPresContext& aPresContext, break; case NS_VK_PAGE_DOWN: case NS_VK_PAGE_UP: + case NS_VK_SPACE: + if (!mCurrentFocus) { + nsIScrollableView* sv = GetNearestScrollingView(aView); + if (sv) { + nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent; + sv->ScrollByPages((keyEvent->keyCode != NS_VK_PAGE_UP) ? 1 : -1); + } + } break; case NS_VK_DOWN: case NS_VK_UP: + if (!mCurrentFocus) { + nsIScrollableView* sv = GetNearestScrollingView(aView); + if (sv) { + nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent; + sv->ScrollByLines((keyEvent->keyCode == NS_VK_DOWN) ? 1 : -1); + } + } break; } } @@ -196,6 +215,24 @@ nsEventStateManager::ClearFrameRefs(nsIFrame* aFrame) return NS_OK; } +nsIScrollableView* +nsEventStateManager::GetNearestScrollingView(nsIView* aView) +{ + nsIScrollableView* sv; + if (NS_OK == aView->QueryInterface(kIScrollableViewIID, (void**)&sv)) { + return sv; + } + + nsIView* parent; + aView->GetParent(parent); + + if (nsnull != parent) { + return GetNearestScrollingView(parent); + } + + return nsnull; +} + void nsEventStateManager::UpdateCursor(nsIPresContext& aPresContext, nsPoint& aPoint, nsIFrame* aTargetFrame, nsEventStatus& aStatus) diff --git a/mozilla/layout/events/src/nsEventStateManager.h b/mozilla/layout/events/src/nsEventStateManager.h index 04545b0d59f..defaeaeae96 100644 --- a/mozilla/layout/events/src/nsEventStateManager.h +++ b/mozilla/layout/events/src/nsEventStateManager.h @@ -22,6 +22,7 @@ #include "nsIEventStateManager.h" #include "nsGUIEvent.h" class nsIDocument; +class nsIScrollableView; /* * Event listener manager @@ -43,7 +44,8 @@ public: NS_IMETHOD PostHandleEvent(nsIPresContext& aPresContext, nsGUIEvent *aEvent, nsIFrame* aTargetFrame, - nsEventStatus& aStatus); + nsEventStatus& aStatus, + nsIView* aView); NS_IMETHOD SetPresContext(nsIPresContext* aPresContext); NS_IMETHOD ClearFrameRefs(nsIFrame* aFrame); @@ -63,6 +65,7 @@ protected: nsIContent* GetNextTabbableContent(nsIContent* aParent, nsIContent* aChild, nsIContent* aTop, PRBool foward); PRInt32 GetNextTabIndex(nsIContent* aParent, PRBool foward); NS_IMETHOD SendFocusBlur(nsIContent *aContent); + nsIScrollableView* GetNearestScrollingView(nsIView* aView); //Any frames here must be checked for validity in ClearFrameRefs nsIFrame* mCurrentTarget; diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index ef3bb1a4df8..7ff6ef121fd 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -2005,7 +2005,7 @@ PresShell::HandleEvent(nsIView *aView, //4. Give event to event manager for post event state changes and generation of synthetic events. if (nsnull != mCurrentEventFrame && NS_OK == rv) { - rv = manager->PostHandleEvent(*mPresContext, aEvent, mCurrentEventFrame, aEventStatus); + rv = manager->PostHandleEvent(*mPresContext, aEvent, mCurrentEventFrame, aEventStatus, aView); } } } diff --git a/mozilla/view/src/nsScrollingView.cpp b/mozilla/view/src/nsScrollingView.cpp index 0413baff44b..dd3eb2947f7 100644 --- a/mozilla/view/src/nsScrollingView.cpp +++ b/mozilla/view/src/nsScrollingView.cpp @@ -745,131 +745,6 @@ void nsScrollingView :: Notify(nsITimer * aTimer) mScrollingTimer->Init(this, 25); } -NS_IMETHODIMP nsScrollingView :: HandleEvent(nsGUIEvent *aEvent, PRUint32 aEventFlags, - nsEventStatus &aStatus) -{ - switch (aEvent->message) - { - case NS_KEY_DOWN: - { - nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent; - - switch (keyEvent->keyCode) - { - case NS_VK_PAGE_DOWN: - case NS_VK_PAGE_UP: - case NS_VK_SPACE: - ScrollByPages((keyEvent->keyCode != NS_VK_PAGE_UP) ? 1 : -1); - break; - - case NS_VK_DOWN: - case NS_VK_UP: - ScrollByLines((keyEvent->keyCode == NS_VK_DOWN) ? 1 : -1); - break; - - default: - break; - } - } - - break; - -#if 0 - case NS_MOUSE_MOVE: - { - nsRect brect; - nscoord lx, ly; - - GetWidget(win); - - GetBounds(brect); - - // XXX Huh. We shouldn't just be doing this for any mouse move. - // If this is for auto-scrolling then only on mouse press and drag... - lx = aEvent->point.x - (brect.x); - ly = aEvent->point.y - (brect.y); - - //nscoord xoff, yoff; - //GetScrolledView()->GetScrollOffset(&xoff, &yoff); - //printf("%d %d %d\n", trect.y, trect.height, yoff); - //printf("mouse %d %d \n", aEvent->point.x, aEvent->point.y); - - if (!brect.Contains(lx, ly)) - { - if (mScrollingTimer == nsnull) - { - if (nsnull != mClientData) - { - if (ly < 0 || ly > brect.y) - { - mScrollingDelta = ly < 0 ? -100 : 100; - NS_NewTimer(&mScrollingTimer); - mScrollingTimer->Init(this, 25); - } - } - } - } - else if (mScrollingTimer != nsnull) - { - mScrollingTimer->Cancel(); - NS_RELEASE(mScrollingTimer); - } - break; - } - - case NS_MOUSE_LEFT_BUTTON_UP: - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_RIGHT_BUTTON_UP: - { - if (mScrollingTimer != nsnull) - { - mScrollingTimer->Cancel(); - NS_RELEASE(mScrollingTimer); - mScrollingTimer = nsnull; - } - - nsRect trect; - nscoord lx, ly; - - GetBounds(trect); - - //GetWidget(win); - //mViewManager->GetDeviceContext(dx); - //dx->GetDevUnitsToAppUnits(p2t); - //offX = offY = 0; - //win->ConvertToDeviceCoordinates(offX,offY); - //offX = NSIntPixelsToTwips(offX, p2t); - //offY = NSIntPixelsToTwips(offY, p2t); - - lx = aEvent->point.x - (trect.x); - ly = aEvent->point.y - (trect.y); - - if (!trect.Contains(lx, ly)) - { - nsEventStatus retval; - - if (nsnull != mClientData) - { - nsIViewObserver *obs; - - if (NS_OK == mViewManager->GetViewObserver(obs)) - { - obs->HandleEvent((nsIView *)this, aEvent, retval); - NS_RELEASE(obs); - } - } - } - break; - } -#endif - - default: - break; - } - - return nsView::HandleEvent(aEvent, aEventFlags, aStatus); -} - NS_IMETHODIMP nsScrollingView :: CreateScrollControls(nsNativeWidget aNative) { nsIDeviceContext *dx; diff --git a/mozilla/view/src/nsScrollingView.h b/mozilla/view/src/nsScrollingView.h index cebe408c491..2dbdebfb4e5 100644 --- a/mozilla/view/src/nsScrollingView.h +++ b/mozilla/view/src/nsScrollingView.h @@ -46,7 +46,6 @@ public: // SetVisibility is overriden so that it will set it's components visibility (ClipView, // CornerView, ScrollBarView's),as well as it's own visibility. NS_IMETHOD SetVisibility(nsViewVisibility visibility); - NS_IMETHOD HandleEvent(nsGUIEvent *aEvent, PRUint32 aEventFlags, nsEventStatus &aStatus); NS_IMETHOD SetWidget(nsIWidget *aWidget); //nsIScrollableView interface