// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from webkit-gir-files
// DO NOT EDIT

use crate::{ffi, NavigationAction, PolicyDecision};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    #[doc(alias = "WebKitNavigationPolicyDecision")]
    pub struct NavigationPolicyDecision(Object<ffi::WebKitNavigationPolicyDecision, ffi::WebKitNavigationPolicyDecisionClass>) @extends PolicyDecision;

    match fn {
        type_ => || ffi::webkit_navigation_policy_decision_get_type(),
    }
}

impl NavigationPolicyDecision {
    #[doc(alias = "webkit_navigation_policy_decision_get_navigation_action")]
    #[doc(alias = "get_navigation_action")]
    #[doc(alias = "navigation-action")]
    pub fn navigation_action(&self) -> Option<NavigationAction> {
        unsafe {
            from_glib_none(
                ffi::webkit_navigation_policy_decision_get_navigation_action(self.to_glib_none().0),
            )
        }
    }

    #[doc(alias = "navigation-action")]
    pub fn connect_navigation_action_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_navigation_action_trampoline<
            F: Fn(&NavigationPolicyDecision) + 'static,
        >(
            this: *mut ffi::WebKitNavigationPolicyDecision,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::navigation-action\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_navigation_action_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}
