Implement support for overscrolling on the Mac.

Requires tomaka/glutin#734, servo/webrender_traits#14, and
servo/webrender#217.
This commit is contained in:
Patrick Walton 2016-03-02 09:29:49 -08:00
parent 059edc3287
commit 8eb2cda438
8 changed files with 152 additions and 49 deletions

10
ports/cef/Cargo.lock generated
View file

@ -708,7 +708,7 @@ dependencies = [
"net_traits 0.0.1",
"script_traits 0.0.1",
"servo-egl 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"servo-glutin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"servo-glutin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"style_traits 0.0.1",
"url 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)",
"util 0.0.1",
@ -1758,7 +1758,7 @@ dependencies = [
[[package]]
name = "servo-glutin"
version = "0.4.9"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"android_glue 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1800,7 +1800,7 @@ dependencies = [
"servo-egl 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"servo-fontconfig 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"servo-freetype-sys 2.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"servo-glutin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"servo-glutin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"x11 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -2168,7 +2168,7 @@ dependencies = [
[[package]]
name = "webrender"
version = "0.1.0"
source = "git+https://github.com/servo/webrender#38031eed57b2df8a57e4cff576e2b5b6f2cd8316"
source = "git+https://github.com/servo/webrender#9309d52279a73ea15f955424899fed9b9ab70c95"
dependencies = [
"app_units 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2189,7 +2189,7 @@ dependencies = [
[[package]]
name = "webrender_traits"
version = "0.1.0"
source = "git+https://github.com/servo/webrender_traits#94f16f55e65d735a9c1dc38733937cb2774322e1"
source = "git+https://github.com/servo/webrender_traits#a4d2e91915512c3d6b08d0d391221bb240d972d5"
dependencies = [
"app_units 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -15,7 +15,7 @@ use euclid::point::Point2D;
use euclid::size::Size2D;
use libc::{c_double, c_int};
use msg::constellation_msg::{self, KeyModifiers, KeyState};
use script_traits::MouseButton;
use script_traits::{MouseButton, TouchEventType};
use std::cell::{Cell, RefCell};
pub struct ServoCefBrowserHost {
@ -469,7 +469,9 @@ full_cef_class_impl! {
let delta_y: c_int = delta_y;
let delta = Point2D::typed(delta_x as f32, delta_y as f32);
let origin = Point2D::typed((*event).x as i32, (*event).y as i32);
this.downcast().send_window_event(WindowEvent::Scroll(delta, origin))
this.downcast().send_window_event(WindowEvent::Scroll(delta,
origin,
TouchEventType::Move))
}}
fn get_zoom_level(&this,) -> c_double {{

View file

@ -16,6 +16,7 @@ use gleam::gl;
use glutin;
#[cfg(feature = "window")]
use glutin::{Api, ElementState, Event, GlRequest, MouseButton, VirtualKeyCode, MouseScrollDelta};
use glutin::{TouchPhase};
use layers::geometry::DevicePixel;
use layers::platform::surface::NativeDisplay;
#[cfg(feature = "window")]
@ -23,6 +24,8 @@ use msg::constellation_msg::{KeyState, NONE, CONTROL, SHIFT, ALT, SUPER};
use msg::constellation_msg::{self, Key};
use net_traits::net_error_list::NetError;
#[cfg(feature = "window")]
use script_traits::TouchEventType;
#[cfg(feature = "window")]
use std::cell::{Cell, RefCell};
use std::os::raw::c_void;
#[cfg(all(feature = "headless", target_os = "linux"))]
@ -226,23 +229,18 @@ impl Window {
self.event_queue.borrow_mut().push(
WindowEvent::MouseWindowMoveEventClass(Point2D::typed(x as f32, y as f32)));
}
Event::MouseWheel(delta) => {
Event::MouseWheel(delta, phase) => {
let (dx, dy) = match delta {
MouseScrollDelta::LineDelta(dx, dy) => (dx, dy * LINE_HEIGHT),
MouseScrollDelta::PixelDelta(dx, dy) => (dx, dy),
};
self.scroll_window(dx, dy);
let phase = glutin_phase_to_touch_event_type(phase);
self.scroll_window(dx, dy, phase);
},
Event::Touch(touch) => {
use glutin::TouchPhase;
use script_traits::{TouchEventType, TouchId};
use script_traits::TouchId;
let phase = match touch.phase {
TouchPhase::Started => TouchEventType::Down,
TouchPhase::Moved => TouchEventType::Move,
TouchPhase::Ended => TouchEventType::Up,
TouchPhase::Cancelled => TouchEventType::Cancel,
};
let phase = glutin_phase_to_touch_event_type(touch.phase);
let id = TouchId(touch.id as i32);
let point = Point2D::typed(touch.location.0 as f32, touch.location.1 as f32);
self.event_queue.borrow_mut().push(WindowEvent::Touch(phase, id, point));
@ -266,10 +264,11 @@ impl Window {
}
/// Helper function to send a scroll event.
fn scroll_window(&self, dx: f32, dy: f32) {
fn scroll_window(&self, dx: f32, dy: f32, phase: TouchEventType) {
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));
Point2D::typed(mouse_pos.x as i32, mouse_pos.y as i32),
phase);
self.event_queue.borrow_mut().push(event);
}
@ -736,23 +735,33 @@ impl WindowMethods for Window {
(NONE, Key::PageDown) |
(NONE, Key::Space) => {
self.scroll_window(0.0, -self.framebuffer_size().as_f32().to_untyped().height + 2.0 * LINE_HEIGHT);
self.scroll_window(0.0,
-self.framebuffer_size()
.as_f32()
.to_untyped()
.height + 2.0 * LINE_HEIGHT,
TouchEventType::Move);
}
(NONE, Key::PageUp) |
(SHIFT, Key::Space) => {
self.scroll_window(0.0, self.framebuffer_size().as_f32().to_untyped().height - 2.0 * LINE_HEIGHT);
self.scroll_window(0.0,
self.framebuffer_size()
.as_f32()
.to_untyped()
.height - 2.0 * LINE_HEIGHT,
TouchEventType::Move);
}
(NONE, Key::Up) => {
self.scroll_window(0.0, 3.0 * LINE_HEIGHT);
self.scroll_window(0.0, 3.0 * LINE_HEIGHT, TouchEventType::Move);
}
(NONE, Key::Down) => {
self.scroll_window(0.0, -3.0 * LINE_HEIGHT);
self.scroll_window(0.0, -3.0 * LINE_HEIGHT, TouchEventType::Move);
}
(NONE, Key::Left) => {
self.scroll_window(LINE_HEIGHT, 0.0);
self.scroll_window(LINE_HEIGHT, 0.0, TouchEventType::Move);
}
(NONE, Key::Right) => {
self.scroll_window(-LINE_HEIGHT, 0.0);
self.scroll_window(-LINE_HEIGHT, 0.0, TouchEventType::Move);
}
_ => {
@ -923,6 +932,16 @@ impl CompositorProxy for GlutinCompositorProxy {
}
}
#[cfg(feature = "window")]
fn glutin_phase_to_touch_event_type(phase: TouchPhase) -> TouchEventType {
match phase {
TouchPhase::Started => TouchEventType::Down,
TouchPhase::Moved => TouchEventType::Move,
TouchPhase::Ended => TouchEventType::Up,
TouchPhase::Cancelled => TouchEventType::Cancel,
}
}
// These functions aren't actually called. They are here as a link
// hack because Skia references them.

8
ports/gonk/Cargo.lock generated
View file

@ -1738,7 +1738,7 @@ dependencies = [
[[package]]
name = "servo-glutin"
version = "0.4.9"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"android_glue 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1780,7 +1780,7 @@ dependencies = [
"servo-egl 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"servo-fontconfig 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"servo-freetype-sys 2.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"servo-glutin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"servo-glutin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"x11 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -2117,7 +2117,7 @@ dependencies = [
[[package]]
name = "webrender"
version = "0.1.0"
source = "git+https://github.com/servo/webrender#38031eed57b2df8a57e4cff576e2b5b6f2cd8316"
source = "git+https://github.com/servo/webrender#9309d52279a73ea15f955424899fed9b9ab70c95"
dependencies = [
"app_units 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2138,7 +2138,7 @@ dependencies = [
[[package]]
name = "webrender_traits"
version = "0.1.0"
source = "git+https://github.com/servo/webrender_traits#94f16f55e65d735a9c1dc38733937cb2774322e1"
source = "git+https://github.com/servo/webrender_traits#a4d2e91915512c3d6b08d0d391221bb240d972d5"
dependencies = [
"app_units 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -6,7 +6,7 @@ use compositing::windowing::{WindowEvent, MouseWindowEvent};
use errno::errno;
use euclid::point::Point2D;
use libc::{c_int, c_long, time_t};
use script_traits::MouseButton;
use script_traits::{MouseButton, TouchEventType};
use std::fs::File;
use std::io::Read;
use std::mem::{size_of, transmute, zeroed};
@ -185,7 +185,8 @@ fn read_input_device(device_path: &Path,
println!("Touch move x: {}, y: {}", slotA.x, slotA.y);
sender.send(
WindowEvent::Scroll(Point2D::typed((slotA.x - last_x) as f32, (slotA.y - last_y) as f32),
Point2D::typed(slotA.x, slotA.y))).ok().unwrap();
Point2D::typed(slotA.x, slotA.y),
TouchEventType::Move)).ok().unwrap();
last_x = slotA.x;
last_y = slotA.y;
if touch_count >= 2 {