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
authorMats Palmgren <matspal@gmail.com>
Mon, 29 Oct 2012 06:44:31 +0100
changeset 111790 49fdae25aac952dc7db9b6c9f3234a3c640668d1
parent 111789 ed720383aab39b79ec98f1c9d6cc9658f49718ef
child 111791 1212408eac299dbecf4036aabe83920e51b6fabc
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersroc
bugs804486
milestone19.0a1
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
content/events/src/nsEventStateManager.cpp
layout/base/nsPresShell.cpp
layout/generic/nsGfxScrollFrame.cpp
layout/generic/nsIScrollableFrame.h
modules/libpref/src/init/all.js
--- a/content/events/src/nsEventStateManager.cpp
+++ b/content/events/src/nsEventStateManager.cpp
@@ -2815,18 +2815,17 @@ nsEventStateManager::GetScrollAmount(nsP
   nsIFrame* rootFrame = aPresContext->PresShell()->GetRootFrame();
   if (!rootFrame) {
     return nsSize(0, 0);
   }
   nsRefPtr<nsFontMetrics> fm;
   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
 nsEventStateManager::DoScrollText(nsIScrollableFrame* aScrollableFrame,
                                   widget::WheelEvent* aEvent)
 {
   MOZ_ASSERT(aScrollableFrame);
   MOZ_ASSERT(aEvent);
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -2210,17 +2210,19 @@ PresShell::ScrollLine(bool aForward)
 }
 
 NS_IMETHODIMP
 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);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PresShell::CompleteScroll(bool aForward)
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -2380,23 +2380,22 @@ nsGfxScrollFrameInner::GetLineScrollAmou
     nsLayoutUtils::FontSizeInflationFor(mOuter));
   NS_ASSERTION(fm, "FontMetrics is null, assuming fontHeight == 1 appunit");
   static nscoord sMinLineScrollAmountInPixels = -1;
   if (sMinLineScrollAmountInPixels < 0) {
     Preferences::AddIntVarCache(&sMinLineScrollAmountInPixels,
                                 "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));
 }
 
 /**
  * Compute the scrollport size excluding any fixed-pos headers and
  * footers. A header or footer is an box that spans that entire width
  * of the viewport and touches the top (or bottom, respectively) of the
  * viewport. Headers and footers that cover more than a quarter of the
  * the viewport are ignored since they probably aren't true headers and
@@ -3417,37 +3416,43 @@ nsGfxScrollFrameInner::ReflowFinished()
   nsCOMPtr<nsIContent> hScroll =
     mHScrollbarBox ? mHScrollbarBox->GetContent() : nullptr;
 
   // Note, in some cases mOuter may get deleted while finishing reflow
   // for scrollbars.
   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,
                                NS_MAX(pageincrement, pageincrementMin),
                                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);
   }
 
   mFrameIsUpdatingScrollbar = false;
   // We used to rely on the curpos attribute changes above to scroll the
   // view.  However, for scrolling to the left of the viewport, we
   // rescale the curpos attribute, which means that operations like
--- a/layout/generic/nsIScrollableFrame.h
+++ b/layout/generic/nsIScrollableFrame.h
@@ -9,17 +9,18 @@
 
 #ifndef nsIScrollFrame_h___
 #define nsIScrollFrame_h___
 
 #include "nsISupports.h"
 #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;
 class nsIFrame;
 
 /**
  * Interface for frames that are scrollable. This interface exposes
  * APIs for examining scroll state, observing changes to scroll state,
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -337,18 +337,18 @@ pref("gfx.use_text_smoothing_setting", f
 // loading and rendering of framesets and iframes
 pref("browser.frames.enabled", true);
 
 // Number of characters to consider emphasizing for rich autocomplete results
 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
 pref("toolkit.telemetry.enabled", false);
 pref("toolkit.telemetry.server", "https://data.mozilla.com");
 // Telemetry server owner. Please change if you set toolkit.telemetry.server to a different server
 pref("toolkit.telemetry.server_owner", "Mozilla");
 // Information page about telemetry (temporary ; will be about:telemetry in the end)