зеркало из https://github.com/mozilla/pjs.git
Bug 737758: part 3: Cleanups and semantic consistency [r=roc]
This commit is contained in:
Родитель
3f69f2350f
Коммит
0ed781bc19
|
@ -1330,7 +1330,7 @@ public:
|
||||||
|
|
||||||
void InitSmoothScroll(TimeStamp aTime, nsPoint aCurrentPos,
|
void InitSmoothScroll(TimeStamp aTime, nsPoint aCurrentPos,
|
||||||
nsSize aCurrentVelocity, nsPoint aDestination,
|
nsSize aCurrentVelocity, nsPoint aDestination,
|
||||||
nsIAtom *aProfile);
|
nsIAtom *aOrigin);
|
||||||
|
|
||||||
bool IsFinished(TimeStamp aTime) {
|
bool IsFinished(TimeStamp aTime) {
|
||||||
return aTime > mStartTime + mDuration; // XXX or if we've hit the wall
|
return aTime > mStartTime + mDuration; // XXX or if we've hit the wall
|
||||||
|
@ -1348,17 +1348,15 @@ public:
|
||||||
bool mIsFirstIteration;
|
bool mIsFirstIteration;
|
||||||
|
|
||||||
// Cached Preferences values to avoid re-reading them when extending an existing
|
// Cached Preferences values to avoid re-reading them when extending an existing
|
||||||
// animation for the same profile (can be as frequent as every 10(!)ms for a quick
|
// animation for the same event origin (can be as frequent as every 10(!)ms for
|
||||||
// roll of the mouse wheel).
|
// a quick roll of the mouse wheel).
|
||||||
// These values are minimum and maximum animation duration per profile, is smoothness
|
// These values are minimum and maximum animation duration per event origin,
|
||||||
// enabled for that profile, and a global ratio which defines how longer is the
|
// and a global ratio which defines how longer is the animation's duration
|
||||||
// animation's duration compared to the average recent events intervals (such
|
// compared to the average recent events intervals (such that for a relatively
|
||||||
// that for a relatively consistent events rate, the next event arrives before
|
// consistent events rate, the next event arrives before current animation ends)
|
||||||
// current animation ends)
|
nsCOMPtr<nsIAtom> mOrigin;
|
||||||
nsIAtom* mProfile;
|
PRInt32 mOriginMinMS;
|
||||||
PRInt32 mProfileMinMS;
|
PRInt32 mOriginMaxMS;
|
||||||
PRInt32 mProfileMaxMS;
|
|
||||||
bool mIsProfileSmoothnessEnabled;
|
|
||||||
double mIntervalRatio;
|
double mIntervalRatio;
|
||||||
|
|
||||||
TimeDuration mDuration;
|
TimeDuration mDuration;
|
||||||
|
@ -1383,7 +1381,7 @@ protected:
|
||||||
nscoord aCurrentPos, nscoord aCurrentVelocity,
|
nscoord aCurrentPos, nscoord aCurrentVelocity,
|
||||||
nscoord aDestination);
|
nscoord aDestination);
|
||||||
|
|
||||||
void InitDuration(nsIAtom *aProfile);
|
void InitDuration(nsIAtom *aOrigin);
|
||||||
};
|
};
|
||||||
|
|
||||||
nsPoint
|
nsPoint
|
||||||
|
@ -1404,56 +1402,58 @@ nsGfxScrollFrameInner::AsyncScroll::VelocityAt(TimeStamp aTime) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calculate/update mDuration, possibly dynamically according to events rate and smoothness profile.
|
* Calculate/update mDuration, possibly dynamically according to events rate and event origin.
|
||||||
* (also maintain previous timestamps - which are only used here).
|
* (also maintain previous timestamps - which are only used here).
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
nsGfxScrollFrameInner::AsyncScroll::InitDuration(nsIAtom *aProfile) {
|
nsGfxScrollFrameInner::AsyncScroll::InitDuration(nsIAtom *aOrigin) {
|
||||||
// Read preferences only on first iteration or for a different profile.
|
if (!aOrigin){
|
||||||
if (mIsFirstIteration || aProfile != mProfile) {
|
aOrigin = nsGkAtoms::other;
|
||||||
mProfile = aProfile;
|
}
|
||||||
mProfileMinMS = mProfileMaxMS = 0;
|
|
||||||
mIsProfileSmoothnessEnabled = false;
|
// Read preferences only on first iteration or for a different event origin.
|
||||||
|
if (mIsFirstIteration || aOrigin != mOrigin) {
|
||||||
|
mOrigin = aOrigin;
|
||||||
|
mOriginMinMS = mOriginMaxMS = 0;
|
||||||
|
bool isOriginSmoothnessEnabled = false;
|
||||||
mIntervalRatio = 1;
|
mIntervalRatio = 1;
|
||||||
|
|
||||||
// Default values for all preferences are defined in all.js
|
// Default values for all preferences are defined in all.js
|
||||||
if (aProfile) {
|
static const PRInt32 kDefaultMinMS = 150, kDefaultMaxMS = 150;
|
||||||
static const PRInt32 kDefaultMinMS = 150, kDefaultMaxMS = 150;
|
static const bool kDefaultIsSmoothEnabled = true;
|
||||||
static const bool kDefaultIsSmoothEnabled = true;
|
|
||||||
|
|
||||||
nsCAutoString profileName;
|
nsCAutoString originName;
|
||||||
aProfile->ToUTF8String(profileName);
|
aOrigin->ToUTF8String(originName);
|
||||||
nsCAutoString prefBase = NS_LITERAL_CSTRING("general.smoothScroll.") + profileName;
|
nsCAutoString prefBase = NS_LITERAL_CSTRING("general.smoothScroll.") + originName;
|
||||||
|
|
||||||
mIsProfileSmoothnessEnabled = Preferences::GetBool(prefBase.get(), kDefaultIsSmoothEnabled);
|
isOriginSmoothnessEnabled = Preferences::GetBool(prefBase.get(), kDefaultIsSmoothEnabled);
|
||||||
if (mIsProfileSmoothnessEnabled) {
|
if (isOriginSmoothnessEnabled) {
|
||||||
nsCAutoString prefMin = prefBase + NS_LITERAL_CSTRING(".durationMinMS");
|
nsCAutoString prefMin = prefBase + NS_LITERAL_CSTRING(".durationMinMS");
|
||||||
nsCAutoString prefMax = prefBase + NS_LITERAL_CSTRING(".durationMaxMS");
|
nsCAutoString prefMax = prefBase + NS_LITERAL_CSTRING(".durationMaxMS");
|
||||||
mProfileMinMS = Preferences::GetInt(prefMin.get(), kDefaultMinMS);
|
mOriginMinMS = Preferences::GetInt(prefMin.get(), kDefaultMinMS);
|
||||||
mProfileMaxMS = Preferences::GetInt(prefMax.get(), kDefaultMaxMS);
|
mOriginMaxMS = Preferences::GetInt(prefMax.get(), kDefaultMaxMS);
|
||||||
|
|
||||||
static const PRInt32 kSmoothScrollMaxAllowedAnimationDurationMS = 10000;
|
static const PRInt32 kSmoothScrollMaxAllowedAnimationDurationMS = 10000;
|
||||||
mProfileMinMS = clamped(mProfileMinMS, 0, kSmoothScrollMaxAllowedAnimationDurationMS);
|
mOriginMaxMS = clamped(mOriginMaxMS, 0, kSmoothScrollMaxAllowedAnimationDurationMS);
|
||||||
mProfileMaxMS = clamped(mProfileMaxMS, mProfileMinMS, kSmoothScrollMaxAllowedAnimationDurationMS);
|
mOriginMinMS = clamped(mOriginMinMS, 0, mOriginMaxMS);
|
||||||
}
|
|
||||||
|
|
||||||
// Keep the animation duration longer than the average event intervals
|
|
||||||
// (to "connect" consecutive scroll animations before the scroll comes to a stop).
|
|
||||||
static const double kDefaultDurationToIntervalRatio = 2; // Duplicated at all.js
|
|
||||||
mIntervalRatio = Preferences::GetInt("general.smoothScroll.durationToIntervalRatio",
|
|
||||||
kDefaultDurationToIntervalRatio * 100) / 100.0;
|
|
||||||
|
|
||||||
// Duration should be at least as long as the intervals -> ratio is at least 1
|
|
||||||
mIntervalRatio = NS_MAX(1.0, mIntervalRatio);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Keep the animation duration longer than the average event intervals
|
||||||
|
// (to "connect" consecutive scroll animations before the scroll comes to a stop).
|
||||||
|
static const double kDefaultDurationToIntervalRatio = 2; // Duplicated at all.js
|
||||||
|
mIntervalRatio = Preferences::GetInt("general.smoothScroll.durationToIntervalRatio",
|
||||||
|
kDefaultDurationToIntervalRatio * 100) / 100.0;
|
||||||
|
|
||||||
|
// Duration should be at least as long as the intervals -> ratio is at least 1
|
||||||
|
mIntervalRatio = NS_MAX(1.0, mIntervalRatio);
|
||||||
|
|
||||||
if (mIsFirstIteration) {
|
if (mIsFirstIteration) {
|
||||||
// Starting a new scroll (i.e. not when extending an existing scroll animation),
|
// Starting a new scroll (i.e. not when extending an existing scroll animation),
|
||||||
// create imaginary prev timestamps with maximum relevant intervals between them.
|
// create imaginary prev timestamps with maximum relevant intervals between them.
|
||||||
mIsFirstIteration = false;
|
mIsFirstIteration = false;
|
||||||
|
|
||||||
// Longest relevant interval (which results in maximum duration)
|
// Longest relevant interval (which results in maximum duration)
|
||||||
TimeDuration maxDelta = TimeDuration::FromMilliseconds(mProfileMaxMS / mIntervalRatio);
|
TimeDuration maxDelta = TimeDuration::FromMilliseconds(mOriginMaxMS / mIntervalRatio);
|
||||||
mPrevStartTime[0] = mStartTime - maxDelta;
|
mPrevStartTime[0] = mStartTime - maxDelta;
|
||||||
mPrevStartTime[1] = mPrevStartTime[0] - maxDelta;
|
mPrevStartTime[1] = mPrevStartTime[0] - maxDelta;
|
||||||
mPrevStartTime[2] = mPrevStartTime[1] - maxDelta;
|
mPrevStartTime[2] = mPrevStartTime[1] - maxDelta;
|
||||||
|
@ -1471,7 +1471,7 @@ nsGfxScrollFrameInner::AsyncScroll::InitDuration(nsIAtom *aProfile) {
|
||||||
// it's easier to follow, but reduce the duration to make it feel more snappy when
|
// it's easier to follow, but reduce the duration to make it feel more snappy when
|
||||||
// scrolling quickly. To reduce fluctuations of the duration, we average event
|
// scrolling quickly. To reduce fluctuations of the duration, we average event
|
||||||
// intervals using the recent 4 timestamps (now + three prev -> 3 intervals).
|
// intervals using the recent 4 timestamps (now + three prev -> 3 intervals).
|
||||||
PRInt32 durationMS = clamped<PRInt32>(eventsDeltaMs * mIntervalRatio, mProfileMinMS, mProfileMaxMS);
|
PRInt32 durationMS = clamped<PRInt32>(eventsDeltaMs * mIntervalRatio, mOriginMinMS, mOriginMaxMS);
|
||||||
|
|
||||||
mDuration = TimeDuration::FromMilliseconds(durationMS);
|
mDuration = TimeDuration::FromMilliseconds(durationMS);
|
||||||
}
|
}
|
||||||
|
@ -1481,11 +1481,11 @@ nsGfxScrollFrameInner::AsyncScroll::InitSmoothScroll(TimeStamp aTime,
|
||||||
nsPoint aCurrentPos,
|
nsPoint aCurrentPos,
|
||||||
nsSize aCurrentVelocity,
|
nsSize aCurrentVelocity,
|
||||||
nsPoint aDestination,
|
nsPoint aDestination,
|
||||||
nsIAtom *aProfile) {
|
nsIAtom *aOrigin) {
|
||||||
mStartTime = aTime;
|
mStartTime = aTime;
|
||||||
mStartPos = aCurrentPos;
|
mStartPos = aCurrentPos;
|
||||||
mDestination = aDestination;
|
mDestination = aDestination;
|
||||||
InitDuration(aProfile);
|
InitDuration(aOrigin);
|
||||||
InitTimingFunction(mTimingFunctionX, mStartPos.x, aCurrentVelocity.width, aDestination.x);
|
InitTimingFunction(mTimingFunctionX, mStartPos.x, aCurrentVelocity.width, aDestination.x);
|
||||||
InitTimingFunction(mTimingFunctionY, mStartPos.y, aCurrentVelocity.height, aDestination.y);
|
InitTimingFunction(mTimingFunctionY, mStartPos.y, aCurrentVelocity.height, aDestination.y);
|
||||||
}
|
}
|
||||||
|
@ -1653,9 +1653,9 @@ nsGfxScrollFrameInner::AsyncScrollCallback(nsITimer *aTimer, void* anInstance)
|
||||||
* based on the setting of the smoothness scroll pref
|
* based on the setting of the smoothness scroll pref
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
nsGfxScrollFrameInner::ScrollToWithSmoothnessProfile(nsPoint aScrollPosition,
|
nsGfxScrollFrameInner::ScrollToWithOrigin(nsPoint aScrollPosition,
|
||||||
nsIScrollableFrame::ScrollMode aMode,
|
nsIScrollableFrame::ScrollMode aMode,
|
||||||
nsIAtom *aProfile)
|
nsIAtom *aOrigin)
|
||||||
{
|
{
|
||||||
if (ShouldClampScrollPosition()) {
|
if (ShouldClampScrollPosition()) {
|
||||||
mDestination = ClampScrollPosition(aScrollPosition);
|
mDestination = ClampScrollPosition(aScrollPosition);
|
||||||
|
@ -1707,7 +1707,7 @@ nsGfxScrollFrameInner::ScrollToWithSmoothnessProfile(nsPoint aScrollPosition,
|
||||||
|
|
||||||
if (isSmoothScroll) {
|
if (isSmoothScroll) {
|
||||||
mAsyncScroll->InitSmoothScroll(now, currentPosition, currentVelocity,
|
mAsyncScroll->InitSmoothScroll(now, currentPosition, currentVelocity,
|
||||||
mDestination, aProfile);
|
mDestination, aOrigin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2371,7 +2371,7 @@ nsGfxScrollFrameInner::ScrollBy(nsIntPoint aDelta,
|
||||||
|
|
||||||
nsPoint newPos = mDestination +
|
nsPoint newPos = mDestination +
|
||||||
nsPoint(aDelta.x*deltaMultiplier.width, aDelta.y*deltaMultiplier.height);
|
nsPoint(aDelta.x*deltaMultiplier.width, aDelta.y*deltaMultiplier.height);
|
||||||
ScrollToWithSmoothnessProfile(newPos, aMode, aOrigin);
|
ScrollToWithOrigin(newPos, aMode, aOrigin);
|
||||||
|
|
||||||
if (aOverflow) {
|
if (aOverflow) {
|
||||||
nsPoint clampAmount = mDestination - newPos;
|
nsPoint clampAmount = mDestination - newPos;
|
||||||
|
@ -2787,9 +2787,9 @@ void nsGfxScrollFrameInner::CurPosAttributeChanged(nsIContent* aContent)
|
||||||
// was.
|
// was.
|
||||||
UpdateScrollbarPosition();
|
UpdateScrollbarPosition();
|
||||||
}
|
}
|
||||||
ScrollToWithSmoothnessProfile(dest,
|
ScrollToWithOrigin(dest,
|
||||||
isSmooth ? nsIScrollableFrame::SMOOTH : nsIScrollableFrame::INSTANT,
|
isSmooth ? nsIScrollableFrame::SMOOTH : nsIScrollableFrame::INSTANT,
|
||||||
nsGkAtoms::scrollbars);
|
nsGkAtoms::scrollbars);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ============= Scroll events ========== */
|
/* ============= Scroll events ========== */
|
||||||
|
|
|
@ -181,7 +181,7 @@ public:
|
||||||
nsPoint ClampScrollPosition(const nsPoint& aPt) const;
|
nsPoint ClampScrollPosition(const nsPoint& aPt) const;
|
||||||
static void AsyncScrollCallback(nsITimer *aTimer, void* anInstance);
|
static void AsyncScrollCallback(nsITimer *aTimer, void* anInstance);
|
||||||
void ScrollTo(nsPoint aScrollPosition, nsIScrollableFrame::ScrollMode aMode) {
|
void ScrollTo(nsPoint aScrollPosition, nsIScrollableFrame::ScrollMode aMode) {
|
||||||
ScrollToWithSmoothnessProfile(aScrollPosition, aMode, nsGkAtoms::other);
|
ScrollToWithOrigin(aScrollPosition, aMode, nsGkAtoms::other);
|
||||||
};
|
};
|
||||||
void ScrollToImpl(nsPoint aScrollPosition);
|
void ScrollToImpl(nsPoint aScrollPosition);
|
||||||
void ScrollVisual(nsPoint aOldScrolledFramePosition);
|
void ScrollVisual(nsPoint aOldScrolledFramePosition);
|
||||||
|
@ -344,10 +344,9 @@ public:
|
||||||
bool mShouldBuildLayer:1;
|
bool mShouldBuildLayer:1;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void ScrollToWithSmoothnessProfile(nsPoint aScrollPosition,
|
void ScrollToWithOrigin(nsPoint aScrollPosition,
|
||||||
nsIScrollableFrame::ScrollMode aMode,
|
nsIScrollableFrame::ScrollMode aMode,
|
||||||
nsIAtom *aProfile); // nsnull indicates no smooth scroll
|
nsIAtom *aOrigin); // nsnull indicates "other" origin
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1356,7 +1356,7 @@ pref("mousewheel.horizscroll.withmetakey.sysnumlines",true);
|
||||||
|
|
||||||
// These define the smooth scroll behavior (min ms, max ms) for different triggers
|
// These define the smooth scroll behavior (min ms, max ms) for different triggers
|
||||||
// Some triggers:
|
// Some triggers:
|
||||||
// Pixels: Discrete mouse wheel events, Synaptics touchpads on windows (generate wheel events)
|
// mouseWheel: Discrete mouse wheel events, Synaptics touchpads on windows (generate wheel events)
|
||||||
// Lines: Up/Down/Left/Right KB arrows
|
// Lines: Up/Down/Left/Right KB arrows
|
||||||
// Pages: Page up/down, Space
|
// Pages: Page up/down, Space
|
||||||
// Scrollbars: Clicking scrollbars arrows, clicking scrollbars tracks
|
// Scrollbars: Clicking scrollbars arrows, clicking scrollbars tracks
|
||||||
|
@ -1374,6 +1374,7 @@ pref("general.smoothScroll.scrollbars.durationMinMS", 150);
|
||||||
pref("general.smoothScroll.scrollbars.durationMaxMS", 150);
|
pref("general.smoothScroll.scrollbars.durationMaxMS", 150);
|
||||||
pref("general.smoothScroll.other.durationMinMS", 150);
|
pref("general.smoothScroll.other.durationMinMS", 150);
|
||||||
pref("general.smoothScroll.other.durationMaxMS", 150);
|
pref("general.smoothScroll.other.durationMaxMS", 150);
|
||||||
|
// Enable disable smooth scrolling for different triggers (when "general.smoothScroll" is enabled)
|
||||||
pref("general.smoothScroll.mouseWheel", true);
|
pref("general.smoothScroll.mouseWheel", true);
|
||||||
pref("general.smoothScroll.pixels", true);
|
pref("general.smoothScroll.pixels", true);
|
||||||
pref("general.smoothScroll.lines", true);
|
pref("general.smoothScroll.lines", true);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче