git.lucas.co / cce-browser
web browser (Servo)
git clone https://git.lucas.co/cce-browser.git

examples/wpe_ctx.rs (1.9K)

 1 //! Right-click → context-menu signal → hit-test info, end to end.
 2 //! `cce-shadow --instance <n> run ./target/release/examples/wpe_ctx`
 3 
 4 #[cfg(not(feature = "wpe"))]
 5 fn main() { eprintln!("build with --features wpe"); }
 6 
 7 #[cfg(feature = "wpe")]
 8 #[derive(Debug, Clone, Copy)]
 9 pub enum EditingCommand { Copy, Cut, Paste }
10 
11 #[cfg(feature = "wpe")]
12 #[path = "../src/pages.rs"]
13 mod pages;
14 #[cfg(feature = "wpe")]
15 #[path = "../src/downloads.rs"]
16 mod downloads;
17 #[cfg(feature = "wpe")]
18 #[path = "../src/wpe/mod.rs"]
19 mod wpe;
20 
21 #[cfg(feature = "wpe")]
22 fn main() {
23     use cce_ui::widget::MouseButton;
24     let url = "http://127.0.0.1:8795/ctx.html";
25     let mut host = wpe::WebKitHost::new(url::Url::parse(url).unwrap(), (1200, 800));
26     let settle = |h: &mut wpe::WebKitHost, n: u32| {
27         for _ in 0..n { h.pump(); std::thread::sleep(std::time::Duration::from_millis(50)); }
28     };
29     settle(&mut host, 30);
30     println!("loaded: {:?}", host.title());
31 
32     let rclick = |h: &mut wpe::WebKitHost, x: f32, y: f32| {
33         h.mouse_move(x, y);
34         h.mouse_button_ui(MouseButton::Right, true, x, y);
35         h.mouse_button_ui(MouseButton::Right, false, x, y);
36     };
37 
38     println!("-- right-click the link (150,40) --");
39     rclick(&mut host, 150.0, 40.0);
40     settle(&mut host, 8);
41     let on_link = host.take_context_menu();
42     println!("   {on_link:?}");
43 
44     println!("-- right-click the input (150,175) --");
45     rclick(&mut host, 150.0, 175.0);
46     settle(&mut host, 8);
47     let on_input = host.take_context_menu();
48     println!("   {on_input:?}");
49 
50     println!("\n=== RESULT ===");
51     let link_ok = on_link.as_ref().and_then(|i| i.link.as_ref())
52         .is_some_and(|(u, _)| u == "https://example.org/target");
53     println!("  link uri      {}", if link_ok { "OK" } else { "MISSING" });
54     println!("  editable flag {}", if on_input.is_some_and(|i| i.is_editable) { "OK" } else { "MISSING" });
55 }