зеркало из https://github.com/mozilla/gecko-dev.git
Bug 383026. Centralize code that converts DOM scroll offsets to/from layout scroll positions. r=dbaron
--HG-- extra : rebase_source : eceb07d8d35e0dd5dd31d065cb04eec12d69a283
This commit is contained in:
Родитель
72c3ab6e67
Коммит
12edf877ff
|
@ -607,10 +607,7 @@ PRInt32
|
||||||
nsGenericElement::GetScrollTop()
|
nsGenericElement::GetScrollTop()
|
||||||
{
|
{
|
||||||
nsIScrollableFrame* sf = GetScrollFrame();
|
nsIScrollableFrame* sf = GetScrollFrame();
|
||||||
|
return sf ? sf->GetScrollPositionCSSPixels().y : 0;
|
||||||
return sf ?
|
|
||||||
nsPresContext::AppUnitsToIntCSSPixels(sf->GetScrollPosition().y) :
|
|
||||||
0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -626,9 +623,7 @@ nsGenericElement::SetScrollTop(PRInt32 aScrollTop)
|
||||||
{
|
{
|
||||||
nsIScrollableFrame* sf = GetScrollFrame();
|
nsIScrollableFrame* sf = GetScrollFrame();
|
||||||
if (sf) {
|
if (sf) {
|
||||||
nsPoint pt = sf->GetScrollPosition();
|
sf->ScrollToCSSPixels(nsIntPoint(sf->GetScrollPositionCSSPixels().x, aScrollTop));
|
||||||
sf->ScrollToCSSPixels(nsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(pt.x),
|
|
||||||
aScrollTop));
|
|
||||||
}
|
}
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -637,10 +632,7 @@ PRInt32
|
||||||
nsGenericElement::GetScrollLeft()
|
nsGenericElement::GetScrollLeft()
|
||||||
{
|
{
|
||||||
nsIScrollableFrame* sf = GetScrollFrame();
|
nsIScrollableFrame* sf = GetScrollFrame();
|
||||||
|
return sf ? sf->GetScrollPositionCSSPixels().x : 0;
|
||||||
return sf ?
|
|
||||||
nsPresContext::AppUnitsToIntCSSPixels(sf->GetScrollPosition().x) :
|
|
||||||
0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -656,9 +648,7 @@ nsGenericElement::SetScrollLeft(PRInt32 aScrollLeft)
|
||||||
{
|
{
|
||||||
nsIScrollableFrame* sf = GetScrollFrame();
|
nsIScrollableFrame* sf = GetScrollFrame();
|
||||||
if (sf) {
|
if (sf) {
|
||||||
nsPoint pt = sf->GetScrollPosition();
|
sf->ScrollToCSSPixels(nsIntPoint(aScrollLeft, sf->GetScrollPositionCSSPixels().y));
|
||||||
sf->ScrollToCSSPixels(nsIntPoint(aScrollLeft,
|
|
||||||
nsPresContext::AppUnitsToIntCSSPixels(pt.y)));
|
|
||||||
}
|
}
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4330,11 +4330,13 @@ nsGlobalWindow::GetScrollXY(PRInt32* aScrollX, PRInt32* aScrollY,
|
||||||
return GetScrollXY(aScrollX, aScrollY, true);
|
return GetScrollXY(aScrollX, aScrollY, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aScrollX)
|
nsIntPoint scrollPosCSSPixels = sf->GetScrollPositionCSSPixels();
|
||||||
*aScrollX = nsPresContext::AppUnitsToIntCSSPixels(scrollPos.x);
|
if (aScrollX) {
|
||||||
if (aScrollY)
|
*aScrollX = scrollPosCSSPixels.x;
|
||||||
*aScrollY = nsPresContext::AppUnitsToIntCSSPixels(scrollPos.y);
|
}
|
||||||
|
if (aScrollY) {
|
||||||
|
*aScrollY = scrollPosCSSPixels.y;
|
||||||
|
}
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1683,18 +1683,19 @@ void
|
||||||
nsGfxScrollFrameInner::ScrollToCSSPixels(nsIntPoint aScrollPosition)
|
nsGfxScrollFrameInner::ScrollToCSSPixels(nsIntPoint aScrollPosition)
|
||||||
{
|
{
|
||||||
nsPoint current = GetScrollPosition();
|
nsPoint current = GetScrollPosition();
|
||||||
|
nsIntPoint currentCSSPixels = GetScrollPositionCSSPixels();
|
||||||
nsPoint pt(nsPresContext::CSSPixelsToAppUnits(aScrollPosition.x),
|
nsPoint pt(nsPresContext::CSSPixelsToAppUnits(aScrollPosition.x),
|
||||||
nsPresContext::CSSPixelsToAppUnits(aScrollPosition.y));
|
nsPresContext::CSSPixelsToAppUnits(aScrollPosition.y));
|
||||||
nscoord halfPixel = nsPresContext::CSSPixelsToAppUnits(0.5f);
|
nscoord halfPixel = nsPresContext::CSSPixelsToAppUnits(0.5f);
|
||||||
nsRect range(pt.x - halfPixel, pt.y - halfPixel, 2*halfPixel - 1, 2*halfPixel - 1);
|
nsRect range(pt.x - halfPixel, pt.y - halfPixel, 2*halfPixel - 1, 2*halfPixel - 1);
|
||||||
if (nsPresContext::AppUnitsToIntCSSPixels(current.x) == aScrollPosition.x) {
|
if (currentCSSPixels.x == aScrollPosition.x) {
|
||||||
pt.x = current.x;
|
pt.x = current.x;
|
||||||
range.x = pt.x;
|
range.x = pt.x;
|
||||||
range.width = 0;
|
range.width = 0;
|
||||||
} else {
|
} else {
|
||||||
// current.x must be outside 'range', so we must move in the correct direction.
|
// current.x must be outside 'range', so we must move in the correct direction.
|
||||||
}
|
}
|
||||||
if (nsPresContext::AppUnitsToIntCSSPixels(current.y) == aScrollPosition.y) {
|
if (currentCSSPixels.y == aScrollPosition.y) {
|
||||||
pt.y = current.y;
|
pt.y = current.y;
|
||||||
range.y = pt.y;
|
range.y = pt.y;
|
||||||
range.height = 0;
|
range.height = 0;
|
||||||
|
@ -1704,6 +1705,14 @@ nsGfxScrollFrameInner::ScrollToCSSPixels(nsIntPoint aScrollPosition)
|
||||||
ScrollTo(pt, nsIScrollableFrame::INSTANT, &range);
|
ScrollTo(pt, nsIScrollableFrame::INSTANT, &range);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsIntPoint
|
||||||
|
nsGfxScrollFrameInner::GetScrollPositionCSSPixels()
|
||||||
|
{
|
||||||
|
nsPoint pt = GetScrollPosition();
|
||||||
|
return nsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(pt.x),
|
||||||
|
nsPresContext::AppUnitsToIntCSSPixels(pt.y));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* this method wraps calls to ScrollToImpl(), either in one shot or incrementally,
|
* this method wraps calls to ScrollToImpl(), either in one shot or incrementally,
|
||||||
* based on the setting of the smoothness scroll pref
|
* based on the setting of the smoothness scroll pref
|
||||||
|
|
|
@ -166,6 +166,7 @@ public:
|
||||||
ScrollToWithOrigin(aScrollPosition, aMode, nsGkAtoms::other, aRange);
|
ScrollToWithOrigin(aScrollPosition, aMode, nsGkAtoms::other, aRange);
|
||||||
}
|
}
|
||||||
void ScrollToCSSPixels(nsIntPoint aScrollPosition);
|
void ScrollToCSSPixels(nsIntPoint aScrollPosition);
|
||||||
|
nsIntPoint GetScrollPositionCSSPixels();
|
||||||
void ScrollToImpl(nsPoint aScrollPosition, const nsRect& aRange);
|
void ScrollToImpl(nsPoint aScrollPosition, const nsRect& aRange);
|
||||||
void ScrollVisual(nsPoint aOldScrolledFramePosition);
|
void ScrollVisual(nsPoint aOldScrolledFramePosition);
|
||||||
void ScrollBy(nsIntPoint aDelta, nsIScrollableFrame::ScrollUnit aUnit,
|
void ScrollBy(nsIntPoint aDelta, nsIScrollableFrame::ScrollUnit aUnit,
|
||||||
|
@ -480,6 +481,9 @@ public:
|
||||||
virtual void ScrollToCSSPixels(nsIntPoint aScrollPosition) {
|
virtual void ScrollToCSSPixels(nsIntPoint aScrollPosition) {
|
||||||
mInner.ScrollToCSSPixels(aScrollPosition);
|
mInner.ScrollToCSSPixels(aScrollPosition);
|
||||||
}
|
}
|
||||||
|
virtual nsIntPoint GetScrollPositionCSSPixels() {
|
||||||
|
return mInner.GetScrollPositionCSSPixels();
|
||||||
|
}
|
||||||
virtual void ScrollBy(nsIntPoint aDelta, ScrollUnit aUnit, ScrollMode aMode,
|
virtual void ScrollBy(nsIntPoint aDelta, ScrollUnit aUnit, ScrollMode aMode,
|
||||||
nsIntPoint* aOverflow, nsIAtom *aOrigin = nullptr) {
|
nsIntPoint* aOverflow, nsIAtom *aOrigin = nullptr) {
|
||||||
mInner.ScrollBy(aDelta, aUnit, aMode, aOverflow, aOrigin);
|
mInner.ScrollBy(aDelta, aUnit, aMode, aOverflow, aOrigin);
|
||||||
|
@ -725,6 +729,9 @@ public:
|
||||||
virtual void ScrollToCSSPixels(nsIntPoint aScrollPosition) {
|
virtual void ScrollToCSSPixels(nsIntPoint aScrollPosition) {
|
||||||
mInner.ScrollToCSSPixels(aScrollPosition);
|
mInner.ScrollToCSSPixels(aScrollPosition);
|
||||||
}
|
}
|
||||||
|
virtual nsIntPoint GetScrollPositionCSSPixels() {
|
||||||
|
return mInner.GetScrollPositionCSSPixels();
|
||||||
|
}
|
||||||
virtual void ScrollBy(nsIntPoint aDelta, ScrollUnit aUnit, ScrollMode aMode,
|
virtual void ScrollBy(nsIntPoint aDelta, ScrollUnit aUnit, ScrollMode aMode,
|
||||||
nsIntPoint* aOverflow, nsIAtom *aOrigin = nullptr) {
|
nsIntPoint* aOverflow, nsIAtom *aOrigin = nullptr) {
|
||||||
mInner.ScrollBy(aDelta, aUnit, aMode, aOverflow, aOrigin);
|
mInner.ScrollBy(aDelta, aUnit, aMode, aOverflow, aOrigin);
|
||||||
|
|
|
@ -138,6 +138,11 @@ public:
|
||||||
* The scroll mode is INSTANT.
|
* The scroll mode is INSTANT.
|
||||||
*/
|
*/
|
||||||
virtual void ScrollToCSSPixels(nsIntPoint aScrollPosition) = 0;
|
virtual void ScrollToCSSPixels(nsIntPoint aScrollPosition) = 0;
|
||||||
|
/**
|
||||||
|
* Returns the scroll position in integer CSS pixels, rounded to the nearest
|
||||||
|
* pixel.
|
||||||
|
*/
|
||||||
|
virtual nsIntPoint GetScrollPositionCSSPixels() = 0;
|
||||||
/**
|
/**
|
||||||
* When scrolling by a relative amount, we can choose various units.
|
* When scrolling by a relative amount, we can choose various units.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -263,9 +263,9 @@ NS_IMETHODIMP nsScrollBoxObject::GetPosition(PRInt32 *x, PRInt32 *y)
|
||||||
if (!sf)
|
if (!sf)
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
nsPoint pt = sf->GetScrollPosition();
|
nsIntPoint pt = sf->GetScrollPositionCSSPixels();
|
||||||
*x = nsPresContext::AppUnitsToIntCSSPixels(pt.x);
|
*x = pt.x;
|
||||||
*y = nsPresContext::AppUnitsToIntCSSPixels(pt.y);
|
*y = pt.y;
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче