mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
implement Touchevent prevent default behavior (#35031)
* implement Touchevent prevent default behavior * The status change logic of the `TouchHandler` is changed. > The `WaitingForScript` state is canceled. TouchAction can be identified based on the current touch type and numbers if touch points. * Sends current event to script thread along with recognized `TouchAction`. > After dispatch event, script thread sends a `TouchEventProcess(EventResult)` message to main thread. If the event is set to `DefaultAllowed`, the corresponding `TouchAction` information is added. * After receiving `DefaultAllowed(TouchAction)` message, main thread executes corresponding action. > `DefaultPrevented(TouchEventType)` is received. Use `prevent_click` to mark that the default `Click` is blocked, and `prevent_move` to mark that the default `Scroll` and `Zoom` are blocked. In this way, all TouchActions implement preventDefault. Signed-off-by: Bi Fuguo <1782765876@qq.com> * fix some suggestions * support preventDefault fling * move `TouchAction` to share touch directory * check preventDefault everytime when touch * fix zoom ineffective Signed-off-by: Bi Fuguo <1782765876@qq.com> * fix some suggestions rename on_event_processed to on_touch_event_processed clear unused features Signed-off-by: Bi Fuguo <1782765876@qq.com> * Optimizes pan performance by continuously sliding without waiting for the eventhandler. Signed-off-by: kongbai1996 <1782765876@qq.com> * resolve conflict Signed-off-by: kongbai1996 <1782765876@qq.com> --------- Signed-off-by: Bi Fuguo <1782765876@qq.com> Signed-off-by: kongbai1996 <1782765876@qq.com>
This commit is contained in:
parent
6dce329acc
commit
3fe42a0b5a
12 changed files with 273 additions and 255 deletions
|
@ -21,7 +21,7 @@ use compositing_traits::{
|
|||
use crossbeam_channel::Sender;
|
||||
use embedder_traits::{
|
||||
Cursor, InputEvent, MouseButton, MouseButtonAction, MouseButtonEvent, MouseMoveEvent,
|
||||
TouchEvent, TouchEventAction, TouchId,
|
||||
TouchAction, TouchEvent, TouchEventType, TouchId,
|
||||
};
|
||||
use euclid::{Point2D, Rect, Scale, Size2D, Transform3D, Vector2D};
|
||||
use fnv::{FnvHashMap, FnvHashSet};
|
||||
|
@ -33,8 +33,8 @@ use pixels::{CorsStatus, Image, PixelFormat};
|
|||
use profile_traits::time::{self as profile_time, ProfilerCategory};
|
||||
use profile_traits::time_profile;
|
||||
use script_traits::{
|
||||
AnimationState, AnimationTickType, ScriptThreadMessage, ScrollState, WindowSizeData,
|
||||
WindowSizeType,
|
||||
AnimationState, AnimationTickType, EventResult, ScriptThreadMessage, ScrollState,
|
||||
WindowSizeData, WindowSizeType,
|
||||
};
|
||||
use servo_geometry::DeviceIndependentPixel;
|
||||
use style_traits::{CSSPixel, PinchZoomFactor};
|
||||
|
@ -56,7 +56,7 @@ use webrender_traits::{
|
|||
CompositorHitTestResult, CrossProcessCompositorMessage, ImageUpdate, UntrustedNodeAddress,
|
||||
};
|
||||
|
||||
use crate::touch::{TouchAction, TouchHandler};
|
||||
use crate::touch::TouchHandler;
|
||||
use crate::webview::{UnknownWebView, WebView, WebViewAlreadyExists, WebViewManager};
|
||||
use crate::windowing::{self, EmbedderCoordinates, WebRenderDebugOption, WindowMethods};
|
||||
use crate::InitialCompositorState;
|
||||
|
@ -501,7 +501,7 @@ impl IOCompositor {
|
|||
},
|
||||
|
||||
CompositorMsg::TouchEventProcessed(result) => {
|
||||
self.touch_handler.on_event_processed(result);
|
||||
self.on_touch_event_processed(result);
|
||||
},
|
||||
|
||||
CompositorMsg::CreatePng(page_rect, reply) => {
|
||||
|
@ -1338,13 +1338,28 @@ impl IOCompositor {
|
|||
InputEvent::MouseButton(event) => {
|
||||
match event.action {
|
||||
MouseButtonAction::Click => {},
|
||||
MouseButtonAction::Down => self.on_touch_down(TouchId(0), event.point),
|
||||
MouseButtonAction::Up => self.on_touch_up(TouchId(0), event.point),
|
||||
MouseButtonAction::Down => self.on_touch_down(TouchEvent {
|
||||
event_type: TouchEventType::Down,
|
||||
id: TouchId(0),
|
||||
point: event.point,
|
||||
action: TouchAction::NoAction,
|
||||
}),
|
||||
MouseButtonAction::Up => self.on_touch_up(TouchEvent {
|
||||
event_type: TouchEventType::Up,
|
||||
id: TouchId(0),
|
||||
point: event.point,
|
||||
action: TouchAction::NoAction,
|
||||
}),
|
||||
}
|
||||
return;
|
||||
},
|
||||
InputEvent::MouseMove(event) => {
|
||||
self.on_touch_move(TouchId(0), event.point);
|
||||
self.on_touch_move(TouchEvent {
|
||||
event_type: TouchEventType::Move,
|
||||
id: TouchId(0),
|
||||
point: event.point,
|
||||
action: TouchAction::NoAction,
|
||||
});
|
||||
return;
|
||||
},
|
||||
_ => {},
|
||||
|
@ -1422,75 +1437,113 @@ impl IOCompositor {
|
|||
return;
|
||||
}
|
||||
|
||||
match event.action {
|
||||
TouchEventAction::Down => self.on_touch_down(event.id, event.point),
|
||||
TouchEventAction::Move => self.on_touch_move(event.id, event.point),
|
||||
TouchEventAction::Up => self.on_touch_up(event.id, event.point),
|
||||
TouchEventAction::Cancel => self.on_touch_cancel(event.id, event.point),
|
||||
match event.event_type {
|
||||
TouchEventType::Down => self.on_touch_down(event),
|
||||
TouchEventType::Move => self.on_touch_move(event),
|
||||
TouchEventType::Up => self.on_touch_up(event),
|
||||
TouchEventType::Cancel => self.on_touch_cancel(event),
|
||||
}
|
||||
}
|
||||
|
||||
fn on_touch_down(&mut self, id: TouchId, point: DevicePoint) {
|
||||
self.touch_handler.on_touch_down(id, point);
|
||||
self.send_touch_event(TouchEvent {
|
||||
action: TouchEventAction::Down,
|
||||
id,
|
||||
point,
|
||||
})
|
||||
fn on_touch_down(&mut self, event: TouchEvent) {
|
||||
self.touch_handler.on_touch_down(event.id, event.point);
|
||||
self.send_touch_event(event);
|
||||
}
|
||||
|
||||
fn on_touch_move(&mut self, id: TouchId, point: DevicePoint) {
|
||||
match self.touch_handler.on_touch_move(id, point) {
|
||||
TouchAction::Scroll(delta) => self.on_scroll_window_event(
|
||||
ScrollLocation::Delta(LayoutVector2D::from_untyped(delta.to_untyped())),
|
||||
point.cast(),
|
||||
),
|
||||
TouchAction::Zoom(magnification, scroll_delta) => {
|
||||
let cursor = Point2D::new(-1, -1); // Make sure this hits the base layer.
|
||||
fn on_touch_move(&mut self, mut event: TouchEvent) {
|
||||
let action: TouchAction = self.touch_handler.on_touch_move(event.id, event.point);
|
||||
if TouchAction::NoAction != action {
|
||||
if !self.touch_handler.prevent_move {
|
||||
match action {
|
||||
TouchAction::Scroll(delta, point) => self.on_scroll_window_event(
|
||||
ScrollLocation::Delta(LayoutVector2D::from_untyped(delta.to_untyped())),
|
||||
point.cast(),
|
||||
),
|
||||
TouchAction::Zoom(magnification, scroll_delta) => {
|
||||
let cursor = Point2D::new(-1, -1); // Make sure this hits the base layer.
|
||||
|
||||
// The order of these events doesn't matter, because zoom is handled by
|
||||
// a root display list and the scroll event here is handled by the scroll
|
||||
// applied to the content display list.
|
||||
self.pending_scroll_zoom_events
|
||||
.push(ScrollZoomEvent::PinchZoom(magnification));
|
||||
self.pending_scroll_zoom_events
|
||||
.push(ScrollZoomEvent::Scroll(ScrollEvent {
|
||||
scroll_location: ScrollLocation::Delta(LayoutVector2D::from_untyped(
|
||||
scroll_delta.to_untyped(),
|
||||
)),
|
||||
cursor,
|
||||
event_count: 1,
|
||||
}));
|
||||
},
|
||||
TouchAction::DispatchEvent => self.send_touch_event(TouchEvent {
|
||||
action: TouchEventAction::Move,
|
||||
id,
|
||||
point,
|
||||
}),
|
||||
_ => {},
|
||||
// The order of these events doesn't matter, because zoom is handled by
|
||||
// a root display list and the scroll event here is handled by the scroll
|
||||
// applied to the content display list.
|
||||
self.pending_scroll_zoom_events
|
||||
.push(ScrollZoomEvent::PinchZoom(magnification));
|
||||
self.pending_scroll_zoom_events
|
||||
.push(ScrollZoomEvent::Scroll(ScrollEvent {
|
||||
scroll_location: ScrollLocation::Delta(
|
||||
LayoutVector2D::from_untyped(scroll_delta.to_untyped()),
|
||||
),
|
||||
cursor,
|
||||
event_count: 1,
|
||||
}));
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
} else {
|
||||
event.action = action;
|
||||
}
|
||||
self.send_touch_event(event);
|
||||
}
|
||||
}
|
||||
|
||||
fn on_touch_up(&mut self, id: TouchId, point: DevicePoint) {
|
||||
self.send_touch_event(TouchEvent {
|
||||
action: TouchEventAction::Up,
|
||||
id,
|
||||
point,
|
||||
});
|
||||
|
||||
if let TouchAction::Click = self.touch_handler.on_touch_up(id, point) {
|
||||
self.simulate_mouse_click(point);
|
||||
}
|
||||
fn on_touch_up(&mut self, mut event: TouchEvent) {
|
||||
let action = self.touch_handler.on_touch_up(event.id, event.point);
|
||||
event.action = action;
|
||||
self.send_touch_event(event);
|
||||
}
|
||||
|
||||
fn on_touch_cancel(&mut self, id: TouchId, point: DevicePoint) {
|
||||
fn on_touch_cancel(&mut self, event: TouchEvent) {
|
||||
// Send the event to script.
|
||||
self.touch_handler.on_touch_cancel(id, point);
|
||||
self.send_touch_event(TouchEvent {
|
||||
action: TouchEventAction::Cancel,
|
||||
id,
|
||||
point,
|
||||
})
|
||||
self.touch_handler.on_touch_cancel(event.id, event.point);
|
||||
self.send_touch_event(event)
|
||||
}
|
||||
|
||||
fn on_touch_event_processed(&mut self, result: EventResult) {
|
||||
match result {
|
||||
EventResult::DefaultPrevented(event_type) => {
|
||||
match event_type {
|
||||
TouchEventType::Down | TouchEventType::Move => {
|
||||
self.touch_handler.prevent_move = true;
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
self.touch_handler.prevent_click = true;
|
||||
},
|
||||
EventResult::DefaultAllowed(action) => {
|
||||
self.touch_handler.prevent_move = false;
|
||||
match action {
|
||||
TouchAction::Click(point) => {
|
||||
if !self.touch_handler.prevent_click {
|
||||
self.simulate_mouse_click(point);
|
||||
}
|
||||
},
|
||||
TouchAction::Flinging(velocity, point) => {
|
||||
self.touch_handler.on_fling(velocity, point);
|
||||
},
|
||||
TouchAction::Scroll(delta, point) => self.on_scroll_window_event(
|
||||
ScrollLocation::Delta(LayoutVector2D::from_untyped(delta.to_untyped())),
|
||||
point.cast(),
|
||||
),
|
||||
TouchAction::Zoom(magnification, scroll_delta) => {
|
||||
let cursor = Point2D::new(-1, -1); // Make sure this hits the base layer.
|
||||
|
||||
// The order of these events doesn't matter, because zoom is handled by
|
||||
// a root display list and the scroll event here is handled by the scroll
|
||||
// applied to the content display list.
|
||||
self.pending_scroll_zoom_events
|
||||
.push(ScrollZoomEvent::PinchZoom(magnification));
|
||||
self.pending_scroll_zoom_events
|
||||
.push(ScrollZoomEvent::Scroll(ScrollEvent {
|
||||
scroll_location: ScrollLocation::Delta(
|
||||
LayoutVector2D::from_untyped(scroll_delta.to_untyped()),
|
||||
),
|
||||
cursor,
|
||||
event_count: 1,
|
||||
}));
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// <http://w3c.github.io/touch-events/#mouse-events>
|
||||
|
@ -1518,18 +1571,18 @@ impl IOCompositor {
|
|||
&mut self,
|
||||
scroll_location: ScrollLocation,
|
||||
cursor: DeviceIntPoint,
|
||||
action: TouchEventAction,
|
||||
event_type: TouchEventType,
|
||||
) {
|
||||
if self.shutdown_state != ShutdownState::NotShuttingDown {
|
||||
return;
|
||||
}
|
||||
|
||||
match action {
|
||||
TouchEventAction::Move => self.on_scroll_window_event(scroll_location, cursor),
|
||||
TouchEventAction::Up | TouchEventAction::Cancel => {
|
||||
match event_type {
|
||||
TouchEventType::Move => self.on_scroll_window_event(scroll_location, cursor),
|
||||
TouchEventType::Up | TouchEventType::Cancel => {
|
||||
self.on_scroll_window_event(scroll_location, cursor);
|
||||
},
|
||||
TouchEventAction::Down => {
|
||||
TouchEventType::Down => {
|
||||
self.on_scroll_window_event(scroll_location, cursor);
|
||||
},
|
||||
}
|
||||
|
|
|
@ -2,10 +2,9 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use embedder_traits::TouchId;
|
||||
use embedder_traits::{TouchAction, TouchId};
|
||||
use euclid::{Point2D, Scale, Vector2D};
|
||||
use log::{debug, warn};
|
||||
use script_traits::EventResult;
|
||||
use webrender_api::units::{DeviceIntPoint, DevicePixel, LayoutVector2D};
|
||||
|
||||
use self::TouchState::*;
|
||||
|
@ -25,6 +24,8 @@ const FLING_MAX_SCREEN_PX: f32 = 4000.0;
|
|||
pub struct TouchHandler {
|
||||
pub state: TouchState,
|
||||
pub active_touch_points: Vec<TouchPoint>,
|
||||
pub prevent_move: bool,
|
||||
pub prevent_click: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
|
@ -44,11 +45,6 @@ impl TouchPoint {
|
|||
pub 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 initial touch point.
|
||||
WaitingForScript,
|
||||
/// Script is consuming the current touch sequence; don't perform default actions.
|
||||
DefaultPrevented,
|
||||
/// A single touch point is active and may perform click or pan default actions.
|
||||
/// Contains the initial touch location.
|
||||
Touching,
|
||||
|
@ -67,21 +63,6 @@ pub enum TouchState {
|
|||
MultiTouch,
|
||||
}
|
||||
|
||||
/// The action to take in response to a touch event
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum TouchAction {
|
||||
/// Simulate a mouse click.
|
||||
Click,
|
||||
/// Scroll by the provided offset.
|
||||
Scroll(Vector2D<f32, DevicePixel>),
|
||||
/// Zoom by a magnification factor and scroll by the provided offset.
|
||||
Zoom(f32, Vector2D<f32, DevicePixel>),
|
||||
/// Send a JavaScript event to content.
|
||||
DispatchEvent,
|
||||
/// Don't do anything.
|
||||
NoAction,
|
||||
}
|
||||
|
||||
pub(crate) struct FlingAction {
|
||||
pub delta: LayoutVector2D,
|
||||
pub cursor: DeviceIntPoint,
|
||||
|
@ -92,20 +73,21 @@ impl TouchHandler {
|
|||
TouchHandler {
|
||||
state: Nothing,
|
||||
active_touch_points: Vec::new(),
|
||||
prevent_move: true,
|
||||
prevent_click: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn on_touch_down(&mut self, id: TouchId, point: Point2D<f32, DevicePixel>) {
|
||||
let point = TouchPoint::new(id, point);
|
||||
self.active_touch_points.push(point);
|
||||
|
||||
self.state = match self.state {
|
||||
Nothing => WaitingForScript,
|
||||
Flinging { .. } => Touching,
|
||||
Touching | Panning { .. } => Pinching,
|
||||
WaitingForScript => WaitingForScript,
|
||||
DefaultPrevented => DefaultPrevented,
|
||||
Pinching | MultiTouch => MultiTouch,
|
||||
self.state = Touching;
|
||||
self.prevent_click = match self.touch_count() {
|
||||
1 => {
|
||||
self.prevent_move = true;
|
||||
false
|
||||
},
|
||||
_ => true,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -140,51 +122,51 @@ impl TouchHandler {
|
|||
},
|
||||
};
|
||||
let old_point = self.active_touch_points[idx].point;
|
||||
let delta = point - old_point;
|
||||
|
||||
let action = match self.state {
|
||||
Touching => {
|
||||
let delta = point - old_point;
|
||||
|
||||
if delta.x.abs() > TOUCH_PAN_MIN_SCREEN_PX ||
|
||||
let action = match self.touch_count() {
|
||||
1 => {
|
||||
if let Panning { ref mut velocity } = self.state {
|
||||
// TODO: Probably we should track 1-3 more points and use a smarter algorithm
|
||||
*velocity += delta;
|
||||
*velocity /= 2.0;
|
||||
TouchAction::Scroll(delta, point)
|
||||
} else if delta.x.abs() > TOUCH_PAN_MIN_SCREEN_PX ||
|
||||
delta.y.abs() > TOUCH_PAN_MIN_SCREEN_PX
|
||||
{
|
||||
self.state = Panning {
|
||||
velocity: Vector2D::new(delta.x, delta.y),
|
||||
};
|
||||
TouchAction::Scroll(delta)
|
||||
self.prevent_click = true;
|
||||
TouchAction::Scroll(delta, point)
|
||||
} else {
|
||||
TouchAction::NoAction
|
||||
}
|
||||
},
|
||||
Panning { ref mut velocity } => {
|
||||
let delta = point - old_point;
|
||||
// TODO: Probably we should track 1-3 more points and use a smarter algorithm
|
||||
*velocity += delta;
|
||||
*velocity /= 2.0;
|
||||
TouchAction::Scroll(delta)
|
||||
2 => {
|
||||
if self.state == Pinching ||
|
||||
delta.x.abs() > TOUCH_PAN_MIN_SCREEN_PX ||
|
||||
delta.y.abs() > TOUCH_PAN_MIN_SCREEN_PX
|
||||
{
|
||||
self.state = Pinching;
|
||||
let (d0, c0) = self.pinch_distance_and_center();
|
||||
self.active_touch_points[idx].point = point;
|
||||
let (d1, c1) = self.pinch_distance_and_center();
|
||||
let magnification = d1 / d0;
|
||||
let scroll_delta = c1 - c0 * Scale::new(magnification);
|
||||
TouchAction::Zoom(magnification, scroll_delta)
|
||||
} else {
|
||||
TouchAction::NoAction
|
||||
}
|
||||
},
|
||||
Flinging { .. } => {
|
||||
unreachable!("Touch Move event received without preceding down.")
|
||||
_ => {
|
||||
self.state = MultiTouch;
|
||||
TouchAction::NoAction
|
||||
},
|
||||
DefaultPrevented => TouchAction::DispatchEvent,
|
||||
Pinching => {
|
||||
let (d0, c0) = self.pinch_distance_and_center();
|
||||
self.active_touch_points[idx].point = point;
|
||||
let (d1, c1) = self.pinch_distance_and_center();
|
||||
|
||||
let magnification = d1 / d0;
|
||||
let scroll_delta = c1 - c0 * Scale::new(magnification);
|
||||
|
||||
TouchAction::Zoom(magnification, scroll_delta)
|
||||
},
|
||||
WaitingForScript => TouchAction::NoAction,
|
||||
MultiTouch => TouchAction::NoAction,
|
||||
Nothing => unreachable!(),
|
||||
};
|
||||
|
||||
// If we're still waiting to see whether this is a click or pan, remember the original
|
||||
// location. Otherwise, update the touch point with the latest location.
|
||||
if self.state != Touching && self.state != WaitingForScript {
|
||||
// update the touch point with the latest location.
|
||||
if self.state != Touching {
|
||||
self.active_touch_points[idx].point = point;
|
||||
}
|
||||
action
|
||||
|
@ -198,56 +180,37 @@ impl TouchHandler {
|
|||
None
|
||||
},
|
||||
};
|
||||
match self.state {
|
||||
Touching => {
|
||||
// FIXME: If the duration exceeds some threshold, send a contextmenu event instead.
|
||||
// FIXME: Don't send a click if preventDefault is called on the touchend event.
|
||||
self.state = Nothing;
|
||||
TouchAction::Click
|
||||
},
|
||||
Nothing => {
|
||||
self.state = Nothing;
|
||||
TouchAction::NoAction
|
||||
},
|
||||
Panning { velocity } if velocity.length().abs() >= FLING_MIN_SCREEN_PX => {
|
||||
// TODO: point != old. Not sure which one is better to take as cursor for flinging.
|
||||
debug!(
|
||||
"Transitioning to Fling. Cursor is {point:?}. Old cursor was {old:?}. \
|
||||
Raw velocity is {velocity:?}."
|
||||
);
|
||||
debug_assert!((point.x as i64) < (i32::MAX as i64));
|
||||
debug_assert!((point.y as i64) < (i32::MAX as i64));
|
||||
let cursor = DeviceIntPoint::new(point.x as i32, point.y as i32);
|
||||
// Multiplying the initial velocity gives the fling a much more snappy feel
|
||||
// and serves well as a poor-mans acceleration algorithm.
|
||||
let velocity = (velocity * 2.0).with_max_length(FLING_MAX_SCREEN_PX);
|
||||
self.state = Flinging { velocity, cursor };
|
||||
TouchAction::NoAction
|
||||
},
|
||||
Panning { .. } => {
|
||||
self.state = Nothing;
|
||||
TouchAction::NoAction
|
||||
},
|
||||
Pinching => {
|
||||
self.state = Panning {
|
||||
velocity: Vector2D::new(0.0, 0.0),
|
||||
};
|
||||
TouchAction::NoAction
|
||||
},
|
||||
Flinging { .. } => {
|
||||
unreachable!("On touchup received, but already flinging.")
|
||||
},
|
||||
WaitingForScript => {
|
||||
if self.active_touch_points.is_empty() {
|
||||
match self.touch_count() {
|
||||
0 => {
|
||||
if let Panning { velocity } = self.state {
|
||||
if velocity.length().abs() >= FLING_MIN_SCREEN_PX {
|
||||
// TODO: point != old. Not sure which one is better to take as cursor for flinging.
|
||||
debug!(
|
||||
"Transitioning to Fling. Cursor is {point:?}. Old cursor was {old:?}. \
|
||||
Raw velocity is {velocity:?}."
|
||||
);
|
||||
debug_assert!((point.x as i64) < (i32::MAX as i64));
|
||||
debug_assert!((point.y as i64) < (i32::MAX as i64));
|
||||
let cursor = DeviceIntPoint::new(point.x as i32, point.y as i32);
|
||||
// Multiplying the initial velocity gives the fling a much more snappy feel
|
||||
// and serves well as a poor-mans acceleration algorithm.
|
||||
let velocity = (velocity * 2.0).with_max_length(FLING_MAX_SCREEN_PX);
|
||||
TouchAction::Flinging(velocity, cursor)
|
||||
} else {
|
||||
self.state = Nothing;
|
||||
TouchAction::NoAction
|
||||
}
|
||||
} else {
|
||||
self.state = Nothing;
|
||||
return TouchAction::Click;
|
||||
if !self.prevent_click {
|
||||
TouchAction::Click(point)
|
||||
} else {
|
||||
TouchAction::NoAction
|
||||
}
|
||||
}
|
||||
TouchAction::NoAction
|
||||
},
|
||||
DefaultPrevented | MultiTouch => {
|
||||
if self.active_touch_points.is_empty() {
|
||||
self.state = Nothing;
|
||||
}
|
||||
_ => {
|
||||
self.state = Touching;
|
||||
TouchAction::NoAction
|
||||
},
|
||||
}
|
||||
|
@ -263,35 +226,11 @@ impl TouchHandler {
|
|||
return;
|
||||
},
|
||||
}
|
||||
match self.state {
|
||||
Nothing => {},
|
||||
Touching | Panning { .. } | Flinging { .. } => {
|
||||
self.state = Nothing;
|
||||
},
|
||||
Pinching => {
|
||||
self.state = Panning {
|
||||
velocity: Vector2D::new(0.0, 0.0),
|
||||
};
|
||||
},
|
||||
WaitingForScript | DefaultPrevented | MultiTouch => {
|
||||
if self.active_touch_points.is_empty() {
|
||||
self.state = Nothing;
|
||||
}
|
||||
},
|
||||
}
|
||||
self.state = Nothing;
|
||||
}
|
||||
|
||||
pub fn on_event_processed(&mut self, result: EventResult) {
|
||||
if let WaitingForScript = self.state {
|
||||
self.state = match result {
|
||||
EventResult::DefaultPrevented => DefaultPrevented,
|
||||
EventResult::DefaultAllowed => match self.touch_count() {
|
||||
1 => Touching,
|
||||
2 => Pinching,
|
||||
_ => MultiTouch,
|
||||
},
|
||||
}
|
||||
}
|
||||
pub fn on_fling(&mut self, velocity: Vector2D<f32, DevicePixel>, cursor: DeviceIntPoint) {
|
||||
self.state = Flinging { velocity, cursor };
|
||||
}
|
||||
|
||||
fn touch_count(&self) -> usize {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue