From c81e1dbc7c2bc939b1629eec671898af1011cfd8 Mon Sep 17 00:00:00 2001 From: "bryner%uiuc.edu" Date: Tue, 25 Apr 2000 06:25:43 +0000 Subject: [PATCH] Reorganizing the mousewheel code, and in the process fixing bug 36886 and working around bug 32344. Also removing some old #ifdef code that is not going to be used. --- content/events/src/nsEventStateManager.cpp | 146 ++++++--------------- content/events/src/nsEventStateManager.h | 9 -- layout/events/src/nsEventStateManager.cpp | 146 ++++++--------------- layout/events/src/nsEventStateManager.h | 9 -- 4 files changed, 76 insertions(+), 234 deletions(-) diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index 307e12eb52c6..b7c89d0223e1 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -83,7 +83,8 @@ PRUint32 nsEventStateManager::mInstanceCount = 0; enum { MOUSE_SCROLL_N_LINES, MOUSE_SCROLL_PAGE, - MOUSE_SCROLL_HISTORY + MOUSE_SCROLL_HISTORY, + MOUSE_SCROLL_TEXTSIZE }; nsEventStateManager::nsEventStateManager() @@ -793,13 +794,9 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, nsISelfScrollingFrame* sf = nsnull; nsIPresContext* mwPresContext = aPresContext; -#ifdef USE_FOCUS_FOR_MOUSEWHEEL - if (NS_SUCCEEDED(GetScrollableFrameOrView(sv, sf, focusView))) -#else if (NS_SUCCEEDED(GetScrollableFrameOrView(mwPresContext, aTargetFrame, aView, sv, sf, focusView))) -#endif { if (sv) { @@ -825,12 +822,8 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, nsIScrollableView* sv = nsnull; nsISelfScrollingFrame* sf = nsnull; -#ifdef USE_FOCUS_FOR_MOUSEWHEEL - if (NS_SUCCEEDED(GetScrollableFrameOrView(sv, sf, focusView))) -#else if (NS_SUCCEEDED(GetScrollableFrameOrView(aPresContext, aTargetFrame, aView, sv, sf, focusView))) -#endif { if (sv) { @@ -859,6 +852,10 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, } break; + case MOUSE_SCROLL_TEXTSIZE: + { + break; + } } *aStatus = nsEventStatus_eConsumeNoDefault; @@ -2262,8 +2259,6 @@ nsEventStateManager::UnregisterAccessKey(nsIFrame * aFrame) return NS_ERROR_FAILURE; } -#ifndef USE_FOCUS_FOR_MOUSEWHEEL - // This function MAY CHANGE the PresContext that you pass into it. It // will be changed to the PresContext for the main document. If the // new PresContext differs from the one you passed in, you should @@ -2312,69 +2307,20 @@ nsEventStateManager::GetDocumentFrame(nsIPresContext* &aPresContext) return aFrame; } -#endif // !USE_FOCUS_FOR_MOUSEWHEEL - -#ifdef USE_FOCUS_FOR_MOUSEWHEEL -// This is some work-in-progress code that uses only the focus -// to determine what to scroll - -nsresult -nsEventStateManager::GetScrollableFrameOrView(nsIScrollableView* &sv, - nsISelfScrollingFrame* &sf, - nsIView* &focusView) -{ - NS_ASSERTION(mPresContext, "ESM has a null prescontext"); - PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: gLastFocusedContent=%p\n", gLastFocusedContent)); - - nsIFrame* focusFrame = nsnull; - nsCOMPtr presShell; - mPresContext->GetShell(getter_AddRefs(presShell)); - if (!presShell || !gLastFocusedContent) - { - sv = nsnull; - sf = nsnull; - focusView = nsnull; - return NS_OK; - } - - presShell->GetPrimaryFrameFor(gLastFocusedContent, &focusFrame); - if (focusFrame) { - PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: got focusFrame\n")); - focusFrame->GetView(mPresContext, &focusView); - } - - if (focusView) { - PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: got focusView\n")); - sv = GetNearestScrollingView(focusView); - if (sv) { - PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: got scrollingView\n")); - sf = nsnull; - return NS_OK; // success - } - } - - if (focusFrame) - sf = GetParentSelfScrollingFrame(focusFrame); - if (sf) - PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: got sf\n")); - return NS_OK; -} - -#else // USE_FOCUS_FOR_MOUSEWHEEL // There are three posibilities for what this function returns: -// sv and focusView non-null, sf null (a view should be scrolled) +// sv and focusView non-null, sf null (a nsIScrollableView should be scrolled) // sv and focusView null, sf non-null (a frame should be scrolled) // sv, focusView, and sf all null (nothing to scroll) +// // The location works like this: -// First, check for a focused frame and try to get its view. -// If we can, and can get an nsIScrollableView for it, use that. -// If there is a focused frame but it does not have a view, or it has -// a view but no nsIScrollableView, check for an nsISelfScrollingFrame. -// If we find one, use that. -// If there is no focused frame, we first look for an nsISelfScrollingFrame -// as an ancestor of the event target. If there isn't one, we try to get -// an nsIView corresponding to the main document. +// First, check aTargetFrame (and its ancestors) looking for an +// nsISelfScrollingFrame. If we find this, stop immediately. +// Next, check for a focused frame and try to get its view. +// If we can, and we can also get an nsIScrollableView for it +// (using GetNearestScrollingView), use that view to scroll. +// If there is no focused frame, we try to get an nsIView corresponding +// to the main document, and then call GetNearestScrollingView on that. // Confused yet? // This function may call GetDocumentFrame, so read the warning above // regarding the PresContext that you pass into this function. @@ -2402,6 +2348,15 @@ nsEventStateManager::GetScrollableFrameOrView(nsIPresContext* &aPresContext, PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("------------------------\n")); PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: aTargetFrame = %p, aView = %p\n", aTargetFrame, aView)); + sf = GetParentSelfScrollingFrame(aTargetFrame); + PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: SelfScrollingFrame = %p\n", sf)); + + if (sf) { + sv = nsnull; + focusView = nsnull; + return NS_OK; + } + if (mCurrentFocus) { PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: mCurrentFocus = %p\n", mCurrentFocus)); @@ -2427,54 +2382,29 @@ nsEventStateManager::GetScrollableFrameOrView(nsIPresContext* &aPresContext, PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: mCurrentFocus = NULL\n")); - // If we can get an nsISelfScrollingFrame, that is preferable to getting - // the document view + focusFrame = GetDocumentFrame(aPresContext); + focusFrame->GetView(aPresContext, &focusView); - sf = GetParentSelfScrollingFrame(aTargetFrame); - if (sf) - PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: Found a SelfScrollingFrame: sf = %p\n", sf)); - else { - focusFrame = GetDocumentFrame(aPresContext); - focusFrame->GetView(aPresContext, &focusView); - - if (focusView) - PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: Got view for document frame!\n")); - else - PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: Couldn't get view for document frame\n")); - - } + if (focusView) + PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: got doc focusView\n")); } PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: focusFrame=%p, focusView=%p\n", focusFrame, focusView)); - - if (focusView) + + sv = nsnull; + + if (focusView) { sv = GetNearestScrollingView(focusView); - - if (sv) { - PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: Found a ScrollingView\n")); - - // We can stop now - sf = nsnull; - return NS_OK; - } - else { - PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: No scrolling view, looking for scrolling frame\n")); - if (!sf) - sf = GetParentSelfScrollingFrame(aTargetFrame); - - if (sf) - PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: Found a scrolling frame\n")); - - sv = nsnull; - focusView = nsnull; - return NS_OK; + + if (sv) + PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: got sv\n")); + else + focusView = nsnull; } - return NS_OK; // should not be reached + return NS_OK; } -#endif // USE_FOCUS_FOR_MOUSEWHEEL - void nsEventStateManager::ForceViewUpdate(nsIView* aView) { // force the update to happen now, otherwise multiple scrolls can diff --git a/content/events/src/nsEventStateManager.h b/content/events/src/nsEventStateManager.h index 6cc7c76af934..da3b26091c04 100644 --- a/content/events/src/nsEventStateManager.h +++ b/content/events/src/nsEventStateManager.h @@ -33,9 +33,6 @@ class nsIDocument; class nsIScrollableView; class nsISelfScrollingFrame; -#undef USE_FOCUS_FOR_MOUSEWHEEL // experimental code to use only the focus - // system to track the mousewheel - /* * Event listener manager */ @@ -115,11 +112,6 @@ protected: // These functions are all for mousewheel scrolling nsISelfScrollingFrame* GetParentSelfScrollingFrame(nsIFrame* aFrame); nsIScrollableView* GetNearestScrollingView(nsIView* aView); -#ifdef USE_FOCUS_FOR_MOUSEWHEEL - nsresult GetScrollableFrameOrView(nsIScrollableView* &sv, - nsISelfScrollingFrame* &sf, - nsIView* &focusView); -#else // This function MAY CHANGE the PresContext that you pass into it. It // will be changed to the PresContext for the main document. If the @@ -136,7 +128,6 @@ protected: nsIScrollableView* &sv, nsISelfScrollingFrame* &sf, nsIView* &focusView); -#endif void ForceViewUpdate(nsIView* aView); nsresult getPrefService(); // end mousewheel functions diff --git a/layout/events/src/nsEventStateManager.cpp b/layout/events/src/nsEventStateManager.cpp index 307e12eb52c6..b7c89d0223e1 100644 --- a/layout/events/src/nsEventStateManager.cpp +++ b/layout/events/src/nsEventStateManager.cpp @@ -83,7 +83,8 @@ PRUint32 nsEventStateManager::mInstanceCount = 0; enum { MOUSE_SCROLL_N_LINES, MOUSE_SCROLL_PAGE, - MOUSE_SCROLL_HISTORY + MOUSE_SCROLL_HISTORY, + MOUSE_SCROLL_TEXTSIZE }; nsEventStateManager::nsEventStateManager() @@ -793,13 +794,9 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, nsISelfScrollingFrame* sf = nsnull; nsIPresContext* mwPresContext = aPresContext; -#ifdef USE_FOCUS_FOR_MOUSEWHEEL - if (NS_SUCCEEDED(GetScrollableFrameOrView(sv, sf, focusView))) -#else if (NS_SUCCEEDED(GetScrollableFrameOrView(mwPresContext, aTargetFrame, aView, sv, sf, focusView))) -#endif { if (sv) { @@ -825,12 +822,8 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, nsIScrollableView* sv = nsnull; nsISelfScrollingFrame* sf = nsnull; -#ifdef USE_FOCUS_FOR_MOUSEWHEEL - if (NS_SUCCEEDED(GetScrollableFrameOrView(sv, sf, focusView))) -#else if (NS_SUCCEEDED(GetScrollableFrameOrView(aPresContext, aTargetFrame, aView, sv, sf, focusView))) -#endif { if (sv) { @@ -859,6 +852,10 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, } break; + case MOUSE_SCROLL_TEXTSIZE: + { + break; + } } *aStatus = nsEventStatus_eConsumeNoDefault; @@ -2262,8 +2259,6 @@ nsEventStateManager::UnregisterAccessKey(nsIFrame * aFrame) return NS_ERROR_FAILURE; } -#ifndef USE_FOCUS_FOR_MOUSEWHEEL - // This function MAY CHANGE the PresContext that you pass into it. It // will be changed to the PresContext for the main document. If the // new PresContext differs from the one you passed in, you should @@ -2312,69 +2307,20 @@ nsEventStateManager::GetDocumentFrame(nsIPresContext* &aPresContext) return aFrame; } -#endif // !USE_FOCUS_FOR_MOUSEWHEEL - -#ifdef USE_FOCUS_FOR_MOUSEWHEEL -// This is some work-in-progress code that uses only the focus -// to determine what to scroll - -nsresult -nsEventStateManager::GetScrollableFrameOrView(nsIScrollableView* &sv, - nsISelfScrollingFrame* &sf, - nsIView* &focusView) -{ - NS_ASSERTION(mPresContext, "ESM has a null prescontext"); - PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: gLastFocusedContent=%p\n", gLastFocusedContent)); - - nsIFrame* focusFrame = nsnull; - nsCOMPtr presShell; - mPresContext->GetShell(getter_AddRefs(presShell)); - if (!presShell || !gLastFocusedContent) - { - sv = nsnull; - sf = nsnull; - focusView = nsnull; - return NS_OK; - } - - presShell->GetPrimaryFrameFor(gLastFocusedContent, &focusFrame); - if (focusFrame) { - PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: got focusFrame\n")); - focusFrame->GetView(mPresContext, &focusView); - } - - if (focusView) { - PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: got focusView\n")); - sv = GetNearestScrollingView(focusView); - if (sv) { - PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: got scrollingView\n")); - sf = nsnull; - return NS_OK; // success - } - } - - if (focusFrame) - sf = GetParentSelfScrollingFrame(focusFrame); - if (sf) - PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: got sf\n")); - return NS_OK; -} - -#else // USE_FOCUS_FOR_MOUSEWHEEL // There are three posibilities for what this function returns: -// sv and focusView non-null, sf null (a view should be scrolled) +// sv and focusView non-null, sf null (a nsIScrollableView should be scrolled) // sv and focusView null, sf non-null (a frame should be scrolled) // sv, focusView, and sf all null (nothing to scroll) +// // The location works like this: -// First, check for a focused frame and try to get its view. -// If we can, and can get an nsIScrollableView for it, use that. -// If there is a focused frame but it does not have a view, or it has -// a view but no nsIScrollableView, check for an nsISelfScrollingFrame. -// If we find one, use that. -// If there is no focused frame, we first look for an nsISelfScrollingFrame -// as an ancestor of the event target. If there isn't one, we try to get -// an nsIView corresponding to the main document. +// First, check aTargetFrame (and its ancestors) looking for an +// nsISelfScrollingFrame. If we find this, stop immediately. +// Next, check for a focused frame and try to get its view. +// If we can, and we can also get an nsIScrollableView for it +// (using GetNearestScrollingView), use that view to scroll. +// If there is no focused frame, we try to get an nsIView corresponding +// to the main document, and then call GetNearestScrollingView on that. // Confused yet? // This function may call GetDocumentFrame, so read the warning above // regarding the PresContext that you pass into this function. @@ -2402,6 +2348,15 @@ nsEventStateManager::GetScrollableFrameOrView(nsIPresContext* &aPresContext, PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("------------------------\n")); PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: aTargetFrame = %p, aView = %p\n", aTargetFrame, aView)); + sf = GetParentSelfScrollingFrame(aTargetFrame); + PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: SelfScrollingFrame = %p\n", sf)); + + if (sf) { + sv = nsnull; + focusView = nsnull; + return NS_OK; + } + if (mCurrentFocus) { PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: mCurrentFocus = %p\n", mCurrentFocus)); @@ -2427,54 +2382,29 @@ nsEventStateManager::GetScrollableFrameOrView(nsIPresContext* &aPresContext, PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: mCurrentFocus = NULL\n")); - // If we can get an nsISelfScrollingFrame, that is preferable to getting - // the document view + focusFrame = GetDocumentFrame(aPresContext); + focusFrame->GetView(aPresContext, &focusView); - sf = GetParentSelfScrollingFrame(aTargetFrame); - if (sf) - PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: Found a SelfScrollingFrame: sf = %p\n", sf)); - else { - focusFrame = GetDocumentFrame(aPresContext); - focusFrame->GetView(aPresContext, &focusView); - - if (focusView) - PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: Got view for document frame!\n")); - else - PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: Couldn't get view for document frame\n")); - - } + if (focusView) + PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: got doc focusView\n")); } PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: focusFrame=%p, focusView=%p\n", focusFrame, focusView)); - - if (focusView) + + sv = nsnull; + + if (focusView) { sv = GetNearestScrollingView(focusView); - - if (sv) { - PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: Found a ScrollingView\n")); - - // We can stop now - sf = nsnull; - return NS_OK; - } - else { - PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: No scrolling view, looking for scrolling frame\n")); - if (!sf) - sf = GetParentSelfScrollingFrame(aTargetFrame); - - if (sf) - PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: Found a scrolling frame\n")); - - sv = nsnull; - focusView = nsnull; - return NS_OK; + + if (sv) + PR_LOG(MOUSEWHEEL, PR_LOG_DEBUG, ("GetScrollableFrameOrView: got sv\n")); + else + focusView = nsnull; } - return NS_OK; // should not be reached + return NS_OK; } -#endif // USE_FOCUS_FOR_MOUSEWHEEL - void nsEventStateManager::ForceViewUpdate(nsIView* aView) { // force the update to happen now, otherwise multiple scrolls can diff --git a/layout/events/src/nsEventStateManager.h b/layout/events/src/nsEventStateManager.h index 6cc7c76af934..da3b26091c04 100644 --- a/layout/events/src/nsEventStateManager.h +++ b/layout/events/src/nsEventStateManager.h @@ -33,9 +33,6 @@ class nsIDocument; class nsIScrollableView; class nsISelfScrollingFrame; -#undef USE_FOCUS_FOR_MOUSEWHEEL // experimental code to use only the focus - // system to track the mousewheel - /* * Event listener manager */ @@ -115,11 +112,6 @@ protected: // These functions are all for mousewheel scrolling nsISelfScrollingFrame* GetParentSelfScrollingFrame(nsIFrame* aFrame); nsIScrollableView* GetNearestScrollingView(nsIView* aView); -#ifdef USE_FOCUS_FOR_MOUSEWHEEL - nsresult GetScrollableFrameOrView(nsIScrollableView* &sv, - nsISelfScrollingFrame* &sf, - nsIView* &focusView); -#else // This function MAY CHANGE the PresContext that you pass into it. It // will be changed to the PresContext for the main document. If the @@ -136,7 +128,6 @@ protected: nsIScrollableView* &sv, nsISelfScrollingFrame* &sf, nsIView* &focusView); -#endif void ForceViewUpdate(nsIView* aView); nsresult getPrefService(); // end mousewheel functions