OSX Cocoa embed opengl view inside webview - macos

I am trying to build an MacOS app which create an OpenGL view and embed it to webview as it's element (using OpenGL instead of WebGL). The main goal is to use the web (html/javascript) as UI and draw the result with OpenGL view. (besides, the OpenGL view will also handle the user input)
The issue is the overlay between the webview and OpenGL view. If OpenGL view on top of webview, the webview UI (like: dropdown box) possible cut by the OpenGL view. The webview on top of OpenGL view, all of the webview view will block the OpenGL view.
Is there any solution to solve this? (OpenGL and Webview)

WebKit has an interesting functionality where you can associate webviews with certain MIME types to your own custom NSView classes.
In your HTML webview, you can put an iframe which has a custom mimetype (e.g. "application/my-custom-view").
After that, from your native app, you can call:
[WebView registerViewClass:[MyCustomView class] representationClass:[MyCustomRepresentation class] forMIMEType:#"application/my-custom-view"];
See https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Webkit/Classes/WebView_Class/Reference/Reference.html#//apple_ref/occ/clm/WebView/registerViewClass:representationClass:forMIMEType:
MyCustomRepresentation can be pretty lightweight, my Representation class doesn't do anything, it just defines stub delegate functions.

Related

Xamarin iOS Storyboard having rendering error NullReferenceException

When opening storyboard recently, the ViewController in the Storyboard will have problem rendering. It is showing NullReferenceException.
What can be the problem?
Found out that we need to disable the rendering of screen in UI Designer (Recent version of Xamarin will add the screen into Custom Components too).
To turn off the rendering, we need to set the DesignTimeVisible flag to false.
[System.ComponentModel.DesignTimeVisible(false)]
public partial class ViewController : UIViewController
I have also written more details in my blog HERE.

CoreAnimation layer causes WebView to not redraw properly

In a project I have been working on I wanted to use CoreAnimation layers to improve tableview rendering, however when i turned on Core Animation for certain layers it caused issues with my WebView.
https://github.com/jozefdransfield/TestWebView demonstrates a WebView inside a view displaying a large image. Which reproduces the issue I am seeing.
If View has Core Animation Layer checked then the WebView does not draw the image properly if you scroll within the webView, with it uncheck the webView behaves as expected.
Has anyone seen this issue before and have an idea how to fix/work around it. Or can you simply not mix webviews with CALayers?

How to render HTML from an NPAPI plugin in Safari

I've been writing a Mac NPAPI-based browser plugin to convert a file of custom mimetype (say, "application/x-foo") into an HTML representation, which can then be viewed directly in a browser. These files are usually directly served, so I'm more concerned about supporting full-page viewing, rather than embedded views via <object> tags.
On Firefox, this has been relatively simple: I make a call to NPN_NewStream with the text/html mimetype, write the converted HTML into the stream, and then clean it up with NPN_DestroySteam. The browser automatically handles the request for a new HTML stream and renders the given HTML into a tab or window. Pretty standard.
For Safari, though, NPN_NewStream does not appear to be implemented (and I did check the WebKit source code). Previously, I was able to use the WebKitPlugin API. With Safari 5.1, this API is gone.
I thought I would be able to create a WebView in a drawing event handler, like this:
NSRect rect = NSMakeRect(0, 0, obj->window.width, obj->window.height);
//...
WebView* webView = [[WebView alloc] initWithFrame:rect frameName:nil groupName:nil];
[[webView mainFrame] loadHTMLString:#"<html><head><title>This is a message from my plug-in!</title></head><body><p><strong>This is a message from my plug-in!</strong></p></body>/html>" baseURL:[NSURL URLWithString:#"http://example.com"]];
[webView drawRect:rect];
and see it in browser. But all that does is render a gray screen with no content, as if not drawn. If I replace the WebView with an NSTextView and set its string to the HTML, everything draws just fine, but of course the HTML is not rendered by an NSTextView.
My question boils down to: is there a good way to render some HTML into a Safari window from an NPAPI plugin? Or if that won't work, into a Google Chrome window? Or some other approach that lets me handle a custom MIME type and display some HTML representation of it?
Honestly, I'm surprised that your newstream approach works on Firefox; that's a new one I've never heard of. If you have to do the drawing yourself, you are limited to either using CoreGraphics with a CGContext or CoreAnimation with a CALayer. In other words, you don't get a NSView, so you can't directly render a WebView into it.
That said, you could put the webview in an offscreen context and render it to your CGContext, then proxy the events; this seems a little complicated for what you're trying to do, but I don't know of another way to do it.
There is an experimental library in FireBreath that does this; scroll wheel isn't implemented, but the other events work, including mouse drag and keyboard. There are still a few strange things with it when using form events, so whether or not this would work for you depends on what content you'll be displaying.
If you're interested in trying to use FireBreath for this you can drop into the FireBreath chat room during business hours (GMT-0600) and I'm usually around and can discuss it with out.

Designing views/windows in Mac OSX first time

I am about to tackle my first Mac OSX project after developing for iOS.
In my iOS applications, it is clear to me the whole NavigationViewController->MyViewController->MyViews paradigm.
A bit more background on the iOS app so it would be easier to understand me:
The application is some sort of graphic viewer. Once you login you have a list of drawings, and if you select one, it opens it up.
Now in the iOS app I have a custom UIViewController that have some menu UI and a UIScrollView that holds a UIView in which I draw the drawing.
The custom UIViewController is responsible for acting as the "application" where the UIView inside is merely a graphic context.
Now - back to Mac:
I was thinking that my main window would show the drawings and once one is selected,
I would add another window with an NSView that is the graphic context of the drawing,
and the window will be acting as the UIViewController in the iOS app.
Does that make sense?
You can have NSViewController or NSWindowController on the Mac, to put your controller logic in. If you're going for separate windows, subclassing NSWindowController would make sense.

Using Webkit to create Skinable custom windows on OSX

There are tutorials for using a webkit view inside a cocoa application to achieve skinnable contents, but what would I do if I wanted to use webkit to create custom, skinnable windows?
Examples would be dashboard widgets, or
BowTie
Beware, I'm a noob.
I've never tried it, but I think you'd just set a WebView as the content view of a transparent borderless window, and tell the WebView not to draw a background. That way, the content of the WebView would define the window boundary.
You create a borderless window by passing NSBorderlessWindowMask to the -initWithContentRect:styleMask:backing:defer: method of NSWindow, and you can set its background to transparent by calling [window setBackgroundColor:[NSColor clearColor]].
You'd have to handle dragging of the window etc yourself. It will probably get a bit messy.
To be honest, it's not something I'd attempt as a first Cocoa project.

Resources