scrollTo and getPosition methods of ScrollBoxObjects should use pixels

bug 52140, r+sr=bzbarsky, a=asa
This commit is contained in:
mvl%exedo.nl 2005-04-26 11:26:31 +00:00
Родитель e306350a3c
Коммит c9234cdfad
2 изменённых файлов: 42 добавлений и 6 удалений

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

@ -44,14 +44,32 @@ interface nsIDOMElement;
[scriptable, uuid(56E2ADA8-4631-11d4-BA11-001083023C1E)]
interface nsIScrollBoxObject : nsISupports
{
/**
* Scroll to the given coordinates, in css pixels.
* (0,0) will put the top left corner of the scrolled element's padding-box
* at the top left corner of the scrollport (which is its inner-border-box).
* Values will be clamped to legal values.
*/
void scrollTo(in long x, in long y);
/**
* Scroll the given amount of device pixels to the right and down.
* Values will be clamped to make the resuling position legal.
*/
void scrollBy(in long dx, in long dy);
void scrollByLine(in long dlines);
void scrollByIndex(in long dindexes);
void scrollToLine(in long line);
void scrollToElement(in nsIDOMElement child);
void scrollToIndex(in long index);
/**
* Get the current scroll position in css pixels.
* @see scrollTo for the definition of x and y.
*/
void getPosition(out long x, out long y);
void getScrolledSize(out long width, out long height);
void ensureElementIsVisible(in nsIDOMElement child);
void ensureIndexIsVisible(in long index);

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

@ -90,13 +90,22 @@ NS_IMETHODIMP nsScrollBoxObject::ScrollTo(PRInt32 x, PRInt32 y)
if (!scrollableView)
return NS_ERROR_FAILURE;
return scrollableView->ScrollTo(x,y, NS_SCROLL_PROPERTY_ALWAYS_BLIT);
float pixelsToTwips = mPresShell->GetPresContext()->PixelsToTwips();
return scrollableView->ScrollTo(NSToIntRound(x * pixelsToTwips),
NSToIntRound(y * pixelsToTwips),
NS_SCROLL_PROPERTY_ALWAYS_BLIT);
}
/* void scrollBy (in long dx, in long dy); */
NS_IMETHODIMP nsScrollBoxObject::ScrollBy(PRInt32 dx, PRInt32 dy)
{
return NS_ERROR_NOT_IMPLEMENTED;
PRInt32 x, y;
nsresult rv = GetPosition(&x, &y);
if (NS_FAILED(rv))
return rv;
return ScrollTo(x + dx, y + dy);
}
/* void scrollByLine (in long dlines); */
@ -231,8 +240,7 @@ NS_IMETHODIMP nsScrollBoxObject::ScrollToElement(nsIDOMElement *child)
return NS_ERROR_FAILURE;
// prepare for twips
float pixelsToTwips = 0.0;
pixelsToTwips = mPresShell->GetPresContext()->PixelsToTwips();
float pixelsToTwips = mPresShell->GetPresContext()->PixelsToTwips();
nsIFrame* scrolledBox = GetScrolledBox(this);
if (!scrolledBox)
@ -294,7 +302,17 @@ NS_IMETHODIMP nsScrollBoxObject::GetPosition(PRInt32 *x, PRInt32 *y)
if (!scrollableView)
return NS_ERROR_FAILURE;
return scrollableView->GetScrollPosition(*x,*y);
nscoord xc, yc;
nsresult rv = scrollableView->GetScrollPosition(xc, yc);
if (NS_FAILED(rv))
return rv;
float twipsToPixels = mPresShell->GetPresContext()->TwipsToPixels();
*x = NSToIntRound(xc * twipsToPixels);
*y = NSToIntRound(yc * twipsToPixels);
return NS_OK;
}
/* void getScrolledSize (out long width, out long height); */