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

examples/wpe_ctx.rs (2K)

 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 // The host's vi channel and scripts.
19 #[path = "../src/vi.rs"]
20 #[allow(dead_code)]
21 mod vi;
22 
23 #[path = "../src/wpe/mod.rs"]
24 mod wpe;
25 
26 #[cfg(feature = "wpe")]
27 fn main() {
28     use cce_ui::widget::MouseButton;
29     let url = "http://127.0.0.1:8795/ctx.html";
30     let mut host = wpe::WebKitHost::new(url::Url::parse(url).unwrap(), (1200, 800));
31     let settle = |h: &mut wpe::WebKitHost, n: u32| {
32         for _ in 0..n { h.pump(); h.frame_drawn(); std::thread::sleep(std::time::Duration::from_millis(50)); }
33     };
34     settle(&mut host, 30);
35     println!("loaded: {:?}", host.title());
36 
37     let rclick = |h: &mut wpe::WebKitHost, x: f32, y: f32| {
38         h.mouse_move(x, y);
39         h.mouse_button_ui(MouseButton::Right, true, x, y);
40         h.mouse_button_ui(MouseButton::Right, false, x, y);
41     };
42 
43     println!("-- right-click the link (150,40) --");
44     rclick(&mut host, 150.0, 40.0);
45     settle(&mut host, 8);
46     let on_link = host.take_context_menu();
47     println!("   {on_link:?}");
48 
49     println!("-- right-click the input (150,175) --");
50     rclick(&mut host, 150.0, 175.0);
51     settle(&mut host, 8);
52     let on_input = host.take_context_menu();
53     println!("   {on_input:?}");
54 
55     println!("\n=== RESULT ===");
56     let link_ok = on_link.as_ref().and_then(|i| i.link.as_ref())
57         .is_some_and(|(u, _)| u == "https://example.org/target");
58     println!("  link uri      {}", if link_ok { "OK" } else { "MISSING" });
59     println!("  editable flag {}", if on_input.is_some_and(|i| i.is_editable) { "OK" } else { "MISSING" });
60 }