add acceptsFirstMouse to webview

This commit is contained in:
max 2022-11-05 13:39:06 +02:00
parent 68da052a8f
commit e5e428cdbc

View file

@ -9,7 +9,7 @@ use std::sync::Once;
use block::Block; use block::Block;
use objc::declare::ClassDecl; 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 objc::{class, msg_send, sel, sel_impl};
use crate::foundation::{id, load_or_register_class, nil, NSArray, NSInteger, NSString, NO, YES}; 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 /// 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 /// 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_class() -> *const Class { 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 /// Registers an `NSViewController` that we effectively turn into a `WebViewController`. Acts as