Make page up and page down leave at most two lines in common between pages. b=175380 r+sr=roc

This commit is contained in:
dbaron%dbaron.org 2004-11-24 22:05:36 +00:00
parent be14f80cef
commit 4b47c345dd
5 changed files with 39 additions and 27 deletions

View File

@ -2867,9 +2867,6 @@ nsSelection::CommonPageMove(PRBool aForward,
if (!mainframe)
return NS_ERROR_FAILURE;
// find out where we are; determine amount to page up/down
nsRect viewRect = aScrollableView->View()->GetBounds();
// find out where the caret is.
// we should know mDesiredX value of nsSelection, but I havent seen that behavior in other windows applications yet.
nsCOMPtr<nsISelection> domSel;
@ -2893,12 +2890,13 @@ nsSelection::CommonPageMove(PRBool aForward,
return result;
//need to adjust caret jump by percentage scroll
viewRect.height = (PRInt32) (viewRect.height * PAGE_SCROLL_PERCENT);
nsSize scrollDelta;
aScrollableView->GetPageScrollDistances(&scrollDelta);
if (aForward)
caretPos.y += viewRect.height;
caretPos.y += scrollDelta.height;
else
caretPos.y -= viewRect.height;
caretPos.y -= scrollDelta.height;
if (caretView)

View File

@ -2867,9 +2867,6 @@ nsSelection::CommonPageMove(PRBool aForward,
if (!mainframe)
return NS_ERROR_FAILURE;
// find out where we are; determine amount to page up/down
nsRect viewRect = aScrollableView->View()->GetBounds();
// find out where the caret is.
// we should know mDesiredX value of nsSelection, but I havent seen that behavior in other windows applications yet.
nsCOMPtr<nsISelection> domSel;
@ -2893,12 +2890,13 @@ nsSelection::CommonPageMove(PRBool aForward,
return result;
//need to adjust caret jump by percentage scroll
viewRect.height = (PRInt32) (viewRect.height * PAGE_SCROLL_PERCENT);
nsSize scrollDelta;
aScrollableView->GetPageScrollDistances(&scrollDelta);
if (aForward)
caretPos.y += viewRect.height;
caretPos.y += scrollDelta.height;
else
caretPos.y -= viewRect.height;
caretPos.y -= scrollDelta.height;
if (caretView)

View File

@ -45,14 +45,12 @@
class nsIView;
class nsIScrollPositionListener;
struct nsMargin;
// the percentage of the page that is scrolled on a page up or down
#define PAGE_SCROLL_PERCENT 0.9
struct nsSize;
// IID for the nsIScrollableView interface
#define NS_ISCROLLABLEVIEW_IID \
{ 0x3b88347a, 0x7a86, 0x4eff, \
{ 0xa8, 0x37, 0xd9, 0xd1, 0x08, 0x8e, 0xc9, 0xa8 } }
{ 0x1a8c8cfa, 0x86aa, 0x4421, \
{ 0xa1, 0x86, 0xae, 0x51, 0x79, 0x03, 0xe9, 0x06 } }
/**
* A scrolling view allows an arbitrary view that you supply to be scrolled
@ -170,6 +168,13 @@ public:
*/
NS_IMETHOD ScrollByLines(PRInt32 aNumLinesX, PRInt32 aNumLinexY) = 0;
/**
* Get the desired size of a page scroll in each dimension.
* ScrollByPages will scroll by independent multiples of these amounts
* unless it hits the edge of the view.
*/
NS_IMETHOD GetPageScrollDistances(nsSize *aDistances) = 0;
/**
* Scroll the view left or right by aNumPagesX pages. Positive values move right.
* Scroll the view up or down by aNumPagesY pages. Positive values move down.

View File

@ -431,20 +431,30 @@ NS_IMETHODIMP nsScrollPortView::ScrollByLines(PRInt32 aNumLinesX, PRInt32 aNumLi
return ScrollTo(mOffsetX + dx, mOffsetY + dy, NS_VMREFRESH_SMOOTHSCROLL);
}
NS_IMETHODIMP nsScrollPortView::ScrollByPages(PRInt32 aNumPagesX, PRInt32 aNumPagesY)
NS_IMETHODIMP nsScrollPortView::GetPageScrollDistances(nsSize *aDistances)
{
nsSize size;
GetDimensions(size);
// The page increment is the size of the page, minus the smaller of
// 10% of the size or 2 lines.
aDistances->width = size.width - PR_MIN(size.width / 10, 2 * mLineHeight);
aDistances->height = size.height - PR_MIN(size.height / 10, 2 * mLineHeight);
return NS_OK;
}
NS_IMETHODIMP nsScrollPortView::ScrollByPages(PRInt32 aNumPagesX, PRInt32 aNumPagesY)
{
nsSize delta;
GetPageScrollDistances(&delta);
// scroll % of the window
nscoord dx = nscoord(float(size.width)*PAGE_SCROLL_PERCENT);
nscoord dy = nscoord(float(size.height)*PAGE_SCROLL_PERCENT);
// put in the number of pages.
dx *= aNumPagesX;
dy *= aNumPagesY;
delta.width *= aNumPagesX;
delta.height *= aNumPagesY;
return ScrollTo(mOffsetX + dx, mOffsetY + dy, NS_VMREFRESH_SMOOTHSCROLL);
return ScrollTo(mOffsetX + delta.width, mOffsetY + delta.height,
NS_VMREFRESH_SMOOTHSCROLL);
}
NS_IMETHODIMP nsScrollPortView::ScrollByWhole(PRBool aTop)

View File

@ -77,6 +77,7 @@ public:
NS_IMETHOD SetLineHeight(nscoord aHeight);
NS_IMETHOD GetLineHeight(nscoord *aHeight);
NS_IMETHOD ScrollByLines(PRInt32 aNumLinesX, PRInt32 aNumLinesY);
NS_IMETHOD GetPageScrollDistances(nsSize *aDistances);
NS_IMETHOD ScrollByPages(PRInt32 aNumPagesX, PRInt32 aNumPagesY);
NS_IMETHOD ScrollByWhole(PRBool aTop);