2020-02-28 13:34:34 +11:00
|
|
|
//! Implements wrappers around `WKNavigationAction` and `WKNavigationActionPolicy`.
|
|
|
|
|
2020-03-01 10:34:07 +11:00
|
|
|
use objc::{msg_send, sel, sel_impl};
|
2020-02-28 13:34:34 +11:00
|
|
|
|
2020-03-20 14:07:44 +11:00
|
|
|
use crate::foundation::{id, BOOL, YES, NO, NSInteger};
|
2020-02-28 13:34:34 +11:00
|
|
|
use crate::networking::URLRequest;
|
|
|
|
|
2020-03-20 14:07:44 +11:00
|
|
|
#[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]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-20 14:07:44 +11:00
|
|
|
#[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 {
|
2020-03-01 10:34:07 +11:00
|
|
|
let can_show: BOOL = msg_send![response, canShowMIMEType];
|
|
|
|
if can_show == YES { true } else { false }
|
2020-02-28 13:34:34 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-20 14:07:44 +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"); }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|