Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OSX NPAPI & NSView

57 views
Skip to first unread message

vinthewrench

unread,
Oct 4, 2008, 2:12:15 AM10/4/08
to
hello;

I am in the process of developing a OSX NPAPI compatible plugin that
will run under both Mozilla
and Webkit and have had quite a bit of success, at least with the
scripting interface. But I
am slightly stuck in the drawing API calls.

My plugin wants to use just CoreGraphics and successfully negotiates
NPNVpluginDrawingModel
into NPDrawingModelCoreGraphics at NPP_New(). But when I am uncertain
about how to handle the
NPP_SetWindow() call properly for both platforms.

From what I have been able to glean from Googlng around, I have put
together some code.
Lets assume that my code creates an NSView and attaches it at the
first NPP_SetWindow(), I
figure that the code that creates my view should look something
like: (greatly simplified)

NPP_SetWindow(NPP instance, NPWindow* npWindow)
{

if( myView not yet attached ..)
{
NP_CGContext* npContext = (NP_CGContext*) npWindow->window;
NSWindow* browserWindow = [[[NSWindow alloc]
initWithWindowRef:npContext->window] autorelease];

// convert to cg coordinates
int y = [browserWindow frame].size.height - npWindow->height -
npWindow->y;
NSView* browserView = [[browserWindow contentView]
hitTest:NSMakePoint(npWindow->x+1 , y+ 1)];

NSView* myView = [[MyViewClass alloc] init];

[myView setFrame: [browserView bounds]];
[browserView addSubview: myView];

}
}

now this works surprising well under Firefox since it seems that it
Mozilla has a NSView
setup for my plugin that the hitTest finds. The major problem is that
if I mouse over
my view Firefox crashes.. I am not sure why, maybe this is a Mozilla
bug?

That said, if I apply the above code under Safari I don't get drawn
because the hitTest finds
a view that looks more like the [browserWindow contentView] minus the
scroll bars and toolbar.
So maybe I need to use the npWindow->clipRect data to calculate the
proper place to hand to setFrame for my NSView.. but not sure.

So my question is what is the proper way to setup the view that works
on both Mozilla
and Webkit or am I way off?

is there a snippet of sample code around that work?

vinthewrench

unread,
Oct 4, 2008, 11:02:03 AM10/4/08
to
sorry if this is a repost.
0 new messages