mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
add cancelable
property to the TouchEvent
(#35713)
* add `cancelable` property to the `TouchEvent` set cancellable = false when sending move events to script, if the first touch_move event did not cancel it Signed-off-by: kongbai1996 <1782765876@qq.com> * modified review commentss Signed-off-by: kongbai1996 <1782765876@qq.com> --------- Signed-off-by: kongbai1996 <1782765876@qq.com>
This commit is contained in:
parent
67bd557f30
commit
929f87f598
3 changed files with 17 additions and 2 deletions
|
@ -1396,7 +1396,7 @@ impl IOCompositor {
|
||||||
self.send_touch_event(event);
|
self.send_touch_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_touch_move(&mut self, event: TouchEvent) {
|
fn on_touch_move(&mut self, mut event: TouchEvent) {
|
||||||
let action: TouchMoveAction = self.touch_handler.on_touch_move(event.id, event.point);
|
let action: TouchMoveAction = self.touch_handler.on_touch_move(event.id, event.point);
|
||||||
if TouchMoveAction::NoAction != action {
|
if TouchMoveAction::NoAction != action {
|
||||||
// if first move processed and allowed, we directly process the move event,
|
// if first move processed and allowed, we directly process the move event,
|
||||||
|
@ -1405,6 +1405,8 @@ impl IOCompositor {
|
||||||
.touch_handler
|
.touch_handler
|
||||||
.move_allowed(self.touch_handler.current_sequence_id)
|
.move_allowed(self.touch_handler.current_sequence_id)
|
||||||
{
|
{
|
||||||
|
// https://w3c.github.io/touch-events/#cancelability
|
||||||
|
event.disable_cancelable();
|
||||||
match action {
|
match action {
|
||||||
TouchMoveAction::Scroll(delta, point) => self.on_scroll_window_event(
|
TouchMoveAction::Scroll(delta, point) => self.on_scroll_window_event(
|
||||||
ScrollLocation::Delta(LayoutVector2D::from_untyped(delta.to_untyped())),
|
ScrollLocation::Delta(LayoutVector2D::from_untyped(delta.to_untyped())),
|
||||||
|
|
|
@ -2090,7 +2090,7 @@ impl Document {
|
||||||
window,
|
window,
|
||||||
DOMString::from(event_name),
|
DOMString::from(event_name),
|
||||||
EventBubbles::Bubbles,
|
EventBubbles::Bubbles,
|
||||||
EventCancelable::Cancelable,
|
EventCancelable::from(event.is_cancelable()),
|
||||||
Some(window),
|
Some(window),
|
||||||
0i32,
|
0i32,
|
||||||
&touches,
|
&touches,
|
||||||
|
|
|
@ -147,6 +147,8 @@ pub struct TouchEvent {
|
||||||
pub event_type: TouchEventType,
|
pub event_type: TouchEventType,
|
||||||
pub id: TouchId,
|
pub id: TouchId,
|
||||||
pub point: DevicePoint,
|
pub point: DevicePoint,
|
||||||
|
/// cancelable default value is true, once the first move has been processed by script disable it.
|
||||||
|
cancelable: bool,
|
||||||
/// The sequence_id will be set by servo's touch handler.
|
/// The sequence_id will be set by servo's touch handler.
|
||||||
sequence_id: Option<TouchSequenceId>,
|
sequence_id: Option<TouchSequenceId>,
|
||||||
}
|
}
|
||||||
|
@ -158,6 +160,7 @@ impl TouchEvent {
|
||||||
id,
|
id,
|
||||||
point,
|
point,
|
||||||
sequence_id: None,
|
sequence_id: None,
|
||||||
|
cancelable: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Embedders should ignore this.
|
/// Embedders should ignore this.
|
||||||
|
@ -175,6 +178,16 @@ impl TouchEvent {
|
||||||
pub fn expect_sequence_id(&self) -> TouchSequenceId {
|
pub fn expect_sequence_id(&self) -> TouchSequenceId {
|
||||||
self.sequence_id.expect("Sequence ID not initialized")
|
self.sequence_id.expect("Sequence ID not initialized")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub fn disable_cancelable(&mut self) {
|
||||||
|
self.cancelable = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub fn is_cancelable(&self) -> bool {
|
||||||
|
self.cancelable
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mode to measure WheelDelta floats in
|
/// Mode to measure WheelDelta floats in
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue