aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2015-10-26 21:01:00 -0500
committerbors-servo <lbergstrom+bors@mozilla.com>2015-10-26 21:01:00 -0500
commite49c7a3acbc36549e52f99ad67048f5e31352bad (patch)
tree0393448bb59d7690261c00333b4439e13bfd017b
parentb8f196f858dea3b6c275eafa57d14679f9be7066 (diff)
parentc36484257bfd5a2a45dc384dfcbc93c9e0d5aee7 (diff)
downloadservo-e49c7a3acbc36549e52f99ad67048f5e31352bad.tar.gz
servo-e49c7a3acbc36549e52f99ad67048f5e31352bad.zip
Auto merge of #8215 - mrobinson:glutin-pinch-sim, r=glennw
Implement pinch zoom emulation to the glutin port The GLFW port had pinch zoom emulation that could be triggered by holding control and using the mouse wheel. This was very useful for testing pinch zoom behavior on desktop machines. This commit implements this for the glutin port. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8215) <!-- Reviewable:end -->
-rw-r--r--ports/glutin/window.rs23
1 files changed, 18 insertions, 5 deletions
diff --git a/ports/glutin/window.rs b/ports/glutin/window.rs
index 2c720fa3853..af8cf8a242b 100644
--- a/ports/glutin/window.rs
+++ b/ports/glutin/window.rs
@@ -200,11 +200,20 @@ impl Window {
WindowEvent::MouseWindowMoveEventClass(Point2D::typed(x as f32, y as f32)));
}
Event::MouseWheel(delta) => {
- match delta {
- MouseScrollDelta::LineDelta(dx, dy) => {
- self.scroll_window(dx, dy * LINE_HEIGHT);
- }
- MouseScrollDelta::PixelDelta(dx, dy) => self.scroll_window(dx, dy)
+ let (dx, dy) = match delta {
+ MouseScrollDelta::LineDelta(dx, dy) => (dx, dy * LINE_HEIGHT),
+ MouseScrollDelta::PixelDelta(dx, dy) => (dx, dy),
+ };
+
+ if !self.key_modifiers.get().intersects(LEFT_CONTROL | RIGHT_CONTROL) {
+ self.scroll_window(dx, dy);
+ } else {
+ let factor = if dy > 0. {
+ 1.1
+ } else {
+ 1.0 / 1.1
+ };
+ self.pinch_zoom(factor);
}
},
Event::Refresh => {
@@ -225,6 +234,10 @@ impl Window {
self.key_modifiers.set(modifiers);
}
+ fn pinch_zoom(&self, factor: f32) {
+ self.event_queue.borrow_mut().push(WindowEvent::PinchZoom(factor));
+ }
+
/// Helper function to send a scroll event.
fn scroll_window(&self, dx: f32, dy: f32) {
let mouse_pos = self.mouse_pos.get();