lector-servo-native 0.1.0

API placeholder for Lector's repository-only native Servo adapter.
Documentation
use std::time::Duration;

#[derive(Debug, Clone)]
pub struct NativeServoFrame {
    pub width: u32,
    pub height: u32,
    pub rgba: Vec<u8>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NativeTabInfo {
    pub title: String,
    pub url: String,
    pub active: bool,
}

#[derive(Debug, Clone)]
pub struct NativeServoConfig {
    pub url: String,
    pub width: u32,
    pub height: u32,
    pub settle_timeout: Duration,
}

impl Default for NativeServoConfig {
    fn default() -> Self {
        Self {
            url: "about:blank".to_string(),
            width: 800,
            height: 600,
            settle_timeout: Duration::from_secs(5),
        }
    }
}

pub struct NativeServoAdapter {
    config: NativeServoConfig,
}

impl NativeServoAdapter {
    pub fn new(config: NativeServoConfig) -> Result<Self, String> {
        Err(format!(
            "native Servo embedding is repository-only for now; build Lector from source with vendored Servo to open {}",
            config.url
        ))
    }

    pub fn spin_until_frame(&self, timeout: Duration) {
        let _ = timeout;
    }

    pub fn pump(&self, timeout: Duration) -> bool {
        let _ = timeout;
        false
    }

    pub fn capture(&self) -> Result<NativeServoFrame, String> {
        Err("native Servo embedding is not available in this placeholder crate".to_string())
    }

    pub fn tabs(&self) -> Vec<NativeTabInfo> {
        vec![NativeTabInfo {
            title: self.config.url.clone(),
            url: self.config.url.clone(),
            active: true,
        }]
    }

    pub fn switch_tab(&self, index: usize) {
        let _ = index;
    }

    pub fn new_tab(&self, url: &str) {
        let _ = url;
    }

    pub fn close_active_tab(&self) {}

    pub fn load_url(&self, url: &str) -> Result<(), String> {
        let _ = url;
        Err("native Servo embedding is not available in this placeholder crate".to_string())
    }

    pub fn resize(&self, width: u32, height: u32) {
        let _ = (width, height);
    }

    pub fn mouse_move(&self, x: u32, y: u32) {
        let _ = (x, y);
    }

    pub fn mouse_button(
        &self,
        action: NativeMouseButtonAction,
        button: NativeMouseButton,
        x: u32,
        y: u32,
    ) {
        let _ = (action, button, x, y);
    }

    pub fn wheel(&self, dx: i32, dy: i32, x: u32, y: u32) {
        let _ = (dx, dy, x, y);
    }

    pub fn insert_text(&self, text: &str) {
        let _ = text;
    }

    pub fn key_press(&self, key: NativeKey) {
        let _ = key;
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NativeMouseButton {
    Left,
    Middle,
    Right,
    Other,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NativeMouseButtonAction {
    Down,
    Up,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NativeKey {
    Up,
    Down,
    Left,
    Right,
    PageUp,
    PageDown,
    Enter,
    Backspace,
}

pub fn render_once(config: NativeServoConfig) -> Result<NativeServoFrame, String> {
    let _ = config;
    Err("native Servo embedding is repository-only for now".to_string())
}