diff --git a/gfx/layers/apz/src/AsyncPanZoomController.cpp b/gfx/layers/apz/src/AsyncPanZoomController.cpp index bd4cda7814dd..306abf20eb6c 100644 --- a/gfx/layers/apz/src/AsyncPanZoomController.cpp +++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp @@ -917,16 +917,8 @@ nsEventStatus AsyncPanZoomController::HandleDragEvent(const MouseInput& aEvent, (uint32_t) ScrollInputMethod::ApzScrollbarDrag); ReentrantMonitorAutoEnter lock(mMonitor); - CSSPoint scrollFramePoint = aEvent.mLocalOrigin / GetFrameMetrics().GetZoom(); - // The scrollbar can be transformed with the frame but the pres shell - // resolution is only applied to the scroll frame. - CSSPoint scrollbarPoint = scrollFramePoint * mFrameMetrics.GetPresShellResolution(); - CSSRect cssCompositionBound = mFrameMetrics.CalculateCompositedRectInCssPixels(); - - CSSCoord mousePosition = GetAxisStart(aDragMetrics.mDirection, scrollbarPoint) - - aDragMetrics.mScrollbarDragOffset - - GetAxisStart(aDragMetrics.mDirection, cssCompositionBound) - - thumbData.mScrollTrackStart; + CSSCoord mousePosition = ConvertScrollbarPoint(aEvent.mLocalOrigin, thumbData) - + aDragMetrics.mScrollbarDragOffset; CSSCoord scrollMax = thumbData.mScrollTrackLength; scrollMax -= thumbData.mThumbLength; @@ -937,7 +929,7 @@ nsEventStatus AsyncPanZoomController::HandleDragEvent(const MouseInput& aEvent, GetAxisStart(aDragMetrics.mDirection, mFrameMetrics.GetScrollableRect().TopLeft()); CSSCoord maxScrollPosition = GetAxisLength(aDragMetrics.mDirection, mFrameMetrics.GetScrollableRect()) - - GetAxisLength(aDragMetrics.mDirection, cssCompositionBound); + GetAxisLength(aDragMetrics.mDirection, mFrameMetrics.CalculateCompositedRectInCssPixels()); CSSCoord scrollPosition = scrollPercent * maxScrollPosition; scrollPosition = std::max(scrollPosition, minScrollPosition); @@ -1575,6 +1567,25 @@ AsyncPanZoomController::ConvertToGecko(const ScreenIntPoint& aPoint, LayoutDevic return false; } +CSSCoord +AsyncPanZoomController::ConvertScrollbarPoint(const ParentLayerPoint& aScrollbarPoint, + const ScrollThumbData& aThumbData) const +{ + ReentrantMonitorAutoEnter lock(mMonitor); + + // First, get it into the right coordinate space. + CSSPoint scrollbarPoint = aScrollbarPoint / mFrameMetrics.GetZoom(); + // The scrollbar can be transformed with the frame but the pres shell + // resolution is only applied to the scroll frame. + scrollbarPoint = scrollbarPoint * mFrameMetrics.GetPresShellResolution(); + + // Now, get it to be relative to the beginning of the scroll track. + CSSRect cssCompositionBound = mFrameMetrics.CalculateCompositedRectInCssPixels(); + return GetAxisStart(aThumbData.mDirection, scrollbarPoint) + - GetAxisStart(aThumbData.mDirection, cssCompositionBound) + - aThumbData.mScrollTrackStart; +} + static bool AllowsScrollingMoreThanOnePage(double aMultiplier) { diff --git a/gfx/layers/apz/src/AsyncPanZoomController.h b/gfx/layers/apz/src/AsyncPanZoomController.h index 1972510a1213..1cfeccdb8c09 100644 --- a/gfx/layers/apz/src/AsyncPanZoomController.h +++ b/gfx/layers/apz/src/AsyncPanZoomController.h @@ -403,6 +403,14 @@ public: // in the given direction. bool CanScroll(ScrollDirection aDirection) const; + /** + * Convert a point on the scrollbar from this APZC's ParentLayer coordinates + * to CSS coordinates relative to the beginning of the scroll track. + * Only the component in the direction of scrolling is returned. + */ + CSSCoord ConvertScrollbarPoint(const ParentLayerPoint& aScrollbarPoint, + const ScrollThumbData& aThumbData) const; + void NotifyMozMouseScrollEvent(const nsString& aString) const; protected: