Merge pull request #69 from maxjvh/trunk

implement acceptsFirstMouse on webview
This commit is contained in:
Ryan McGrath 2023-06-08 14:50:48 -07:00 committed by GitHub
commit eecdb13f5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,7 +9,7 @@ use std::sync::Once;
use block::Block;
use objc::declare::ClassDecl;
use objc::runtime::{Class, Object, Sel};
use objc::runtime::{Class, Object, Sel, BOOL};
use objc::{class, msg_send, sel, sel_impl};
use crate::foundation::{id, load_or_register_class, nil, NSArray, NSInteger, NSString, NO, YES};
@ -166,11 +166,21 @@ extern "C" fn handle_download<T: WebViewDelegate>(this: &Object, _: Sel, downloa
});
}
/// Whether the view should be sent a mouseDown event for the first click when not focused.
extern "C" fn accepts_first_mouse(_: &mut Object, _: Sel, _: id) -> BOOL {
YES
}
/// Registers an `NSViewController` that we effectively turn into a `WebViewController`. Acts as
/// both a subclass of `NSViewController` and a delegate of the held `WKWebView` (for the various
/// varieties of delegates needed there).
pub fn register_webview_class() -> *const Class {
load_or_register_class("WKWebView", "CacaoWebView", |decl| unsafe {})
load_or_register_class("WKWebView", "CacaoWebView", |decl| unsafe {
decl.add_method(
sel!(acceptsFirstMouse:),
accepts_first_mouse as extern "C" fn(&mut Object, Sel, id) -> BOOL
);
})
}
/// Registers an `NSViewController` that we effectively turn into a `WebViewController`. Acts as