Bug 804486 - Add toolkit.scrollbox.horizontalScrollDistance pref, default 5. Change horizontal scroll increment from 10px to horizontalScrollDistance * GetLineScrollAmount().width(). Make GetLineScrollAmount() use the font's AveCharWidth() for the horizontal amount rather than MaxHeight(). r=roc

This commit is contained in:
Mats Palmgren 2012-10-29 06:44:31 +01:00
parent 8fe699d05c
commit cbfa147ac8
5 changed files with 23 additions and 16 deletions

View File

@ -2820,8 +2820,7 @@ nsEventStateManager::GetScrollAmount(nsPresContext* aPresContext,
nsLayoutUtils::GetFontMetricsForFrame(rootFrame, getter_AddRefs(fm),
nsLayoutUtils::FontSizeInflationFor(rootFrame));
NS_ENSURE_TRUE(fm, nsSize(0, 0));
int32_t fontHeight = fm->MaxHeight();
return nsSize(fontHeight, fontHeight);
return nsSize(fm->AveCharWidth(), fm->MaxHeight());
}
void

View File

@ -2215,7 +2215,9 @@ PresShell::ScrollCharacter(bool aRight)
nsIScrollableFrame* scrollFrame =
GetFrameToScrollAsScrollable(nsIPresShell::eHorizontal);
if (scrollFrame) {
scrollFrame->ScrollBy(nsIntPoint(aRight ? 1 : -1, 0),
int32_t h = Preferences::GetInt("toolkit.scrollbox.horizontalScrollDistance",
NS_DEFAULT_HORIZONTAL_SCROLL_DISTANCE);
scrollFrame->ScrollBy(nsIntPoint(aRight ? h : -h, 0),
nsIScrollableFrame::LINES,
nsIScrollableFrame::SMOOTH);
}

View File

@ -2385,13 +2385,12 @@ nsGfxScrollFrameInner::GetLineScrollAmount() const
"mousewheel.min_line_scroll_amount", 1);
}
uint32_t appUnitsPerDevPixel = mOuter->PresContext()->AppUnitsPerDevPixel();
nscoord fontHeight =
nscoord minScrollAmountInAppUnits =
NS_MAX(1, sMinLineScrollAmountInPixels) * appUnitsPerDevPixel;
if (fm) {
fontHeight = NS_MAX(fm->MaxHeight(), fontHeight);
}
return nsSize(fontHeight, fontHeight);
nscoord horizontalAmount = fm ? fm->AveCharWidth() : 0;
nscoord verticalAmount = fm ? fm->MaxHeight() : 0;
return nsSize(NS_MAX(horizontalAmount, minScrollAmountInAppUnits),
NS_MAX(verticalAmount, minScrollAmountInAppUnits));
}
/**
@ -3422,17 +3421,19 @@ nsGfxScrollFrameInner::ReflowFinished()
if (vScroll || hScroll) {
nsWeakFrame weakFrame(mOuter);
nsPoint scrollPos = GetScrollPosition();
// XXX shouldn't we use GetPageScrollAmount/GetLineScrollAmount here?
nsSize lineScrollAmount = GetLineScrollAmount();
if (vScroll) {
const double kScrollMultiplier = Preferences::GetInt("toolkit.scrollbox.verticalScrollDistance",
NS_DEFAULT_VERTICAL_SCROLL_DISTANCE);
nscoord fontHeight = GetLineScrollAmount().height * kScrollMultiplier;
const double kScrollMultiplier =
Preferences::GetInt("toolkit.scrollbox.verticalScrollDistance",
NS_DEFAULT_VERTICAL_SCROLL_DISTANCE);
nscoord fontHeight = lineScrollAmount.height * kScrollMultiplier;
// We normally use (scrollArea.height - fontHeight) for height
// of page scrolling. However, it is too small when
// fontHeight is very large. (If fontHeight is larger than
// scrollArea.height, direction of scrolling will be opposite).
// To avoid it, we use (float(scrollArea.height) * 0.8) as
// lower bound value of height of page scrolling. (bug 383267)
// XXX shouldn't we use GetPageScrollAmount here?
nscoord pageincrement = nscoord(mScrollPort.height - fontHeight);
nscoord pageincrementMin = nscoord(float(mScrollPort.height) * 0.8);
FinishReflowForScrollbar(vScroll, minY, maxY, scrollPos.y,
@ -3440,9 +3441,13 @@ nsGfxScrollFrameInner::ReflowFinished()
fontHeight);
}
if (hScroll) {
const double kScrollMultiplier =
Preferences::GetInt("toolkit.scrollbox.horizontalScrollDistance",
NS_DEFAULT_HORIZONTAL_SCROLL_DISTANCE);
nscoord increment = lineScrollAmount.width * kScrollMultiplier;
FinishReflowForScrollbar(hScroll, minX, maxX, scrollPos.x,
nscoord(float(mScrollPort.width) * 0.8),
nsPresContext::CSSPixelsToAppUnits(10));
increment);
}
NS_ENSURE_TRUE(weakFrame.IsAlive(), false);
}

View File

@ -14,7 +14,8 @@
#include "nsCoord.h"
#include "nsPresContext.h"
#define NS_DEFAULT_VERTICAL_SCROLL_DISTANCE 3
#define NS_DEFAULT_VERTICAL_SCROLL_DISTANCE 3
#define NS_DEFAULT_HORIZONTAL_SCROLL_DISTANCE 5
class nsBoxLayoutState;
class nsIScrollPositionListener;

View File

@ -342,8 +342,8 @@ pref("toolkit.autocomplete.richBoundaryCutoff", 200);
pref("toolkit.scrollbox.smoothScroll", true);
pref("toolkit.scrollbox.scrollIncrement", 20);
// Make sure to update NS_DEFAULT_VERTICAL_SCROLL_DISTANCE if changing this default.
pref("toolkit.scrollbox.verticalScrollDistance", 3);
pref("toolkit.scrollbox.horizontalScrollDistance", 5);
pref("toolkit.scrollbox.clickToScroll.scrollDelay", 150);
// Telemetry