Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions webview-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ fn main() {
}
}
} else if target.contains("apple") {
build
.file("webview_cocoa.c")
.flag("-x")
.flag("objective-c");
build.file("webview_cocoa.c").flag("-x").flag("objective-c");
println!("cargo:rustc-link-lib=framework=Cocoa");
println!("cargo:rustc-link-lib=framework=WebKit");
} else {
Expand Down
40 changes: 20 additions & 20 deletions webview-sys/webview_cocoa.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ WEBVIEW_API void* webview_get_user_data(webview_t w) {
}

WEBVIEW_API webview_t webview_new(
const char* title, const char* url,
const char* title, const char* url,
int width, int height, int resizable, int debug, int frameless, int visible, int min_width, int min_height, int hide_instead_of_close,
webview_external_invoke_cb_t external_invoke_cb, void* userdata) {
struct cocoa_webview* wv = (struct cocoa_webview*)calloc(1, sizeof(*wv));
Expand Down Expand Up @@ -120,7 +120,7 @@ static void webview_window_will_close(id self, SEL cmd, id notification) {
We are going to first create an event with the type
NSApplicationDefined, and zero for all the other properties.
***/
id event = ((id(*)(id, SEL, id, id, id, double, id, id, id, id, id))objc_msgSend)((id)objc_getClass("NSEvent"),
id event = ((id(*)(id, SEL, int, id, id, double, id, id, id, id, id))objc_msgSend)((id)objc_getClass("NSEvent"),
sel_registerName("otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:"),
NSApplicationDefinedEvent,
(id)objc_getClass("NSZeroPoint"),
Expand All @@ -135,7 +135,7 @@ static void webview_window_will_close(id self, SEL cmd, id notification) {
event on the application allowing the `webview_loop` to continue
its current iteration.
***/
((id(*)(id, SEL, id, id))objc_msgSend)(app, sel_registerName("postEvent:atStart:"), event,
((id(*)(id, SEL, id, id))objc_msgSend)(app, sel_registerName("postEvent:atStart:"), event,
((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSDate"),
sel_registerName("distantPast")));
}
Expand Down Expand Up @@ -176,8 +176,8 @@ static void run_open_panel(id self, SEL cmd, id webView, id parameters,
openPanel, sel_registerName("setAllowsMultipleSelection:"),
((id(*)(id, SEL))objc_msgSend)(parameters, sel_registerName("allowsMultipleSelection")));

((id(*)(id, SEL, id))objc_msgSend)(openPanel, sel_registerName("setCanChooseFiles:"), 1);
((id(*)(id, SEL, id))objc_msgSend)(
((id(*)(id, SEL, int))objc_msgSend)(openPanel, sel_registerName("setCanChooseFiles:"), 1);
((id(*)(id, SEL, void (^)(id)))objc_msgSend)(
openPanel, sel_registerName("beginWithCompletionHandler:"), ^(id result) {
if (result == (id)NSModalResponseOK) {
completionHandler(((id(*)(id, SEL))objc_msgSend)(openPanel, sel_registerName("URLs")));
Expand All @@ -192,10 +192,10 @@ static void run_save_panel(id self, SEL cmd, id download, id filename,
id destination)) {
id savePanel = ((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSSavePanel"),
sel_registerName("savePanel"));
((id(*)(id, SEL, id))objc_msgSend)(savePanel, sel_registerName("setCanCreateDirectories:"), 1);
((id(*)(id, SEL, int))objc_msgSend)(savePanel, sel_registerName("setCanCreateDirectories:"), 1);
((id(*)(id, SEL, id))objc_msgSend)(savePanel, sel_registerName("setNameFieldStringValue:"),
filename);
((id(*)(id, SEL, id))objc_msgSend)(savePanel, sel_registerName("beginWithCompletionHandler:"),
((id(*)(id, SEL, void (^)(id)))objc_msgSend)(savePanel, sel_registerName("beginWithCompletionHandler:"),
^(id result) {
if (result == (id)NSModalResponseOK) {
id url = ((id(*)(id, SEL))objc_msgSend)(savePanel, sel_registerName("URL"));
Expand Down Expand Up @@ -311,7 +311,7 @@ WEBVIEW_API int webview_init(webview_t w) {
(IMP)download_failed, "v@:@@");
objc_registerClassPair(__WKDownloadDelegate);
}

id downloadDelegate =
((id(*)(id, SEL))objc_msgSend)((id)__WKDownloadDelegate, sel_registerName("new"));

Expand All @@ -327,7 +327,7 @@ WEBVIEW_API int webview_init(webview_t w) {
}
id wkPref = ((id(*)(id, SEL))objc_msgSend)((id)__WKPreferences, sel_registerName("new"));
((id(*)(id, SEL, id, id))objc_msgSend)(wkPref, sel_registerName("setValue:forKey:"),
((id(*)(id, SEL, id))objc_msgSend)((id)objc_getClass("NSNumber"),
((id(*)(id, SEL, int))objc_msgSend)((id)objc_getClass("NSNumber"),
sel_registerName("numberWithBool:"), !!wv->debug),
((id(*)(id, SEL, const char*))objc_msgSend)((id)objc_getClass("NSString"),
sel_registerName("stringWithUTF8String:"),
Expand Down Expand Up @@ -390,7 +390,7 @@ WEBVIEW_API int webview_init(webview_t w) {
OBJC_ASSOCIATION_ASSIGN);

id nsTitle =
((id(*)(id, SEL, id))objc_msgSend)((id)objc_getClass("NSString"),
((id(*)(id, SEL, const char*))objc_msgSend)((id)objc_getClass("NSString"),
sel_registerName("stringWithUTF8String:"), wv->title);

CGRect r = CGRectMake(0, 0, wv->width, wv->height);
Expand All @@ -407,7 +407,7 @@ WEBVIEW_API int webview_init(webview_t w) {

wv->priv.window =
((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSWindow"), sel_registerName("alloc"));
((id(*)(id, SEL, CGRect, id, id, id))objc_msgSend)(wv->priv.window,
((id(*)(id, SEL, CGRect, int, int, int))objc_msgSend)(wv->priv.window,
sel_registerName("initWithContentRect:styleMask:backing:defer:"),
r, style, NSBackingStoreBuffered, 0);

Expand Down Expand Up @@ -468,16 +468,16 @@ WEBVIEW_API int webview_init(webview_t w) {
((id(*)(id, SEL, id))objc_msgSend)(wv->priv.webview, sel_registerName("loadRequest:"),
((id(*)(id, SEL, id))objc_msgSend)((id)objc_getClass("NSURLRequest"),
sel_registerName("requestWithURL:"), nsURL));
((id(*)(id, SEL, id))objc_msgSend)(wv->priv.webview, sel_registerName("setAutoresizesSubviews:"), 1);
((id(*)(id, SEL, id))objc_msgSend)(wv->priv.webview, sel_registerName("setAutoresizingMask:"),
((id(*)(id, SEL, int))objc_msgSend)(wv->priv.webview, sel_registerName("setAutoresizesSubviews:"), 1);
((id(*)(id, SEL, int))objc_msgSend)(wv->priv.webview, sel_registerName("setAutoresizingMask:"),
(NSViewWidthSizable | NSViewHeightSizable));
((id(*)(id, SEL, id))objc_msgSend)(((id(*)(id, SEL))objc_msgSend)(wv->priv.window, sel_registerName("contentView")),
sel_registerName("addSubview:"), wv->priv.webview);

if (wv->visible) {
((id(*)(id, SEL))objc_msgSend)(wv->priv.window, sel_registerName("orderFrontRegardless"));
}

((id(*)(id, SEL, CGSize))objc_msgSend)(wv->priv.window, sel_registerName("setMinSize:"), CGSizeMake(wv->min_width, wv->min_height));

((id(*)(id, SEL, id))objc_msgSend)(((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSApplication"),
Expand All @@ -489,7 +489,7 @@ WEBVIEW_API int webview_init(webview_t w) {
sel_registerName("sharedApplication")),
sel_registerName("finishLaunching"));

((id(*)(id, SEL, id))objc_msgSend)(((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSApplication"),
((id(*)(id, SEL, int))objc_msgSend)(((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSApplication"),
sel_registerName("sharedApplication")),
sel_registerName("activateIgnoringOtherApps:"), 1);

Expand Down Expand Up @@ -524,7 +524,7 @@ WEBVIEW_API int webview_init(webview_t w) {

item = create_menu_item(get_nsstring("Hide Others"),
"hideOtherApplications:", "h");
((id(*)(id, SEL, id))objc_msgSend)(item, sel_registerName("setKeyEquivalentModifierMask:"),
((id(*)(id, SEL, int))objc_msgSend)(item, sel_registerName("setKeyEquivalentModifierMask:"),
(NSEventModifierFlagOption | NSEventModifierFlagCommand));
((id(*)(id, SEL, id))objc_msgSend)(appMenu, sel_registerName("addItem:"), item);

Expand Down Expand Up @@ -557,7 +557,7 @@ WEBVIEW_API int webview_loop(webview_t w, int blocking) {
sel_registerName("distantPast")));
id app = ((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSApplication"),
sel_registerName("sharedApplication"));
id event = ((id(*)(id, SEL, id, id, id, id))objc_msgSend)(
id event = ((id(*)(id, SEL, long, id, id, bool))objc_msgSend)(
app,
sel_registerName("nextEventMatchingMask:untilDate:inMode:dequeue:"),
ULONG_MAX, until,
Expand Down Expand Up @@ -623,7 +623,7 @@ WEBVIEW_API void webview_set_minimized(webview_t w, int minimize) {
} else {
((id(*)(id, SEL, id))objc_msgSend)(wv->priv.window, sel_registerName("deminiaturize:"), NULL);
}

}

WEBVIEW_API void webview_set_visible(webview_t w, int visible) {
Expand Down Expand Up @@ -658,8 +658,8 @@ WEBVIEW_API void webview_set_color(webview_t w, uint8_t r, uint8_t g,
sel_registerName("appearanceNamed:"),
get_nsstring("NSAppearanceNameVibrantLight")));
}
((id(*)(id, SEL, id))objc_msgSend)(wv->priv.window, sel_registerName("setOpaque:"), 0);
((id(*)(id, SEL, id))objc_msgSend)(wv->priv.window,
((id(*)(id, SEL, int))objc_msgSend)(wv->priv.window, sel_registerName("setOpaque:"), 0);
((id(*)(id, SEL, int))objc_msgSend)(wv->priv.window,
sel_registerName("setTitlebarAppearsTransparent:"), 1);
}

Expand Down