NS_IMETHODIMP nsListBoxBodyFrame::PositionChanged(nsScrollbarFrame* aScrollbar, PRInt32 aOldIndex, PRInt32& aNewIndex) { if (mScrolling || mRowHeight == 0) return NS_OK; nscoord oldTwipIndex, newTwipIndex; oldTwipIndex = mCurrentIndex*mRowHeight; newTwipIndex = nsPresContext::CSSPixelsToAppUnits(aNewIndex); PRInt32 twipDelta = newTwipIndex > oldTwipIndex ? newTwipIndex - oldTwipIndex : oldTwipIndex - newTwipIndex; PRInt32 rowDelta = twipDelta / mRowHeight; PRInt32 remainder = twipDelta % mRowHeight; if (remainder > (mRowHeight/2)) rowDelta++; if (rowDelta == 0) return NS_OK; // update the position to be row based. PRInt32 newIndex = newTwipIndex > oldTwipIndex ? mCurrentIndex + rowDelta : mCurrentIndex - rowDelta; //aNewIndex = newIndex*mRowHeight/mOnePixel; nsListScrollSmoother* smoother = GetSmoother(); // if we can't scroll the rows in time then start a timer. We will eat // events until the user stops moving and the timer stops. if (smoother->IsRunning() || rowDelta*mTimePerRow > USER_TIME_THRESHOLD) { smoother->Stop(); smoother->mDelta = newTwipIndex > oldTwipIndex ? rowDelta : -rowDelta; smoother->Start(); return NS_OK; } smoother->Stop(); mCurrentIndex = newIndex; smoother->mDelta = 0; if (mCurrentIndex < 0) { mCurrentIndex = 0; return NS_OK; } return InternalPositionChanged(newTwipIndex < oldTwipIndex, rowDelta); }
NS_IMETHODIMP nsListBoxBodyFrame::VisibilityChanged(nsISupports* aScrollbar, PRBool aVisible) { PRInt32 lastPageTopRow = GetRowCount() - (GetAvailableHeight() / mRowHeight); if (lastPageTopRow < 0) lastPageTopRow = 0; PRInt32 delta = mCurrentIndex - lastPageTopRow; if (delta > 0) { mCurrentIndex = lastPageTopRow; InternalPositionChanged(PR_TRUE, delta); } return NS_OK; }
NS_IMETHODIMP nsListBoxBodyFrame::ScrollbarButtonPressed(nsScrollbarFrame* aScrollbar, PRInt32 aOldIndex, PRInt32 aNewIndex) { if (aOldIndex == aNewIndex) return NS_OK; if (aNewIndex < aOldIndex) mCurrentIndex--; else mCurrentIndex++; if (mCurrentIndex < 0) { mCurrentIndex = 0; return NS_OK; } InternalPositionChanged(aNewIndex < aOldIndex, 1); return NS_OK; }
NS_IMETHODIMP nsListBoxBodyFrame::VisibilityChanged(bool aVisible) { if (mRowHeight == 0) return NS_OK; PRInt32 lastPageTopRow = GetRowCount() - (GetAvailableHeight() / mRowHeight); if (lastPageTopRow < 0) lastPageTopRow = 0; PRInt32 delta = mCurrentIndex - lastPageTopRow; if (delta > 0) { mCurrentIndex = lastPageTopRow; InternalPositionChanged(true, delta); } return NS_OK; }