Esempio n. 1
0
        private static NativeClassDefinition CreateSchemeHandler()
        {
            // note: WKURLSchemeHandler is not available at runtime and returns null, it's kept for completeness
            var definition = NativeClassDefinition.FromObject(
                "SpiderEyeSchemeHandler",
                WebKit.GetProtocol("WKURLSchemeHandler"));

            definition.AddMethod <SchemeHandlerDelegate>(
                "webView:startURLSchemeTask:",
                "v@:@@",
                (self, op, view, schemeTask) =>
            {
                var instance = definition.GetParent <CocoaWebview>(self);
                UriSchemeStartCallback(instance, schemeTask);
            });

            definition.AddMethod <SchemeHandlerDelegate>(
                "webView:stopURLSchemeTask:",
                "v@:@@",
                (self, op, view, schemeTask) => { /* don't think anything needs to be done here */ });

            definition.FinishDeclaration();

            return(definition);
        }
Esempio n. 2
0
        private static NativeClassDefinition CreateWindowDelegate()
        {
            var definition = NativeClassDefinition.FromObject(
                "SpiderEyeWindowDelegate",
                AppKit.GetProtocol("NSWindowDelegate"));

            definition.AddMethod <WindowShouldCloseDelegate>(
                "windowShouldClose:",
                "c@:@",
                (self, op, window) =>
            {
                var instance = definition.GetParent <CocoaWindow>(self);
                var args     = new CancelableEventArgs();
                instance.Closing?.Invoke(instance, args);

                return(args.Cancel ? (byte)0 : (byte)1);
            });

            definition.AddMethod <NotificationDelegate>(
                "windowWillClose:",
                "v@:@",
                (self, op, notification) =>
            {
                var instance = definition.GetParent <CocoaWindow>(self);
                instance.webview.TitleChanged -= instance.Webview_TitleChanged;
                instance.Closed?.Invoke(instance, EventArgs.Empty);
            });

            definition.FinishDeclaration();

            return(definition);
        }
Esempio n. 3
0
        private static NativeClassDefinition CreateAppDelegate()
        {
            var definition = NativeClassDefinition.FromClass(
                "SpiderEyeAppDelegate",
                AppKit.GetClass("NSResponder"),
                // note: NSApplicationDelegate is not available at runtime and returns null
                AppKit.GetProtocol("NSApplicationDelegate"),
                AppKit.GetProtocol("NSTouchBarProvider"));

            definition.AddMethod <ShouldTerminateDelegate>(
                "applicationShouldTerminateAfterLastWindowClosed:",
                "c@:@",
                (self, op, notification) => (byte)(Application.ExitWithLastWindow ? 1 : 0));

            definition.AddMethod <NotificationDelegate>(
                "applicationDidFinishLaunching:",
                "v@:@",
                (self, op, notification) =>
            {
                var instance = definition.GetParent <CocoaApplication>(self);
                ObjC.Call(instance.Handle, "activateIgnoringOtherApps:", true);
            });

            definition.FinishDeclaration();

            return(definition);
        }
Esempio n. 4
0
        private static NativeClassDefinition CreateCallbackClass()
        {
            var definition = NativeClassDefinition.FromObject(
                "SpiderEyeWebviewCallbacks",
                WebKit.GetProtocol("WKNavigationDelegate"),
                // note: WKScriptMessageHandler is not available at runtime and returns null
                WebKit.GetProtocol("WKScriptMessageHandler"));

            definition.AddMethod <NavigationDecideDelegate>(
                "webView:decidePolicyForNavigationAction:decisionHandler:",
                "v@:@@@",
                (self, op, view, navigationAction, decisionHandler) =>
            {
                var instance = definition.GetParent <CocoaWebview>(self);
                if (instance == null)
                {
                    return;
                }

                var args = new NavigatingEventArgs(instance.Uri);
                instance.Navigating?.Invoke(instance, args);

                var block    = Marshal.PtrToStructure <NSBlock.BlockLiteral>(decisionHandler);
                var callback = Marshal.GetDelegateForFunctionPointer <NavigationDecisionDelegate>(block.Invoke);
                callback(decisionHandler, args.Cancel ? IntPtr.Zero : new IntPtr(1));
            });

            definition.AddMethod <ObserveValueDelegate>(
                "observeValueForKeyPath:ofObject:change:context:",
                "v@:@@@@",
                (self, op, keyPath, obj, change, context) =>
            {
                var instance = definition.GetParent <CocoaWebview>(self);
                if (instance != null)
                {
                    ObservedValueChanged(instance, keyPath);
                }
            });

            definition.AddMethod <ScriptCallbackDelegate>(
                "userContentController:didReceiveScriptMessage:",
                "v@:@@",
                (self, op, notification, message) =>
            {
                var instance = definition.GetParent <CocoaWebview>(self);
                if (instance != null)
                {
                    ScriptCallback(instance, message);
                }
            });

            definition.FinishDeclaration();

            return(definition);
        }
Esempio n. 5
0
        private static NativeClassDefinition CreateCallbackClass()
        {
            var definition = NativeClassDefinition.FromObject("SpiderEyeMenuCallback");

            definition.AddMethod <MenuCallbackDelegate>(
                "menuCallback:",
                "v@:@",
                (self, op, menu) =>
            {
                var instance = definition.GetParent <CocoaLabelMenuItem>(self);
                instance.Click?.Invoke(instance, EventArgs.Empty);
            });

            definition.FinishDeclaration();

            return(definition);
        }
Esempio n. 6
0
 static CocoaLabelMenuItem()
 {
     CallbackClassDefinition = CreateCallbackClass();
 }
Esempio n. 7
0
 static CocoaWindow()
 {
     WindowDelegateDefinition = CreateWindowDelegate();
 }
Esempio n. 8
0
 static CocoaWebview()
 {
     CallbackClassDefinition = CreateCallbackClass();
     SchemeHandlerDefinition = CreateSchemeHandler();
 }
Esempio n. 9
0
 static CocoaApplication()
 {
     AppDelegateDefinition = CreateAppDelegate();
 }