Update webview implementation to use load_or_register_class (Issue #63)
This commit is contained in:
parent
b187b1dc49
commit
2525cbfee4
|
@ -12,7 +12,7 @@ use objc::declare::ClassDecl;
|
||||||
use objc::runtime::{Class, Object, Sel};
|
use objc::runtime::{Class, Object, Sel};
|
||||||
use objc::{class, msg_send, sel, sel_impl};
|
use objc::{class, msg_send, sel, sel_impl};
|
||||||
|
|
||||||
use crate::foundation::{id, nil, NSArray, NSInteger, NSString, NO, YES};
|
use crate::foundation::{id, nil, NSArray, NSInteger, NSString, NO, YES, load_or_register_class};
|
||||||
use crate::webview::actions::{NavigationAction, NavigationResponse};
|
use crate::webview::actions::{NavigationAction, NavigationResponse};
|
||||||
use crate::webview::{mimetype::MimeType, WebViewDelegate, WEBVIEW_DELEGATE_PTR}; //, OpenPanelParameters};
|
use crate::webview::{mimetype::MimeType, WebViewDelegate, WEBVIEW_DELEGATE_PTR}; //, OpenPanelParameters};
|
||||||
//use crate::webview::enums::{NavigationPolicy, NavigationResponsePolicy};
|
//use crate::webview::enums::{NavigationPolicy, NavigationResponsePolicy};
|
||||||
|
@ -186,13 +186,7 @@ pub fn register_webview_class() -> *const Class {
|
||||||
/// both a subclass of `NSViewController` and a delegate of the held `WKWebView` (for the various
|
/// both a subclass of `NSViewController` and a delegate of the held `WKWebView` (for the various
|
||||||
/// varieties of delegates needed there).
|
/// varieties of delegates needed there).
|
||||||
pub fn register_webview_delegate_class<T: WebViewDelegate>() -> *const Class {
|
pub fn register_webview_delegate_class<T: WebViewDelegate>() -> *const Class {
|
||||||
static mut VIEW_CLASS: *const Class = 0 as *const Class;
|
load_or_register_class("NSObject", "RSTWebViewDelegate", |decl| unsafe {
|
||||||
static INIT: Once = Once::new();
|
|
||||||
|
|
||||||
INIT.call_once(|| unsafe {
|
|
||||||
let superclass = class!(NSObject);
|
|
||||||
let mut decl = ClassDecl::new("RSTWebViewDelegate", superclass).unwrap();
|
|
||||||
|
|
||||||
decl.add_ivar::<usize>(WEBVIEW_DELEGATE_PTR);
|
decl.add_ivar::<usize>(WEBVIEW_DELEGATE_PTR);
|
||||||
|
|
||||||
// WKNavigationDelegate
|
// WKNavigationDelegate
|
||||||
|
@ -239,9 +233,5 @@ pub fn register_webview_delegate_class<T: WebViewDelegate>() -> *const Class {
|
||||||
sel!(_download:decideDestinationWithSuggestedFilename:completionHandler:),
|
sel!(_download:decideDestinationWithSuggestedFilename:completionHandler:),
|
||||||
handle_download::<T> as extern "C" fn(&Object, _, id, id, usize)
|
handle_download::<T> as extern "C" fn(&Object, _, id, id, usize)
|
||||||
);
|
);
|
||||||
|
})
|
||||||
VIEW_CLASS = decl.register();
|
|
||||||
});
|
|
||||||
|
|
||||||
unsafe { VIEW_CLASS }
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue