From 658df6047703aa24c88dacc0d17fe5076b778186 Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Sun, 14 Jun 2015 00:39:25 +0100 Subject: [PATCH] Use a faster scroll speed under X11 Platforms may report scroll deltas either in chunks/lines/rows or pixels, depending on the platform API and device capabilities. If the platform reports a line/chunk-based delta then the application needs to convert the delta into a suitable number of pixels. This commit just hardcodes it to 57 as a starting point which matches the value that Firefox calculates as the max char height for the root frame on my system. Fixes #5660 --- components/servo/Cargo.lock | 2 +- ports/cef/Cargo.lock | 2 +- ports/glutin/window.rs | 22 ++++++++++++++++------ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 136ddccb090..7fe068ab664 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -476,7 +476,7 @@ dependencies = [ [[package]] name = "glutin" version = "0.0.26" -source = "git+https://github.com/servo/glutin?branch=servo#3d39d1bb45a6f76be846ed92f946424e24109141" +source = "git+https://github.com/servo/glutin?branch=servo#abb5ba69eb6188d24567b47e7b5a289adc595f29" dependencies = [ "android_glue 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "cocoa 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index 981d17cec79..e0b2455da70 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -468,7 +468,7 @@ dependencies = [ [[package]] name = "glutin" version = "0.0.26" -source = "git+https://github.com/servo/glutin?branch=servo#3d39d1bb45a6f76be846ed92f946424e24109141" +source = "git+https://github.com/servo/glutin?branch=servo#abb5ba69eb6188d24567b47e7b5a289adc595f29" dependencies = [ "android_glue 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "cocoa 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ports/glutin/window.rs b/ports/glutin/window.rs index 83121be8217..83968aebeca 100644 --- a/ports/glutin/window.rs +++ b/ports/glutin/window.rs @@ -28,7 +28,7 @@ use compositing::windowing::{MouseWindowEvent, WindowNavigateMsg}; #[cfg(feature = "window")] use euclid::point::Point2D; #[cfg(feature = "window")] -use glutin::{Api, ElementState, Event, GlRequest, MouseButton, VirtualKeyCode}; +use glutin::{Api, ElementState, Event, GlRequest, MouseButton, VirtualKeyCode, MouseScrollDelta}; #[cfg(feature = "window")] use msg::constellation_msg::{KeyState, CONTROL, SHIFT, ALT}; #[cfg(feature = "window")] @@ -187,15 +187,25 @@ impl Window { Event::MouseWheel(delta) => { if self.ctrl_pressed() { // Ctrl-Scrollwheel simulates a "pinch zoom" gesture. - if delta < 0 { + let dy = match delta { + MouseScrollDelta::LineDelta(_, dy) => dy, + MouseScrollDelta::PixelDelta(_, dy) => dy + }; + if dy < 0.0 { self.event_queue.borrow_mut().push(WindowEvent::PinchZoom(1.0/1.1)); - } else if delta > 0 { + } else if dy > 0.0 { self.event_queue.borrow_mut().push(WindowEvent::PinchZoom(1.1)); } } else { - let dx = 0.0; - let dy = delta as f32; - self.scroll_window(dx, dy); + match delta { + MouseScrollDelta::LineDelta(dx, dy) => { + // this should use the actual line height + // of the frame under the mouse + let line_height = 57.0; + self.scroll_window(dx, dy * line_height); + } + MouseScrollDelta::PixelDelta(dx, dy) => self.scroll_window(dx, dy) + } } }, Event::Refresh => {