Bug 1066459 - Clamp the new top row index to the valid range before assigning it to mTopRowIndex when scrolling. r=kip
--- a/layout/xul/tree/nsTreeBodyFrame.cpp
+++ b/layout/xul/tree/nsTreeBodyFrame.cpp
@@ -6,16 +6,17 @@
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/ContentEvents.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/Likely.h"
+#include "nsAlgorithm.h"
#include "nsCOMPtr.h"
#include "nsPresContext.h"
#include "nsNameSpaceManager.h"
#include "nsTreeBodyFrame.h"
#include "nsTreeSelection.h"
#include "nsTreeImageListener.h"
@@ -4041,88 +4042,65 @@ nsTreeBodyFrame::ScrollToHorizontalPosit
UpdateScrollbars(parts);
return rv;
}
nsresult
nsTreeBodyFrame::ScrollToRow(int32_t aRow)
{
ScrollParts parts = GetScrollParts();
- nsresult rv = ScrollToRowInternal(parts, aRow);
- NS_ENSURE_SUCCESS(rv, rv);
+ ScrollToRowInternal(parts, aRow);
UpdateScrollbars(parts);
- return rv;
+ return NS_OK;
}
nsresult nsTreeBodyFrame::ScrollToRowInternal(const ScrollParts& aParts, int32_t aRow)
{
ScrollInternal(aParts, aRow);
return NS_OK;
}
nsresult
nsTreeBodyFrame::ScrollByLines(int32_t aNumLines)
{
- if (!mView)
+ if (!mView) {
return NS_OK;
-
+ }
int32_t newIndex = mTopRowIndex + aNumLines;
- if (newIndex < 0)
- newIndex = 0;
- else {
- int32_t lastPageTopRow = mRowCount - mPageLength;
- if (newIndex > lastPageTopRow)
- newIndex = lastPageTopRow;
- }
ScrollToRow(newIndex);
-
return NS_OK;
}
nsresult
nsTreeBodyFrame::ScrollByPages(int32_t aNumPages)
{
- if (!mView)
+ if (!mView) {
return NS_OK;
-
+ }
int32_t newIndex = mTopRowIndex + aNumPages * mPageLength;
- if (newIndex < 0)
- newIndex = 0;
- else {
- int32_t lastPageTopRow = mRowCount - mPageLength;
- if (newIndex > lastPageTopRow)
- newIndex = lastPageTopRow;
- }
ScrollToRow(newIndex);
-
return NS_OK;
}
nsresult
nsTreeBodyFrame::ScrollInternal(const ScrollParts& aParts, int32_t aRow)
{
- if (!mView)
+ if (!mView) {
return NS_OK;
-
- int32_t delta = aRow - mTopRowIndex;
-
- if (delta > 0) {
- if (mTopRowIndex == (mRowCount - mPageLength + 1))
- return NS_OK;
}
- else {
- if (mTopRowIndex == 0)
- return NS_OK;
+ int32_t maxTopRowIndex = std::max(0, mRowCount - mPageLength);
+ MOZ_ASSERT(mTopRowIndex == mozilla::clamped(mTopRowIndex, 0, maxTopRowIndex));
+
+ aRow = mozilla::clamped(aRow, 0, maxTopRowIndex);
+ if (aRow == mTopRowIndex) {
+ return NS_OK;
}
-
- mTopRowIndex += delta;
-
+ mTopRowIndex = aRow;
Invalidate();
-
PostScrollEvent();
return NS_OK;
}
nsresult
nsTreeBodyFrame::ScrollHorzInternal(const ScrollParts& aParts, int32_t aPosition)
{
if (!mView || !aParts.mColumnsScrollFrame || !aParts.mHScrollbar)