aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/compositing/compositor.rs92
1 files changed, 36 insertions, 56 deletions
diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs
index d265112ae82..58efffe6d6c 100644
--- a/components/compositing/compositor.rs
+++ b/components/compositing/compositor.rs
@@ -182,12 +182,6 @@ pub struct IOCompositor<Window: WindowMethods> {
/// Touch input state machine
touch_gesture_state: TouchState,
- /// When tracking a touch for gesture detection, the point where it started
- first_touch_point: Option<TypedPoint2D<DevicePixel, f32>>,
-
- /// When tracking a touch for gesture detection, its most recent point
- last_touch_point: Option<TypedPoint2D<DevicePixel, f32>>,
-
/// Pending scroll events.
pending_scroll_events: Vec<ScrollEvent>,
@@ -213,15 +207,16 @@ enum TouchState {
/// Not tracking any touch point
Nothing,
/// A touchstart event was dispatched to the page, but the response wasn't received yet.
- /// Contains the number of active touch points.
- WaitingForScript(u32),
+ /// Contains the number of active touch points and the initial touch location.
+ WaitingForScript(u32, TypedPoint2D<DevicePixel, f32>),
/// Script is consuming the current touch sequence; don't perform default actions.
/// Contains the number of active touch points.
DefaultPrevented(u32),
/// A single touch point is active and may perform click or pan default actions.
- Touching,
- /// A single touch point is active and has started panning.
- Panning,
+ /// Contains the initial touch location.
+ Touching(TypedPoint2D<DevicePixel, f32>),
+ /// A single touch point is active and has started panning. Contains the latest touch location.
+ Panning(TypedPoint2D<DevicePixel, f32>),
/// A multi-touch gesture is in progress. Contains the number of active touch points.
MultiTouch(u32),
}
@@ -352,8 +347,6 @@ impl<Window: WindowMethods> IOCompositor<Window> {
scrolling_timer: ScrollingTimerProxy::new(state.sender),
composition_request: CompositionRequest::NoCompositingNecessary,
touch_gesture_state: TouchState::Nothing,
- first_touch_point: None,
- last_touch_point: None,
pending_scroll_events: Vec::new(),
composite_target: composite_target,
shutdown_state: ShutdownState::NotShuttingDown,
@@ -564,13 +557,13 @@ impl<Window: WindowMethods> IOCompositor<Window> {
(Msg::TouchEventProcessed(result), ShutdownState::NotShuttingDown) => {
match self.touch_gesture_state {
- TouchState::WaitingForScript(n) => {
+ TouchState::WaitingForScript(n, p) => {
self.touch_gesture_state = match result {
EventResult::DefaultPrevented => TouchState::DefaultPrevented(n),
EventResult::DefaultAllowed => if n > 1 {
TouchState::MultiTouch(n)
} else {
- TouchState::Touching
+ TouchState::Touching(p)
}
};
}
@@ -1233,18 +1226,15 @@ impl<Window: WindowMethods> IOCompositor<Window> {
fn on_touch_down(&mut self, identifier: TouchId, point: TypedPoint2D<DevicePixel, f32>) {
self.touch_gesture_state = match self.touch_gesture_state {
TouchState::Nothing => {
- // TODO: Don't wait for script if we know the page has no touch event listeners.
- self.first_touch_point = Some(point);
- self.last_touch_point = Some(point);
- TouchState::WaitingForScript(1)
+ TouchState::WaitingForScript(1, point)
}
- TouchState::Touching |
- TouchState::Panning => {
+ TouchState::Touching(_) |
+ TouchState::Panning(_) => {
// Was a single-touch sequence; now a multi-touch sequence:
TouchState::MultiTouch(2)
}
- TouchState::WaitingForScript(n) => {
- TouchState::WaitingForScript(n + 1)
+ TouchState::WaitingForScript(n, p) => {
+ TouchState::WaitingForScript(n + 1, p)
}
TouchState::DefaultPrevented(n) => {
TouchState::DefaultPrevented(n + 1)
@@ -1263,34 +1253,25 @@ impl<Window: WindowMethods> IOCompositor<Window> {
match self.touch_gesture_state {
TouchState::Nothing => warn!("Got unexpected touch move event"),
- TouchState::WaitingForScript(_) => {
+ TouchState::WaitingForScript(..) => {
// TODO: Queue events while waiting for script?
}
- TouchState::Touching => {
- match self.first_touch_point {
- Some(p0) => {
- let delta = point - p0;
- let px: TypedPoint2D<ScreenPx, _> = delta / self.device_pixels_per_screen_px();
- let px = px.to_untyped();
-
- if px.x.abs() > TOUCH_PAN_MIN_SCREEN_PX ||
- px.y.abs() > TOUCH_PAN_MIN_SCREEN_PX
- {
- self.touch_gesture_state = TouchState::Panning;
- self.on_scroll_window_event(delta, point.cast().unwrap());
- }
- }
- None => warn!("first_touch_point not set")
+ TouchState::Touching(p0) => {
+ let delta = point - p0;
+ let px: TypedPoint2D<ScreenPx, _> = delta / self.device_pixels_per_screen_px();
+ let px = px.to_untyped();
+
+ if px.x.abs() > TOUCH_PAN_MIN_SCREEN_PX ||
+ px.y.abs() > TOUCH_PAN_MIN_SCREEN_PX
+ {
+ self.touch_gesture_state = TouchState::Panning(point);
+ self.on_scroll_window_event(delta, point.cast().unwrap());
}
}
- TouchState::Panning => {
- match self.last_touch_point {
- Some(p0) => {
- let delta = point - p0;
- self.on_scroll_window_event(delta, point.cast().unwrap());
- }
- None => warn!("last_touch_point not set")
- }
+ TouchState::Panning(p0) => {
+ let delta = point - p0;
+ self.on_scroll_window_event(delta, point.cast().unwrap());
+ self.touch_gesture_state = TouchState::Panning(point);
}
TouchState::DefaultPrevented(_) => {
// Send the event to script.
@@ -1303,7 +1284,6 @@ impl<Window: WindowMethods> IOCompositor<Window> {
// TODO: Pinch zooming.
}
}
- self.last_touch_point = Some(point);
}
fn on_touch_up(&mut self, identifier: TouchId, point: TypedPoint2D<DevicePixel, f32>) {
@@ -1314,20 +1294,20 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}
self.touch_gesture_state = match self.touch_gesture_state {
- TouchState::Touching => {
+ TouchState::Touching(_) => {
// TODO: If the duration exceeds some threshold, send a contextmenu event instead.
// TODO: Don't send a click if preventDefault is called on the touchend event.
self.simulate_mouse_click(point);
TouchState::Nothing
}
TouchState::Nothing |
- TouchState::Panning |
- TouchState::WaitingForScript(1) |
+ TouchState::Panning(_) |
+ TouchState::WaitingForScript(1, _) |
TouchState::DefaultPrevented(1) |
TouchState::MultiTouch(1) => {
TouchState::Nothing
}
- TouchState::WaitingForScript(n) => TouchState::WaitingForScript(n - 1),
+ TouchState::WaitingForScript(n, p) => TouchState::WaitingForScript(n - 1, p),
TouchState::DefaultPrevented(n) => TouchState::DefaultPrevented(n - 1),
TouchState::MultiTouch(n) => TouchState::MultiTouch(n - 1),
};
@@ -1342,14 +1322,14 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.touch_gesture_state = match self.touch_gesture_state {
TouchState::Nothing |
- TouchState::Touching |
- TouchState::Panning |
- TouchState::WaitingForScript(1) |
+ TouchState::Touching(_) |
+ TouchState::Panning(_) |
+ TouchState::WaitingForScript(1, _) |
TouchState::DefaultPrevented(1) |
TouchState::MultiTouch(1) => {
TouchState::Nothing
}
- TouchState::WaitingForScript(n) => TouchState::WaitingForScript(n - 1),
+ TouchState::WaitingForScript(n, p) => TouchState::WaitingForScript(n - 1, p),
TouchState::DefaultPrevented(n) => TouchState::DefaultPrevented(n - 1),
TouchState::MultiTouch(n) => TouchState::MultiTouch(n - 1),
};