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:
Bi Fuguo 2025-02-17 18:50:04 +08:00 committed by GitHub
parent 6dce329acc
commit 3fe42a0b5a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 273 additions and 255 deletions

View file

@ -23,7 +23,8 @@ use servo::{
InputMethodType, Key, KeyState, KeyboardEvent, LoadStatus, MediaSessionActionType,
MediaSessionEvent, MouseButton, MouseButtonAction, MouseButtonEvent, MouseMoveEvent,
NavigationRequest, PermissionRequest, PromptDefinition, PromptOrigin, PromptResult, Servo,
ServoDelegate, ServoError, TouchEvent, TouchEventAction, TouchId, WebView, WebViewDelegate,
ServoDelegate, ServoError, TouchAction, TouchEvent, TouchEventType, TouchId, WebView,
WebViewDelegate,
};
use url::Url;
@ -449,7 +450,7 @@ impl RunningAppState {
self.active_webview().notify_scroll_event(
scroll_location,
Point2D::new(x, y),
TouchEventAction::Down,
TouchEventType::Down,
);
self.perform_updates();
}
@ -463,7 +464,7 @@ impl RunningAppState {
self.active_webview().notify_scroll_event(
scroll_location,
Point2D::new(x, y),
TouchEventAction::Move,
TouchEventType::Move,
);
self.perform_updates();
}
@ -478,7 +479,7 @@ impl RunningAppState {
self.active_webview().notify_scroll_event(
scroll_location,
Point2D::new(x, y),
TouchEventAction::Up,
TouchEventType::Up,
);
self.perform_updates();
}
@ -487,9 +488,10 @@ impl RunningAppState {
pub fn touch_down(&self, x: f32, y: f32, pointer_id: i32) {
self.active_webview()
.notify_input_event(InputEvent::Touch(TouchEvent {
action: TouchEventAction::Down,
event_type: TouchEventType::Down,
id: TouchId(pointer_id),
point: Point2D::new(x, y),
action: TouchAction::NoAction,
}));
self.perform_updates();
}
@ -498,9 +500,10 @@ impl RunningAppState {
pub fn touch_move(&self, x: f32, y: f32, pointer_id: i32) {
self.active_webview()
.notify_input_event(InputEvent::Touch(TouchEvent {
action: TouchEventAction::Move,
event_type: TouchEventType::Move,
id: TouchId(pointer_id),
point: Point2D::new(x, y),
action: TouchAction::NoAction,
}));
self.perform_updates();
}
@ -509,9 +512,10 @@ impl RunningAppState {
pub fn touch_up(&self, x: f32, y: f32, pointer_id: i32) {
self.active_webview()
.notify_input_event(InputEvent::Touch(TouchEvent {
action: TouchEventAction::Up,
event_type: TouchEventType::Up,
id: TouchId(pointer_id),
point: Point2D::new(x, y),
action: TouchAction::NoAction,
}));
self.perform_updates();
}
@ -520,9 +524,10 @@ impl RunningAppState {
pub fn touch_cancel(&self, x: f32, y: f32, pointer_id: i32) {
self.active_webview()
.notify_input_event(InputEvent::Touch(TouchEvent {
action: TouchEventAction::Cancel,
event_type: TouchEventType::Cancel,
id: TouchId(pointer_id),
point: Point2D::new(x, y),
action: TouchAction::NoAction,
}));
self.perform_updates();
}