S006: R4-05 clicks, keys and wheel reach web pages again
window_input asked egui's is_pointer_over_egui, which is true over the page because it sits in the central panel; only floating layers count now. Selftest click/rclick/pagescroll go through window_input, pagetype types into the page, assert fails the smoke run; tests/smoke/input.txt fails on the old code. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
parent
bed183c2db
commit
3f213ccbe1
3 changed files with 139 additions and 20 deletions
|
|
@ -1846,7 +1846,7 @@ impl ApplicationHandler<AppEvent> for App {
|
|||
|
||||
impl App {
|
||||
/// Keyboard and pointer input that isn't a redraw, resize or focus change.
|
||||
fn window_input(&mut self, window_id: WindowId, event: &WindowEvent) {
|
||||
pub(crate) fn window_input(&mut self, window_id: WindowId, event: &WindowEvent) {
|
||||
let keymap_action = if let WindowEvent::KeyboardInput { event: key, .. } = event {
|
||||
let mods = self.windows.get(&window_id).map(|w| w.modifiers).unwrap_or_default();
|
||||
Shortcut::from_event(key, mods).and_then(|s| self.shared.keymap.borrow().action_for(&s))
|
||||
|
|
@ -1856,7 +1856,11 @@ impl App {
|
|||
let Some(win) = self.windows.get_mut(&window_id) else { return };
|
||||
win.last_input = Instant::now();
|
||||
let egui_wants_keys = win.egui.egui_ctx.egui_wants_keyboard_input();
|
||||
let pointer_over_ui = win.egui.egui_ctx.is_pointer_over_egui();
|
||||
// Not `is_pointer_over_egui`: the page sits in egui's central panel, so that is true over the page too.
|
||||
let pointer_over_ui = match event {
|
||||
WindowEvent::CursorMoved { position, .. } => win.over_overlay(*position),
|
||||
_ => win.pointer.is_some_and(|p| win.over_overlay(p)),
|
||||
};
|
||||
let dialog_open = win.tab().is_some_and(|t| t.dialog.is_some()) || win.ui.blocks_page();
|
||||
match event {
|
||||
WindowEvent::ModifiersChanged(mods) => {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,12 @@
|
|||
//! update_lists, check_updates, close_tab, select <n>, zoom <step>,
|
||||
//! find <text>, download <url>, navigate <typed text>, mute, pin
|
||||
//! js <script> run JavaScript in the current tab; the result goes to the log
|
||||
//! click <x> <y> click in the page at CSS-ish pixel x,y (from the page's top left)
|
||||
//! assert <js expression> the expression must give true, else `ASSERT FAILED` in the log fails the smoke run
|
||||
//! click <x> <y> click in the page at CSS-ish pixel x,y (from the page's top left), through the
|
||||
//! window's input path; `rclick` the same with the right button (context menu)
|
||||
//! pagescroll <x> <y> <dy> turn the wheel over the page at x,y (as `click`) by dy pixels (positive: down)
|
||||
//! pagetype <text> type text into the page, if it has keyboard focus (after a `click` in a field);
|
||||
//! `{enter}` in the text presses Enter
|
||||
//! pointer <x> <y> | off move the interface's pointer to x,y in the page area (new tab backgrounds follow it)
|
||||
//! key <name> press and release a key in the interface: enter, escape, tab, space or a letter
|
||||
//! tap <x> <y> click the interface (not the web page) at x,y in the window (logical px, as in a
|
||||
|
|
@ -263,31 +268,92 @@ impl App {
|
|||
};
|
||||
self.run_in(window, command);
|
||||
},
|
||||
"js" => {
|
||||
"js" | "assert" => {
|
||||
let Some(web) = self.windows.get(&window).and_then(|w| w.active_webview()).cloned() else {
|
||||
self.selftest_log("js: no page");
|
||||
self.selftest_log(&format!("{verb}: no page"));
|
||||
if verb == "assert" {
|
||||
self.selftest_log(&format!("ASSERT FAILED (no page): {rest}"));
|
||||
}
|
||||
return;
|
||||
};
|
||||
let log_path = dir.join("selftest.log");
|
||||
let assert = verb == "assert";
|
||||
let script = rest.to_owned();
|
||||
web.evaluate_javascript(rest.to_owned(), move |result| {
|
||||
use std::io::Write as _;
|
||||
if let Ok(mut f) = std::fs::OpenOptions::new().create(true).append(true).open(&log_path) {
|
||||
let _ = writeln!(f, "js -> {result:?}");
|
||||
if !assert {
|
||||
let _ = writeln!(f, "js -> {result:?}");
|
||||
} else if matches!(result, Ok(servo::JSValue::Boolean(true))) {
|
||||
let _ = writeln!(f, "assert ok: {script}");
|
||||
} else {
|
||||
let _ = writeln!(f, "ASSERT FAILED ({result:?}): {script}");
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
"click" => {
|
||||
"pagescroll" => {
|
||||
// Turn the wheel over the page at x,y (page pixels, as `click`) by dy pixels, through `window_input`.
|
||||
let mut parts = rest.split_whitespace().filter_map(|p| p.parse::<f64>().ok());
|
||||
let (x, y, dy) = (parts.next().unwrap_or(0.0), parts.next().unwrap_or(0.0), parts.next().unwrap_or(0.0));
|
||||
let pos = self.windows.get(&window).and_then(|win| {
|
||||
let rect = win.page_rect?;
|
||||
let scale = win.egui.egui_ctx.pixels_per_point() as f64;
|
||||
Some(winit::dpi::PhysicalPosition::new((rect.min.x as f64 + x) * scale, (rect.min.y as f64 + y) * scale))
|
||||
});
|
||||
if let Some(position) = pos {
|
||||
use winit::event::{DeviceId, MouseScrollDelta, TouchPhase, WindowEvent};
|
||||
let device_id = DeviceId::dummy();
|
||||
self.window_input(window, &WindowEvent::CursorMoved { device_id, position });
|
||||
let delta = MouseScrollDelta::PixelDelta(winit::dpi::PhysicalPosition::new(0.0, -dy));
|
||||
self.window_input(window, &WindowEvent::MouseWheel { device_id, delta, phase: TouchPhase::Moved });
|
||||
} else {
|
||||
self.selftest_log("pagescroll: no web page in this tab");
|
||||
}
|
||||
},
|
||||
"click" | "rclick" => {
|
||||
// Through the window's real input path (pointer over UI, dialogs, focus), as a user's click would.
|
||||
let mut parts = rest.split_whitespace().filter_map(|p| p.parse::<f64>().ok());
|
||||
let (x, y) = (parts.next().unwrap_or(0.0), parts.next().unwrap_or(0.0));
|
||||
if let Some(win) = self.windows.get_mut(&window)
|
||||
&& let Some(rect) = win.page_rect
|
||||
{
|
||||
let pos = self.windows.get(&window).and_then(|win| {
|
||||
let rect = win.page_rect?;
|
||||
let scale = win.egui.egui_ctx.pixels_per_point() as f64;
|
||||
let pos = winit::dpi::PhysicalPosition::new((rect.min.x as f64 + x) * scale, (rect.min.y as f64 + y) * scale);
|
||||
win.pointer = Some(pos);
|
||||
win.send_mouse_move(pos);
|
||||
win.send_mouse_button(winit::event::ElementState::Pressed, winit::event::MouseButton::Left);
|
||||
win.send_mouse_button(winit::event::ElementState::Released, winit::event::MouseButton::Left);
|
||||
Some(winit::dpi::PhysicalPosition::new((rect.min.x as f64 + x) * scale, (rect.min.y as f64 + y) * scale))
|
||||
});
|
||||
if let Some(position) = pos {
|
||||
use winit::event::{DeviceId, ElementState, MouseButton, WindowEvent};
|
||||
let button = if verb == "rclick" { MouseButton::Right } else { MouseButton::Left };
|
||||
let device_id = DeviceId::dummy();
|
||||
self.window_input(window, &WindowEvent::CursorMoved { device_id, position });
|
||||
for state in [ElementState::Pressed, ElementState::Released] {
|
||||
self.window_input(window, &WindowEvent::MouseInput { device_id, state, button });
|
||||
}
|
||||
} else {
|
||||
self.selftest_log("click: no web page in this tab");
|
||||
}
|
||||
},
|
||||
"pagetype" => {
|
||||
// Type text into the focused web page, if the page has keyboard focus as `window_input` decides it.
|
||||
if let Some(win) = self.windows.get(&window) {
|
||||
let takes = win.page_focused && !win.egui.egui_ctx.egui_wants_keyboard_input() && !win.tab().is_some_and(|t| t.dialog.is_some());
|
||||
match (takes, win.active_webview()) {
|
||||
(true, Some(web)) => {
|
||||
let mut keys: Vec<(keyboard_types::Key, keyboard_types::Code)> = Vec::new();
|
||||
for (i, part) in rest.split("{enter}").enumerate() {
|
||||
if i > 0 {
|
||||
keys.push((keyboard_types::Key::Named(keyboard_types::NamedKey::Enter), keyboard_types::Code::Enter));
|
||||
}
|
||||
keys.extend(part.chars().map(|c| (keyboard_types::Key::Character(c.to_string()), keyboard_types::Code::Unidentified)));
|
||||
}
|
||||
for (key, code) in keys {
|
||||
for state in [keyboard_types::KeyState::Down, keyboard_types::KeyState::Up] {
|
||||
let ev = keyboard_types::KeyboardEvent { state, key: key.clone(), code, ..Default::default() };
|
||||
web.notify_input_event(servo::InputEvent::Keyboard(servo::KeyboardEvent::new(ev)));
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => self.selftest_log("pagetype: the page doesn't have keyboard focus"),
|
||||
}
|
||||
}
|
||||
},
|
||||
"type" => {
|
||||
|
|
|
|||
|
|
@ -325,6 +325,14 @@ impl BrowserWindow {
|
|||
(x >= 0.0 && y >= 0.0 && x < w && y < h).then(|| servo::DevicePoint::new(x as f32, y as f32))
|
||||
}
|
||||
|
||||
/// A flyout, menu, toast or other floating egui layer is under the pointer (the chrome's panels and the page
|
||||
/// area are background layers and don't count).
|
||||
pub fn over_overlay(&self, pos: PhysicalPosition<f64>) -> bool {
|
||||
let scale = self.egui.egui_ctx.pixels_per_point() as f64;
|
||||
let p = egui::pos2((pos.x / scale) as f32, (pos.y / scale) as f32);
|
||||
self.egui.egui_ctx.layer_id_at(p).is_some_and(|l| l.order != egui::Order::Background)
|
||||
}
|
||||
|
||||
/// Like `page_point` but clamped, for drags that leave the page.
|
||||
pub fn page_point_clamped(&self, pos: PhysicalPosition<f64>) -> Option<servo::DevicePoint> {
|
||||
let rect = self.page_rect?;
|
||||
|
|
|
|||
Loading…
Reference in a new issue