mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
ohos: Remove custom touch history code (#33113)
The TouchHandler in servo already does the equivalent, so there is no need to have this code in the OH specific code. Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>
This commit is contained in:
parent
e078353bf0
commit
3576c02ae2
1 changed files with 13 additions and 97 deletions
|
@ -77,7 +77,6 @@ enum TouchEventType {
|
|||
Down,
|
||||
Up,
|
||||
Move,
|
||||
Scroll { dx: f32, dy: f32 },
|
||||
Cancel,
|
||||
Unknown,
|
||||
}
|
||||
|
@ -95,45 +94,10 @@ enum ServoAction {
|
|||
Initialize(Box<InitOpts>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
enum Direction2D {
|
||||
Horizontal,
|
||||
Vertical,
|
||||
#[default]
|
||||
Free,
|
||||
}
|
||||
#[derive(Clone, Debug)]
|
||||
struct TouchTracker {
|
||||
last_position: Point2D<f32, f32>,
|
||||
}
|
||||
|
||||
impl TouchTracker {
|
||||
fn new(first_point: Point2D<f32, f32>) -> Self {
|
||||
TouchTracker {
|
||||
last_position: first_point,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Todo: Need to check if OnceLock is suitable, or if the TS function can be destroyed, e.g.
|
||||
// if the activity gets suspended.
|
||||
static SET_URL_BAR_CB: OnceLock<ThreadsafeFunction<String, ErrorStrategy::Fatal>> = OnceLock::new();
|
||||
|
||||
struct TsThreadState {
|
||||
// last_touch_event: Option<OH_NativeXComponent_TouchEvent>,
|
||||
velocity_tracker: Option<TouchTracker>,
|
||||
}
|
||||
|
||||
impl TsThreadState {
|
||||
const fn new() -> Self {
|
||||
Self {
|
||||
velocity_tracker: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static mut TS_THREAD_STATE: TsThreadState = TsThreadState::new();
|
||||
|
||||
impl ServoAction {
|
||||
fn dispatch_touch_event(
|
||||
servo: &mut ServoGlue,
|
||||
|
@ -145,7 +109,6 @@ impl ServoAction {
|
|||
match kind {
|
||||
TouchEventType::Down => servo.touch_down(x, y, pointer_id),
|
||||
TouchEventType::Up => servo.touch_up(x, y, pointer_id),
|
||||
TouchEventType::Scroll { dx, dy } => servo.scroll(dx, dy, x as i32, y as i32),
|
||||
TouchEventType::Move => servo.touch_move(x, y, pointer_id),
|
||||
TouchEventType::Cancel => servo.touch_cancel(x, y, pointer_id),
|
||||
TouchEventType::Unknown => Err("Can't dispatch Unknown Touch Event"),
|
||||
|
@ -252,66 +215,19 @@ pub extern "C" fn on_dispatch_touch_event_cb(
|
|||
return;
|
||||
}
|
||||
let touch_event = unsafe { touch_event.assume_init() };
|
||||
let kind: TouchEventType =
|
||||
match touch_event.type_ {
|
||||
OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_DOWN => {
|
||||
if touch_event.id == 0 {
|
||||
unsafe {
|
||||
let old = TS_THREAD_STATE.velocity_tracker.replace(TouchTracker::new(
|
||||
Point2D::new(touch_event.x, touch_event.y),
|
||||
));
|
||||
assert!(old.is_none());
|
||||
}
|
||||
}
|
||||
TouchEventType::Down
|
||||
},
|
||||
OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_UP => {
|
||||
if touch_event.id == 0 {
|
||||
unsafe {
|
||||
let old = TS_THREAD_STATE.velocity_tracker.take();
|
||||
assert!(old.is_some());
|
||||
}
|
||||
}
|
||||
TouchEventType::Up
|
||||
},
|
||||
OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_MOVE => {
|
||||
// SAFETY: We only access TS_THREAD_STATE from the main TS thread.
|
||||
if touch_event.id == 0 {
|
||||
let (lastX, lastY) = unsafe {
|
||||
if let Some(last_event) = &mut TS_THREAD_STATE.velocity_tracker {
|
||||
let touch_point = last_event.last_position;
|
||||
last_event.last_position = Point2D::new(touch_event.x, touch_event.y);
|
||||
(touch_point.x, touch_point.y)
|
||||
} else {
|
||||
error!("Move Event received, but no previous touch event was stored!");
|
||||
// todo: handle this error case
|
||||
panic!("Move Event received, but no previous touch event was stored!");
|
||||
}
|
||||
};
|
||||
let dx = touch_event.x - lastX;
|
||||
let dy = touch_event.y - lastY;
|
||||
TouchEventType::Scroll { dx, dy }
|
||||
} else {
|
||||
TouchEventType::Move
|
||||
}
|
||||
},
|
||||
OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_CANCEL => {
|
||||
if touch_event.id == 0 {
|
||||
unsafe {
|
||||
let old = TS_THREAD_STATE.velocity_tracker.take();
|
||||
assert!(old.is_some());
|
||||
}
|
||||
}
|
||||
TouchEventType::Cancel
|
||||
},
|
||||
_ => {
|
||||
error!(
|
||||
"Failed to dispatch call for touch Event {:?}",
|
||||
touch_event.type_
|
||||
);
|
||||
TouchEventType::Unknown
|
||||
},
|
||||
};
|
||||
let kind: TouchEventType = match touch_event.type_ {
|
||||
OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_DOWN => TouchEventType::Down,
|
||||
OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_UP => TouchEventType::Up,
|
||||
OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_MOVE => TouchEventType::Move,
|
||||
OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_CANCEL => TouchEventType::Cancel,
|
||||
_ => {
|
||||
error!(
|
||||
"Failed to dispatch call for touch Event {:?}",
|
||||
touch_event.type_
|
||||
);
|
||||
TouchEventType::Unknown
|
||||
},
|
||||
};
|
||||
if let Err(e) = call(ServoAction::TouchEvent {
|
||||
kind,
|
||||
x: touch_event.x,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue