lector_servo_native/
lib.rs1use std::time::Duration;
2
3#[derive(Debug, Clone)]
4pub struct NativeServoFrame {
5 pub width: u32,
6 pub height: u32,
7 pub rgba: Vec<u8>,
8}
9
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub struct NativeTabInfo {
12 pub title: String,
13 pub url: String,
14 pub active: bool,
15}
16
17#[derive(Debug, Clone)]
18pub struct NativeServoConfig {
19 pub url: String,
20 pub width: u32,
21 pub height: u32,
22 pub settle_timeout: Duration,
23}
24
25impl Default for NativeServoConfig {
26 fn default() -> Self {
27 Self {
28 url: "about:blank".to_string(),
29 width: 800,
30 height: 600,
31 settle_timeout: Duration::from_secs(5),
32 }
33 }
34}
35
36pub struct NativeServoAdapter {
37 config: NativeServoConfig,
38}
39
40impl NativeServoAdapter {
41 pub fn new(config: NativeServoConfig) -> Result<Self, String> {
42 Err(format!(
43 "native Servo embedding is repository-only for now; build Lector from source with vendored Servo to open {}",
44 config.url
45 ))
46 }
47
48 pub fn spin_until_frame(&self, timeout: Duration) {
49 let _ = timeout;
50 }
51
52 pub fn pump(&self, timeout: Duration) -> bool {
53 let _ = timeout;
54 false
55 }
56
57 pub fn capture(&self) -> Result<NativeServoFrame, String> {
58 Err("native Servo embedding is not available in this placeholder crate".to_string())
59 }
60
61 pub fn tabs(&self) -> Vec<NativeTabInfo> {
62 vec![NativeTabInfo {
63 title: self.config.url.clone(),
64 url: self.config.url.clone(),
65 active: true,
66 }]
67 }
68
69 pub fn switch_tab(&self, index: usize) {
70 let _ = index;
71 }
72
73 pub fn new_tab(&self, url: &str) {
74 let _ = url;
75 }
76
77 pub fn close_active_tab(&self) {}
78
79 pub fn load_url(&self, url: &str) -> Result<(), String> {
80 let _ = url;
81 Err("native Servo embedding is not available in this placeholder crate".to_string())
82 }
83
84 pub fn resize(&self, width: u32, height: u32) {
85 let _ = (width, height);
86 }
87
88 pub fn mouse_move(&self, x: u32, y: u32) {
89 let _ = (x, y);
90 }
91
92 pub fn mouse_button(
93 &self,
94 action: NativeMouseButtonAction,
95 button: NativeMouseButton,
96 x: u32,
97 y: u32,
98 ) {
99 let _ = (action, button, x, y);
100 }
101
102 pub fn wheel(&self, dx: i32, dy: i32, x: u32, y: u32) {
103 let _ = (dx, dy, x, y);
104 }
105
106 pub fn insert_text(&self, text: &str) {
107 let _ = text;
108 }
109
110 pub fn key_press(&self, key: NativeKey) {
111 let _ = key;
112 }
113}
114
115#[derive(Debug, Clone, Copy, PartialEq, Eq)]
116pub enum NativeMouseButton {
117 Left,
118 Middle,
119 Right,
120 Other,
121}
122
123#[derive(Debug, Clone, Copy, PartialEq, Eq)]
124pub enum NativeMouseButtonAction {
125 Down,
126 Up,
127}
128
129#[derive(Debug, Clone, Copy, PartialEq, Eq)]
130pub enum NativeKey {
131 Up,
132 Down,
133 Left,
134 Right,
135 PageUp,
136 PageDown,
137 Enter,
138 Backspace,
139}
140
141pub fn render_once(config: NativeServoConfig) -> Result<NativeServoFrame, String> {
142 let _ = config;
143 Err("native Servo embedding is repository-only for now".to_string())
144}