diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index a421bd5299f..6fb752bb87d 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -607,10 +607,7 @@ PRInt32 nsGenericElement::GetScrollTop() { nsIScrollableFrame* sf = GetScrollFrame(); - - return sf ? - nsPresContext::AppUnitsToIntCSSPixels(sf->GetScrollPosition().y) : - 0; + return sf ? sf->GetScrollPositionCSSPixels().y : 0; } NS_IMETHODIMP @@ -626,9 +623,7 @@ nsGenericElement::SetScrollTop(PRInt32 aScrollTop) { nsIScrollableFrame* sf = GetScrollFrame(); if (sf) { - nsPoint pt = sf->GetScrollPosition(); - sf->ScrollToCSSPixels(nsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(pt.x), - aScrollTop)); + sf->ScrollToCSSPixels(nsIntPoint(sf->GetScrollPositionCSSPixels().x, aScrollTop)); } return NS_OK; } @@ -637,10 +632,7 @@ PRInt32 nsGenericElement::GetScrollLeft() { nsIScrollableFrame* sf = GetScrollFrame(); - - return sf ? - nsPresContext::AppUnitsToIntCSSPixels(sf->GetScrollPosition().x) : - 0; + return sf ? sf->GetScrollPositionCSSPixels().x : 0; } NS_IMETHODIMP @@ -656,9 +648,7 @@ nsGenericElement::SetScrollLeft(PRInt32 aScrollLeft) { nsIScrollableFrame* sf = GetScrollFrame(); if (sf) { - nsPoint pt = sf->GetScrollPosition(); - sf->ScrollToCSSPixels(nsIntPoint(aScrollLeft, - nsPresContext::AppUnitsToIntCSSPixels(pt.y))); + sf->ScrollToCSSPixels(nsIntPoint(aScrollLeft, sf->GetScrollPositionCSSPixels().y)); } return NS_OK; } diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index a88830f850d..6abdd59ffed 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -4322,11 +4322,13 @@ nsGlobalWindow::GetScrollXY(PRInt32* aScrollX, PRInt32* aScrollY, return GetScrollXY(aScrollX, aScrollY, true); } - if (aScrollX) - *aScrollX = nsPresContext::AppUnitsToIntCSSPixels(scrollPos.x); - if (aScrollY) - *aScrollY = nsPresContext::AppUnitsToIntCSSPixels(scrollPos.y); - + nsIntPoint scrollPosCSSPixels = sf->GetScrollPositionCSSPixels(); + if (aScrollX) { + *aScrollX = scrollPosCSSPixels.x; + } + if (aScrollY) { + *aScrollY = scrollPosCSSPixels.y; + } return NS_OK; } diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index fa4b7e148d1..b18e1b11316 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -1683,18 +1683,19 @@ void nsGfxScrollFrameInner::ScrollToCSSPixels(nsIntPoint aScrollPosition) { nsPoint current = GetScrollPosition(); + nsIntPoint currentCSSPixels = GetScrollPositionCSSPixels(); nsPoint pt(nsPresContext::CSSPixelsToAppUnits(aScrollPosition.x), nsPresContext::CSSPixelsToAppUnits(aScrollPosition.y)); nscoord halfPixel = nsPresContext::CSSPixelsToAppUnits(0.5f); 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; range.x = pt.x; range.width = 0; } else { // 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; range.y = pt.y; range.height = 0; @@ -1704,6 +1705,14 @@ nsGfxScrollFrameInner::ScrollToCSSPixels(nsIntPoint aScrollPosition) 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, * based on the setting of the smoothness scroll pref diff --git a/layout/generic/nsGfxScrollFrame.h b/layout/generic/nsGfxScrollFrame.h index 8552c90a476..3c0ff345d1e 100644 --- a/layout/generic/nsGfxScrollFrame.h +++ b/layout/generic/nsGfxScrollFrame.h @@ -166,6 +166,7 @@ public: ScrollToWithOrigin(aScrollPosition, aMode, nsGkAtoms::other, aRange); } void ScrollToCSSPixels(nsIntPoint aScrollPosition); + nsIntPoint GetScrollPositionCSSPixels(); void ScrollToImpl(nsPoint aScrollPosition, const nsRect& aRange); void ScrollVisual(nsPoint aOldScrolledFramePosition); void ScrollBy(nsIntPoint aDelta, nsIScrollableFrame::ScrollUnit aUnit, @@ -480,6 +481,9 @@ public: virtual void ScrollToCSSPixels(nsIntPoint aScrollPosition) { mInner.ScrollToCSSPixels(aScrollPosition); } + virtual nsIntPoint GetScrollPositionCSSPixels() { + return mInner.GetScrollPositionCSSPixels(); + } virtual void ScrollBy(nsIntPoint aDelta, ScrollUnit aUnit, ScrollMode aMode, nsIntPoint* aOverflow, nsIAtom *aOrigin = nullptr) { mInner.ScrollBy(aDelta, aUnit, aMode, aOverflow, aOrigin); @@ -725,6 +729,9 @@ public: virtual void ScrollToCSSPixels(nsIntPoint aScrollPosition) { mInner.ScrollToCSSPixels(aScrollPosition); } + virtual nsIntPoint GetScrollPositionCSSPixels() { + return mInner.GetScrollPositionCSSPixels(); + } virtual void ScrollBy(nsIntPoint aDelta, ScrollUnit aUnit, ScrollMode aMode, nsIntPoint* aOverflow, nsIAtom *aOrigin = nullptr) { mInner.ScrollBy(aDelta, aUnit, aMode, aOverflow, aOrigin); diff --git a/layout/generic/nsIScrollableFrame.h b/layout/generic/nsIScrollableFrame.h index 51a564ca8b8..5fd73a52f5d 100644 --- a/layout/generic/nsIScrollableFrame.h +++ b/layout/generic/nsIScrollableFrame.h @@ -138,6 +138,11 @@ public: * The scroll mode is INSTANT. */ 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. */ diff --git a/layout/xul/base/src/nsScrollBoxObject.cpp b/layout/xul/base/src/nsScrollBoxObject.cpp index ad503afbee2..620b0ab26ab 100644 --- a/layout/xul/base/src/nsScrollBoxObject.cpp +++ b/layout/xul/base/src/nsScrollBoxObject.cpp @@ -263,9 +263,9 @@ NS_IMETHODIMP nsScrollBoxObject::GetPosition(PRInt32 *x, PRInt32 *y) if (!sf) return NS_ERROR_FAILURE; - nsPoint pt = sf->GetScrollPosition(); - *x = nsPresContext::AppUnitsToIntCSSPixels(pt.x); - *y = nsPresContext::AppUnitsToIntCSSPixels(pt.y); + nsIntPoint pt = sf->GetScrollPositionCSSPixels(); + *x = pt.x; + *y = pt.y; return NS_OK; }