Make trees capable of scrolling by full pages with the mouse wheel.

General cleanup and additions to mousewheel debugging code (which is
#ifdef DEBUG_scroll).  r=hyatt.
This commit is contained in:
bryner%uiuc.edu 2000-01-16 05:30:49 +00:00
Родитель 6b9b799616
Коммит 6012d905b7
7 изменённых файлов: 181 добавлений и 58 удалений

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

@ -835,8 +835,9 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext,
nsIView* focusView = nsnull;
nsIScrollableView* sv = nsnull;
nsISelfScrollingFrame* sf = nsnull;
if (NS_SUCCEEDED(GetScrollableFrameOrView(aPresContext, aTargetFrame, aView, sv, sf, focusView)))
if (NS_SUCCEEDED(GetScrollableFrameOrView(aPresContext, aTargetFrame,
aView, sv, sf, focusView)))
{
if (sv)
{
@ -846,17 +847,29 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext,
else if (sf)
sf->ScrollByLines(aPresContext, numLines);
}
break;
}
case MOUSE_SCROLL_PAGE:
if (!mCurrentFocus) {
nsIScrollableView* sv = GetNearestScrollingView(aView);
if (sv) {
sv->ScrollByPages((numLines > 0) ? 1 : -1);
}
}
break;
case MOUSE_SCROLL_PAGE:
{
nsIView* focusView = nsnull;
nsIScrollableView* sv = nsnull;
nsISelfScrollingFrame* sf = nsnull;
if (NS_SUCCEEDED(GetScrollableFrameOrView(aPresContext, aTargetFrame,
aView, sv, sf, focusView)))
{
if (sv)
{
sv->ScrollByPages((numLines > 0) ? 1 : -1);
ForceViewUpdate(focusView);
}
else if (sf)
sf->ScrollByPages(aPresContext, (numLines > 0) ? 1 : -1);
}
}
break;
case MOUSE_SCROLL_HISTORY:
{
nsCOMPtr<nsIWebShell> webShell;
@ -2252,19 +2265,32 @@ nsEventStateManager::GetDocumentFrame(nsIPresContext* aPresContext)
nsIView* aView;
aPresContext->GetShell(getter_AddRefs(presShell));
if (nsnull == presShell) {
#ifdef DEBUG_scroll
printf("Got a null PresShell\n");
printf("GetDocumentFrame: Got a null PresShell\n");
#endif
return nsnull;
}
presShell->GetDocument(&aDocument);
presShell->GetPrimaryFrameFor(aDocument->GetRootContent(), &aFrame);
#ifdef DEBUG_scroll
printf("GetDocumentFrame: aDocument = %p, aFrame = %p\n", aDocument, aFrame);
printf("GetDocumentFrame: mDocument = %p, gLastFocusedDocument = %p\n",
mDocument, gLastFocusedDocument);
printf("GetDocumentFrame: aDocument.parent=%p, mDocument.parent=%p, gLFD.parent=%p\n", aDocument->GetParentDocument(), (mDocument ? mDocument->GetParentDocument() : 0), (gLastFocusedDocument ? gLastFocusedDocument->GetParentDocument() : 0));
#endif
aFrame->GetView(aPresContext, &aView);
#ifdef DEBUG_scroll
printf("GetDocumentFrame: got document view = %p\n", aView);
#endif
if (!aView) {
#ifdef DEBUG_scroll
printf("looking for a parent with a view\n");
printf("GetDocumentFrame: looking for a parent with a view\n");
#endif
aFrame->GetParentWithView(aPresContext, &aFrame);
}
@ -2306,6 +2332,7 @@ nsresult nsEventStateManager::GetScrollableFrameOrView(nsIPresContext* aPresCont
}
#ifdef DEBUG_scroll
printf("------------------------\n");
printf("GetScrollableFrameOrView: aTargetFrame = %p, aView = %p\n",
aTargetFrame, aView);
#endif
@ -2327,7 +2354,7 @@ nsresult nsEventStateManager::GetScrollableFrameOrView(nsIPresContext* aPresCont
// XXX this might not be right
#ifdef DEBUG_scroll
printf("Could not get a view for the focused frame\n");
printf("GetScrollableFrameOrView: Could not get a view for the focused frame\n");
#endif
focusFrame = aTargetFrame;
@ -2347,7 +2374,7 @@ nsresult nsEventStateManager::GetScrollableFrameOrView(nsIPresContext* aPresCont
sf = GetParentSelfScrollingFrame(aTargetFrame);
if (sf) {
#ifdef DEBUG_scroll
printf("Found a SelfScrollingFrame: sf = %p\n", sf);
printf("GetScrollableFrameOrView: Found a SelfScrollingFrame: sf = %p\n", sf);
#endif
focusView = aView;
} else {
@ -2356,9 +2383,9 @@ nsresult nsEventStateManager::GetScrollableFrameOrView(nsIPresContext* aPresCont
#ifdef DEBUG_scroll
if (focusView)
printf("Got view for document frame!\n");
printf("GetScrollableFrameOrView: Got view for document frame!\n");
else // hopefully we won't be here
printf("Couldn't get view for document frame\n");
printf("GetScrollableFrameOrView: Couldn't get view for document frame\n");
#endif
}
@ -2373,7 +2400,7 @@ nsresult nsEventStateManager::GetScrollableFrameOrView(nsIPresContext* aPresCont
if (sv) {
#ifdef DEBUG_scroll
printf("Found a ScrollingView\n");
printf("GetScrollableFrameOrView: Found a ScrollingView\n");
#endif
// We can stop now
@ -2382,14 +2409,14 @@ nsresult nsEventStateManager::GetScrollableFrameOrView(nsIPresContext* aPresCont
}
else {
#ifdef DEBUG_scroll
printf("No scrolling view, looking for a scrolling frame\n");
printf("GetScrollableFrameOrView: No scrolling view, looking for a scrolling frame\n");
#endif
if (!sf)
sf = GetParentSelfScrollingFrame(aTargetFrame);
if (sf) {
#ifdef DEBUG_scroll
printf("Found a scrolling frame\n");
printf("GetScrollableFrameOrView: Found a scrolling frame\n");
#endif
sv = nsnull;
@ -2399,7 +2426,7 @@ nsresult nsEventStateManager::GetScrollableFrameOrView(nsIPresContext* aPresCont
}
else {
#ifdef DEBUG_scroll
printf("Could not find a scrolling frame\n");
printf("GetScrollableFrameOrView: Could not find a scrolling frame\n");
#endif
sf = nsnull;
sv = nsnull;

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

@ -18,6 +18,7 @@ class nsISelfScrollingFrame : public nsISupports {
NS_IMETHOD ScrollByLines(nsIPresContext* aPresContext, PRInt32 lines)=0;
NS_IMETHOD CollapseScrollbar(nsIPresContext* aPresContext, PRBool aHide) = 0;
NS_IMETHOD ScrollByPages(nsIPresContext* aPresContext, PRInt32 pages) = 0;
};
#endif /* _nsISelfScrollingFrame_h */

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

@ -835,8 +835,9 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext,
nsIView* focusView = nsnull;
nsIScrollableView* sv = nsnull;
nsISelfScrollingFrame* sf = nsnull;
if (NS_SUCCEEDED(GetScrollableFrameOrView(aPresContext, aTargetFrame, aView, sv, sf, focusView)))
if (NS_SUCCEEDED(GetScrollableFrameOrView(aPresContext, aTargetFrame,
aView, sv, sf, focusView)))
{
if (sv)
{
@ -846,17 +847,29 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext,
else if (sf)
sf->ScrollByLines(aPresContext, numLines);
}
break;
}
case MOUSE_SCROLL_PAGE:
if (!mCurrentFocus) {
nsIScrollableView* sv = GetNearestScrollingView(aView);
if (sv) {
sv->ScrollByPages((numLines > 0) ? 1 : -1);
}
}
break;
case MOUSE_SCROLL_PAGE:
{
nsIView* focusView = nsnull;
nsIScrollableView* sv = nsnull;
nsISelfScrollingFrame* sf = nsnull;
if (NS_SUCCEEDED(GetScrollableFrameOrView(aPresContext, aTargetFrame,
aView, sv, sf, focusView)))
{
if (sv)
{
sv->ScrollByPages((numLines > 0) ? 1 : -1);
ForceViewUpdate(focusView);
}
else if (sf)
sf->ScrollByPages(aPresContext, (numLines > 0) ? 1 : -1);
}
}
break;
case MOUSE_SCROLL_HISTORY:
{
nsCOMPtr<nsIWebShell> webShell;
@ -2252,19 +2265,32 @@ nsEventStateManager::GetDocumentFrame(nsIPresContext* aPresContext)
nsIView* aView;
aPresContext->GetShell(getter_AddRefs(presShell));
if (nsnull == presShell) {
#ifdef DEBUG_scroll
printf("Got a null PresShell\n");
printf("GetDocumentFrame: Got a null PresShell\n");
#endif
return nsnull;
}
presShell->GetDocument(&aDocument);
presShell->GetPrimaryFrameFor(aDocument->GetRootContent(), &aFrame);
#ifdef DEBUG_scroll
printf("GetDocumentFrame: aDocument = %p, aFrame = %p\n", aDocument, aFrame);
printf("GetDocumentFrame: mDocument = %p, gLastFocusedDocument = %p\n",
mDocument, gLastFocusedDocument);
printf("GetDocumentFrame: aDocument.parent=%p, mDocument.parent=%p, gLFD.parent=%p\n", aDocument->GetParentDocument(), (mDocument ? mDocument->GetParentDocument() : 0), (gLastFocusedDocument ? gLastFocusedDocument->GetParentDocument() : 0));
#endif
aFrame->GetView(aPresContext, &aView);
#ifdef DEBUG_scroll
printf("GetDocumentFrame: got document view = %p\n", aView);
#endif
if (!aView) {
#ifdef DEBUG_scroll
printf("looking for a parent with a view\n");
printf("GetDocumentFrame: looking for a parent with a view\n");
#endif
aFrame->GetParentWithView(aPresContext, &aFrame);
}
@ -2306,6 +2332,7 @@ nsresult nsEventStateManager::GetScrollableFrameOrView(nsIPresContext* aPresCont
}
#ifdef DEBUG_scroll
printf("------------------------\n");
printf("GetScrollableFrameOrView: aTargetFrame = %p, aView = %p\n",
aTargetFrame, aView);
#endif
@ -2327,7 +2354,7 @@ nsresult nsEventStateManager::GetScrollableFrameOrView(nsIPresContext* aPresCont
// XXX this might not be right
#ifdef DEBUG_scroll
printf("Could not get a view for the focused frame\n");
printf("GetScrollableFrameOrView: Could not get a view for the focused frame\n");
#endif
focusFrame = aTargetFrame;
@ -2347,7 +2374,7 @@ nsresult nsEventStateManager::GetScrollableFrameOrView(nsIPresContext* aPresCont
sf = GetParentSelfScrollingFrame(aTargetFrame);
if (sf) {
#ifdef DEBUG_scroll
printf("Found a SelfScrollingFrame: sf = %p\n", sf);
printf("GetScrollableFrameOrView: Found a SelfScrollingFrame: sf = %p\n", sf);
#endif
focusView = aView;
} else {
@ -2356,9 +2383,9 @@ nsresult nsEventStateManager::GetScrollableFrameOrView(nsIPresContext* aPresCont
#ifdef DEBUG_scroll
if (focusView)
printf("Got view for document frame!\n");
printf("GetScrollableFrameOrView: Got view for document frame!\n");
else // hopefully we won't be here
printf("Couldn't get view for document frame\n");
printf("GetScrollableFrameOrView: Couldn't get view for document frame\n");
#endif
}
@ -2373,7 +2400,7 @@ nsresult nsEventStateManager::GetScrollableFrameOrView(nsIPresContext* aPresCont
if (sv) {
#ifdef DEBUG_scroll
printf("Found a ScrollingView\n");
printf("GetScrollableFrameOrView: Found a ScrollingView\n");
#endif
// We can stop now
@ -2382,14 +2409,14 @@ nsresult nsEventStateManager::GetScrollableFrameOrView(nsIPresContext* aPresCont
}
else {
#ifdef DEBUG_scroll
printf("No scrolling view, looking for a scrolling frame\n");
printf("GetScrollableFrameOrView: No scrolling view, looking for a scrolling frame\n");
#endif
if (!sf)
sf = GetParentSelfScrollingFrame(aTargetFrame);
if (sf) {
#ifdef DEBUG_scroll
printf("Found a scrolling frame\n");
printf("GetScrollableFrameOrView: Found a scrolling frame\n");
#endif
sv = nsnull;
@ -2399,7 +2426,7 @@ nsresult nsEventStateManager::GetScrollableFrameOrView(nsIPresContext* aPresCont
}
else {
#ifdef DEBUG_scroll
printf("Could not find a scrolling frame\n");
printf("GetScrollableFrameOrView: Could not find a scrolling frame\n");
#endif
sf = nsnull;
sv = nsnull;

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

@ -617,6 +617,33 @@ nsTreeFrame::ScrollByLines(nsIPresContext* aPresContext, PRInt32 lines)
return NS_OK;
}
NS_IMETHODIMP
nsTreeFrame::ScrollByPages(nsIPresContext* aPresContext, PRInt32 pages)
{
printf("nsTreeFrame::ScrollByPages\n");
PRInt32 lines;
// Get our treechildren child frame.
nsTreeRowGroupFrame* treeRowGroup = nsnull;
GetTreeBody(&treeRowGroup);
if (!treeRowGroup)
return NS_OK; // No tree body. Just bail.
PRInt32 absPages = (pages > 0) ? pages : -pages;
PRInt32 treeRows;
treeRowGroup->GetRowCount(treeRows);
lines = (absPages * treeRows) - 1;
if (pages < 0)
lines = -lines;
printf("nsTreeFrame::ScrollByPages : scrolling treeRowGroup by %d lines\n", lines);
treeRowGroup->ScrollByLines(aPresContext, lines);
return NS_OK;
}
NS_IMETHODIMP
nsTreeFrame::CollapseScrollbar(nsIPresContext* aPresContext, PRBool aHide)
{

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

@ -95,6 +95,7 @@ public:
// nsISelfScrollingFrame interface
NS_IMETHOD ScrollByLines(nsIPresContext* aPresContext, PRInt32 lines);
NS_IMETHOD CollapseScrollbar(nsIPresContext* aPresContext, PRBool aHide);
NS_IMETHOD ScrollByPages(nsIPresContext* aPresContext, PRInt32 pages);
// nsITreeFrame.h
NS_IMETHOD EnsureRowIsVisible(PRInt32 aRowIndex);

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

@ -203,6 +203,25 @@ nsTreeOuterFrame::FixBadReflowState(const nsHTMLReflowState& aParentReflowState,
return NS_OK;
}
nsITreeFrame*
nsTreeOuterFrame::FindTreeFrame()
{
nsITreeFrame* treeframe;
nsIFrame* child;
FirstChild(nsnull, &child);
while (child != nsnull) {
if (NS_OK == child->QueryInterface(NS_GET_IID(nsITreeFrame),
(void**)&treeframe)) {
return treeframe;
}
child->GetNextSibling(&child);
}
return nsnull;
}
NS_IMETHODIMP
nsTreeOuterFrame::ScrollByLines(nsIPresContext* aPresContext, PRInt32 lines)
{
@ -210,16 +229,35 @@ nsTreeOuterFrame::ScrollByLines(nsIPresContext* aPresContext, PRInt32 lines)
// In most cases the TreeFrame will be the only child, but just to make
// sure we'll check for the right interface
nsISelfScrollingFrame* sf;
nsIFrame* child;
FirstChild(NULL, &child);
nsITreeFrame* treeframe = FindTreeFrame();
nsISelfScrollingFrame* ssf;
while (child != nsnull) {
if (NS_OK == child->QueryInterface(NS_GET_IID(nsISelfScrollingFrame),
(void**)&sf)) {
return sf->ScrollByLines(aPresContext, lines);
if (treeframe) {
if (NS_OK == treeframe->QueryInterface(NS_GET_IID(nsISelfScrollingFrame),
(void**)&ssf)) {
return ssf->ScrollByLines(aPresContext, lines);
}
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsTreeOuterFrame::ScrollByPages(nsIPresContext* aPresContext, PRInt32 pages)
{
printf("nsTreeOuterFrame::ScrollByPages\n");
// What we need to do is call the corresponding method on our TreeFrame
// In most cases the TreeFrame will be the only child, but just to make
// sure we'll check for the right interface
nsITreeFrame* treeframe = FindTreeFrame();
nsISelfScrollingFrame* ssf;
if (treeframe) {
if (NS_OK == treeframe->QueryInterface(NS_GET_IID(nsISelfScrollingFrame),
(void**)&ssf)) {
return ssf->ScrollByPages(aPresContext, pages);
}
child->GetNextSibling(&child);
}
return NS_ERROR_FAILURE;
@ -232,16 +270,14 @@ nsTreeOuterFrame::CollapseScrollbar(nsIPresContext* aPresContext, PRBool aHide)
// In most cases the TreeFrame will be the only child, but just to make
// sure we'll check for the right interface
nsISelfScrollingFrame* sf;
nsIFrame* child;
FirstChild(NULL, &child);
nsITreeFrame* treeframe = FindTreeFrame();
nsISelfScrollingFrame* ssf;
while (child != nsnull) {
if (NS_OK == child->QueryInterface(NS_GET_IID(nsISelfScrollingFrame),
(void**)&sf)) {
return sf->CollapseScrollbar(aPresContext, aHide);
if (treeframe) {
if (NS_OK == treeframe->QueryInterface(NS_GET_IID(nsISelfScrollingFrame),
(void**)&ssf)) {
return ssf->CollapseScrollbar(aPresContext, aHide);
}
child->GetNextSibling(&child);
}
return NS_ERROR_FAILURE;

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

@ -23,6 +23,7 @@
#include "nsTableOuterFrame.h"
#include "nsIBox.h"
#include "nsISelfScrollingFrame.h"
#include "nsITreeFrame.h"
class nsTreeOuterFrame : public nsTableOuterFrame, nsIBox, nsISelfScrollingFrame
{
@ -54,11 +55,14 @@ public:
NS_IMETHOD ScrollByLines(nsIPresContext* aPresContext, PRInt32 lines);
NS_IMETHOD CollapseScrollbar(nsIPresContext* aPresContext, PRBool aHide);
NS_IMETHOD ScrollByPages(nsIPresContext* aPresContext, PRInt32 pages);
protected:
nsTreeOuterFrame();
virtual ~nsTreeOuterFrame();
nsITreeFrame* FindTreeFrame();
protected: // Data Members
}; // class nsTreeOuterFrame