Bug 481768 - mouse wheel scrolls too far when viewport is smallish, p=karlt+me, r=karlt, sr=roc
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Sun, 08 Mar 2009 22:58:47 +0200
changeset 25844 797e33c3e9091e7fd7601d6db7c0e1196d81259c
parent 25843 5559ef92719ea1b80a13a6dee7289868b6793d78
child 25845 6760e7395b5ae02991473c3562f28fcf216bb2a8
push idunknown
push userunknown
push dateunknown
reviewerskarlt, roc
bugs481768
milestone1.9.2a1pre
Bug 481768 - mouse wheel scrolls too far when viewport is smallish, p=karlt+me, r=karlt, sr=roc
content/events/src/nsEventStateManager.cpp
--- a/content/events/src/nsEventStateManager.cpp
+++ b/content/events/src/nsEventStateManager.cpp
@@ -2812,16 +2812,38 @@ nsEventStateManager::DoScrollText(nsPres
             nsMouseWheelTransaction::EndTransaction();
           }
         }
       }
     }
   }
 
   if (!passToParent && scrollView) {
+    if (aScrollQuantity == eScrollByLine) {
+      // Limit scrolling to be at most one page, but if possible, try to
+      // just adjust the number of scrolled lines.
+      nscoord lineHeight = 0;
+      scrollView->GetLineHeight(&lineHeight);
+      if (lineHeight) {
+        nsSize pageScrollDistances(0, 0);
+        scrollView->GetPageScrollDistances(&pageScrollDistances);
+        nscoord pageScroll = aScrollHorizontal ?
+          pageScrollDistances.width : pageScrollDistances.height;
+
+        if (PR_ABS(aNumLines) * lineHeight > pageScroll) {
+          nscoord maxLines = (pageScroll / lineHeight);
+          if (maxLines >= 1) {
+            aNumLines = ((aNumLines < 0) ? -1 : 1) * maxLines;
+          } else {
+            aScrollQuantity = eScrollByPage;
+          }
+        }
+      }
+    }
+
     PRInt32 scrollX = 0;
     PRInt32 scrollY = aNumLines;
 
     if (aScrollQuantity == eScrollByPage)
       scrollY = (scrollY > 0) ? 1 : -1;
       
     if (aScrollHorizontal) {
       scrollX = scrollY;