use crate::{Frame, ffi};
use glib::{
object::ObjectType as _,
prelude::*,
signal::{SignalHandlerId, connect_raw},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
#[doc(alias = "WebKitWebFormManager")]
pub struct WebFormManager(Object<ffi::WebKitWebFormManager, ffi::WebKitWebFormManagerClass>);
match fn {
type_ => || ffi::webkit_web_form_manager_get_type(),
}
}
impl WebFormManager {
pub const NONE: Option<&'static WebFormManager> = None;
#[doc(alias = "webkit_web_form_manager_input_element_auto_fill")]
pub fn input_element_auto_fill(element: &javascriptcore::Value, value: &str) {
assert_initialized_main_thread!();
unsafe {
ffi::webkit_web_form_manager_input_element_auto_fill(
element.to_glib_none().0,
value.to_glib_none().0,
);
}
}
#[doc(alias = "webkit_web_form_manager_input_element_is_auto_filled")]
pub fn input_element_is_auto_filled(element: &javascriptcore::Value) -> bool {
assert_initialized_main_thread!();
unsafe {
from_glib(ffi::webkit_web_form_manager_input_element_is_auto_filled(
element.to_glib_none().0,
))
}
}
#[doc(alias = "webkit_web_form_manager_input_element_is_user_edited")]
pub fn input_element_is_user_edited(element: &javascriptcore::Value) -> bool {
assert_initialized_main_thread!();
unsafe {
from_glib(ffi::webkit_web_form_manager_input_element_is_user_edited(
element.to_glib_none().0,
))
}
}
}
pub trait WebFormManagerExt: IsA<WebFormManager> + 'static {
#[doc(alias = "will-send-submit-event")]
fn connect_will_send_submit_event<
F: Fn(&Self, &javascriptcore::Value, &Frame, &Frame) + 'static,
>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn will_send_submit_event_trampoline<
P: IsA<WebFormManager>,
F: Fn(&P, &javascriptcore::Value, &Frame, &Frame) + 'static,
>(
this: *mut ffi::WebKitWebFormManager,
form: *mut javascriptcore::ffi::JSCValue,
source_frame: *mut ffi::WebKitFrame,
target_frame: *mut ffi::WebKitFrame,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(
WebFormManager::from_glib_borrow(this).unsafe_cast_ref(),
&from_glib_borrow(form),
&from_glib_borrow(source_frame),
&from_glib_borrow(target_frame),
)
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"will-send-submit-event".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
will_send_submit_event_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "will-submit-form")]
fn connect_will_submit_form<F: Fn(&Self, &javascriptcore::Value, &Frame, &Frame) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn will_submit_form_trampoline<
P: IsA<WebFormManager>,
F: Fn(&P, &javascriptcore::Value, &Frame, &Frame) + 'static,
>(
this: *mut ffi::WebKitWebFormManager,
form: *mut javascriptcore::ffi::JSCValue,
source_frame: *mut ffi::WebKitFrame,
target_frame: *mut ffi::WebKitFrame,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(
WebFormManager::from_glib_borrow(this).unsafe_cast_ref(),
&from_glib_borrow(form),
&from_glib_borrow(source_frame),
&from_glib_borrow(target_frame),
)
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"will-submit-form".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
will_submit_form_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<WebFormManager>> WebFormManagerExt for O {}