Skip to content

Commit

Permalink
Backed out changeset ccde95bd3c7e (bug 1074165) for bustage
Browse files Browse the repository at this point in the history
  • Loading branch information
BavarianTomcat committed Oct 9, 2014
1 parent d4ee6e6 commit 02cf7c3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 50 deletions.
87 changes: 41 additions & 46 deletions layout/xul/nsListBoxBodyFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "nsListBoxLayout.h"

#include "nsAlgorithm.h"
#include "nsCOMPtr.h"
#include "nsGridRowGroupLayout.h"
#include "nsIServiceManager.h"
Expand Down Expand Up @@ -329,56 +328,39 @@ void
nsListBoxBodyFrame::ScrollByPage(nsScrollbarFrame* aScrollbar, int32_t aDirection)
{
MOZ_ASSERT(aScrollbar != nullptr);
UpdateIndex(aDirection);
aScrollbar->SetIncrementToPage(aDirection);
nsWeakFrame weakFrame(this);
int32_t newPos = aScrollbar->MoveToNewPosition();
if (!weakFrame.IsAlive()) {
return;
}
UpdateIndex(newPos);
aScrollbar->MoveToNewPosition();
}

void
nsListBoxBodyFrame::ScrollByWhole(nsScrollbarFrame* aScrollbar, int32_t aDirection)
{
MOZ_ASSERT(aScrollbar != nullptr);
MOZ_ASSERT(aScrollbar != nullptr);
UpdateIndex(aDirection);
aScrollbar->SetIncrementToWhole(aDirection);
nsWeakFrame weakFrame(this);
int32_t newPos = aScrollbar->MoveToNewPosition();
if (!weakFrame.IsAlive()) {
return;
}
UpdateIndex(newPos);
aScrollbar->MoveToNewPosition();
}

void
nsListBoxBodyFrame::ScrollByLine(nsScrollbarFrame* aScrollbar, int32_t aDirection)
{
MOZ_ASSERT(aScrollbar != nullptr);
MOZ_ASSERT(aScrollbar != nullptr);
UpdateIndex(aDirection);
aScrollbar->SetIncrementToLine(aDirection);
nsWeakFrame weakFrame(this);
int32_t newPos = aScrollbar->MoveToNewPosition();
if (!weakFrame.IsAlive()) {
return;
}
UpdateIndex(newPos);
aScrollbar->MoveToNewPosition();
}

void
nsListBoxBodyFrame::RepeatButtonScroll(nsScrollbarFrame* aScrollbar)
{
nsWeakFrame weakFrame(this);
int32_t newPos = aScrollbar->MoveToNewPosition();
if (!weakFrame.IsAlive()) {
return;
int32_t increment = aScrollbar->GetIncrement();
if (increment < 0) {
UpdateIndex(-1);
} else if (increment > 0) {
UpdateIndex(1);
}
UpdateIndex(newPos);
}

int32_t
nsListBoxBodyFrame::ToRowIndex(nscoord aPos) const
{
return NS_roundf(float(std::max(aPos, 0)) / mRowHeight);
aScrollbar->MoveToNewPosition();
}

void
Expand All @@ -389,21 +371,32 @@ nsListBoxBodyFrame::ThumbMoved(nsScrollbarFrame* aScrollbar,
if (mScrolling || mRowHeight == 0)
return;

int32_t newIndex = ToRowIndex(aNewPos);
if (newIndex == mCurrentIndex) {
nscoord oldTwipIndex;
oldTwipIndex = mCurrentIndex*mRowHeight;
int32_t twipDelta = aNewPos > oldTwipIndex ? aNewPos - oldTwipIndex : oldTwipIndex - aNewPos;

int32_t rowDelta = twipDelta / mRowHeight;
int32_t remainder = twipDelta % mRowHeight;
if (remainder > (mRowHeight/2))
rowDelta++;

if (rowDelta == 0)
return;
}
int32_t rowDelta = newIndex - mCurrentIndex;

// update the position to be row based.

int32_t newIndex = aNewPos > 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() || Abs(rowDelta)*mTimePerRow > USER_TIME_THRESHOLD) {
if (smoother->IsRunning() || rowDelta*mTimePerRow > USER_TIME_THRESHOLD) {

smoother->Stop();

smoother->mDelta = rowDelta;
smoother->mDelta = aNewPos > oldTwipIndex ? rowDelta : -rowDelta;

smoother->Start();

Expand All @@ -419,7 +412,7 @@ nsListBoxBodyFrame::ThumbMoved(nsScrollbarFrame* aScrollbar,
mCurrentIndex = 0;
return;
}
InternalPositionChanged(rowDelta < 0, Abs(rowDelta));
InternalPositionChanged(aNewPos < oldTwipIndex, rowDelta);
}

void
Expand All @@ -446,16 +439,18 @@ nsListBoxBodyFrame::GetScrollbarBox(bool aVertical)
}

void
nsListBoxBodyFrame::UpdateIndex(int32_t aNewPos)
nsListBoxBodyFrame::UpdateIndex(int32_t aDirection)
{
int32_t newIndex = ToRowIndex(nsPresContext::CSSPixelsToAppUnits(aNewPos));
if (newIndex == mCurrentIndex) {
if (aDirection == 0)
return;
if (aDirection < 0)
mCurrentIndex--;
else mCurrentIndex++;
if (mCurrentIndex < 0) {
mCurrentIndex = 0;
return;
}
bool up = newIndex < mCurrentIndex;
int32_t indexDelta = Abs(newIndex - mCurrentIndex);
mCurrentIndex = newIndex;
InternalPositionChanged(up, indexDelta);
InternalPositionChanged(aDirection < 0, 1);
}

///////////// nsIReflowCallback ///////////////
Expand Down
4 changes: 1 addition & 3 deletions layout/xul/nsListBoxBodyFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ class nsListBoxBodyFrame MOZ_FINAL : public nsBoxFrame,
nsresult DoInternalPositionChanged(bool aUp, int32_t aDelta);
nsListScrollSmoother* GetSmoother();
void VerticalScroll(int32_t aDelta);
// Update the scroll index given a position, in CSS pixels
void UpdateIndex(int32_t aNewPos);
void UpdateIndex(int32_t aDirection);

// frames
nsIFrame* GetFirstFrame();
Expand Down Expand Up @@ -167,7 +166,6 @@ class nsListBoxBodyFrame MOZ_FINAL : public nsBoxFrame,
};

void ComputeTotalRowCount();
int32_t ToRowIndex(nscoord aPos) const;
void RemoveChildFrame(nsBoxLayoutState &aState, nsIFrame *aChild);

nsTArray< nsRefPtr<nsPositionChangedEvent> > mPendingPositionChangeEvents;
Expand Down
1 change: 0 additions & 1 deletion layout/xul/nsScrollbarFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class nsScrollbarFrame : public nsBoxFrame
/**
* MoveToNewPosition() adds mIncrement to the current position and
* updates the curpos attribute.
* @returns The new position after clamping, in CSS Pixels
* @note This method might destroy the frame, pres shell, and other objects.
*/
int32_t MoveToNewPosition();
Expand Down

0 comments on commit 02cf7c3

Please sign in to comment.