cacao/appkit/webview/actions.rs

73 lines
2 KiB
Rust
Raw Normal View History

2020-02-28 13:34:34 +11:00
//! Implements wrappers around `WKNavigationAction` and `WKNavigationActionPolicy`.
use objc::{msg_send, sel, sel_impl};
2020-02-28 13:34:34 +11:00
use crate::foundation::{id, BOOL, YES, NO, NSInteger};
2020-02-28 13:34:34 +11:00
use crate::networking::URLRequest;
#[derive(Debug)]
2020-02-28 13:34:34 +11:00
pub struct NavigationAction {
pub navigation_type: NavigationType,
pub request: URLRequest
}
impl NavigationAction {
pub fn new(action: id) -> Self {
NavigationAction {
navigation_type: unsafe {
let nav_type: NSInteger = msg_send![action, navigationType];
nav_type.into()
},
request: URLRequest::with(unsafe {
msg_send![action, request]
})
}
}
}
#[derive(Copy, Clone, Debug, Default)]
2020-02-28 13:34:34 +11:00
pub struct NavigationResponse {
pub can_show_mime_type: bool
}
impl NavigationResponse {
pub fn new(response: id) -> Self {
NavigationResponse {
can_show_mime_type: unsafe {
let can_show: BOOL = msg_send![response, canShowMIMEType];
if can_show == YES { true } else { false }
2020-02-28 13:34:34 +11:00
}
}
}
}
#[derive(Copy, Clone, Debug, Default)]
2020-02-28 13:34:34 +11:00
pub struct OpenPanelParameters {
pub allows_directories: bool,
pub allows_multiple_selection: bool
}
impl From<id> for OpenPanelParameters {
fn from(params: id) -> Self {
OpenPanelParameters {
allows_directories: unsafe {
match msg_send![params, allowsDirectories] {
YES => true,
NO => false,
_ => { panic!("Invalid value from WKOpenPanelParameters:allowsDirectories"); }
}
},
allows_multiple_selection: unsafe {
match msg_send![params, allowsMultipleSelection] {
YES => true,
NO => false,
_ => { panic!("Invalid value from WKOpenPanelParameters:allowsMultipleSelection"); }
}
}
}
}
}