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

@ -18,6 +18,7 @@ webxr = ["dep:webxr-api"]
base = { workspace = true }
cfg-if = { workspace = true }
crossbeam-channel = { workspace = true }
euclid = { workspace = true }
http = { workspace = true }
hyper_serde = { workspace = true }
ipc-channel = { workspace = true }

View file

@ -2,10 +2,11 @@
* 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 euclid::Vector2D;
use keyboard_types::{CompositionEvent, KeyboardEvent};
use malloc_size_of_derive::MallocSizeOf;
use serde::{Deserialize, Serialize};
pub use webrender_api::units::DevicePoint;
use webrender_api::units::{DeviceIntPoint, DevicePixel, DevicePoint};
/// An input event that is sent from the embedder to Servo.
#[derive(Clone, Debug, Deserialize, Serialize)]
@ -104,7 +105,7 @@ pub struct MouseMoveEvent {
/// The type of input represented by a multi-touch event.
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub enum TouchEventAction {
pub enum TouchEventType {
/// A new touch point came in contact with the screen.
Down,
/// An existing touch point changed location.
@ -115,6 +116,21 @@ pub enum TouchEventAction {
Cancel,
}
/// The action to take in response to a touch event
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
pub enum TouchAction {
/// Simulate a mouse click.
Click(DevicePoint),
/// Fling by the provided offset
Flinging(Vector2D<f32, DevicePixel>, DeviceIntPoint),
/// Scroll by the provided offset.
Scroll(Vector2D<f32, DevicePixel>, DevicePoint),
/// Zoom by a magnification factor and scroll by the provided offset.
Zoom(f32, Vector2D<f32, DevicePixel>),
/// Don't do anything.
NoAction,
}
/// An opaque identifier for a touch point.
///
/// <http://w3c.github.io/touch-events/#widl-Touch-identifier>
@ -123,9 +139,10 @@ pub struct TouchId(pub i32);
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub struct TouchEvent {
pub action: TouchEventAction,
pub event_type: TouchEventType,
pub id: TouchId,
pub point: DevicePoint,
pub action: TouchAction,
}
/// Mode to measure WheelDelta floats in