servo: Merge #10387 - Snap scrolling to major axis of movement (from tschneidereit:snap-scroll-axis); r=paulrouget
authorTill Schneidereit <till@tillschneidereit.net>
Wed, 06 Apr 2016 16:47:54 +0500
changeset 338424 adfaee395308aeff6a4edf292ed4c2150588fc1b
parent 338423 f6846c0685a52f8986ab656aa08674e93d87dba9
child 338425 89413377579dda43388c9a7366eeb066cf8c486f
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspaulrouget
servo: Merge #10387 - Snap scrolling to major axis of movement (from tschneidereit:snap-scroll-axis); r=paulrouget This is what Safari does, and it leads to much better behavior, in particular wrt overscrolling. It does cause a staircase effect when scrolling diagonally, which again Safari has, too. I don't think that bad, because it should occur very rarely in practice. Fixes #10341 Source-Repo: https://github.com/servo/servo Source-Revision: 84b30b06413511ad54689f31514da8ba1ad286e3
servo/ports/glutin/window.rs
--- a/servo/ports/glutin/window.rs
+++ b/servo/ports/glutin/window.rs
@@ -261,17 +261,24 @@ impl Window {
 
     fn toggle_modifier(&self, modifier: KeyModifiers) {
         let mut modifiers = self.key_modifiers.get();
         modifiers.toggle(modifier);
         self.key_modifiers.set(modifiers);
     }
 
     /// Helper function to send a scroll event.
-    fn scroll_window(&self, dx: f32, dy: f32, phase: TouchEventType) {
+    fn scroll_window(&self, mut dx: f32, mut dy: f32, phase: TouchEventType) {
+        // Scroll events snap to the major axis of movement, with vertical
+        // preferred over horizontal.
+        if dy.abs() >= dx.abs() {
+            dx = 0.0;
+        } else {
+            dy = 0.0;
+        }
         let mouse_pos = self.mouse_pos.get();
         let event = WindowEvent::Scroll(Point2D::typed(dx as f32, dy as f32),
                                         Point2D::typed(mouse_pos.x as i32, mouse_pos.y as i32),
                                         phase);
         self.event_queue.borrow_mut().push(event);
     }
 
     /// Helper function to handle a click